OLD | NEW |
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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "content/browser/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
9 #include "content/browser/frame_host/render_frame_host_impl.h" | 9 #include "content/browser/frame_host/render_frame_host_impl.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // This should not cause the nested iframe to change its zoom. | 364 // This should not cause the nested iframe to change its zoom. |
365 host_zoom_map->SetZoomLevelForHost("b.com", new_zoom_level); | 365 host_zoom_map->SetZoomLevelForHost("b.com", new_zoom_level); |
366 | 366 |
367 EXPECT_DOUBLE_EQ( | 367 EXPECT_DOUBLE_EQ( |
368 1.0, GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); | 368 1.0, GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); |
369 EXPECT_EQ(scale_one_child_width, GetSubframeWidth(child)); | 369 EXPECT_EQ(scale_one_child_width, GetSubframeWidth(child)); |
370 EXPECT_EQ(scale_one_grandchild_width, GetSubframeWidth(grandchild)); | 370 EXPECT_EQ(scale_one_grandchild_width, GetSubframeWidth(grandchild)); |
371 | 371 |
372 // We exclude the remainder of this test on Android since Android does not | 372 // We exclude the remainder of this test on Android since Android does not |
373 // set page zoom levels for loading pages. | 373 // set page zoom levels for loading pages. |
374 // See RenderViewImpl::OnSetZoomLevelForLoadingURL(). | 374 // See RenderFrameImpl::SetHostZoomLevel(). |
375 #if !defined(OS_ANDROID) | 375 #if !defined(OS_ANDROID) |
376 // When we navigate so that b.com is the top-level site, then it has the | 376 // When we navigate so that b.com is the top-level site, then it has the |
377 // expected zoom. | 377 // expected zoom. |
378 GURL new_url = embedded_test_server()->GetURL("b.com", "/title1.html"); | 378 GURL new_url = embedded_test_server()->GetURL("b.com", "/title1.html"); |
379 EXPECT_TRUE(NavigateToURL(shell(), new_url)); | 379 EXPECT_TRUE(NavigateToURL(shell(), new_url)); |
380 EXPECT_DOUBLE_EQ( | 380 EXPECT_DOUBLE_EQ( |
381 new_zoom_factor, | 381 new_zoom_factor, |
382 GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); | 382 GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); |
383 #endif | 383 #endif |
384 } | 384 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 EXPECT_TRUE(IsLastCommittedEntryOfPageType(web_contents(), PAGE_TYPE_NORMAL)); | 584 EXPECT_TRUE(IsLastCommittedEntryOfPageType(web_contents(), PAGE_TYPE_NORMAL)); |
585 EXPECT_EQ(redirect_url, web_contents()->GetLastCommittedURL()); | 585 EXPECT_EQ(redirect_url, web_contents()->GetLastCommittedURL()); |
586 | 586 |
587 EXPECT_NEAR( | 587 EXPECT_NEAR( |
588 kZoomFactorForRedirectedHost, | 588 kZoomFactorForRedirectedHost, |
589 GetMainFrameZoomFactor(web_contents(), main_frame_window_border), | 589 GetMainFrameZoomFactor(web_contents(), main_frame_window_border), |
590 0.001); | 590 0.001); |
591 } | 591 } |
592 #endif | 592 #endif |
593 | 593 |
| 594 // Tests that on cross-site navigation from a page that has a subframe, the |
| 595 // appropriate zoom is applied to the new page. |
| 596 // crbug.com/673065 |
| 597 // Note: We exclude the this test on Android since Android does not set page |
| 598 // zoom levels for loading pages. |
| 599 // See RenderFrameImpl::SetHostZoomLevel(). |
| 600 #if !defined(OS_ANDROID) |
| 601 IN_PROC_BROWSER_TEST_F(IFrameZoomBrowserTest, |
| 602 SubframesDontBreakConnectionToRenderer) { |
| 603 std::string top_level_host("a.com"); |
| 604 GURL main_url(embedded_test_server()->GetURL( |
| 605 top_level_host, "/page_with_iframe_and_link.html")); |
| 606 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 607 NavigationEntry* entry = |
| 608 web_contents()->GetController().GetLastCommittedEntry(); |
| 609 ASSERT_TRUE(entry); |
| 610 GURL loaded_url = HostZoomMap::GetURLFromEntry(entry); |
| 611 EXPECT_EQ(top_level_host, loaded_url.host()); |
| 612 |
| 613 // The following calls must be made when the page's scale factor = 1.0. |
| 614 double main_frame_window_border = GetMainframeWindowBorder(web_contents()); |
| 615 |
| 616 HostZoomMap* host_zoom_map = HostZoomMap::GetForWebContents(web_contents()); |
| 617 double default_zoom_level = host_zoom_map->GetDefaultZoomLevel(); |
| 618 EXPECT_EQ(0.0, default_zoom_level); |
| 619 EXPECT_DOUBLE_EQ( |
| 620 1.0, GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); |
| 621 |
| 622 // Set a zoom for a host that will be navigated to below. |
| 623 const double new_zoom_factor = 2.0; |
| 624 const double new_zoom_level = |
| 625 default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor); |
| 626 host_zoom_map->SetZoomLevelForHost("foo.com", new_zoom_level); |
| 627 |
| 628 // Navigate forward in the same RFH to a site with that host via a |
| 629 // renderer-initiated navigation. |
| 630 { |
| 631 const char kReplacePortNumber[] = |
| 632 "window.domAutomationController.send(setPortNumber(%d));"; |
| 633 uint16_t port_number = embedded_test_server()->port(); |
| 634 bool success = false; |
| 635 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 636 shell(), base::StringPrintf(kReplacePortNumber, port_number), |
| 637 &success)); |
| 638 TestNavigationObserver observer(shell()->web_contents()); |
| 639 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 640 success = false; |
| 641 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 642 shell(), "window.domAutomationController.send(clickCrossSiteLink());", |
| 643 &success)); |
| 644 EXPECT_TRUE(success); |
| 645 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 646 EXPECT_EQ(url, observer.last_navigation_url()); |
| 647 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 648 } |
| 649 |
| 650 // Check that the requested zoom has been applied to the new site. |
| 651 // NOTE: Local observation on Linux has shown that this comparison has to be |
| 652 // approximate. As the common failure mode would be that the zoom is ~1 |
| 653 // instead of ~2, this approximation shouldn't be problematic. |
| 654 EXPECT_NEAR( |
| 655 new_zoom_factor, |
| 656 GetMainFrameZoomFactor(web_contents(), main_frame_window_border), |
| 657 .1); |
| 658 } |
| 659 #endif |
| 660 |
594 } // namespace content | 661 } // namespace content |
OLD | NEW |