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

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

Issue 12039058: content: convert zoom notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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 "chrome/browser/net/ssl_config_service_manager.h" 7 #include "chrome/browser/net/ssl_config_service_manager.h"
8 #include "chrome/browser/prefs/browser_prefs.h" 8 #include "chrome/browser/prefs/browser_prefs.h"
9 #include "chrome/browser/prefs/pref_registry_simple.h" 9 #include "chrome/browser/prefs/pref_registry_simple.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/prefs/scoped_user_pref_update.h" 11 #include "chrome/browser/prefs/scoped_user_pref_update.h"
12 #include "chrome/browser/profiles/profile_dependency_manager.h" 12 #include "chrome/browser/profiles/profile_dependency_manager.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/browser_with_test_window_test.h" 14 #include "chrome/test/base/browser_with_test_window_test.h"
15 #include "chrome/test/base/testing_browser_process.h" 15 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_pref_service.h" 16 #include "chrome/test/base/testing_pref_service.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/browser/host_zoom_map.h" 18 #include "content/public/browser/host_zoom_map.h"
19 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/notification_types.h"
22 19
23 using content::HostZoomMap; 20 using content::HostZoomMap;
24 21
25 namespace { 22 namespace {
26 23
27 class TestingProfileWithHostZoomMap : public TestingProfile, 24 class TestingProfileWithHostZoomMap : public TestingProfile {
28 public content::NotificationObserver {
29 public: 25 public:
30 TestingProfileWithHostZoomMap() { 26 TestingProfileWithHostZoomMap()
31 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); 27 : zoom_callback_(
32 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 28 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged,
33 content::Source<HostZoomMap>(host_zoom_map)); 29 base::Unretained(this))) {
30 HostZoomMap::GetForBrowserContext(this)->AddZoomLevelChangedCallback(
31 zoom_callback_);
34 } 32 }
35 33
36 virtual ~TestingProfileWithHostZoomMap() {} 34 virtual ~TestingProfileWithHostZoomMap() {
35 HostZoomMap::GetForBrowserContext(this)->RemoveZoomLevelChangedCallback(
36 zoom_callback_);
37 }
37 38
38 virtual Profile* GetOffTheRecordProfile() OVERRIDE { 39 virtual Profile* GetOffTheRecordProfile() OVERRIDE {
39 if (!off_the_record_profile_.get()) 40 if (!off_the_record_profile_.get())
40 off_the_record_profile_.reset(CreateOffTheRecordProfile()); 41 off_the_record_profile_.reset(CreateOffTheRecordProfile());
41 return off_the_record_profile_.get(); 42 return off_the_record_profile_.get();
42 } 43 }
43 44
44 virtual PrefServiceSyncable* GetOffTheRecordPrefs() OVERRIDE { 45 virtual PrefServiceSyncable* GetOffTheRecordPrefs() OVERRIDE {
45 return GetPrefs(); 46 return GetPrefs();
46 } 47 }
47 48
48 virtual void Observe(int type, 49 private:
49 const content::NotificationSource& source, 50 void OnZoomLevelChanged(const std::string& host) {
50 const content::NotificationDetails& details) OVERRIDE {
51 const std::string& host =
52 *(content::Details<const std::string>(details).ptr());
53 DCHECK(type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED);
54 if (host.empty()) 51 if (host.empty())
55 return; 52 return;
56 53
57 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); 54 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
58 double level = host_zoom_map->GetZoomLevel(host); 55 double level = host_zoom_map->GetZoomLevel(host);
59 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); 56 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
60 DictionaryValue* host_zoom_dictionary = update.Get(); 57 DictionaryValue* host_zoom_dictionary = update.Get();
61 if (level == host_zoom_map->GetDefaultZoomLevel()) { 58 if (level == host_zoom_map->GetDefaultZoomLevel()) {
62 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); 59 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
63 } else { 60 } else {
64 host_zoom_dictionary->SetWithoutPathExpansion( 61 host_zoom_dictionary->SetWithoutPathExpansion(
65 host, Value::CreateDoubleValue(level)); 62 host, Value::CreateDoubleValue(level));
66 } 63 }
67 } 64 }
68 65
69 private:
70 content::NotificationRegistrar registrar_;
71 scoped_ptr<Profile> off_the_record_profile_; 66 scoped_ptr<Profile> off_the_record_profile_;
72 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_; 67 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
73 68
69 content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_;
70
74 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); 71 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap);
75 }; 72 };
76 73
77 } // namespace 74 } // namespace
78 75
79 // We need to have a BrowserProcess in g_browser_process variable, since 76 // We need to have a BrowserProcess in g_browser_process variable, since
80 // OffTheRecordProfileImpl ctor uses it in 77 // OffTheRecordProfileImpl ctor uses it in
81 // ProfileIOData::InitializeProfileParams. 78 // ProfileIOData::InitializeProfileParams.
82 class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest { 79 class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest {
83 protected: 80 protected:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 128
132 // Prepare parent host zoom map. 129 // Prepare parent host zoom map.
133 HostZoomMap* parent_zoom_map = 130 HostZoomMap* parent_zoom_map =
134 HostZoomMap::GetForBrowserContext(parent_profile.get()); 131 HostZoomMap::GetForBrowserContext(parent_profile.get());
135 ASSERT_TRUE(parent_zoom_map); 132 ASSERT_TRUE(parent_zoom_map);
136 133
137 parent_zoom_map->SetZoomLevel(host, zoom_level_25); 134 parent_zoom_map->SetZoomLevel(host, zoom_level_25);
138 ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_25); 135 ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_25);
139 136
140 // TODO(yosin) We need to wait ProfileImpl::Observe done for 137 // TODO(yosin) We need to wait ProfileImpl::Observe done for
141 // NOTIFICATION_ZOOM_LEVEL_CHANGED. 138 // OnZoomLevelChanged.
142 139
143 // Prepare child profile as off the record profile. 140 // Prepare child profile as off the record profile.
144 scoped_ptr<OffTheRecordProfileImpl> child_profile( 141 scoped_ptr<OffTheRecordProfileImpl> child_profile(
145 new OffTheRecordProfileImpl(parent_profile.get())); 142 new OffTheRecordProfileImpl(parent_profile.get()));
146 child_profile->InitHostZoomMap(); 143 child_profile->InitHostZoomMap();
147 144
148 ProfileDependencyManager::GetInstance()->CreateProfileServices( 145 ProfileDependencyManager::GetInstance()->CreateProfileServices(
149 child_profile.get(), false); 146 child_profile.get(), false);
150 147
151 // Prepare child host zoom map. 148 // Prepare child host zoom map.
(...skipping 15 matching lines...) Expand all
167 child_zoom_map->GetZoomLevel(host)) << 164 child_zoom_map->GetZoomLevel(host)) <<
168 "Child change must not propagate to parent."; 165 "Child change must not propagate to parent.";
169 166
170 parent_zoom_map->SetZoomLevel(host, zoom_level_40); 167 parent_zoom_map->SetZoomLevel(host, zoom_level_40);
171 ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_40); 168 ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_40);
172 169
173 EXPECT_EQ(parent_zoom_map->GetZoomLevel(host), 170 EXPECT_EQ(parent_zoom_map->GetZoomLevel(host),
174 child_zoom_map->GetZoomLevel(host)) << 171 child_zoom_map->GetZoomLevel(host)) <<
175 "Parent change should propagate to child."; 172 "Parent change should propagate to child.";
176 } 173 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/off_the_record_profile_impl.cc ('k') | chrome/browser/profiles/profile_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698