OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/webui/settings/site_settings_handler.h" | 5 #include "chrome/browser/ui/webui/settings/site_settings_handler.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/ui/webui/site_settings_helper.h" | 10 #include "chrome/browser/ui/webui/site_settings_helper.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 std::string callback_id; | 142 std::string callback_id; |
143 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | 143 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
144 EXPECT_EQ("onIncognitoStatusChanged", callback_id); | 144 EXPECT_EQ("onIncognitoStatusChanged", callback_id); |
145 | 145 |
146 bool incognito; | 146 bool incognito; |
147 ASSERT_TRUE(data.arg2()->GetAsBoolean(&incognito)); | 147 ASSERT_TRUE(data.arg2()->GetAsBoolean(&incognito)); |
148 EXPECT_EQ(expected_incognito, incognito); | 148 EXPECT_EQ(expected_incognito, incognito); |
149 } | 149 } |
150 | 150 |
| 151 void ValidateZoom(const std::string& expected_host, |
| 152 const std::string& expected_zoom, size_t expected_total_calls) { |
| 153 EXPECT_EQ(expected_total_calls, web_ui()->call_data().size()); |
| 154 |
| 155 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 156 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); |
| 157 |
| 158 std::string callback_id; |
| 159 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 160 EXPECT_EQ("onZoomLevelsChanged", callback_id); |
| 161 |
| 162 const base::ListValue* exceptions; |
| 163 ASSERT_TRUE(data.arg2()->GetAsList(&exceptions)); |
| 164 EXPECT_EQ(1U, exceptions->GetSize()); |
| 165 |
| 166 const base::DictionaryValue* exception; |
| 167 ASSERT_TRUE(exceptions->GetDictionary(0, &exception)); |
| 168 |
| 169 std::string host; |
| 170 ASSERT_TRUE(exception->GetString("origin", &host)); |
| 171 ASSERT_EQ(expected_host, host); |
| 172 |
| 173 std::string zoom; |
| 174 ASSERT_TRUE(exception->GetString("zoom", &zoom)); |
| 175 ASSERT_EQ(expected_zoom, zoom); |
| 176 } |
| 177 |
151 void CreateIncognitoProfile() { | 178 void CreateIncognitoProfile() { |
152 incognito_profile_ = TestingProfile::Builder().BuildIncognito(&profile_); | 179 incognito_profile_ = TestingProfile::Builder().BuildIncognito(&profile_); |
153 } | 180 } |
154 | 181 |
155 void DestroyIncognitoProfile() { | 182 void DestroyIncognitoProfile() { |
156 content::NotificationService::current()->Notify( | 183 content::NotificationService::current()->Notify( |
157 chrome::NOTIFICATION_PROFILE_DESTROYED, | 184 chrome::NOTIFICATION_PROFILE_DESTROYED, |
158 content::Source<Profile>(static_cast<Profile*>(incognito_profile_)), | 185 content::Source<Profile>(static_cast<Profile*>(incognito_profile_)), |
159 content::NotificationService::NoDetails()); | 186 content::NotificationService::NoDetails()); |
160 profile_.SetOffTheRecordProfile(nullptr); | 187 profile_.SetOffTheRecordProfile(nullptr); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 handler()->HandleUpdateIncognitoStatus(&args); | 273 handler()->HandleUpdateIncognitoStatus(&args); |
247 ValidateIncognitoExists(false, 1U); | 274 ValidateIncognitoExists(false, 1U); |
248 | 275 |
249 CreateIncognitoProfile(); | 276 CreateIncognitoProfile(); |
250 ValidateIncognitoExists(true, 2U); | 277 ValidateIncognitoExists(true, 2U); |
251 | 278 |
252 DestroyIncognitoProfile(); | 279 DestroyIncognitoProfile(); |
253 ValidateIncognitoExists(false, 3U); | 280 ValidateIncognitoExists(false, 3U); |
254 } | 281 } |
255 | 282 |
| 283 TEST_F(SiteSettingsHandlerTest, ZoomLevels) { |
| 284 std::string host("http://www.google.com"); |
| 285 double zoom_level = 1.1; |
| 286 |
| 287 content::HostZoomMap* host_zoom_map = |
| 288 content::HostZoomMap::GetDefaultForBrowserContext(profile()); |
| 289 host_zoom_map->SetZoomLevelForHost(host, zoom_level); |
| 290 |
| 291 base::ListValue args; |
| 292 handler()->HandleFetchZoomLevels(&args); |
| 293 ValidateZoom(host, "122%", 1U); |
| 294 |
| 295 args.AppendString("http://www.google.com"); |
| 296 handler()->HandleRemoveZoomLevel(&args); |
| 297 |
| 298 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
| 299 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host); |
| 300 EXPECT_EQ(default_level, level); |
| 301 } |
| 302 |
256 } // namespace settings | 303 } // namespace settings |
OLD | NEW |