| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 22 | 22 |
| 23 using content::HostZoomMap; | 23 using content::HostZoomMap; |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class TestingProfileWithHostZoomMap : public TestingProfile { | 27 class TestingProfileWithHostZoomMap : public TestingProfile { |
| 28 public: | 28 public: |
| 29 TestingProfileWithHostZoomMap() { | 29 TestingProfileWithHostZoomMap() { |
| 30 zoom_subscription_ = | 30 zoom_subscription_ = |
| 31 HostZoomMap::GetForBrowserContext(this)->AddZoomLevelChangedCallback( | 31 HostZoomMap::GetDefaultForBrowserContext(this) |
| 32 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, | 32 ->AddZoomLevelChangedCallback( |
| 33 base::Unretained(this))); | 33 base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, |
| 34 base::Unretained(this))); |
| 34 } | 35 } |
| 35 | 36 |
| 36 virtual ~TestingProfileWithHostZoomMap() {} | 37 virtual ~TestingProfileWithHostZoomMap() {} |
| 37 | 38 |
| 38 // Profile overrides: | 39 // Profile overrides: |
| 39 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE { | 40 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE { |
| 40 return GetPrefs(); | 41 return GetPrefs(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { | 45 void OnZoomLevelChanged(const HostZoomMap::ZoomLevelChange& change) { |
| 45 | 46 |
| 46 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) | 47 if (change.mode != HostZoomMap::ZOOM_CHANGED_FOR_HOST) |
| 47 return; | 48 return; |
| 48 | 49 |
| 49 HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); | 50 HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this); |
| 50 | 51 |
| 51 double level = change.zoom_level; | 52 double level = change.zoom_level; |
| 52 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); | 53 DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); |
| 53 base::DictionaryValue* host_zoom_dictionary = update.Get(); | 54 base::DictionaryValue* host_zoom_dictionary = update.Get(); |
| 54 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) { | 55 if (content::ZoomValuesEqual(level, host_zoom_map->GetDefaultZoomLevel())) { |
| 55 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); | 56 host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, NULL); |
| 56 } else { | 57 } else { |
| 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 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 const double zoom_level_40 = 4.0; | 125 const double zoom_level_40 = 4.0; |
| 125 | 126 |
| 126 // The TestingProfile from CreateProfile above is the parent. | 127 // The TestingProfile from CreateProfile above is the parent. |
| 127 TestingProfile* parent_profile = GetProfile(); | 128 TestingProfile* parent_profile = GetProfile(); |
| 128 ASSERT_TRUE(parent_profile); | 129 ASSERT_TRUE(parent_profile); |
| 129 ASSERT_TRUE(parent_profile->GetPrefs()); | 130 ASSERT_TRUE(parent_profile->GetPrefs()); |
| 130 ASSERT_TRUE(parent_profile->GetOffTheRecordPrefs()); | 131 ASSERT_TRUE(parent_profile->GetOffTheRecordPrefs()); |
| 131 | 132 |
| 132 // Prepare parent host zoom map. | 133 // Prepare parent host zoom map. |
| 133 HostZoomMap* parent_zoom_map = | 134 HostZoomMap* parent_zoom_map = |
| 134 HostZoomMap::GetForBrowserContext(parent_profile); | 135 HostZoomMap::GetDefaultForBrowserContext(parent_profile); |
| 135 ASSERT_TRUE(parent_zoom_map); | 136 ASSERT_TRUE(parent_zoom_map); |
| 136 | 137 |
| 137 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_25); | 138 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_25); |
| 138 ASSERT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 139 ASSERT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
| 139 zoom_level_25); | 140 zoom_level_25); |
| 140 | 141 |
| 141 // TODO(yosin) We need to wait ProfileImpl::Observe done for | 142 // TODO(yosin) We need to wait ProfileImpl::Observe done for |
| 142 // OnZoomLevelChanged. | 143 // OnZoomLevelChanged. |
| 143 | 144 |
| 144 // Prepare an off the record profile owned by the parent profile. | 145 // 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 = | 146 OffTheRecordProfileImpl* child_profile = |
| 148 static_cast<OffTheRecordProfileImpl*>( | 147 static_cast<OffTheRecordProfileImpl*>( |
| 149 parent_profile->GetOffTheRecordProfile()); | 148 parent_profile->GetOffTheRecordProfile()); |
| 150 child_profile->InitIoData(); | |
| 151 child_profile->InitHostZoomMap(); | |
| 152 | 149 |
| 153 // Prepare child host zoom map. | 150 // Prepare child host zoom map. |
| 154 HostZoomMap* child_zoom_map = | 151 HostZoomMap* child_zoom_map = |
| 155 HostZoomMap::GetForBrowserContext(child_profile); | 152 HostZoomMap::GetDefaultForBrowserContext(child_profile); |
| 156 ASSERT_TRUE(child_zoom_map); | 153 ASSERT_TRUE(child_zoom_map); |
| 157 | 154 |
| 158 // Verify. | 155 // Verify. |
| 159 EXPECT_NE(parent_zoom_map, child_zoom_map); | 156 EXPECT_NE(parent_zoom_map, child_zoom_map); |
| 160 | 157 |
| 161 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 158 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
| 162 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << | 159 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << |
| 163 "Child must inherit from parent."; | 160 "Child must inherit from parent."; |
| 164 | 161 |
| 165 child_zoom_map->SetZoomLevelForHost(host, zoom_level_30); | 162 child_zoom_map->SetZoomLevelForHost(host, zoom_level_30); |
| 166 ASSERT_EQ( | 163 ASSERT_EQ( |
| 167 child_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 164 child_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
| 168 zoom_level_30); | 165 zoom_level_30); |
| 169 | 166 |
| 170 EXPECT_NE(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 167 EXPECT_NE(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
| 171 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << | 168 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << |
| 172 "Child change must not propagate to parent."; | 169 "Child change must not propagate to parent."; |
| 173 | 170 |
| 174 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); | 171 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); |
| 175 ASSERT_EQ( | 172 ASSERT_EQ( |
| 176 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 173 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
| 177 zoom_level_40); | 174 zoom_level_40); |
| 178 | 175 |
| 179 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | 176 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), |
| 180 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << | 177 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << |
| 181 "Parent change should propagate to child."; | 178 "Parent change should propagate to child."; |
| 182 base::RunLoop().RunUntilIdle(); | 179 base::RunLoop().RunUntilIdle(); |
| 183 } | 180 } |
| OLD | NEW |