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

Side by Side Diff: chrome/browser/ui/webui/settings/site_settings_handler_unittest.cc

Issue 2323693002: Site Settings Desktop: Implement Zoom Levels category. (Closed)
Patch Set: Fix test Created 4 years, 3 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
OLDNEW
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
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 if (expected_host.empty()) {
165 EXPECT_EQ(0U, exceptions->GetSize());
166 } else {
167 EXPECT_EQ(1U, exceptions->GetSize());
168
169 const base::DictionaryValue* exception;
170 ASSERT_TRUE(exceptions->GetDictionary(0, &exception));
171
172 std::string host;
173 ASSERT_TRUE(exception->GetString("origin", &host));
174 ASSERT_EQ(expected_host, host);
175
176 std::string zoom;
177 ASSERT_TRUE(exception->GetString("zoom", &zoom));
178 ASSERT_EQ(expected_zoom, zoom);
179 }
180 }
181
151 void CreateIncognitoProfile() { 182 void CreateIncognitoProfile() {
152 incognito_profile_ = TestingProfile::Builder().BuildIncognito(&profile_); 183 incognito_profile_ = TestingProfile::Builder().BuildIncognito(&profile_);
153 } 184 }
154 185
155 void DestroyIncognitoProfile() { 186 void DestroyIncognitoProfile() {
156 content::NotificationService::current()->Notify( 187 content::NotificationService::current()->Notify(
157 chrome::NOTIFICATION_PROFILE_DESTROYED, 188 chrome::NOTIFICATION_PROFILE_DESTROYED,
158 content::Source<Profile>(static_cast<Profile*>(incognito_profile_)), 189 content::Source<Profile>(static_cast<Profile*>(incognito_profile_)),
159 content::NotificationService::NoDetails()); 190 content::NotificationService::NoDetails());
160 profile_.SetOffTheRecordProfile(nullptr); 191 profile_.SetOffTheRecordProfile(nullptr);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 handler()->HandleUpdateIncognitoStatus(&args); 277 handler()->HandleUpdateIncognitoStatus(&args);
247 ValidateIncognitoExists(false, 1U); 278 ValidateIncognitoExists(false, 1U);
248 279
249 CreateIncognitoProfile(); 280 CreateIncognitoProfile();
250 ValidateIncognitoExists(true, 2U); 281 ValidateIncognitoExists(true, 2U);
251 282
252 DestroyIncognitoProfile(); 283 DestroyIncognitoProfile();
253 ValidateIncognitoExists(false, 3U); 284 ValidateIncognitoExists(false, 3U);
254 } 285 }
255 286
287 TEST_F(SiteSettingsHandlerTest, ZoomLevels) {
288 std::string host("http://www.google.com");
289 double zoom_level = 1.1;
290
291 content::HostZoomMap* host_zoom_map =
292 content::HostZoomMap::GetDefaultForBrowserContext(profile());
293 host_zoom_map->SetZoomLevelForHost(host, zoom_level);
294 ValidateZoom(host, "122%", 1U);
295
296 base::ListValue args;
297 handler()->HandleFetchZoomLevels(&args);
298 ValidateZoom(host, "122%", 2U);
299
300 args.AppendString("http://www.google.com");
301 handler()->HandleRemoveZoomLevel(&args);
302 ValidateZoom("", "", 3U);
303
304 double default_level = host_zoom_map->GetDefaultZoomLevel();
305 double level = host_zoom_map->GetZoomLevelForHostAndScheme("http", host);
306 EXPECT_EQ(default_level, level);
307 }
308
256 } // namespace settings 309 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698