| 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/command_line.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 17 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_impl.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/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 29 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
| 30 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
| 31 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
| 32 #include "components/signin/core/common/profile_management_switches.h" | 33 #include "components/signin/core/common/profile_management_switches.h" |
| 34 #include "components/signin/core/common/signin_switches.h" |
| 33 #include "components/ui/zoom/page_zoom.h" | 35 #include "components/ui/zoom/page_zoom.h" |
| 34 #include "components/ui/zoom/zoom_event_manager.h" | 36 #include "components/ui/zoom/zoom_event_manager.h" |
| 35 #include "content/public/test/test_utils.h" | 37 #include "content/public/test/test_utils.h" |
| 36 #include "net/dns/mock_host_resolver.h" | 38 #include "net/dns/mock_host_resolver.h" |
| 37 #include "net/test/embedded_test_server/embedded_test_server.h" | 39 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 38 #include "net/test/embedded_test_server/http_response.h" | 40 #include "net/test/embedded_test_server/http_response.h" |
| 39 #include "testing/gmock/include/gmock/gmock.h" | 41 #include "testing/gmock/include/gmock/gmock.h" |
| 40 #include "url/gurl.h" | 42 #include "url/gurl.h" |
| 41 | 43 |
| 42 using content::HostZoomMap; | 44 using content::HostZoomMap; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 233 |
| 232 double new_zoom_level = | 234 double new_zoom_level = |
| 233 host_zoom_map->GetZoomLevelForHostAndScheme(test_scheme, test_host) + 0.5; | 235 host_zoom_map->GetZoomLevelForHostAndScheme(test_scheme, test_host) + 0.5; |
| 234 host_zoom_map->SetZoomLevelForHostAndScheme(test_scheme, test_host, | 236 host_zoom_map->SetZoomLevelForHostAndScheme(test_scheme, test_host, |
| 235 new_zoom_level); | 237 new_zoom_level); |
| 236 observer.BlockUntilZoomLevelForHostHasChanged(test_host); | 238 observer.BlockUntilZoomLevelForHostHasChanged(test_host); |
| 237 EXPECT_EQ(new_zoom_level, host_zoom_map->GetZoomLevelForHostAndScheme( | 239 EXPECT_EQ(new_zoom_level, host_zoom_map->GetZoomLevelForHostAndScheme( |
| 238 test_scheme, test_host)); | 240 test_scheme, test_host)); |
| 239 } | 241 } |
| 240 | 242 |
| 243 IN_PROC_BROWSER_TEST_F( |
| 244 HostZoomMapBrowserTest, |
| 245 WebviewBasedSigninUsesDefaultStoragePartitionForEmbedder) { |
| 246 GURL test_url = ConstructTestServerURL(chrome::kChromeUIChromeSigninURL); |
| 247 std::string test_host(test_url.host()); |
| 248 std::string test_scheme(test_url.scheme()); |
| 249 ui_test_utils::NavigateToURL(browser(), test_url); |
| 250 |
| 251 content::WebContents* web_contents = |
| 252 browser()->tab_strip_model()->GetActiveWebContents(); |
| 253 |
| 254 HostZoomMap* host_zoom_map = HostZoomMap::GetForWebContents(web_contents); |
| 255 |
| 256 // For the webview based sign-in code, the sign in page uses the default host |
| 257 // zoom map. |
| 258 HostZoomMap* default_profile_host_zoom_map = |
| 259 HostZoomMap::GetDefaultForBrowserContext(browser()->profile()); |
| 260 // Since ChromeOS still uses IFrame-based signin, we should expect the |
| 261 // storage partition to be different if Webview signin is not enabled. |
| 262 if (switches::IsEnableWebviewBasedSignin()) |
| 263 EXPECT_EQ(host_zoom_map, default_profile_host_zoom_map); |
| 264 else |
| 265 EXPECT_NE(host_zoom_map, default_profile_host_zoom_map); |
| 266 } |
| 267 |
| 268 class HostZoomMapIframeSigninBrowserTest : public HostZoomMapBrowserTest { |
| 269 public: |
| 270 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 271 command_line->AppendSwitch(switches::kEnableIframeBasedSignin); |
| 272 } |
| 273 }; |
| 274 |
| 241 // Regression test for crbug.com/435017. | 275 // Regression test for crbug.com/435017. |
| 242 IN_PROC_BROWSER_TEST_F(HostZoomMapBrowserTest, | 276 IN_PROC_BROWSER_TEST_F(HostZoomMapIframeSigninBrowserTest, |
| 243 EventsForNonDefaultStoragePartition) { | 277 EventsForNonDefaultStoragePartition) { |
| 244 ZoomLevelChangeObserver observer(browser()->profile()); | 278 ZoomLevelChangeObserver observer(browser()->profile()); |
| 245 // TODO(wjmaclean): Make this test more general by implementing a way to | 279 // TODO(wjmaclean): Make this test more general by implementing a way to |
| 246 // force a generic URL to be loaded in a non-default storage partition. This | 280 // force a generic URL to be loaded in a non-default storage partition. This |
| 247 // test currently relies on the signin page being loaded into a non-default | 281 // test currently relies on the signin page being loaded into a non-default |
| 248 // storage partition (and verifies this is the case), but ultimately it would | 282 // storage partition (and verifies this is the case), but ultimately it would |
| 249 // be better not to rely on what the signin page is doing. | 283 // be better not to rely on what the signin page is doing. |
| 250 GURL test_url = ConstructTestServerURL(chrome::kChromeUIChromeSigninURL); | 284 GURL test_url = ConstructTestServerURL(chrome::kChromeUIChromeSigninURL); |
| 251 std::string test_host(test_url.host()); | 285 std::string test_host(test_url.host()); |
| 252 std::string test_scheme(test_url.scheme()); | 286 std::string test_scheme(test_url.scheme()); |
| 253 ui_test_utils::NavigateToURL(browser(), test_url); | 287 ui_test_utils::NavigateToURL(browser(), test_url); |
| 254 | 288 |
| 255 content::WebContents* web_contents = | 289 content::WebContents* web_contents = |
| 256 browser()->tab_strip_model()->GetActiveWebContents(); | 290 browser()->tab_strip_model()->GetActiveWebContents(); |
| 257 | 291 |
| 258 // Verify that our loaded page is using a HostZoomMap different from the | 292 // We are forcing non-webview based signin, so we expect the signin page to |
| 259 // one for the default StoragePartition. | 293 // be in a different storage partition, and hence a different HostZoomMap. |
| 260 HostZoomMap* host_zoom_map = HostZoomMap::GetForWebContents(web_contents); | 294 HostZoomMap* host_zoom_map = HostZoomMap::GetForWebContents(web_contents); |
| 261 | 295 |
| 262 // For the webview based sign-in code, the sign in page uses the default host | 296 EXPECT_FALSE(switches::IsEnableWebviewBasedSignin()); |
| 263 // zoom map. | 297 HostZoomMap* default_profile_host_zoom_map = |
| 264 if (!switches::IsEnableWebviewBasedSignin()) { | 298 HostZoomMap::GetDefaultForBrowserContext(browser()->profile()); |
| 265 HostZoomMap* default_profile_host_zoom_map = | 299 EXPECT_NE(host_zoom_map, default_profile_host_zoom_map); |
| 266 HostZoomMap::GetDefaultForBrowserContext(browser()->profile()); | |
| 267 EXPECT_NE(host_zoom_map, default_profile_host_zoom_map); | |
| 268 } | |
| 269 | 300 |
| 270 double new_zoom_level = | 301 double new_zoom_level = |
| 271 host_zoom_map->GetZoomLevelForHostAndScheme(test_scheme, test_host) + 0.5; | 302 host_zoom_map->GetZoomLevelForHostAndScheme(test_scheme, test_host) + 0.5; |
| 272 host_zoom_map->SetZoomLevelForHostAndScheme(test_scheme, test_host, | 303 host_zoom_map->SetZoomLevelForHostAndScheme(test_scheme, test_host, |
| 273 new_zoom_level); | 304 new_zoom_level); |
| 274 observer.BlockUntilZoomLevelForHostHasChanged(test_host); | 305 observer.BlockUntilZoomLevelForHostHasChanged(test_host); |
| 275 EXPECT_EQ(new_zoom_level, host_zoom_map->GetZoomLevelForHostAndScheme( | 306 EXPECT_EQ(new_zoom_level, host_zoom_map->GetZoomLevelForHostAndScheme( |
| 276 test_scheme, test_host)); | 307 test_scheme, test_host)); |
| 277 } | 308 } |
| 278 | 309 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 HostZoomMap::GetDefaultForBrowserContext(child_profile); | 511 HostZoomMap::GetDefaultForBrowserContext(child_profile); |
| 481 ASSERT_TRUE(parent_host_zoom_map); | 512 ASSERT_TRUE(parent_host_zoom_map); |
| 482 ASSERT_TRUE(child_host_zoom_map); | 513 ASSERT_TRUE(child_host_zoom_map); |
| 483 EXPECT_NE(parent_host_zoom_map, child_host_zoom_map); | 514 EXPECT_NE(parent_host_zoom_map, child_host_zoom_map); |
| 484 EXPECT_NE(new_default_zoom_level, child_host_zoom_map->GetDefaultZoomLevel()); | 515 EXPECT_NE(new_default_zoom_level, child_host_zoom_map->GetDefaultZoomLevel()); |
| 485 | 516 |
| 486 parent_profile->GetZoomLevelPrefs()->SetDefaultZoomLevelPref( | 517 parent_profile->GetZoomLevelPrefs()->SetDefaultZoomLevelPref( |
| 487 new_default_zoom_level); | 518 new_default_zoom_level); |
| 488 EXPECT_EQ(new_default_zoom_level, child_host_zoom_map->GetDefaultZoomLevel()); | 519 EXPECT_EQ(new_default_zoom_level, child_host_zoom_map->GetDefaultZoomLevel()); |
| 489 } | 520 } |
| OLD | NEW |