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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // This should not cause the nested iframe to change its zoom. | 251 // This should not cause the nested iframe to change its zoom. |
252 host_zoom_map->SetZoomLevelForHost("b.com", new_zoom_level); | 252 host_zoom_map->SetZoomLevelForHost("b.com", new_zoom_level); |
253 | 253 |
254 EXPECT_DOUBLE_EQ( | 254 EXPECT_DOUBLE_EQ( |
255 1.0, GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); | 255 1.0, GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); |
256 EXPECT_EQ(scale_one_child_width, GetSubframeWidth(child)); | 256 EXPECT_EQ(scale_one_child_width, GetSubframeWidth(child)); |
257 EXPECT_EQ(scale_one_grandchild_width, GetSubframeWidth(grandchild)); | 257 EXPECT_EQ(scale_one_grandchild_width, GetSubframeWidth(grandchild)); |
258 | 258 |
259 // We exclude the remainder of this test on Android since Android does not | 259 // We exclude the remainder of this test on Android since Android does not |
260 // set page zoom levels for loading pages. | 260 // set page zoom levels for loading pages. |
261 // See RenderViewImpl::OnSetZoomLevelForLoadingURL(). | 261 // See RenderFrameImpl::SetHostZoomLevel(). |
262 #if !defined(OS_ANDROID) | 262 #if !defined(OS_ANDROID) |
263 // When we navigate so that b.com is the top-level site, then it has the | 263 // When we navigate so that b.com is the top-level site, then it has the |
264 // expected zoom. | 264 // expected zoom. |
265 GURL new_url = embedded_test_server()->GetURL("b.com", "/title1.html"); | 265 GURL new_url = embedded_test_server()->GetURL("b.com", "/title1.html"); |
266 EXPECT_TRUE(NavigateToURL(shell(), new_url)); | 266 EXPECT_TRUE(NavigateToURL(shell(), new_url)); |
267 EXPECT_DOUBLE_EQ( | 267 EXPECT_DOUBLE_EQ( |
268 new_zoom_factor, | 268 new_zoom_factor, |
269 GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); | 269 GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); |
270 #endif | 270 #endif |
271 } | 271 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 EXPECT_TRUE(IsLastCommittedEntryOfPageType(web_contents(), PAGE_TYPE_NORMAL)); | 471 EXPECT_TRUE(IsLastCommittedEntryOfPageType(web_contents(), PAGE_TYPE_NORMAL)); |
472 EXPECT_EQ(redirect_url, web_contents()->GetLastCommittedURL()); | 472 EXPECT_EQ(redirect_url, web_contents()->GetLastCommittedURL()); |
473 | 473 |
474 EXPECT_NEAR( | 474 EXPECT_NEAR( |
475 kZoomFactorForRedirectedHost, | 475 kZoomFactorForRedirectedHost, |
476 GetMainFrameZoomFactor(web_contents(), main_frame_window_border), | 476 GetMainFrameZoomFactor(web_contents(), main_frame_window_border), |
477 0.001); | 477 0.001); |
478 } | 478 } |
479 #endif | 479 #endif |
480 | 480 |
| 481 // Tests that on cross-site navigation from a page that has a subframe, the |
| 482 // appropriate zoom is applied to the new page. |
| 483 // crbug.com/673065 |
| 484 // Note: We exclude the this test on Android since Android does not set page |
| 485 // zoom levels for loading pages. |
| 486 // See RenderFrameImpl::SetHostZoomLevel(). |
| 487 #if !defined(OS_ANDROID) |
| 488 IN_PROC_BROWSER_TEST_F(IFrameZoomBrowserTest, |
| 489 SubframesDontBreakConnectionToRenderer) { |
| 490 std::string top_level_host("a.com"); |
| 491 GURL main_url(embedded_test_server()->GetURL( |
| 492 top_level_host, "/page_with_iframe_and_link.html")); |
| 493 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 494 NavigationEntry* entry = |
| 495 web_contents()->GetController().GetLastCommittedEntry(); |
| 496 ASSERT_TRUE(entry); |
| 497 GURL loaded_url = HostZoomMap::GetURLFromEntry(entry); |
| 498 EXPECT_EQ(top_level_host, loaded_url.host()); |
| 499 |
| 500 // The following calls must be made when the page's scale factor = 1.0. |
| 501 double main_frame_window_border = GetMainframeWindowBorder(web_contents()); |
| 502 |
| 503 HostZoomMap* host_zoom_map = HostZoomMap::GetForWebContents(web_contents()); |
| 504 double default_zoom_level = host_zoom_map->GetDefaultZoomLevel(); |
| 505 EXPECT_EQ(0.0, default_zoom_level); |
| 506 EXPECT_DOUBLE_EQ( |
| 507 1.0, GetMainFrameZoomFactor(web_contents(), main_frame_window_border)); |
| 508 |
| 509 // Set a zoom for a host that will be navigated to below. |
| 510 const double new_zoom_factor = 2.0; |
| 511 const double new_zoom_level = |
| 512 default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor); |
| 513 host_zoom_map->SetZoomLevelForHost("foo.com", new_zoom_level); |
| 514 |
| 515 // Navigate forward in the same RFH to a site with that host via a |
| 516 // renderer-initiated navigation. |
| 517 { |
| 518 const char kReplacePortNumber[] = |
| 519 "window.domAutomationController.send(setPortNumber(%d));"; |
| 520 uint16_t port_number = embedded_test_server()->port(); |
| 521 bool success = false; |
| 522 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 523 shell(), base::StringPrintf(kReplacePortNumber, port_number), |
| 524 &success)); |
| 525 TestNavigationObserver observer(shell()->web_contents()); |
| 526 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); |
| 527 success = false; |
| 528 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 529 shell(), "window.domAutomationController.send(clickCrossSiteLink());", |
| 530 &success)); |
| 531 EXPECT_TRUE(success); |
| 532 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 533 EXPECT_EQ(url, observer.last_navigation_url()); |
| 534 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 535 } |
| 536 |
| 537 // Check that the requested zoom has been applied to the new site. |
| 538 // NOTE: Local observation on Linux has shown that this comparison has to be |
| 539 // approximate. As the common failure mode would be that the zoom is ~1 |
| 540 // instead of ~2, this approximation shouldn't be problematic. |
| 541 EXPECT_NEAR( |
| 542 new_zoom_factor, |
| 543 GetMainFrameZoomFactor(web_contents(), main_frame_window_border), |
| 544 .1); |
| 545 } |
| 546 #endif |
| 547 |
481 } // namespace content | 548 } // namespace content |
OLD | NEW |