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 |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 EXPECT_TRUE(GetHostsWithZoomLevels().empty()); | 348 EXPECT_TRUE(GetHostsWithZoomLevels().empty()); |
| 349 EXPECT_TRUE(GetHostsWithZoomLevelsFromPrefs().empty()); | 349 EXPECT_TRUE(GetHostsWithZoomLevelsFromPrefs().empty()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 // Test that garbage data from crbug.com/364399 is cleared up on startup. | 352 // Test that garbage data from crbug.com/364399 is cleared up on startup. |
| 353 IN_PROC_BROWSER_TEST_F(HostZoomMapSanitizationBrowserTest, ClearOnStartup) { | 353 IN_PROC_BROWSER_TEST_F(HostZoomMapSanitizationBrowserTest, ClearOnStartup) { |
| 354 EXPECT_THAT(GetHostsWithZoomLevels(), testing::ElementsAre("host2")); | 354 EXPECT_THAT(GetHostsWithZoomLevels(), testing::ElementsAre("host2")); |
| 355 EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(), testing::ElementsAre("host2")); | 355 EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(), testing::ElementsAre("host2")); |
| 356 } | 356 } |
| 357 | 357 |
| 358 // In this case we migrate the zoom level data from the profile prefs. | |
|
gab
2015/08/18 20:39:40
Includes cleanup from https://codereview.chromium.
wjmaclean
2015/08/19 13:53:34
Did you want me to revert the changes to HostZoomM
gab
2015/08/20 16:34:28
Don't feel strongly there, feels like most of the
| |
| 359 const char kMigrationTestPrefs[] = | |
| 360 "{'profile': {" | |
| 361 " 'default_zoom_level': 1.2," | |
| 362 " 'per_host_zoom_levels': {'': 1.1, 'host1': 1.20001, 'host2': " | |
| 363 "1.3}" | |
| 364 "}}"; | |
| 365 | |
| 366 class HostZoomMapMigrationBrowserTest : public HostZoomMapBrowserTestWithPrefs { | |
| 367 public: | |
| 368 HostZoomMapMigrationBrowserTest() | |
| 369 : HostZoomMapBrowserTestWithPrefs(kMigrationTestPrefs) {} | |
| 370 | |
| 371 static const double kOriginalDefaultZoomLevel; | |
| 372 | |
| 373 private: | |
| 374 DISALLOW_COPY_AND_ASSIGN(HostZoomMapMigrationBrowserTest); | |
| 375 }; | |
| 376 | |
| 377 const double HostZoomMapMigrationBrowserTest::kOriginalDefaultZoomLevel = 1.2; | |
| 378 | |
| 379 // This test is the same as HostZoomMapSanitizationBrowserTest, except that the | |
| 380 // zoom level data is loaded from the profile prefs, transfered to the | |
| 381 // zoom-level prefs, and we verify that the profile zoom level prefs are | |
| 382 // erased in the process. We also test that changes to the host zoom map and the | |
| 383 // default zoom level don't propagate back to the profile prefs. | |
| 384 IN_PROC_BROWSER_TEST_F(HostZoomMapMigrationBrowserTest, | |
| 385 MigrateProfileZoomPreferences) { | |
| 386 EXPECT_THAT(GetHostsWithZoomLevels(), testing::ElementsAre("host2")); | |
| 387 EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(), testing::ElementsAre("host2")); | |
| 388 | |
| 389 PrefService* profile_prefs = | |
| 390 browser()->profile()->GetPrefs(); | |
| 391 chrome::ChromeZoomLevelPrefs* zoom_level_prefs = | |
| 392 browser()->profile()->GetZoomLevelPrefs(); | |
| 393 // Make sure that the profile pref for default zoom level has been set to | |
| 394 // its default value of 0.0. | |
| 395 EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kDefaultZoomLevelDeprecated)); | |
| 396 EXPECT_EQ(kOriginalDefaultZoomLevel, | |
| 397 zoom_level_prefs->GetDefaultZoomLevelPref()); | |
| 398 | |
| 399 // Make sure that the profile prefs for per-host zoom levels are erased. | |
| 400 { | |
| 401 const base::DictionaryValue* profile_host_zoom_dictionary = | |
| 402 profile_prefs->GetDictionary(prefs::kPerHostZoomLevelsDeprecated); | |
| 403 EXPECT_EQ(0UL, profile_host_zoom_dictionary->size()); | |
| 404 } | |
| 405 | |
| 406 ZoomLevelChangeObserver observer(browser()->profile()); | |
| 407 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( | |
| 408 content::HostZoomMap::GetDefaultForBrowserContext( | |
| 409 browser()->profile())); | |
| 410 | |
| 411 // Make sure that a change to a host zoom level doesn't propagate to the | |
| 412 // profile prefs. | |
| 413 std::string host3("host3"); | |
| 414 host_zoom_map->SetZoomLevelForHost(host3, 1.3); | |
| 415 observer.BlockUntilZoomLevelForHostHasChanged(host3); | |
| 416 EXPECT_THAT(GetHostsWithZoomLevelsFromPrefs(), | |
| 417 testing::ElementsAre("host2", host3)); | |
| 418 { | |
| 419 const base::DictionaryValue* profile_host_zoom_dictionary = | |
| 420 profile_prefs->GetDictionary(prefs::kPerHostZoomLevelsDeprecated); | |
| 421 EXPECT_EQ(0UL, profile_host_zoom_dictionary->size()); | |
| 422 } | |
| 423 | |
| 424 // Make sure a change to the default zoom level doesn't propagate to the | |
| 425 // profile prefs. | |
| 426 | |
| 427 // First, we need a host at the default zoom level to respond when the | |
| 428 // default zoom level changes. | |
| 429 const double kNewDefaultZoomLevel = 1.5; | |
| 430 GURL test_url = ConstructTestServerURL("http://host4:%u/"); | |
| 431 ui_test_utils::NavigateToURL(browser(), test_url); | |
| 432 EXPECT_TRUE(content::ZoomValuesEqual(kOriginalDefaultZoomLevel, | |
| 433 GetZoomLevel(test_url))); | |
| 434 | |
| 435 // Change the default zoom level and observe. | |
| 436 SetDefaultZoomLevel(kNewDefaultZoomLevel); | |
| 437 observer.BlockUntilZoomLevelForHostHasChanged(test_url.host()); | |
| 438 EXPECT_TRUE( | |
| 439 content::ZoomValuesEqual(kNewDefaultZoomLevel, GetZoomLevel(test_url))); | |
| 440 EXPECT_EQ(kNewDefaultZoomLevel, zoom_level_prefs->GetDefaultZoomLevelPref()); | |
| 441 EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kDefaultZoomLevelDeprecated)); | |
| 442 } | |
| 443 | |
| 444 // Test four things: | 358 // Test four things: |
| 445 // 1. Host zoom maps of parent profile and child profile are different. | 359 // 1. Host zoom maps of parent profile and child profile are different. |
| 446 // 2. Child host zoom map inherits zoom level at construction. | 360 // 2. Child host zoom map inherits zoom level at construction. |
| 447 // 3. Change of zoom level doesn't propagate from child to parent. | 361 // 3. Change of zoom level doesn't propagate from child to parent. |
| 448 // 4. Change of zoom level propagates from parent to child. | 362 // 4. Change of zoom level propagates from parent to child. |
| 449 IN_PROC_BROWSER_TEST_F(HostZoomMapBrowserTest, | 363 IN_PROC_BROWSER_TEST_F(HostZoomMapBrowserTest, |
| 450 OffTheRecordProfileHostZoomMap) { | 364 OffTheRecordProfileHostZoomMap) { |
| 451 // Constants for test case. | 365 // Constants for test case. |
| 452 const std::string host("example.com"); | 366 const std::string host("example.com"); |
| 453 const double zoom_level_25 = 2.5; | 367 const double zoom_level_25 = 2.5; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 HostZoomMap::GetDefaultForBrowserContext(child_profile); | 425 HostZoomMap::GetDefaultForBrowserContext(child_profile); |
| 512 ASSERT_TRUE(parent_host_zoom_map); | 426 ASSERT_TRUE(parent_host_zoom_map); |
| 513 ASSERT_TRUE(child_host_zoom_map); | 427 ASSERT_TRUE(child_host_zoom_map); |
| 514 EXPECT_NE(parent_host_zoom_map, child_host_zoom_map); | 428 EXPECT_NE(parent_host_zoom_map, child_host_zoom_map); |
| 515 EXPECT_NE(new_default_zoom_level, child_host_zoom_map->GetDefaultZoomLevel()); | 429 EXPECT_NE(new_default_zoom_level, child_host_zoom_map->GetDefaultZoomLevel()); |
| 516 | 430 |
| 517 parent_profile->GetZoomLevelPrefs()->SetDefaultZoomLevelPref( | 431 parent_profile->GetZoomLevelPrefs()->SetDefaultZoomLevelPref( |
| 518 new_default_zoom_level); | 432 new_default_zoom_level); |
| 519 EXPECT_EQ(new_default_zoom_level, child_host_zoom_map->GetDefaultZoomLevel()); | 433 EXPECT_EQ(new_default_zoom_level, child_host_zoom_map->GetDefaultZoomLevel()); |
| 520 } | 434 } |
| OLD | NEW |