Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: chrome/browser/profiles/off_the_record_profile_impl_unittest.cc

Issue 393133002: Migrate HostZoomMap to live in StoragePartition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to r288093. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/off_the_record_profile_impl.h" 5 #include "chrome/browser/profiles/off_the_record_profile_impl.h"
6 6
7 #include "base/prefs/pref_registry_simple.h" 7 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/prefs/scoped_user_pref_update.h" 9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "chrome/browser/prefs/browser_prefs.h" 11 #include "chrome/browser/prefs/browser_prefs.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/browser_with_test_window_test.h" 13 #include "chrome/test/base/browser_with_test_window_test.h"
14 #include "chrome/test/base/testing_browser_process.h" 14 #include "chrome/test/base/testing_browser_process.h"
15 #include "chrome/test/base/testing_io_thread_state.h" 15 #include "chrome/test/base/testing_io_thread_state.h"
16 #include "chrome/test/base/testing_pref_service_syncable.h" 16 #include "chrome/test/base/testing_pref_service_syncable.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/base/testing_profile_manager.h" 18 #include "chrome/test/base/testing_profile_manager.h"
19 #include "content/public/browser/host_zoom_map.h" 19 #include "content/public/browser/host_zoom_map.h"
20 #include "content/public/common/page_zoom.h" 20 #include "content/public/common/page_zoom.h"
21 #include "content/public/test/mock_resource_context.h"
21 #include "net/dns/mock_host_resolver.h" 22 #include "net/dns/mock_host_resolver.h"
22 23
23 using content::HostZoomMap; 24 using content::HostZoomMap;
24 25
25 namespace { 26 namespace {
26 27
27 class TestingProfileWithHostZoomMap : public TestingProfile { 28 class TestingProfileWithHostZoomMap : public TestingProfile {
28 public: 29 public:
29 TestingProfileWithHostZoomMap() { 30 TestingProfileWithHostZoomMap() {
30 zoom_subscription_ = 31 zoom_subscription_ =
(...skipping 26 matching lines...) Expand all
57 host_zoom_dictionary->SetWithoutPathExpansion( 58 host_zoom_dictionary->SetWithoutPathExpansion(
58 change.host, new base::FundamentalValue(level)); 59 change.host, new base::FundamentalValue(level));
59 } 60 }
60 } 61 }
61 62
62 scoped_ptr<HostZoomMap::Subscription> zoom_subscription_; 63 scoped_ptr<HostZoomMap::Subscription> zoom_subscription_;
63 64
64 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); 65 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap);
65 }; 66 };
66 67
68 base::Closure ThreadSafeQuit(base::RunLoop* run_loop) {
69 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) {
70 return run_loop->QuitClosure();
71 } else {
72 using base::Bind;
73 using base::IgnoreResult;
74 return Bind(IgnoreResult(&base::MessageLoopProxy::PostTask),
75 base::MessageLoopProxy::current(),
76 FROM_HERE,
77 run_loop->QuitClosure());
78 }
79 }
80
67 } // namespace 81 } // namespace
68 82
69 // We need to have a BrowserProcess in g_browser_process variable, since 83 // We need to have a BrowserProcess in g_browser_process variable, since
70 // OffTheRecordProfileImpl ctor uses it in 84 // OffTheRecordProfileImpl ctor uses it in
71 // ProfileIOData::InitializeProfileParams. 85 // ProfileIOData::InitializeProfileParams.
72 class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest { 86 class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
73 protected: 87 protected:
74 OffTheRecordProfileImplTest() {} 88 OffTheRecordProfileImplTest() {}
75 89
76 virtual ~OffTheRecordProfileImplTest() {} 90 virtual ~OffTheRecordProfileImplTest() {}
77 91
78 // testing::Test overrides: 92 // testing::Test overrides:
79 virtual void SetUp() OVERRIDE { 93 virtual void SetUp() OVERRIDE {
80 profile_manager_.reset(new TestingProfileManager(browser_process())); 94 profile_manager_.reset(new TestingProfileManager(browser_process()));
81 ASSERT_TRUE(profile_manager_->SetUp()); 95 ASSERT_TRUE(profile_manager_->SetUp());
82 96
83 testing_io_thread_state_.reset(new chrome::TestingIOThreadState()); 97 testing_io_thread_state_.reset(new chrome::TestingIOThreadState());
98 base::RunLoop run_loop;
awong 2014/08/11 22:36:33 Is it possible to use something like: https://co
wjmaclean 2014/08/12 16:57:44 Actually, don't even need that. This is cruft from
99 CHECK(content::BrowserThread::PostTask(
100 content::BrowserThread::IO,
101 FROM_HERE,
102 base::Bind(&OffTheRecordProfileImplTest::InitResolver,
103 base::Unretained(this),
104 ThreadSafeQuit(&run_loop))));
105 run_loop.Run();
106
107 BrowserWithTestWindowTest::SetUp();
108 }
109
110 void InitResolver(const base::Closure& done) {
84 testing_io_thread_state_->io_thread_state()->globals()->host_resolver.reset( 111 testing_io_thread_state_->io_thread_state()->globals()->host_resolver.reset(
85 new net::MockHostResolver()); 112 new net::MockHostResolver());
86 113 done.Run();
87 BrowserWithTestWindowTest::SetUp();
88 } 114 }
89 115
90 virtual void TearDown() OVERRIDE { 116 virtual void TearDown() OVERRIDE {
91 BrowserWithTestWindowTest::TearDown(); 117 BrowserWithTestWindowTest::TearDown();
92 118
93 testing_io_thread_state_.reset(); 119 testing_io_thread_state_.reset();
94 120
95 profile_manager_.reset(); 121 profile_manager_.reset();
96 } 122 }
97 123
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 ASSERT_TRUE(parent_zoom_map); 161 ASSERT_TRUE(parent_zoom_map);
136 162
137 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_25); 163 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_25);
138 ASSERT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), 164 ASSERT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host),
139 zoom_level_25); 165 zoom_level_25);
140 166
141 // TODO(yosin) We need to wait ProfileImpl::Observe done for 167 // TODO(yosin) We need to wait ProfileImpl::Observe done for
142 // OnZoomLevelChanged. 168 // OnZoomLevelChanged.
143 169
144 // Prepare an off the record profile owned by the parent profile. 170 // Prepare an off the record profile owned by the parent profile.
145 parent_profile->SetOffTheRecordProfile(
146 scoped_ptr<Profile>(new OffTheRecordProfileImpl(parent_profile)));
147 OffTheRecordProfileImpl* child_profile = 171 OffTheRecordProfileImpl* child_profile =
148 static_cast<OffTheRecordProfileImpl*>( 172 static_cast<OffTheRecordProfileImpl*>(
149 parent_profile->GetOffTheRecordProfile()); 173 parent_profile->GetOffTheRecordProfile());
150 child_profile->InitIoData();
151 child_profile->InitHostZoomMap();
152 174
153 // Prepare child host zoom map. 175 // Prepare child host zoom map.
154 HostZoomMap* child_zoom_map = 176 HostZoomMap* child_zoom_map =
155 HostZoomMap::GetForBrowserContext(child_profile); 177 HostZoomMap::GetForBrowserContext(child_profile);
156 ASSERT_TRUE(child_zoom_map); 178 ASSERT_TRUE(child_zoom_map);
157 179
158 // Verify. 180 // Verify.
159 EXPECT_NE(parent_zoom_map, child_zoom_map); 181 EXPECT_NE(parent_zoom_map, child_zoom_map);
160 182
161 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), 183 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host),
(...skipping 12 matching lines...) Expand all
174 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); 196 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40);
175 ASSERT_EQ( 197 ASSERT_EQ(
176 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), 198 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host),
177 zoom_level_40); 199 zoom_level_40);
178 200
179 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), 201 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host),
180 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << 202 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) <<
181 "Parent change should propagate to child."; 203 "Parent change should propagate to child.";
182 base::RunLoop().RunUntilIdle(); 204 base::RunLoop().RunUntilIdle();
183 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698