Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/public/browser/host_zoom_map.h" | 5 #include "content/public/browser/host_zoom_map.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/chrome_page_zoom.h" | 20 #include "chrome/browser/chrome_page_zoom.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_impl.h" | |
| 22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | 25 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
| 25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 26 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/test/base/in_process_browser_test.h" | 29 #include "chrome/test/base/in_process_browser_test.h" |
| 29 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 | 335 |
| 335 // Change the default zoom level and observe. | 336 // Change the default zoom level and observe. |
| 336 SetDefaultZoomLevel(kNewDefaultZoomLevel); | 337 SetDefaultZoomLevel(kNewDefaultZoomLevel); |
| 337 observer.BlockUntilZoomLevelForHostHasChanged(test_url.host()); | 338 observer.BlockUntilZoomLevelForHostHasChanged(test_url.host()); |
| 338 EXPECT_TRUE( | 339 EXPECT_TRUE( |
| 339 content::ZoomValuesEqual(kNewDefaultZoomLevel, GetZoomLevel(test_url))); | 340 content::ZoomValuesEqual(kNewDefaultZoomLevel, GetZoomLevel(test_url))); |
| 340 EXPECT_EQ(kNewDefaultZoomLevel, zoom_level_prefs->GetDefaultZoomLevelPref()); | 341 EXPECT_EQ(kNewDefaultZoomLevel, zoom_level_prefs->GetDefaultZoomLevelPref()); |
| 341 EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kDefaultZoomLevelDeprecated)); | 342 EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kDefaultZoomLevelDeprecated)); |
| 342 } | 343 } |
| 343 | 344 |
| 345 // Test four things: | |
| 346 // 1. Host zoom maps of parent profile and child profile are different. | |
| 347 // 2. Child host zoom map inherites zoom level at construction. | |
|
Charlie Reis
2014/11/04 23:43:16
nit: inherits
wjmaclean
2014/11/05 21:55:42
Done.
Ahh, the dangers of transferring comments w
| |
| 348 // 3. Change of zoom level doesn't propagate from child to parent. | |
| 349 // 4. Change of zoom level propagate from parent to child. | |
|
Charlie Reis
2014/11/04 23:43:16
nit: propagates
wjmaclean
2014/11/05 21:55:42
Done.
| |
| 350 IN_PROC_BROWSER_TEST_F(HostZoomMapBrowserTest, | |
| 351 OffTheRecordProfileHostZoomMap) { | |
| 352 using content::HostZoomMap; | |
|
Charlie Reis
2014/11/04 23:43:16
Is it common to do this within a test or block? I
wjmaclean
2014/11/05 21:55:42
Done.
| |
| 353 | |
| 354 // Constants for test case. | |
| 355 const std::string host("example.com"); | |
| 356 const double zoom_level_25 = 2.5; | |
| 357 const double zoom_level_30 = 3.0; | |
| 358 const double zoom_level_40 = 4.0; | |
| 359 | |
| 360 Profile* parent_profile = browser()->profile(); | |
| 361 Profile* child_profile = | |
| 362 static_cast<ProfileImpl*>(parent_profile)->GetOffTheRecordProfile(); | |
| 363 HostZoomMap* parent_zoom_map = | |
| 364 HostZoomMap::GetDefaultForBrowserContext(parent_profile); | |
| 365 ASSERT_TRUE(parent_zoom_map); | |
| 366 | |
| 367 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_25); | |
| 368 ASSERT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | |
| 369 zoom_level_25); | |
| 370 | |
| 371 // Prepare child host zoom map. | |
| 372 HostZoomMap* child_zoom_map = | |
| 373 HostZoomMap::GetDefaultForBrowserContext(child_profile); | |
| 374 ASSERT_TRUE(child_zoom_map); | |
| 375 | |
| 376 // Verify. | |
| 377 EXPECT_NE(parent_zoom_map, child_zoom_map); | |
| 378 | |
| 379 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | |
| 380 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << | |
| 381 "Child must inherit from parent."; | |
| 382 | |
| 383 child_zoom_map->SetZoomLevelForHost(host, zoom_level_30); | |
| 384 ASSERT_EQ( | |
| 385 child_zoom_map->GetZoomLevelForHostAndScheme("http", host), | |
| 386 zoom_level_30); | |
| 387 | |
| 388 EXPECT_NE(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | |
| 389 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << | |
| 390 "Child change must not propagate to parent."; | |
| 391 | |
| 392 parent_zoom_map->SetZoomLevelForHost(host, zoom_level_40); | |
| 393 ASSERT_EQ( | |
| 394 parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | |
| 395 zoom_level_40); | |
| 396 | |
| 397 EXPECT_EQ(parent_zoom_map->GetZoomLevelForHostAndScheme("http", host), | |
| 398 child_zoom_map->GetZoomLevelForHostAndScheme("http", host)) << | |
| 399 "Parent change should propagate to child."; | |
|
Charlie Reis
2014/11/04 23:43:16
Huh. I was surprised that this was Chrome's behav
wjmaclean
2014/11/05 21:55:42
Acknowledged.
| |
| 400 base::RunLoop().RunUntilIdle(); | |
| 401 } | |
| OLD | NEW |