Clean up OffTheRecordProfileImplTest unit test

The previous version of this test could create up to 4 TestingProfiles:
1. TestingProfile from BrowserWithTestWindowTest::CreateProfile
2. TestingProfileWithHostZoomMap in the test body
3. An incognito version created by (2) via GetOffTheRecordProfile().
4. An incognito version created in the test body

Also the master/incognito relationships between these profiles are unclear.

Reduce this to the 2 needed instances:
1. TestingProfileWithHostZoomMap owned by BrowserWithTestWindowTest
2. An incognito version in the test body

BUG=395329
TEST=unit_tests OffTheRecordProfileImplTest.*

Review URL: https://codereview.chromium.org/403103003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284590 0039d316-1c4b-4281-b951-d872f2087c98
parent fa246fbb
......@@ -17,7 +17,6 @@
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/common/page_zoom.h"
#include "net/dns/mock_host_resolver.h"
......@@ -37,12 +36,7 @@ class TestingProfileWithHostZoomMap : public TestingProfile {
virtual ~TestingProfileWithHostZoomMap() {}
virtual Profile* GetOffTheRecordProfile() OVERRIDE {
if (!off_the_record_profile_)
off_the_record_profile_.reset(CreateOffTheRecordProfile());
return off_the_record_profile_.get();
}
// Profile overrides:
virtual PrefService* GetOffTheRecordPrefs() OVERRIDE {
return GetPrefs();
}
......@@ -66,7 +60,6 @@ class TestingProfileWithHostZoomMap : public TestingProfile {
}
}
scoped_ptr<Profile> off_the_record_profile_;
scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
scoped_ptr<HostZoomMap::Subscription> zoom_subscription_;
......@@ -85,6 +78,7 @@ class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
virtual ~OffTheRecordProfileImplTest() {}
// testing::Test overrides:
virtual void SetUp() OVERRIDE {
profile_manager_.reset(new TestingProfileManager(browser_process()));
ASSERT_TRUE(profile_manager_->SetUp());
......@@ -97,7 +91,6 @@ class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
}
virtual void TearDown() OVERRIDE {
DestroyBrowserAndProfile();
BrowserWithTestWindowTest::TearDown();
testing_io_thread_state_.reset();
......@@ -105,6 +98,11 @@ class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
profile_manager_.reset();
}
// BrowserWithTestWindowTest overrides:
virtual TestingProfile* CreateProfile() OVERRIDE {
return new TestingProfileWithHostZoomMap;
}
private:
TestingBrowserProcess* browser_process() {
return TestingBrowserProcess::GetGlobal();
......@@ -123,20 +121,20 @@ class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
// 4. Change of zoom level propagate from parent to child.
TEST_F(OffTheRecordProfileImplTest, GetHostZoomMap) {
// Constants for test case.
std::string const host("example.com");
double const zoom_level_25 = 2.5;
double const zoom_level_30 = 3.0;
double const zoom_level_40 = 4.0;
// Prepare parent profile.
scoped_ptr<Profile> parent_profile(new TestingProfileWithHostZoomMap);
ASSERT_TRUE(parent_profile.get());
const std::string host("example.com");
const double zoom_level_25 = 2.5;
const double zoom_level_30 = 3.0;
const double zoom_level_40 = 4.0;
// The TestingProfile from CreateProfile above is the parent.
TestingProfile* parent_profile = GetProfile();
ASSERT_TRUE(parent_profile);
ASSERT_TRUE(parent_profile->GetPrefs());
ASSERT_TRUE(parent_profile->GetOffTheRecordPrefs());
// Prepare parent host zoom map.
HostZoomMap* parent_zoom_map =
HostZoomMap::GetForBrowserContext(parent_profile.get());
HostZoomMap::GetForBrowserContext(parent_profile);
ASSERT_TRUE(parent_zoom_map);
parent_zoom_map->SetZoomLevelForHost(host, zoom_level_25);
......@@ -146,21 +144,21 @@ TEST_F(OffTheRecordProfileImplTest, GetHostZoomMap) {
// TODO(yosin) We need to wait ProfileImpl::Observe done for
// OnZoomLevelChanged.
// Prepare child profile as off the record profile.
scoped_ptr<OffTheRecordProfileImpl> child_profile(
new OffTheRecordProfileImpl(parent_profile.get()));
// Prepare an off the record profile owned by the parent profile.
parent_profile->SetOffTheRecordProfile(
scoped_ptr<Profile>(new OffTheRecordProfileImpl(parent_profile)));
OffTheRecordProfileImpl* child_profile =
static_cast<OffTheRecordProfileImpl*>(
parent_profile->GetOffTheRecordProfile());
child_profile->InitIoData();
child_profile->InitHostZoomMap();
BrowserContextDependencyManager::GetInstance()->
CreateBrowserContextServicesForTest(child_profile.get());
// Prepare child host zoom map.
HostZoomMap* child_zoom_map =
HostZoomMap::GetForBrowserContext(child_profile.get());
HostZoomMap::GetForBrowserContext(child_profile);
ASSERT_TRUE(child_zoom_map);
// Verity.
// Verify.
EXPECT_NE(parent_zoom_map, child_zoom_map);
EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment