| 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" |
| 32 #include "net/dns/mock_host_resolver.h" | 33 #include "net/dns/mock_host_resolver.h" |
| 33 #include "net/test/embedded_test_server/embedded_test_server.h" | 34 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 34 #include "net/test/embedded_test_server/http_response.h" | 35 #include "net/test/embedded_test_server/http_response.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 37 | 38 |
| 39 using content::HostZoomMap; |
| 40 |
| 38 namespace { | 41 namespace { |
| 39 | 42 |
| 40 class ZoomLevelChangeObserver { | 43 class ZoomLevelChangeObserver { |
| 41 public: | 44 public: |
| 42 explicit ZoomLevelChangeObserver(Profile* profile) | 45 explicit ZoomLevelChangeObserver(Profile* profile) |
| 43 : message_loop_runner_(new content::MessageLoopRunner) { | 46 : message_loop_runner_(new content::MessageLoopRunner) { |
| 44 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( | 47 content::HostZoomMap* host_zoom_map = static_cast<content::HostZoomMap*>( |
| 45 content::HostZoomMap::GetDefaultForBrowserContext(profile)); | 48 content::HostZoomMap::GetDefaultForBrowserContext(profile)); |
| 46 subscription_ = host_zoom_map->AddZoomLevelChangedCallback(base::Bind( | 49 subscription_ = host_zoom_map->AddZoomLevelChangedCallback(base::Bind( |
| 47 &ZoomLevelChangeObserver::OnZoomLevelChanged, base::Unretained(this))); | 50 &ZoomLevelChangeObserver::OnZoomLevelChanged, base::Unretained(this))); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 337 |
| 335 // Change the default zoom level and observe. | 338 // Change the default zoom level and observe. |
| 336 SetDefaultZoomLevel(kNewDefaultZoomLevel); | 339 SetDefaultZoomLevel(kNewDefaultZoomLevel); |
| 337 observer.BlockUntilZoomLevelForHostHasChanged(test_url.host()); | 340 observer.BlockUntilZoomLevelForHostHasChanged(test_url.host()); |
| 338 EXPECT_TRUE( | 341 EXPECT_TRUE( |
| 339 content::ZoomValuesEqual(kNewDefaultZoomLevel, GetZoomLevel(test_url))); | 342 content::ZoomValuesEqual(kNewDefaultZoomLevel, GetZoomLevel(test_url))); |
| 340 EXPECT_EQ(kNewDefaultZoomLevel, zoom_level_prefs->GetDefaultZoomLevelPref()); | 343 EXPECT_EQ(kNewDefaultZoomLevel, zoom_level_prefs->GetDefaultZoomLevelPref()); |
| 341 EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kDefaultZoomLevelDeprecated)); | 344 EXPECT_EQ(0.0, profile_prefs->GetDouble(prefs::kDefaultZoomLevelDeprecated)); |
| 342 } | 345 } |
| 343 | 346 |
| 347 // Test four things: |
| 348 // 1. Host zoom maps of parent profile and child profile are different. |
| 349 // 2. Child host zoom map inherits zoom level at construction. |
| 350 // 3. Change of zoom level doesn't propagate from child to parent. |
| 351 // 4. Change of zoom level propagates from parent to child. |
| 352 IN_PROC_BROWSER_TEST_F(HostZoomMapBrowserTest, |
| 353 OffTheRecordProfileHostZoomMap) { |
| 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."; |
| 400 base::RunLoop().RunUntilIdle(); |
| 401 } |
| OLD | NEW |