OLD | NEW |
---|---|
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/files/file_path.h" | |
Bernhard Bauer
2014/09/12 10:28:49
Remove
wjmaclean
2014/09/16 18:44:44
Opps, removed!
| |
7 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
11 #include "chrome/browser/prefs/browser_prefs.h" | 12 #include "chrome/browser/prefs/browser_prefs.h" |
13 #include "chrome/browser/ui/zoom/zoom_level_prefs_store_impl.h" | |
12 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/browser_with_test_window_test.h" | 15 #include "chrome/test/base/browser_with_test_window_test.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_io_thread_state.h" | 17 #include "chrome/test/base/testing_io_thread_state.h" |
16 #include "chrome/test/base/testing_pref_service_syncable.h" | 18 #include "chrome/test/base/testing_pref_service_syncable.h" |
17 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
18 #include "chrome/test/base/testing_profile_manager.h" | 20 #include "chrome/test/base/testing_profile_manager.h" |
19 #include "content/public/browser/host_zoom_map.h" | 21 #include "content/public/browser/host_zoom_map.h" |
20 #include "content/public/common/page_zoom.h" | 22 #include "content/public/common/page_zoom.h" |
21 #include "net/dns/mock_host_resolver.h" | 23 #include "net/dns/mock_host_resolver.h" |
22 | 24 |
23 using content::HostZoomMap; | 25 using content::HostZoomMap; |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 class TestingProfileWithHostZoomMap : public TestingProfile { | 29 class TestingProfileWithHostZoomMap : public TestingProfile { |
28 public: | 30 public: |
29 TestingProfileWithHostZoomMap() { | 31 TestingProfileWithHostZoomMap() { |
30 zoom_subscription_ = | 32 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
31 HostZoomMap::GetDefaultForBrowserContext(this) | 33 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( |
32 ->AddZoomLevelChangedCallback( | 34 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, |
33 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, | 35 base::Unretained(this))); |
34 base::Unretained(this))); | 36 zoom_level_prefs_.reset(new chrome::ZoomLevelPrefsStoreImpl); |
37 zoom_level_prefs_->InitPrefsAndCopyToHostZoomMap(GetPath(), host_zoom_map); | |
35 } | 38 } |
36 | 39 |
37 virtual ~TestingProfileWithHostZoomMap() {} | 40 virtual ~TestingProfileWithHostZoomMap() {} |
38 | 41 |
39 // Profile overrides: | 42 // Profile overrides: |
40 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE { | 43 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE { |
41 return GetPrefs(); | 44 return GetPrefs(); |
42 } | 45 } |
43 | 46 |
44 private: | 47 private: |
45 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { | 48 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { |
46 | 49 |
47 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) | 50 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) |
48 return; | 51 return; |
49 | 52 |
50 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); | 53 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
51 | 54 |
52 double level = change.zoom_level; | 55 double level = change.zoom_level; |
53 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 56 DictionaryPrefUpdate update(zoom_level_prefs_->GetPrefs(), |
57 prefs::kPerHostZoomLevels); | |
54 base::DictionaryValue* host_zoom_dictionary = update.Get(); | 58 base::DictionaryValue* host_zoom_dictionary = update.Get(); |
55 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) { | 59 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) { |
56 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | 60 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); |
57 } else { | 61 } else { |
58 host_zoom_dictionary->SetWithoutPathExpansion( | 62 host_zoom_dictionary->SetWithoutPathExpansion( |
59 change.host, new base::FundamentalValue(level)); | 63 change.host, new base::FundamentalValue(level)); |
60 } | 64 } |
61 } | 65 } |
62 | 66 |
63 scoped_ptr<HostZoomMap::Subscription> zoom_subscription_; | 67 scoped_ptr<HostZoomMap::Subscription> zoom_subscription_; |
68 scoped_ptr<chrome::ZoomLevelPrefsStoreImpl> zoom_level_prefs_; | |
64 | 69 |
65 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); | 70 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); |
66 }; | 71 }; |
67 | 72 |
68 } // namespace | 73 } // namespace |
69 | 74 |
70 // We need to have a BrowserProcess in g_browser_process variable, since | 75 // We need to have a BrowserProcess in g_browser_process variable, since |
71 // OffTheRecordProfileImpl ctor uses it in | 76 // OffTheRecordProfileImpl ctor uses it in |
72 // ProfileIOData::InitializeProfileParams. | 77 // ProfileIOData::InitializeProfileParams. |
73 class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest { | 78 class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); | 180 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); |
176 ASSERT_EQ( | 181 ASSERT_EQ( |
177 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 182 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
178 zoom_level_40); | 183 zoom_level_40); |
179 | 184 |
180 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 185 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
181 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << | 186 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << |
182 "Parent change should propagate to child."; | 187 "Parent change should propagate to child."; |
183 base::RunLoop().RunUntilIdle(); | 188 base::RunLoop().RunUntilIdle(); |
184 } | 189 } |
OLD | NEW |