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

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: callbacks 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_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/prefs/scoped_user_pref_update.h" 10 #include "chrome/browser/prefs/scoped_user_pref_update.h"
11 #include "chrome/browser/profiles/profile_dependency_manager.h" 11 #include "chrome/browser/profiles/profile_dependency_manager.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_pref_service.h" 15 #include "chrome/test/base/testing_pref_service.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/browser/host_zoom_map.h" 17 #include "content/public/browser/host_zoom_map.h"
18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_types.h"
21 18
22 using content::HostZoomMap; 19 using content::HostZoomMap;
20 using content::HostZoomMapObserver;
23 21
24 namespace { 22 namespace {
25 23
26 class TestingProfileWithHostZoomMap : public TestingProfile, 24 class TestingProfileWithHostZoomMap : public TestingProfile {
27 public content::NotificationObserver {
28 public: 25 public:
29 TestingProfileWithHostZoomMap() { 26 TestingProfileWithHostZoomMap() {
30 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); 27 HostZoomMap::GetForBrowserContext(this)->AddZoomLevelChangedCallback(
31 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 28 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, this));
32 content::Source<HostZoomMap>(host_zoom_map));
33 } 29 }
34 30
35 virtual ~TestingProfileWithHostZoomMap() {} 31 virtual ~TestingProfileWithHostZoomMap() {
32 HostZoomMap::GetForBrowserContext(this)->RemoveZoomLevelChangedCallback(
33 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, this));
34 }
36 35
37 virtual Profile* GetOffTheRecordProfile() OVERRIDE { 36 virtual Profile* GetOffTheRecordProfile() OVERRIDE {
38 if (!off_the_record_profile_.get()) 37 if (!off_the_record_profile_.get())
39 off_the_record_profile_.reset(CreateOffTheRecordProfile()); 38 off_the_record_profile_.reset(CreateOffTheRecordProfile());
40 return off_the_record_profile_.get(); 39 return off_the_record_profile_.get();
41 } 40 }
42 41
43 virtual PrefServiceSyncable* GetOffTheRecordPrefs() OVERRIDE { 42 virtual PrefServiceSyncable* GetOffTheRecordPrefs() OVERRIDE {
44 return GetPrefs(); 43 return GetPrefs();
45 } 44 }
46 45
47 virtual void Observe(int type, 46 void OnZoomLevelChanged(const std::string& host) {
48 const content::NotificationSource& source,
49 const content::NotificationDetails& details) OVERRIDE {
50 const std::string& host =
51 *(content::Details<const std::string>(details).ptr());
52 DCHECK(type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED);
53 if (host.empty()) 47 if (host.empty())
54 return; 48 return;
55 49
56 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); 50 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this);
57 double level = host_zoom_map->GetZoomLevel(host); 51 double level = host_zoom_map->GetZoomLevel(host);
58 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); 52 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels);
59 DictionaryValue* host_zoom_dictionary = update.Get(); 53 DictionaryValue* host_zoom_dictionary = update.Get();
60 if (level == host_zoom_map->GetDefaultZoomLevel()) { 54 if (level == host_zoom_map->GetDefaultZoomLevel()) {
61 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); 55 host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL);
62 } else { 56 } else {
63 host_zoom_dictionary->SetWithoutPathExpansion( 57 host_zoom_dictionary->SetWithoutPathExpansion(
64 host, Value::CreateDoubleValue(level)); 58 host, Value::CreateDoubleValue(level));
65 } 59 }
66 } 60 }
67 61
68 private: 62 private:
69 content::NotificationRegistrar registrar_;
70 scoped_ptr<Profile> off_the_record_profile_; 63 scoped_ptr<Profile> off_the_record_profile_;
71 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_; 64 scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
72 65
73 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); 66 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap);
74 }; 67 };
75 68
76 } // namespace 69 } // namespace
77 70
78 // We need to have a BrowserProcess in g_browser_process variable, since 71 // We need to have a BrowserProcess in g_browser_process variable, since
79 // OffTheRecordProfileImpl ctor uses it in 72 // OffTheRecordProfileImpl ctor uses it in
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 123
131 // Prepare parent host zoom map. 124 // Prepare parent host zoom map.
132 HostZoomMap* parent_zoom_map = 125 HostZoomMap* parent_zoom_map =
133 HostZoomMap::GetForBrowserContext(parent_profile.get()); 126 HostZoomMap::GetForBrowserContext(parent_profile.get());
134 ASSERT_TRUE(parent_zoom_map); 127 ASSERT_TRUE(parent_zoom_map);
135 128
136 parent_zoom_map->SetZoomLevel(host, zoom_level_25); 129 parent_zoom_map->SetZoomLevel(host, zoom_level_25);
137 ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_25); 130 ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_25);
138 131
139 // TODO(yosin) We need to wait ProfileImpl::Observe done for 132 // TODO(yosin) We need to wait ProfileImpl::Observe done for
140 // NOTIFICATION_ZOOM_LEVEL_CHANGED. 133 // content::HostZoomMapObserver::OnZoomLevelChanged.
141 134
142 // Prepare child profile as off the record profile. 135 // Prepare child profile as off the record profile.
143 scoped_ptr<OffTheRecordProfileImpl> child_profile( 136 scoped_ptr<OffTheRecordProfileImpl> child_profile(
144 new OffTheRecordProfileImpl(parent_profile.get())); 137 new OffTheRecordProfileImpl(parent_profile.get()));
145 child_profile->InitHostZoomMap(); 138 child_profile->InitHostZoomMap();
146 139
147 ProfileDependencyManager::GetInstance()->CreateProfileServices( 140 ProfileDependencyManager::GetInstance()->CreateProfileServices(
148 child_profile.get(), false); 141 child_profile.get(), false);
149 142
150 // Prepare child host zoom map. 143 // Prepare child host zoom map.
(...skipping 15 matching lines...) Expand all
166 child_zoom_map->GetZoomLevel(host)) << 159 child_zoom_map->GetZoomLevel(host)) <<
167 "Child change must not propagate to parent."; 160 "Child change must not propagate to parent.";
168 161
169 parent_zoom_map->SetZoomLevel(host, zoom_level_40); 162 parent_zoom_map->SetZoomLevel(host, zoom_level_40);
170 ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_40); 163 ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_40);
171 164
172 EXPECT_EQ(parent_zoom_map->GetZoomLevel(host), 165 EXPECT_EQ(parent_zoom_map->GetZoomLevel(host),
173 child_zoom_map->GetZoomLevel(host)) << 166 child_zoom_map->GetZoomLevel(host)) <<
174 "Parent change should propagate to child."; 167 "Parent change should propagate to child.";
175 } 168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698