| 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/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/browser/ui/zoom/chrome_zoom_level_prefs.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/base/browser_with_test_window_test.h" | 14 #include "chrome/test/base/browser_with_test_window_test.h" |
| 14 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
| 15 #include "chrome/test/base/testing_io_thread_state.h" | 16 #include "chrome/test/base/testing_io_thread_state.h" |
| 16 #include "chrome/test/base/testing_pref_service_syncable.h" | 17 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 18 #include "chrome/test/base/testing_profile_manager.h" | 19 #include "chrome/test/base/testing_profile_manager.h" |
| 19 #include "content/public/browser/host_zoom_map.h" | 20 #include "content/public/browser/host_zoom_map.h" |
| 20 #include "content/public/common/page_zoom.h" | 21 #include "content/public/common/page_zoom.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 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
| 31 HostZoomMap::GetDefaultForBrowserContext(this) | 32 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( |
| 32 ->AddZoomLevelChangedCallback( | 33 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, |
| 33 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, | 34 base::Unretained(this))); |
| 34 base::Unretained(this))); | 35 zoom_level_prefs_.reset( |
| 36 new chrome::ChromeZoomLevelPrefs(GetPrefs(), GetPath())); |
| 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 std::string per_host_zoom_levels(prefs::kPartitionPerHostZoomLevels); |
| 57 per_host_zoom_levels.append(".0"); |
| 58 DictionaryPrefUpdate update(GetPrefs(), |
| 59 prefs::kPartitionPerHostZoomLevels); |
| 54 base::DictionaryValue* host_zoom_dictionary = update.Get(); | 60 base::DictionaryValue* host_zoom_dictionary = update.Get(); |
| 55 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) { | 61 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) { |
| 56 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | 62 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); |
| 57 } else { | 63 } else { |
| 58 host_zoom_dictionary->SetWithoutPathExpansion( | 64 host_zoom_dictionary->SetWithoutPathExpansion( |
| 59 change.host, new base::FundamentalValue(level)); | 65 change.host, new base::FundamentalValue(level)); |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 | 68 |
| 63 scoped_ptr<HostZoomMap::Subscription> zoom_subscription_; | 69 scoped_ptr<HostZoomMap::Subscription> zoom_subscription_; |
| 70 scoped_ptr<chrome::ChromeZoomLevelPrefs> zoom_level_prefs_; |
| 64 | 71 |
| 65 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); | 72 DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); |
| 66 }; | 73 }; |
| 67 | 74 |
| 68 } // namespace | 75 } // namespace |
| 69 | 76 |
| 70 // We need to have a BrowserProcess in g_browser_process variable, since | 77 // We need to have a BrowserProcess in g_browser_process variable, since |
| 71 // OffTheRecordProfileImpl ctor uses it in | 78 // OffTheRecordProfileImpl ctor uses it in |
| 72 // ProfileIOData::InitializeProfileParams. | 79 // ProfileIOData::InitializeProfileParams. |
| 73 class OffTheRecordProfileImplTest : public BrowserWithTestWindowTest { | 80 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); | 182 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); |
| 176 ASSERT_EQ( | 183 ASSERT_EQ( |
| 177 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 184 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
| 178 zoom_level_40); | 185 zoom_level_40); |
| 179 | 186 |
| 180 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 187 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
| 181 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << | 188 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << |
| 182 "Parent change should propagate to child."; | 189 "Parent change should propagate to child."; |
| 183 base::RunLoop().RunUntilIdle(); | 190 base::RunLoop().RunUntilIdle(); |
| 184 } | 191 } |
| OLD | NEW |