| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // when it receives a reply. | 84 // when it receives a reply. |
| 85 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, | 85 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, |
| 86 const std::string& post_message_script, | 86 const std::string& post_message_script, |
| 87 const std::string& reply_status) { | 87 const std::string& reply_status) { |
| 88 // Subtle: msg_queue needs to be declared before the ExecuteScript below, or | 88 // Subtle: msg_queue needs to be declared before the ExecuteScript below, or |
| 89 // else it might miss the message of interest. See https://crbug.com/518729. | 89 // else it might miss the message of interest. See https://crbug.com/518729. |
| 90 DOMMessageQueue msg_queue; | 90 DOMMessageQueue msg_queue; |
| 91 | 91 |
| 92 bool success = false; | 92 bool success = false; |
| 93 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 93 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 94 sender_ftn->current_frame_host(), | 94 sender_ftn, |
| 95 "window.domAutomationController.send(" + post_message_script + ");", | 95 "window.domAutomationController.send(" + post_message_script + ");", |
| 96 &success)); | 96 &success)); |
| 97 EXPECT_TRUE(success); | 97 EXPECT_TRUE(success); |
| 98 | 98 |
| 99 std::string status; | 99 std::string status; |
| 100 while (msg_queue.WaitForMessage(&status)) { | 100 while (msg_queue.WaitForMessage(&status)) { |
| 101 if (status == reply_status) | 101 if (status == reply_status) |
| 102 break; | 102 break; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Helper function to extract and return "window.receivedMessages" from the | 106 // Helper function to extract and return "window.receivedMessages" from the |
| 107 // |sender_ftn| frame. This variable is used in post_message.html to count the | 107 // |sender_ftn| frame. This variable is used in post_message.html to count the |
| 108 // number of messages received via postMessage by the current window. | 108 // number of messages received via postMessage by the current window. |
| 109 int GetReceivedMessages(FrameTreeNode* ftn) { | 109 int GetReceivedMessages(FrameTreeNode* ftn) { |
| 110 int received_messages = 0; | 110 int received_messages = 0; |
| 111 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 111 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 112 ftn->current_frame_host(), | 112 ftn, "window.domAutomationController.send(window.receivedMessages);", |
| 113 "window.domAutomationController.send(window.receivedMessages);", | |
| 114 &received_messages)); | 113 &received_messages)); |
| 115 return received_messages; | 114 return received_messages; |
| 116 } | 115 } |
| 117 | 116 |
| 118 // Helper function to perform a window.open from the |caller_frame| targeting a | 117 // Helper function to perform a window.open from the |caller_frame| targeting a |
| 119 // frame with the specified name. | 118 // frame with the specified name. |
| 120 void NavigateNamedFrame(const ToRenderFrameHost& caller_frame, | 119 void NavigateNamedFrame(const ToRenderFrameHost& caller_frame, |
| 121 const GURL& url, | 120 const GURL& url, |
| 122 const std::string& name) { | 121 const std::string& name) { |
| 123 bool success = false; | 122 bool success = false; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 138 mouse_event.button = blink::WebPointerProperties::ButtonLeft; | 137 mouse_event.button = blink::WebPointerProperties::ButtonLeft; |
| 139 mouse_event.x = x; | 138 mouse_event.x = x; |
| 140 mouse_event.y = y; | 139 mouse_event.y = y; |
| 141 rwh->ForwardMouseEvent(mouse_event); | 140 rwh->ForwardMouseEvent(mouse_event); |
| 142 } | 141 } |
| 143 | 142 |
| 144 // Retrieve document.origin for the frame |ftn|. | 143 // Retrieve document.origin for the frame |ftn|. |
| 145 std::string GetDocumentOrigin(FrameTreeNode* ftn) { | 144 std::string GetDocumentOrigin(FrameTreeNode* ftn) { |
| 146 std::string origin; | 145 std::string origin; |
| 147 EXPECT_TRUE(ExecuteScriptAndExtractString( | 146 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 148 ftn->current_frame_host(), | 147 ftn, "domAutomationController.send(document.origin)", &origin)); |
| 149 "domAutomationController.send(document.origin)", &origin)); | |
| 150 return origin; | 148 return origin; |
| 151 } | 149 } |
| 152 | 150 |
| 153 class RenderWidgetHostMouseEventMonitor { | 151 class RenderWidgetHostMouseEventMonitor { |
| 154 public: | 152 public: |
| 155 explicit RenderWidgetHostMouseEventMonitor(RenderWidgetHost* host) | 153 explicit RenderWidgetHostMouseEventMonitor(RenderWidgetHost* host) |
| 156 : host_(host), event_received_(false) { | 154 : host_(host), event_received_(false) { |
| 157 host_->AddMouseEventCallback( | 155 host_->AddMouseEventCallback( |
| 158 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, | 156 base::Bind(&RenderWidgetHostMouseEventMonitor::MouseEventCallback, |
| 159 base::Unretained(this))); | 157 base::Unretained(this))); |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 ->GetProcess() | 1290 ->GetProcess() |
| 1293 ->GetID(); | 1291 ->GetID(); |
| 1294 int subframe_rvh_id = root->child_at(0) | 1292 int subframe_rvh_id = root->child_at(0) |
| 1295 ->current_frame_host() | 1293 ->current_frame_host() |
| 1296 ->render_view_host() | 1294 ->render_view_host() |
| 1297 ->GetRoutingID(); | 1295 ->GetRoutingID(); |
| 1298 EXPECT_TRUE(RenderViewHost::FromID(subframe_process_id, subframe_rvh_id)); | 1296 EXPECT_TRUE(RenderViewHost::FromID(subframe_process_id, subframe_rvh_id)); |
| 1299 | 1297 |
| 1300 // Use Javascript in the parent to remove one of the frames and ensure that | 1298 // Use Javascript in the parent to remove one of the frames and ensure that |
| 1301 // the subframe goes away. | 1299 // the subframe goes away. |
| 1302 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 1300 EXPECT_TRUE(ExecuteScript(shell(), |
| 1303 "document.body.removeChild(" | 1301 "document.body.removeChild(" |
| 1304 "document.querySelectorAll('iframe')[0])")); | 1302 "document.querySelectorAll('iframe')[0])")); |
| 1305 ASSERT_EQ(1U, root->child_count()); | 1303 ASSERT_EQ(1U, root->child_count()); |
| 1306 | 1304 |
| 1307 // Load a new same-site page in the top-level frame and ensure the other | 1305 // Load a new same-site page in the top-level frame and ensure the other |
| 1308 // subframe goes away. | 1306 // subframe goes away. |
| 1309 GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | 1307 GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 1310 NavigateToURL(shell(), new_url); | 1308 NavigateToURL(shell(), new_url); |
| 1311 ASSERT_EQ(0U, root->child_count()); | 1309 ASSERT_EQ(0U, root->child_count()); |
| 1312 | 1310 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 " D = http://f00.com/", | 1552 " D = http://f00.com/", |
| 1555 DepictFrameTree(root)); | 1553 DepictFrameTree(root)); |
| 1556 | 1554 |
| 1557 // Navigate the iframe itself to about:blank using a script executing in its | 1555 // Navigate the iframe itself to about:blank using a script executing in its |
| 1558 // own context. It should stay in the same SiteInstance as before, not the | 1556 // own context. It should stay in the same SiteInstance as before, not the |
| 1559 // parent one. | 1557 // parent one. |
| 1560 std::string script( | 1558 std::string script( |
| 1561 "window.domAutomationController.send(" | 1559 "window.domAutomationController.send(" |
| 1562 "window.location.href = 'about:blank');"); | 1560 "window.location.href = 'about:blank');"); |
| 1563 TestFrameNavigationObserver frame_observer(child); | 1561 TestFrameNavigationObserver frame_observer(child); |
| 1564 EXPECT_TRUE(ExecuteScript(child->current_frame_host(), script)); | 1562 EXPECT_TRUE(ExecuteScript(child, script)); |
| 1565 frame_observer.Wait(); | 1563 frame_observer.Wait(); |
| 1566 EXPECT_EQ(about_blank_url, child->current_url()); | 1564 EXPECT_EQ(about_blank_url, child->current_url()); |
| 1567 | 1565 |
| 1568 // Ensure that we have navigated using the top level process. | 1566 // Ensure that we have navigated using the top level process. |
| 1569 EXPECT_EQ( | 1567 EXPECT_EQ( |
| 1570 " Site A ------------ proxies for D\n" | 1568 " Site A ------------ proxies for D\n" |
| 1571 " |--Site D ------- proxies for A\n" | 1569 " |--Site D ------- proxies for A\n" |
| 1572 " +--Site A ------- proxies for D\n" | 1570 " +--Site A ------- proxies for D\n" |
| 1573 " +--Site A -- proxies for D\n" | 1571 " +--Site A -- proxies for D\n" |
| 1574 "Where A = http://a.com/\n" | 1572 "Where A = http://a.com/\n" |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 RenderProcessHost* child_process = | 1973 RenderProcessHost* child_process = |
| 1976 root->child_at(0)->current_frame_host()->GetProcess(); | 1974 root->child_at(0)->current_frame_host()->GetProcess(); |
| 1977 RenderProcessHostWatcher crash_observer( | 1975 RenderProcessHostWatcher crash_observer( |
| 1978 child_process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 1976 child_process, RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
| 1979 child_process->Shutdown(0, false); | 1977 child_process->Shutdown(0, false); |
| 1980 crash_observer.Wait(); | 1978 crash_observer.Wait(); |
| 1981 | 1979 |
| 1982 // Add a new child frame to the third subframe. | 1980 // Add a new child frame to the third subframe. |
| 1983 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); | 1981 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); |
| 1984 EXPECT_TRUE(ExecuteScript( | 1982 EXPECT_TRUE(ExecuteScript( |
| 1985 root->child_at(2)->current_frame_host(), | 1983 root->child_at(2), |
| 1986 "document.body.appendChild(document.createElement('iframe'));")); | 1984 "document.body.appendChild(document.createElement('iframe'));")); |
| 1987 frame_observer.Wait(); | 1985 frame_observer.Wait(); |
| 1988 | 1986 |
| 1989 // The new frame should have a RenderFrameProxyHost for B, but it should not | 1987 // The new frame should have a RenderFrameProxyHost for B, but it should not |
| 1990 // be alive, and B should still not have a process (verified by last line of | 1988 // be alive, and B should still not have a process (verified by last line of |
| 1991 // expected DepictFrameTree output). | 1989 // expected DepictFrameTree output). |
| 1992 EXPECT_EQ( | 1990 EXPECT_EQ( |
| 1993 " Site A ------------ proxies for B\n" | 1991 " Site A ------------ proxies for B\n" |
| 1994 " |--Site B ------- proxies for A\n" | 1992 " |--Site B ------- proxies for A\n" |
| 1995 " |--Site A ------- proxies for B\n" | 1993 " |--Site A ------- proxies for B\n" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2031 CreateChildFrameAfterKillingOpener) { | 2029 CreateChildFrameAfterKillingOpener) { |
| 2032 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | 2030 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 2033 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 2031 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 2034 | 2032 |
| 2035 // It is safe to obtain the root frame tree node here, as it doesn't change. | 2033 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 2036 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 2034 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 2037 SiteInstance* site_instance_a = root->current_frame_host()->GetSiteInstance(); | 2035 SiteInstance* site_instance_a = root->current_frame_host()->GetSiteInstance(); |
| 2038 | 2036 |
| 2039 // Open a popup and navigate it cross-process to b.com. | 2037 // Open a popup and navigate it cross-process to b.com. |
| 2040 ShellAddedObserver new_shell_observer; | 2038 ShellAddedObserver new_shell_observer; |
| 2041 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), | 2039 EXPECT_TRUE(ExecuteScript(root, "popup = window.open('about:blank');")); |
| 2042 "popup = window.open('about:blank');")); | |
| 2043 Shell* popup = new_shell_observer.GetShell(); | 2040 Shell* popup = new_shell_observer.GetShell(); |
| 2044 GURL popup_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | 2041 GURL popup_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 2045 EXPECT_TRUE(NavigateToURL(popup, popup_url)); | 2042 EXPECT_TRUE(NavigateToURL(popup, popup_url)); |
| 2046 | 2043 |
| 2047 // Verify that each top-level frame has proxies in the other's SiteInstance. | 2044 // Verify that each top-level frame has proxies in the other's SiteInstance. |
| 2048 FrameTreeNode* popup_root = | 2045 FrameTreeNode* popup_root = |
| 2049 static_cast<WebContentsImpl*>(popup->web_contents()) | 2046 static_cast<WebContentsImpl*>(popup->web_contents()) |
| 2050 ->GetFrameTree() | 2047 ->GetFrameTree() |
| 2051 ->root(); | 2048 ->root(); |
| 2052 EXPECT_EQ( | 2049 EXPECT_EQ( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2078 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 2075 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 2079 | 2076 |
| 2080 // The popup's proxy in a.com should still not be live. Re-navigating the | 2077 // The popup's proxy in a.com should still not be live. Re-navigating the |
| 2081 // main window to a.com doesn't reinitialize a.com proxies for popups | 2078 // main window to a.com doesn't reinitialize a.com proxies for popups |
| 2082 // previously opened from the main window. | 2079 // previously opened from the main window. |
| 2083 EXPECT_FALSE(rfph->is_render_frame_proxy_live()); | 2080 EXPECT_FALSE(rfph->is_render_frame_proxy_live()); |
| 2084 | 2081 |
| 2085 // Add a new child frame on the popup. | 2082 // Add a new child frame on the popup. |
| 2086 RenderFrameHostCreatedObserver frame_observer(popup->web_contents(), 1); | 2083 RenderFrameHostCreatedObserver frame_observer(popup->web_contents(), 1); |
| 2087 EXPECT_TRUE(ExecuteScript( | 2084 EXPECT_TRUE(ExecuteScript( |
| 2088 popup->web_contents(), | 2085 popup, "document.body.appendChild(document.createElement('iframe'));")); |
| 2089 "document.body.appendChild(document.createElement('iframe'));")); | |
| 2090 frame_observer.Wait(); | 2086 frame_observer.Wait(); |
| 2091 | 2087 |
| 2092 // Both the child frame's and its parent's proxies should still not be live. | 2088 // Both the child frame's and its parent's proxies should still not be live. |
| 2093 // The main page can't reach them since it lost reference to the popup after | 2089 // The main page can't reach them since it lost reference to the popup after |
| 2094 // it crashed, so there is no need to create them. | 2090 // it crashed, so there is no need to create them. |
| 2095 EXPECT_FALSE(rfph->is_render_frame_proxy_live()); | 2091 EXPECT_FALSE(rfph->is_render_frame_proxy_live()); |
| 2096 RenderFrameProxyHost* child_rfph = | 2092 RenderFrameProxyHost* child_rfph = |
| 2097 popup_root->child_at(0)->render_manager()->GetRenderFrameProxyHost( | 2093 popup_root->child_at(0)->render_manager()->GetRenderFrameProxyHost( |
| 2098 site_instance_a); | 2094 site_instance_a); |
| 2099 EXPECT_TRUE(child_rfph); | 2095 EXPECT_TRUE(child_rfph); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2261 | 2257 |
| 2262 EXPECT_EQ( | 2258 EXPECT_EQ( |
| 2263 " Site A ------------ proxies for B\n" | 2259 " Site A ------------ proxies for B\n" |
| 2264 " +--Site B ------- proxies for A\n" | 2260 " +--Site B ------- proxies for A\n" |
| 2265 "Where A = http://b.com/\n" | 2261 "Where A = http://b.com/\n" |
| 2266 " B = http://baz.com/", | 2262 " B = http://baz.com/", |
| 2267 DepictFrameTree(root)); | 2263 DepictFrameTree(root)); |
| 2268 | 2264 |
| 2269 // Add a new child frame to the top-level frame. | 2265 // Add a new child frame to the top-level frame. |
| 2270 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); | 2266 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); |
| 2271 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 2267 EXPECT_TRUE(ExecuteScript(shell(), "addFrame('data:text/html,foo');")); |
| 2272 "window.domAutomationController.send(" | |
| 2273 " addFrame('data:text/html,foo'));")); | |
| 2274 frame_observer.Wait(); | 2268 frame_observer.Wait(); |
| 2275 | 2269 |
| 2276 // The new frame should have a proxy in Site B, for use by the old frame. | 2270 // The new frame should have a proxy in Site B, for use by the old frame. |
| 2277 EXPECT_EQ( | 2271 EXPECT_EQ( |
| 2278 " Site A ------------ proxies for B\n" | 2272 " Site A ------------ proxies for B\n" |
| 2279 " |--Site B ------- proxies for A\n" | 2273 " |--Site B ------- proxies for A\n" |
| 2280 " +--Site A ------- proxies for B\n" | 2274 " +--Site A ------- proxies for B\n" |
| 2281 "Where A = http://b.com/\n" | 2275 "Where A = http://b.com/\n" |
| 2282 " B = http://baz.com/", | 2276 " B = http://baz.com/", |
| 2283 DepictFrameTree(root)); | 2277 DepictFrameTree(root)); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2714 " Site A ------------ proxies for B\n" | 2708 " Site A ------------ proxies for B\n" |
| 2715 " +--Site B ------- proxies for A\n" | 2709 " +--Site B ------- proxies for A\n" |
| 2716 "Where A = http://a.com/\n" | 2710 "Where A = http://a.com/\n" |
| 2717 " B = http://b.com/", | 2711 " B = http://b.com/", |
| 2718 DepictFrameTree(root)); | 2712 DepictFrameTree(root)); |
| 2719 | 2713 |
| 2720 FrameTreeNode* child = root->child_at(0); | 2714 FrameTreeNode* child = root->child_at(0); |
| 2721 | 2715 |
| 2722 std::string margin_width; | 2716 std::string margin_width; |
| 2723 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2717 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2724 child->current_frame_host(), | 2718 child, |
| 2725 "window.domAutomationController.send(" | 2719 "window.domAutomationController.send(" |
| 2726 "document.body.getAttribute('marginwidth'));", | 2720 "document.body.getAttribute('marginwidth'));", |
| 2727 &margin_width)); | 2721 &margin_width)); |
| 2728 EXPECT_EQ("10", margin_width); | 2722 EXPECT_EQ("10", margin_width); |
| 2729 | 2723 |
| 2730 std::string margin_height; | 2724 std::string margin_height; |
| 2731 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2725 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2732 child->current_frame_host(), | 2726 child, |
| 2733 "window.domAutomationController.send(" | 2727 "window.domAutomationController.send(" |
| 2734 "document.body.getAttribute('marginheight'));", | 2728 "document.body.getAttribute('marginheight'));", |
| 2735 &margin_height)); | 2729 &margin_height)); |
| 2736 EXPECT_EQ("50", margin_height); | 2730 EXPECT_EQ("50", margin_height); |
| 2737 | 2731 |
| 2738 // Run the test over variety of parent/child cases. | 2732 // Run the test over variety of parent/child cases. |
| 2739 GURL urls[] = { | 2733 GURL urls[] = { |
| 2740 // Remote to remote. | 2734 // Remote to remote. |
| 2741 embedded_test_server()->GetURL("c.com", "/title2.html"), | 2735 embedded_test_server()->GetURL("c.com", "/title2.html"), |
| 2742 // Remote to local. | 2736 // Remote to local. |
| 2743 embedded_test_server()->GetURL("a.com", "/title1.html"), | 2737 embedded_test_server()->GetURL("a.com", "/title1.html"), |
| 2744 // Local to remote. | 2738 // Local to remote. |
| 2745 embedded_test_server()->GetURL("b.com", "/title2.html") | 2739 embedded_test_server()->GetURL("b.com", "/title2.html") |
| 2746 }; | 2740 }; |
| 2747 | 2741 |
| 2748 int current_margin_width = 15; | 2742 int current_margin_width = 15; |
| 2749 int current_margin_height = 25; | 2743 int current_margin_height = 25; |
| 2750 | 2744 |
| 2751 // Before each navigation, we change the marginwidth and marginheight | 2745 // Before each navigation, we change the marginwidth and marginheight |
| 2752 // properties of the frame. We then check whether those properties are applied | 2746 // properties of the frame. We then check whether those properties are applied |
| 2753 // correctly after the navigation has completed. | 2747 // correctly after the navigation has completed. |
| 2754 for (size_t i = 0; i < arraysize(urls); ++i) { | 2748 for (size_t i = 0; i < arraysize(urls); ++i) { |
| 2755 // Change marginwidth and marginheight before navigating. | 2749 // Change marginwidth and marginheight before navigating. |
| 2756 EXPECT_TRUE(ExecuteScript( | 2750 EXPECT_TRUE(ExecuteScript( |
| 2757 root->current_frame_host(), | 2751 root, |
| 2758 base::StringPrintf( | 2752 base::StringPrintf("document.getElementById('child-1').setAttribute(" |
| 2759 "document.getElementById('child-1').setAttribute(" | 2753 " 'marginwidth', '%d');", |
| 2760 " 'marginwidth', '%d');", current_margin_width))); | 2754 current_margin_width))); |
| 2761 EXPECT_TRUE(ExecuteScript( | 2755 EXPECT_TRUE(ExecuteScript( |
| 2762 root->current_frame_host(), | 2756 root, |
| 2763 base::StringPrintf( | 2757 base::StringPrintf("document.getElementById('child-1').setAttribute(" |
| 2764 "document.getElementById('child-1').setAttribute(" | 2758 " 'marginheight', '%d');", |
| 2765 " 'marginheight', '%d');", current_margin_height))); | 2759 current_margin_height))); |
| 2766 | 2760 |
| 2767 NavigateFrameToURL(child, urls[i]); | 2761 NavigateFrameToURL(child, urls[i]); |
| 2768 | 2762 |
| 2769 std::string actual_margin_width; | 2763 std::string actual_margin_width; |
| 2770 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2764 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2771 child->current_frame_host(), | 2765 child, |
| 2772 "window.domAutomationController.send(" | 2766 "window.domAutomationController.send(" |
| 2773 "document.body.getAttribute('marginwidth'));", | 2767 "document.body.getAttribute('marginwidth'));", |
| 2774 &actual_margin_width)); | 2768 &actual_margin_width)); |
| 2775 EXPECT_EQ(base::IntToString(current_margin_width), actual_margin_width); | 2769 EXPECT_EQ(base::IntToString(current_margin_width), actual_margin_width); |
| 2776 | 2770 |
| 2777 std::string actual_margin_height; | 2771 std::string actual_margin_height; |
| 2778 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2772 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2779 child->current_frame_host(), | 2773 child, |
| 2780 "window.domAutomationController.send(" | 2774 "window.domAutomationController.send(" |
| 2781 "document.body.getAttribute('marginheight'));", | 2775 "document.body.getAttribute('marginheight'));", |
| 2782 &actual_margin_height)); | 2776 &actual_margin_height)); |
| 2783 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); | 2777 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); |
| 2784 | 2778 |
| 2785 current_margin_width += 5; | 2779 current_margin_width += 5; |
| 2786 current_margin_height += 10; | 2780 current_margin_height += 10; |
| 2787 } | 2781 } |
| 2788 } | 2782 } |
| 2789 | 2783 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2814 FrameTreeNode* tiptop_child = root->child_at(0); | 2808 FrameTreeNode* tiptop_child = root->child_at(0); |
| 2815 FrameTreeNode* middle_child = root->child_at(0)->child_at(0); | 2809 FrameTreeNode* middle_child = root->child_at(0)->child_at(0); |
| 2816 FrameTreeNode* lowest_child = root->child_at(0)->child_at(0)->child_at(0); | 2810 FrameTreeNode* lowest_child = root->child_at(0)->child_at(0)->child_at(0); |
| 2817 | 2811 |
| 2818 // Check that b.com frame's location.ancestorOrigins contains the correct | 2812 // Check that b.com frame's location.ancestorOrigins contains the correct |
| 2819 // origin for the parent. The origin should have been replicated as part of | 2813 // origin for the parent. The origin should have been replicated as part of |
| 2820 // the ViewMsg_New message that created the parent's RenderFrameProxy in | 2814 // the ViewMsg_New message that created the parent's RenderFrameProxy in |
| 2821 // b.com's process. | 2815 // b.com's process. |
| 2822 int ancestor_origins_length = 0; | 2816 int ancestor_origins_length = 0; |
| 2823 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 2817 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 2824 tiptop_child->current_frame_host(), | 2818 tiptop_child, |
| 2825 "window.domAutomationController.send(location.ancestorOrigins.length);", | 2819 "window.domAutomationController.send(location.ancestorOrigins.length);", |
| 2826 &ancestor_origins_length)); | 2820 &ancestor_origins_length)); |
| 2827 EXPECT_EQ(1, ancestor_origins_length); | 2821 EXPECT_EQ(1, ancestor_origins_length); |
| 2828 std::string result; | 2822 std::string result; |
| 2829 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2823 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2830 tiptop_child->current_frame_host(), | 2824 tiptop_child, |
| 2831 "window.domAutomationController.send(location.ancestorOrigins[0]);", | 2825 "window.domAutomationController.send(location.ancestorOrigins[0]);", |
| 2832 &result)); | 2826 &result)); |
| 2833 EXPECT_EQ(a_origin, result + "/"); | 2827 EXPECT_EQ(a_origin, result + "/"); |
| 2834 | 2828 |
| 2835 // Check that c.com frame's location.ancestorOrigins contains the correct | 2829 // Check that c.com frame's location.ancestorOrigins contains the correct |
| 2836 // origin for its two ancestors. The topmost parent origin should be | 2830 // origin for its two ancestors. The topmost parent origin should be |
| 2837 // replicated as part of ViewMsg_New, and the middle frame (b.com's) origin | 2831 // replicated as part of ViewMsg_New, and the middle frame (b.com's) origin |
| 2838 // should be replicated as part of FrameMsg_NewFrameProxy sent for b.com's | 2832 // should be replicated as part of FrameMsg_NewFrameProxy sent for b.com's |
| 2839 // frame in c.com's process. | 2833 // frame in c.com's process. |
| 2840 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 2834 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 2841 middle_child->current_frame_host(), | 2835 middle_child, |
| 2842 "window.domAutomationController.send(location.ancestorOrigins.length);", | 2836 "window.domAutomationController.send(location.ancestorOrigins.length);", |
| 2843 &ancestor_origins_length)); | 2837 &ancestor_origins_length)); |
| 2844 EXPECT_EQ(2, ancestor_origins_length); | 2838 EXPECT_EQ(2, ancestor_origins_length); |
| 2845 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2839 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2846 middle_child->current_frame_host(), | 2840 middle_child, |
| 2847 "window.domAutomationController.send(location.ancestorOrigins[0]);", | 2841 "window.domAutomationController.send(location.ancestorOrigins[0]);", |
| 2848 &result)); | 2842 &result)); |
| 2849 EXPECT_EQ(b_origin, result + "/"); | 2843 EXPECT_EQ(b_origin, result + "/"); |
| 2850 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2844 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2851 middle_child->current_frame_host(), | 2845 middle_child, |
| 2852 "window.domAutomationController.send(location.ancestorOrigins[1]);", | 2846 "window.domAutomationController.send(location.ancestorOrigins[1]);", |
| 2853 &result)); | 2847 &result)); |
| 2854 EXPECT_EQ(a_origin, result + "/"); | 2848 EXPECT_EQ(a_origin, result + "/"); |
| 2855 | 2849 |
| 2856 // Check that the nested a.com frame's location.ancestorOrigins contains the | 2850 // Check that the nested a.com frame's location.ancestorOrigins contains the |
| 2857 // correct origin for its three ancestors. | 2851 // correct origin for its three ancestors. |
| 2858 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 2852 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 2859 lowest_child->current_frame_host(), | 2853 lowest_child, |
| 2860 "window.domAutomationController.send(location.ancestorOrigins.length);", | 2854 "window.domAutomationController.send(location.ancestorOrigins.length);", |
| 2861 &ancestor_origins_length)); | 2855 &ancestor_origins_length)); |
| 2862 EXPECT_EQ(3, ancestor_origins_length); | 2856 EXPECT_EQ(3, ancestor_origins_length); |
| 2863 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2857 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2864 lowest_child->current_frame_host(), | 2858 lowest_child, |
| 2865 "window.domAutomationController.send(location.ancestorOrigins[0]);", | 2859 "window.domAutomationController.send(location.ancestorOrigins[0]);", |
| 2866 &result)); | 2860 &result)); |
| 2867 EXPECT_EQ(c_origin, result + "/"); | 2861 EXPECT_EQ(c_origin, result + "/"); |
| 2868 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2862 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2869 lowest_child->current_frame_host(), | 2863 lowest_child, |
| 2870 "window.domAutomationController.send(location.ancestorOrigins[1]);", | 2864 "window.domAutomationController.send(location.ancestorOrigins[1]);", |
| 2871 &result)); | 2865 &result)); |
| 2872 EXPECT_EQ(b_origin, result + "/"); | 2866 EXPECT_EQ(b_origin, result + "/"); |
| 2873 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2867 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2874 lowest_child->current_frame_host(), | 2868 lowest_child, |
| 2875 "window.domAutomationController.send(location.ancestorOrigins[2]);", | 2869 "window.domAutomationController.send(location.ancestorOrigins[2]);", |
| 2876 &result)); | 2870 &result)); |
| 2877 EXPECT_EQ(a_origin, result + "/"); | 2871 EXPECT_EQ(a_origin, result + "/"); |
| 2878 } | 2872 } |
| 2879 | 2873 |
| 2880 // Check that iframe sandbox flags are replicated correctly. | 2874 // Check that iframe sandbox flags are replicated correctly. |
| 2881 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SandboxFlagsReplication) { | 2875 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SandboxFlagsReplication) { |
| 2882 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); | 2876 GURL main_url(embedded_test_server()->GetURL("/sandboxed_frames.html")); |
| 2883 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 2877 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 2884 | 2878 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2901 // Load cross-site page into subframe's subframe. | 2895 // Load cross-site page into subframe's subframe. |
| 2902 ASSERT_EQ(2U, root->child_at(1)->child_count()); | 2896 ASSERT_EQ(2U, root->child_at(1)->child_count()); |
| 2903 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title1.html")); | 2897 GURL bar_url(embedded_test_server()->GetURL("bar.com", "/title1.html")); |
| 2904 NavigateFrameToURL(root->child_at(1)->child_at(0), bar_url); | 2898 NavigateFrameToURL(root->child_at(1)->child_at(0), bar_url); |
| 2905 EXPECT_TRUE(observer.last_navigation_succeeded()); | 2899 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 2906 EXPECT_EQ(bar_url, observer.last_navigation_url()); | 2900 EXPECT_EQ(bar_url, observer.last_navigation_url()); |
| 2907 | 2901 |
| 2908 // Opening a popup in the sandboxed foo.com iframe should fail. | 2902 // Opening a popup in the sandboxed foo.com iframe should fail. |
| 2909 bool success = false; | 2903 bool success = false; |
| 2910 EXPECT_TRUE( | 2904 EXPECT_TRUE( |
| 2911 ExecuteScriptAndExtractBool(root->child_at(1)->current_frame_host(), | 2905 ExecuteScriptAndExtractBool(root->child_at(1), |
| 2912 "window.domAutomationController.send(" | 2906 "window.domAutomationController.send(" |
| 2913 "!window.open('data:text/html,dataurl'));", | 2907 "!window.open('data:text/html,dataurl'));", |
| 2914 &success)); | 2908 &success)); |
| 2915 EXPECT_TRUE(success); | 2909 EXPECT_TRUE(success); |
| 2916 EXPECT_EQ(1u, Shell::windows().size()); | 2910 EXPECT_EQ(1u, Shell::windows().size()); |
| 2917 | 2911 |
| 2918 // Opening a popup in a frame whose parent is sandboxed should also fail. | 2912 // Opening a popup in a frame whose parent is sandboxed should also fail. |
| 2919 // Here, bar.com frame's sandboxed parent frame is a remote frame in | 2913 // Here, bar.com frame's sandboxed parent frame is a remote frame in |
| 2920 // bar.com's process. | 2914 // bar.com's process. |
| 2921 success = false; | 2915 success = false; |
| 2922 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2916 EXPECT_TRUE( |
| 2923 root->child_at(1)->child_at(0)->current_frame_host(), | 2917 ExecuteScriptAndExtractBool(root->child_at(1)->child_at(0), |
| 2924 "window.domAutomationController.send(" | 2918 "window.domAutomationController.send(" |
| 2925 "!window.open('data:text/html,dataurl'));", | 2919 "!window.open('data:text/html,dataurl'));", |
| 2926 &success)); | 2920 &success)); |
| 2927 EXPECT_TRUE(success); | 2921 EXPECT_TRUE(success); |
| 2928 EXPECT_EQ(1u, Shell::windows().size()); | 2922 EXPECT_EQ(1u, Shell::windows().size()); |
| 2929 | 2923 |
| 2930 // Same, but now try the case where bar.com frame's sandboxed parent is a | 2924 // Same, but now try the case where bar.com frame's sandboxed parent is a |
| 2931 // local frame in bar.com's process. | 2925 // local frame in bar.com's process. |
| 2932 success = false; | 2926 success = false; |
| 2933 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2927 EXPECT_TRUE( |
| 2934 root->child_at(2)->child_at(0)->current_frame_host(), | 2928 ExecuteScriptAndExtractBool(root->child_at(2)->child_at(0), |
| 2935 "window.domAutomationController.send(" | 2929 "window.domAutomationController.send(" |
| 2936 "!window.open('data:text/html,dataurl'));", | 2930 "!window.open('data:text/html,dataurl'));", |
| 2937 &success)); | 2931 &success)); |
| 2938 EXPECT_TRUE(success); | 2932 EXPECT_TRUE(success); |
| 2939 EXPECT_EQ(1u, Shell::windows().size()); | 2933 EXPECT_EQ(1u, Shell::windows().size()); |
| 2940 | 2934 |
| 2941 // Check that foo.com frame's location.ancestorOrigins contains the correct | 2935 // Check that foo.com frame's location.ancestorOrigins contains the correct |
| 2942 // origin for the parent, which should be unaffected by sandboxing. | 2936 // origin for the parent, which should be unaffected by sandboxing. |
| 2943 int ancestor_origins_length = 0; | 2937 int ancestor_origins_length = 0; |
| 2944 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 2938 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 2945 root->child_at(1)->current_frame_host(), | 2939 root->child_at(1), |
| 2946 "window.domAutomationController.send(location.ancestorOrigins.length);", | 2940 "window.domAutomationController.send(location.ancestorOrigins.length);", |
| 2947 &ancestor_origins_length)); | 2941 &ancestor_origins_length)); |
| 2948 EXPECT_EQ(1, ancestor_origins_length); | 2942 EXPECT_EQ(1, ancestor_origins_length); |
| 2949 std::string result; | 2943 std::string result; |
| 2950 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2944 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2951 root->child_at(1)->current_frame_host(), | 2945 root->child_at(1), |
| 2952 "window.domAutomationController.send(location.ancestorOrigins[0]);", | 2946 "window.domAutomationController.send(location.ancestorOrigins[0]);", |
| 2953 &result)); | 2947 &result)); |
| 2954 EXPECT_EQ(result + "/", main_url.GetOrigin().spec()); | 2948 EXPECT_EQ(result + "/", main_url.GetOrigin().spec()); |
| 2955 | 2949 |
| 2956 // Now check location.ancestorOrigins for the bar.com frame. The middle frame | 2950 // Now check location.ancestorOrigins for the bar.com frame. The middle frame |
| 2957 // (foo.com's) origin should be unique, since that frame is sandboxed, and | 2951 // (foo.com's) origin should be unique, since that frame is sandboxed, and |
| 2958 // the top frame should match |main_url|. | 2952 // the top frame should match |main_url|. |
| 2959 FrameTreeNode* bottom_child = root->child_at(1)->child_at(0); | 2953 FrameTreeNode* bottom_child = root->child_at(1)->child_at(0); |
| 2960 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 2954 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 2961 bottom_child->current_frame_host(), | 2955 bottom_child, |
| 2962 "window.domAutomationController.send(location.ancestorOrigins.length);", | 2956 "window.domAutomationController.send(location.ancestorOrigins.length);", |
| 2963 &ancestor_origins_length)); | 2957 &ancestor_origins_length)); |
| 2964 EXPECT_EQ(2, ancestor_origins_length); | 2958 EXPECT_EQ(2, ancestor_origins_length); |
| 2965 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2959 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2966 bottom_child->current_frame_host(), | 2960 bottom_child, |
| 2967 "window.domAutomationController.send(location.ancestorOrigins[0]);", | 2961 "window.domAutomationController.send(location.ancestorOrigins[0]);", |
| 2968 &result)); | 2962 &result)); |
| 2969 EXPECT_EQ("null", result); | 2963 EXPECT_EQ("null", result); |
| 2970 EXPECT_TRUE(ExecuteScriptAndExtractString( | 2964 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2971 bottom_child->current_frame_host(), | 2965 bottom_child, |
| 2972 "window.domAutomationController.send(location.ancestorOrigins[1]);", | 2966 "window.domAutomationController.send(location.ancestorOrigins[1]);", |
| 2973 &result)); | 2967 &result)); |
| 2974 EXPECT_EQ(main_url.GetOrigin().spec(), result + "/"); | 2968 EXPECT_EQ(main_url.GetOrigin().spec(), result + "/"); |
| 2975 } | 2969 } |
| 2976 | 2970 |
| 2977 // Check that dynamic updates to iframe sandbox flags are propagated correctly. | 2971 // Check that dynamic updates to iframe sandbox flags are propagated correctly. |
| 2978 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DynamicSandboxFlags) { | 2972 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DynamicSandboxFlags) { |
| 2979 GURL main_url( | 2973 GURL main_url( |
| 2980 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); | 2974 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); |
| 2981 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 2975 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3000 EXPECT_EQ(blink::WebSandboxFlags::None, | 2994 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3001 root->child_at(0)->pending_sandbox_flags()); | 2995 root->child_at(0)->pending_sandbox_flags()); |
| 3002 EXPECT_EQ(blink::WebSandboxFlags::None, | 2996 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3003 root->child_at(0)->effective_sandbox_flags()); | 2997 root->child_at(0)->effective_sandbox_flags()); |
| 3004 EXPECT_EQ(blink::WebSandboxFlags::None, | 2998 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3005 root->child_at(1)->pending_sandbox_flags()); | 2999 root->child_at(1)->pending_sandbox_flags()); |
| 3006 EXPECT_EQ(blink::WebSandboxFlags::None, | 3000 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3007 root->child_at(1)->effective_sandbox_flags()); | 3001 root->child_at(1)->effective_sandbox_flags()); |
| 3008 | 3002 |
| 3009 // Dynamically update sandbox flags for the first frame. | 3003 // Dynamically update sandbox flags for the first frame. |
| 3010 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 3004 EXPECT_TRUE(ExecuteScript( |
| 3011 "window.domAutomationController.send(" | 3005 shell(), |
| 3012 "document.querySelector('iframe').sandbox=" | 3006 "document.querySelector('iframe').sandbox='allow-scripts';")); |
| 3013 "'allow-scripts');")); | |
| 3014 | 3007 |
| 3015 // Check that updated sandbox flags are propagated to browser process. | 3008 // Check that updated sandbox flags are propagated to browser process. |
| 3016 // The new flags should be reflected in pending_sandbox_flags(), while | 3009 // The new flags should be reflected in pending_sandbox_flags(), while |
| 3017 // effective_sandbox_flags() should still reflect the old flags, because | 3010 // effective_sandbox_flags() should still reflect the old flags, because |
| 3018 // sandbox flag updates take place only after navigations. "allow-scripts" | 3011 // sandbox flag updates take place only after navigations. "allow-scripts" |
| 3019 // resets both SandboxFlags::Scripts and SandboxFlags::AutomaticFeatures bits | 3012 // resets both SandboxFlags::Scripts and SandboxFlags::AutomaticFeatures bits |
| 3020 // per blink::parseSandboxPolicy(). | 3013 // per blink::parseSandboxPolicy(). |
| 3021 blink::WebSandboxFlags expected_flags = | 3014 blink::WebSandboxFlags expected_flags = |
| 3022 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 3015 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 3023 ~blink::WebSandboxFlags::AutomaticFeatures; | 3016 ~blink::WebSandboxFlags::AutomaticFeatures; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3045 " C = http://baz.com/", | 3038 " C = http://baz.com/", |
| 3046 DepictFrameTree(root)); | 3039 DepictFrameTree(root)); |
| 3047 | 3040 |
| 3048 // Confirm that the browser process has updated the frame's current sandbox | 3041 // Confirm that the browser process has updated the frame's current sandbox |
| 3049 // flags. | 3042 // flags. |
| 3050 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 3043 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 3051 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 3044 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| 3052 | 3045 |
| 3053 // Opening a popup in the now-sandboxed frame should fail. | 3046 // Opening a popup in the now-sandboxed frame should fail. |
| 3054 bool success = false; | 3047 bool success = false; |
| 3055 EXPECT_TRUE( | 3048 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3056 ExecuteScriptAndExtractBool(root->child_at(0)->current_frame_host(), | 3049 root->child_at(0), |
| 3057 "window.domAutomationController.send(" | 3050 "window.domAutomationController.send(" |
| 3058 "!window.open('data:text/html,dataurl'));", | 3051 " !window.open('data:text/html,dataurl'));", |
| 3059 &success)); | 3052 &success)); |
| 3060 EXPECT_TRUE(success); | 3053 EXPECT_TRUE(success); |
| 3061 EXPECT_EQ(1u, Shell::windows().size()); | 3054 EXPECT_EQ(1u, Shell::windows().size()); |
| 3062 | 3055 |
| 3063 // Navigate the child of the now-sandboxed frame to a page on baz.com. The | 3056 // Navigate the child of the now-sandboxed frame to a page on baz.com. The |
| 3064 // child should inherit the latest sandbox flags from its parent frame, which | 3057 // child should inherit the latest sandbox flags from its parent frame, which |
| 3065 // is currently a proxy in baz.com's renderer process. This checks that the | 3058 // is currently a proxy in baz.com's renderer process. This checks that the |
| 3066 // proxies of |root->child_at(0)| were also updated with the latest sandbox | 3059 // proxies of |root->child_at(0)| were also updated with the latest sandbox |
| 3067 // flags. | 3060 // flags. |
| 3068 GURL baz_child_url(embedded_test_server()->GetURL("baz.com", "/title2.html")); | 3061 GURL baz_child_url(embedded_test_server()->GetURL("baz.com", "/title2.html")); |
| 3069 NavigateFrameToURL(root->child_at(0)->child_at(0), baz_child_url); | 3062 NavigateFrameToURL(root->child_at(0)->child_at(0), baz_child_url); |
| 3070 EXPECT_TRUE(observer.last_navigation_succeeded()); | 3063 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 3071 EXPECT_EQ(baz_child_url, observer.last_navigation_url()); | 3064 EXPECT_EQ(baz_child_url, observer.last_navigation_url()); |
| 3072 | 3065 |
| 3073 EXPECT_EQ( | 3066 EXPECT_EQ( |
| 3074 " Site A ------------ proxies for B C\n" | 3067 " Site A ------------ proxies for B C\n" |
| 3075 " |--Site B ------- proxies for A C\n" | 3068 " |--Site B ------- proxies for A C\n" |
| 3076 " | +--Site C -- proxies for A B\n" | 3069 " | +--Site C -- proxies for A B\n" |
| 3077 " +--Site C ------- proxies for A B\n" | 3070 " +--Site C ------- proxies for A B\n" |
| 3078 "Where A = http://127.0.0.1/\n" | 3071 "Where A = http://127.0.0.1/\n" |
| 3079 " B = http://bar.com/\n" | 3072 " B = http://bar.com/\n" |
| 3080 " C = http://baz.com/", | 3073 " C = http://baz.com/", |
| 3081 DepictFrameTree(root)); | 3074 DepictFrameTree(root)); |
| 3082 | 3075 |
| 3083 // Opening a popup in the child of a sandboxed frame should fail. | 3076 // Opening a popup in the child of a sandboxed frame should fail. |
| 3084 success = false; | 3077 success = false; |
| 3085 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3078 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3086 root->child_at(0)->child_at(0)->current_frame_host(), | 3079 root->child_at(0)->child_at(0), |
| 3087 "window.domAutomationController.send(" | 3080 "window.domAutomationController.send(" |
| 3088 "!window.open('data:text/html,dataurl'));", | 3081 " !window.open('data:text/html,dataurl'));", |
| 3089 &success)); | 3082 &success)); |
| 3090 EXPECT_TRUE(success); | 3083 EXPECT_TRUE(success); |
| 3091 EXPECT_EQ(1u, Shell::windows().size()); | 3084 EXPECT_EQ(1u, Shell::windows().size()); |
| 3092 | 3085 |
| 3093 // Child of a sandboxed frame should also be sandboxed on the browser side. | 3086 // Child of a sandboxed frame should also be sandboxed on the browser side. |
| 3094 EXPECT_EQ(expected_flags, | 3087 EXPECT_EQ(expected_flags, |
| 3095 root->child_at(0)->child_at(0)->effective_sandbox_flags()); | 3088 root->child_at(0)->child_at(0)->effective_sandbox_flags()); |
| 3096 } | 3089 } |
| 3097 | 3090 |
| 3098 // Check that dynamic updates to iframe sandbox flags are propagated correctly. | 3091 // Check that dynamic updates to iframe sandbox flags are propagated correctly. |
| 3099 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 3092 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 3100 DynamicSandboxFlagsRemoteToLocal) { | 3093 DynamicSandboxFlagsRemoteToLocal) { |
| 3101 GURL main_url( | 3094 GURL main_url( |
| 3102 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); | 3095 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); |
| 3103 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3096 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3104 | 3097 |
| 3105 // It is safe to obtain the root frame tree node here, as it doesn't change. | 3098 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 3106 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 3099 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 3107 | 3100 |
| 3108 TestNavigationObserver observer(shell()->web_contents()); | 3101 TestNavigationObserver observer(shell()->web_contents()); |
| 3109 ASSERT_EQ(2U, root->child_count()); | 3102 ASSERT_EQ(2U, root->child_count()); |
| 3110 | 3103 |
| 3111 // Make sure the two frames starts out at correct URLs. | 3104 // Make sure the two frames starts out at correct URLs. |
| 3112 EXPECT_EQ(embedded_test_server()->GetURL("bar.com", "/title1.html"), | 3105 EXPECT_EQ(embedded_test_server()->GetURL("bar.com", "/title1.html"), |
| 3113 root->child_at(0)->current_url()); | 3106 root->child_at(0)->current_url()); |
| 3114 EXPECT_EQ(embedded_test_server()->GetURL("/title1.html"), | 3107 EXPECT_EQ(embedded_test_server()->GetURL("/title1.html"), |
| 3115 root->child_at(1)->current_url()); | 3108 root->child_at(1)->current_url()); |
| 3116 | 3109 |
| 3117 // Update the second frame's sandbox flags. | 3110 // Update the second frame's sandbox flags. |
| 3118 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 3111 EXPECT_TRUE(ExecuteScript( |
| 3119 "window.domAutomationController.send(" | 3112 shell(), |
| 3120 "document.querySelectorAll('iframe')[1].sandbox=" | 3113 "document.querySelectorAll('iframe')[1].sandbox='allow-scripts'")); |
| 3121 "'allow-scripts');")); | |
| 3122 | 3114 |
| 3123 // Check that the current sandbox flags are updated but the effective | 3115 // Check that the current sandbox flags are updated but the effective |
| 3124 // sandbox flags are not. | 3116 // sandbox flags are not. |
| 3125 blink::WebSandboxFlags expected_flags = | 3117 blink::WebSandboxFlags expected_flags = |
| 3126 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 3118 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 3127 ~blink::WebSandboxFlags::AutomaticFeatures; | 3119 ~blink::WebSandboxFlags::AutomaticFeatures; |
| 3128 EXPECT_EQ(expected_flags, root->child_at(1)->pending_sandbox_flags()); | 3120 EXPECT_EQ(expected_flags, root->child_at(1)->pending_sandbox_flags()); |
| 3129 EXPECT_EQ(blink::WebSandboxFlags::None, | 3121 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3130 root->child_at(1)->effective_sandbox_flags()); | 3122 root->child_at(1)->effective_sandbox_flags()); |
| 3131 | 3123 |
| 3132 // Navigate the second subframe to a page on bar.com. This will trigger a | 3124 // Navigate the second subframe to a page on bar.com. This will trigger a |
| 3133 // remote-to-local frame swap in bar.com's process. | 3125 // remote-to-local frame swap in bar.com's process. |
| 3134 GURL bar_url(embedded_test_server()->GetURL( | 3126 GURL bar_url(embedded_test_server()->GetURL( |
| 3135 "bar.com", "/frame_tree/page_with_one_frame.html")); | 3127 "bar.com", "/frame_tree/page_with_one_frame.html")); |
| 3136 NavigateFrameToURL(root->child_at(1), bar_url); | 3128 NavigateFrameToURL(root->child_at(1), bar_url); |
| 3137 EXPECT_EQ(bar_url, root->child_at(1)->current_url()); | 3129 EXPECT_EQ(bar_url, root->child_at(1)->current_url()); |
| 3138 ASSERT_EQ(1U, root->child_at(1)->child_count()); | 3130 ASSERT_EQ(1U, root->child_at(1)->child_count()); |
| 3139 | 3131 |
| 3140 // Confirm that the browser process has updated the current sandbox flags. | 3132 // Confirm that the browser process has updated the current sandbox flags. |
| 3141 EXPECT_EQ(expected_flags, root->child_at(1)->pending_sandbox_flags()); | 3133 EXPECT_EQ(expected_flags, root->child_at(1)->pending_sandbox_flags()); |
| 3142 EXPECT_EQ(expected_flags, root->child_at(1)->effective_sandbox_flags()); | 3134 EXPECT_EQ(expected_flags, root->child_at(1)->effective_sandbox_flags()); |
| 3143 | 3135 |
| 3144 // Opening a popup in the sandboxed second frame should fail. | 3136 // Opening a popup in the sandboxed second frame should fail. |
| 3145 bool success = false; | 3137 bool success = false; |
| 3146 EXPECT_TRUE( | 3138 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3147 ExecuteScriptAndExtractBool(root->child_at(1)->current_frame_host(), | 3139 root->child_at(1), |
| 3148 "window.domAutomationController.send(" | 3140 "window.domAutomationController.send(" |
| 3149 "!window.open('data:text/html,dataurl'));", | 3141 " !window.open('data:text/html,dataurl'));", |
| 3150 &success)); | 3142 &success)); |
| 3151 EXPECT_TRUE(success); | 3143 EXPECT_TRUE(success); |
| 3152 EXPECT_EQ(1u, Shell::windows().size()); | 3144 EXPECT_EQ(1u, Shell::windows().size()); |
| 3153 | 3145 |
| 3154 // Make sure that the child frame inherits the sandbox flags of its | 3146 // Make sure that the child frame inherits the sandbox flags of its |
| 3155 // now-sandboxed parent frame. | 3147 // now-sandboxed parent frame. |
| 3156 success = false; | 3148 success = false; |
| 3157 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3149 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3158 root->child_at(1)->child_at(0)->current_frame_host(), | 3150 root->child_at(1)->child_at(0), |
| 3159 "window.domAutomationController.send(" | 3151 "window.domAutomationController.send(" |
| 3160 "!window.open('data:text/html,dataurl'));", | 3152 " !window.open('data:text/html,dataurl'));", |
| 3161 &success)); | 3153 &success)); |
| 3162 EXPECT_TRUE(success); | 3154 EXPECT_TRUE(success); |
| 3163 EXPECT_EQ(1u, Shell::windows().size()); | 3155 EXPECT_EQ(1u, Shell::windows().size()); |
| 3164 } | 3156 } |
| 3165 | 3157 |
| 3166 // Check that dynamic updates to iframe sandbox flags are propagated correctly. | 3158 // Check that dynamic updates to iframe sandbox flags are propagated correctly. |
| 3167 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 3159 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 3168 DynamicSandboxFlagsRendererInitiatedNavigation) { | 3160 DynamicSandboxFlagsRendererInitiatedNavigation) { |
| 3169 GURL main_url( | 3161 GURL main_url( |
| 3170 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); | 3162 embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); |
| 3171 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3163 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3172 | 3164 |
| 3173 // It is safe to obtain the root frame tree node here, as it doesn't change. | 3165 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 3174 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 3166 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 3175 | 3167 |
| 3176 TestNavigationObserver observer(shell()->web_contents()); | 3168 TestNavigationObserver observer(shell()->web_contents()); |
| 3177 ASSERT_EQ(1U, root->child_count()); | 3169 ASSERT_EQ(1U, root->child_count()); |
| 3178 | 3170 |
| 3179 // Make sure the frame starts out at the correct cross-site page. | 3171 // Make sure the frame starts out at the correct cross-site page. |
| 3180 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title1.html"), | 3172 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title1.html"), |
| 3181 root->child_at(0)->current_url()); | 3173 root->child_at(0)->current_url()); |
| 3182 | 3174 |
| 3183 // The frame should not be sandboxed to start with. | 3175 // The frame should not be sandboxed to start with. |
| 3184 EXPECT_EQ(blink::WebSandboxFlags::None, | 3176 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3185 root->child_at(0)->pending_sandbox_flags()); | 3177 root->child_at(0)->pending_sandbox_flags()); |
| 3186 EXPECT_EQ(blink::WebSandboxFlags::None, | 3178 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3187 root->child_at(0)->effective_sandbox_flags()); | 3179 root->child_at(0)->effective_sandbox_flags()); |
| 3188 | 3180 |
| 3189 // Dynamically update the frame's sandbox flags. | 3181 // Dynamically update the frame's sandbox flags. |
| 3190 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 3182 EXPECT_TRUE(ExecuteScript( |
| 3191 "window.domAutomationController.send(" | 3183 shell(), "document.querySelector('iframe').sandbox='allow-scripts';")); |
| 3192 "document.querySelector('iframe').sandbox=" | |
| 3193 "'allow-scripts');")); | |
| 3194 | 3184 |
| 3195 // Check that updated sandbox flags are propagated to browser process. | 3185 // Check that updated sandbox flags are propagated to browser process. |
| 3196 // The new flags should be set in pending_sandbox_flags(), while | 3186 // The new flags should be set in pending_sandbox_flags(), while |
| 3197 // effective_sandbox_flags() should still reflect the old flags, because | 3187 // effective_sandbox_flags() should still reflect the old flags, because |
| 3198 // sandbox flag updates take place only after navigations. "allow-scripts" | 3188 // sandbox flag updates take place only after navigations. "allow-scripts" |
| 3199 // resets both SandboxFlags::Scripts and SandboxFlags::AutomaticFeatures bits | 3189 // resets both SandboxFlags::Scripts and SandboxFlags::AutomaticFeatures bits |
| 3200 // per blink::parseSandboxPolicy(). | 3190 // per blink::parseSandboxPolicy(). |
| 3201 blink::WebSandboxFlags expected_flags = | 3191 blink::WebSandboxFlags expected_flags = |
| 3202 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 3192 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 3203 ~blink::WebSandboxFlags::AutomaticFeatures; | 3193 ~blink::WebSandboxFlags::AutomaticFeatures; |
| 3204 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 3194 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 3205 EXPECT_EQ(blink::WebSandboxFlags::None, | 3195 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 3206 root->child_at(0)->effective_sandbox_flags()); | 3196 root->child_at(0)->effective_sandbox_flags()); |
| 3207 | 3197 |
| 3208 // Perform a renderer-initiated same-site navigation in the first frame. The | 3198 // Perform a renderer-initiated same-site navigation in the first frame. The |
| 3209 // new sandbox flags should take effect. | 3199 // new sandbox flags should take effect. |
| 3210 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 3200 TestFrameNavigationObserver frame_observer(root->child_at(0)); |
| 3211 ASSERT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), | 3201 ASSERT_TRUE( |
| 3212 "window.location.href='/title2.html'")); | 3202 ExecuteScript(root->child_at(0), "window.location.href='/title2.html'")); |
| 3213 frame_observer.Wait(); | 3203 frame_observer.Wait(); |
| 3214 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title2.html"), | 3204 EXPECT_EQ(embedded_test_server()->GetURL("baz.com", "/title2.html"), |
| 3215 root->child_at(0)->current_url()); | 3205 root->child_at(0)->current_url()); |
| 3216 | 3206 |
| 3217 // Confirm that the browser process has updated the frame's current sandbox | 3207 // Confirm that the browser process has updated the frame's current sandbox |
| 3218 // flags. | 3208 // flags. |
| 3219 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 3209 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 3220 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 3210 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| 3221 | 3211 |
| 3222 // Opening a popup in the now-sandboxed frame should fail. | 3212 // Opening a popup in the now-sandboxed frame should fail. |
| 3223 bool success = false; | 3213 bool success = false; |
| 3224 EXPECT_TRUE( | 3214 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3225 ExecuteScriptAndExtractBool(root->child_at(0)->current_frame_host(), | 3215 root->child_at(0), |
| 3226 "window.domAutomationController.send(" | 3216 "window.domAutomationController.send(" |
| 3227 "!window.open('data:text/html,dataurl'));", | 3217 " !window.open('data:text/html,dataurl'));", |
| 3228 &success)); | 3218 &success)); |
| 3229 EXPECT_TRUE(success); | 3219 EXPECT_TRUE(success); |
| 3230 EXPECT_EQ(1u, Shell::windows().size()); | 3220 EXPECT_EQ(1u, Shell::windows().size()); |
| 3231 } | 3221 } |
| 3232 | 3222 |
| 3233 // Verify that when a new child frame is added, the proxies created for it in | 3223 // Verify that when a new child frame is added, the proxies created for it in |
| 3234 // other SiteInstances have correct sandbox flags and origin. | 3224 // other SiteInstances have correct sandbox flags and origin. |
| 3235 // | 3225 // |
| 3236 // A A A | 3226 // A A A |
| 3237 // / / \ / \ . | 3227 // / / \ / \ . |
| 3238 // B -> B A -> B A | 3228 // B -> B A -> B A |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3260 " +--Site B ------- proxies for A\n" | 3250 " +--Site B ------- proxies for A\n" |
| 3261 "Where A = http://127.0.0.1/\n" | 3251 "Where A = http://127.0.0.1/\n" |
| 3262 " B = http://baz.com/", | 3252 " B = http://baz.com/", |
| 3263 DepictFrameTree(root)); | 3253 DepictFrameTree(root)); |
| 3264 | 3254 |
| 3265 // In the root frame, add a new sandboxed local frame, which itself has a | 3255 // In the root frame, add a new sandboxed local frame, which itself has a |
| 3266 // child frame on baz.com. Wait for three RenderFrameHosts to be created: | 3256 // child frame on baz.com. Wait for three RenderFrameHosts to be created: |
| 3267 // the new sandboxed local frame, its child (while it's still local), and a | 3257 // the new sandboxed local frame, its child (while it's still local), and a |
| 3268 // pending RFH when starting the cross-site navigation to baz.com. | 3258 // pending RFH when starting the cross-site navigation to baz.com. |
| 3269 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 3); | 3259 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 3); |
| 3270 EXPECT_TRUE( | 3260 EXPECT_TRUE(ExecuteScript(root, |
| 3271 ExecuteScript(root->current_frame_host(), | 3261 "addFrame('/frame_tree/page_with_one_frame.html'," |
| 3272 "window.domAutomationController.send(" | 3262 " 'allow-scripts allow-same-origin'))")); |
| 3273 " addFrame('/frame_tree/page_with_one_frame.html'," | |
| 3274 " 'allow-scripts allow-same-origin'))")); | |
| 3275 frame_observer.Wait(); | 3263 frame_observer.Wait(); |
| 3276 | 3264 |
| 3277 // Wait for the cross-site navigation to baz.com in the grandchild to finish. | 3265 // Wait for the cross-site navigation to baz.com in the grandchild to finish. |
| 3278 FrameTreeNode* bottom_child = root->child_at(1)->child_at(0); | 3266 FrameTreeNode* bottom_child = root->child_at(1)->child_at(0); |
| 3279 TestFrameNavigationObserver navigation_observer(bottom_child); | 3267 TestFrameNavigationObserver navigation_observer(bottom_child); |
| 3280 navigation_observer.Wait(); | 3268 navigation_observer.Wait(); |
| 3281 | 3269 |
| 3282 EXPECT_EQ( | 3270 EXPECT_EQ( |
| 3283 " Site A ------------ proxies for B\n" | 3271 " Site A ------------ proxies for B\n" |
| 3284 " |--Site B ------- proxies for A\n" | 3272 " |--Site B ------- proxies for A\n" |
| 3285 " +--Site A ------- proxies for B\n" | 3273 " +--Site A ------- proxies for B\n" |
| 3286 " +--Site B -- proxies for A\n" | 3274 " +--Site B -- proxies for A\n" |
| 3287 "Where A = http://127.0.0.1/\n" | 3275 "Where A = http://127.0.0.1/\n" |
| 3288 " B = http://baz.com/", | 3276 " B = http://baz.com/", |
| 3289 DepictFrameTree(root)); | 3277 DepictFrameTree(root)); |
| 3290 | 3278 |
| 3291 // Use location.ancestorOrigins to check that the grandchild on baz.com sees | 3279 // Use location.ancestorOrigins to check that the grandchild on baz.com sees |
| 3292 // correct origin for its parent. | 3280 // correct origin for its parent. |
| 3293 int ancestor_origins_length = 0; | 3281 int ancestor_origins_length = 0; |
| 3294 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 3282 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 3295 bottom_child->current_frame_host(), | 3283 bottom_child, |
| 3296 "window.domAutomationController.send(location.ancestorOrigins.length);", | 3284 "window.domAutomationController.send(location.ancestorOrigins.length);", |
| 3297 &ancestor_origins_length)); | 3285 &ancestor_origins_length)); |
| 3298 EXPECT_EQ(2, ancestor_origins_length); | 3286 EXPECT_EQ(2, ancestor_origins_length); |
| 3299 std::string parent_origin; | 3287 std::string parent_origin; |
| 3300 EXPECT_TRUE(ExecuteScriptAndExtractString( | 3288 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 3301 bottom_child->current_frame_host(), | 3289 bottom_child, |
| 3302 "window.domAutomationController.send(location.ancestorOrigins[0]);", | 3290 "window.domAutomationController.send(location.ancestorOrigins[0]);", |
| 3303 &parent_origin)); | 3291 &parent_origin)); |
| 3304 EXPECT_EQ(main_url.GetOrigin().spec(), parent_origin + "/"); | 3292 EXPECT_EQ(main_url.GetOrigin().spec(), parent_origin + "/"); |
| 3305 | 3293 |
| 3306 // Check that the sandbox flags in the browser process are correct. | 3294 // Check that the sandbox flags in the browser process are correct. |
| 3307 // "allow-scripts" resets both WebSandboxFlags::Scripts and | 3295 // "allow-scripts" resets both WebSandboxFlags::Scripts and |
| 3308 // WebSandboxFlags::AutomaticFeatures bits per blink::parseSandboxPolicy(). | 3296 // WebSandboxFlags::AutomaticFeatures bits per blink::parseSandboxPolicy(). |
| 3309 blink::WebSandboxFlags expected_flags = | 3297 blink::WebSandboxFlags expected_flags = |
| 3310 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 3298 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 3311 ~blink::WebSandboxFlags::AutomaticFeatures & | 3299 ~blink::WebSandboxFlags::AutomaticFeatures & |
| 3312 ~blink::WebSandboxFlags::Origin; | 3300 ~blink::WebSandboxFlags::Origin; |
| 3313 EXPECT_EQ(expected_flags, root->child_at(1)->effective_sandbox_flags()); | 3301 EXPECT_EQ(expected_flags, root->child_at(1)->effective_sandbox_flags()); |
| 3314 | 3302 |
| 3315 // The child of the sandboxed frame should've inherited sandbox flags, so it | 3303 // The child of the sandboxed frame should've inherited sandbox flags, so it |
| 3316 // should not be able to create popups. | 3304 // should not be able to create popups. |
| 3317 EXPECT_EQ(expected_flags, bottom_child->effective_sandbox_flags()); | 3305 EXPECT_EQ(expected_flags, bottom_child->effective_sandbox_flags()); |
| 3318 bool success = false; | 3306 bool success = false; |
| 3319 EXPECT_TRUE( | 3307 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3320 ExecuteScriptAndExtractBool(bottom_child->current_frame_host(), | 3308 bottom_child, |
| 3321 "window.domAutomationController.send(" | 3309 "window.domAutomationController.send(" |
| 3322 "!window.open('data:text/html,dataurl'));", | 3310 " !window.open('data:text/html,dataurl'));", |
| 3323 &success)); | 3311 &success)); |
| 3324 EXPECT_TRUE(success); | 3312 EXPECT_TRUE(success); |
| 3325 EXPECT_EQ(1u, Shell::windows().size()); | 3313 EXPECT_EQ(1u, Shell::windows().size()); |
| 3326 } | 3314 } |
| 3327 | 3315 |
| 3328 // Verify that a child frame can retrieve the name property set by its parent. | 3316 // Verify that a child frame can retrieve the name property set by its parent. |
| 3329 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, WindowNameReplication) { | 3317 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, WindowNameReplication) { |
| 3330 GURL main_url(embedded_test_server()->GetURL("/frame_tree/2-4.html")); | 3318 GURL main_url(embedded_test_server()->GetURL("/frame_tree/2-4.html")); |
| 3331 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3319 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3332 | 3320 |
| 3333 // It is safe to obtain the root frame tree node here, as it doesn't change. | 3321 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 3334 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 3322 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 3335 | 3323 |
| 3336 TestNavigationObserver observer(shell()->web_contents()); | 3324 TestNavigationObserver observer(shell()->web_contents()); |
| 3337 | 3325 |
| 3338 // Load cross-site page into iframe. | 3326 // Load cross-site page into iframe. |
| 3339 GURL frame_url = | 3327 GURL frame_url = |
| 3340 embedded_test_server()->GetURL("foo.com", "/frame_tree/3-1.html"); | 3328 embedded_test_server()->GetURL("foo.com", "/frame_tree/3-1.html"); |
| 3341 NavigateFrameToURL(root->child_at(0), frame_url); | 3329 NavigateFrameToURL(root->child_at(0), frame_url); |
| 3342 EXPECT_TRUE(observer.last_navigation_succeeded()); | 3330 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 3343 EXPECT_EQ(frame_url, observer.last_navigation_url()); | 3331 EXPECT_EQ(frame_url, observer.last_navigation_url()); |
| 3344 | 3332 |
| 3345 // Ensure that a new process is created for the subframe. | 3333 // Ensure that a new process is created for the subframe. |
| 3346 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 3334 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 3347 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 3335 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 3348 | 3336 |
| 3349 // Check that the window.name seen by the frame matches the name attribute | 3337 // Check that the window.name seen by the frame matches the name attribute |
| 3350 // specified by its parent in the iframe tag. | 3338 // specified by its parent in the iframe tag. |
| 3351 std::string result; | 3339 std::string result; |
| 3352 EXPECT_TRUE(ExecuteScriptAndExtractString( | 3340 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 3353 root->child_at(0)->current_frame_host(), | 3341 root->child_at(0), "window.domAutomationController.send(window.name);", |
| 3354 "window.domAutomationController.send(window.name);", &result)); | 3342 &result)); |
| 3355 EXPECT_EQ("3-1-name", result); | 3343 EXPECT_EQ("3-1-name", result); |
| 3356 } | 3344 } |
| 3357 | 3345 |
| 3358 // Verify that dynamic updates to a frame's window.name propagate to the | 3346 // Verify that dynamic updates to a frame's window.name propagate to the |
| 3359 // frame's proxies, so that the latest frame names can be used in navigations. | 3347 // frame's proxies, so that the latest frame names can be used in navigations. |
| 3360 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DynamicWindowName) { | 3348 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DynamicWindowName) { |
| 3361 GURL main_url(embedded_test_server()->GetURL("/frame_tree/2-4.html")); | 3349 GURL main_url(embedded_test_server()->GetURL("/frame_tree/2-4.html")); |
| 3362 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3350 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3363 | 3351 |
| 3364 // It is safe to obtain the root frame tree node here, as it doesn't change. | 3352 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 3365 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 3353 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 3366 TestNavigationObserver observer(shell()->web_contents()); | 3354 TestNavigationObserver observer(shell()->web_contents()); |
| 3367 | 3355 |
| 3368 // Load cross-site page into iframe. | 3356 // Load cross-site page into iframe. |
| 3369 GURL frame_url = | 3357 GURL frame_url = |
| 3370 embedded_test_server()->GetURL("foo.com", "/frame_tree/3-1.html"); | 3358 embedded_test_server()->GetURL("foo.com", "/frame_tree/3-1.html"); |
| 3371 NavigateFrameToURL(root->child_at(0), frame_url); | 3359 NavigateFrameToURL(root->child_at(0), frame_url); |
| 3372 EXPECT_TRUE(observer.last_navigation_succeeded()); | 3360 EXPECT_TRUE(observer.last_navigation_succeeded()); |
| 3373 EXPECT_EQ(frame_url, observer.last_navigation_url()); | 3361 EXPECT_EQ(frame_url, observer.last_navigation_url()); |
| 3374 | 3362 |
| 3375 // Browser process should know the child frame's original window.name | 3363 // Browser process should know the child frame's original window.name |
| 3376 // specified in the iframe element. | 3364 // specified in the iframe element. |
| 3377 EXPECT_EQ(root->child_at(0)->frame_name(), "3-1-name"); | 3365 EXPECT_EQ(root->child_at(0)->frame_name(), "3-1-name"); |
| 3378 | 3366 |
| 3379 // Update the child frame's window.name. | 3367 // Update the child frame's window.name. |
| 3380 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), | 3368 EXPECT_TRUE( |
| 3381 "window.domAutomationController.send(" | 3369 ExecuteScript(root->child_at(0), "window.name = 'updated-name';")); |
| 3382 "window.name = 'updated-name');")); | |
| 3383 | 3370 |
| 3384 // The change should propagate to the browser process. | 3371 // The change should propagate to the browser process. |
| 3385 EXPECT_EQ(root->child_at(0)->frame_name(), "updated-name"); | 3372 EXPECT_EQ(root->child_at(0)->frame_name(), "updated-name"); |
| 3386 | 3373 |
| 3387 // The proxy in the parent process should also receive the updated name. | 3374 // The proxy in the parent process should also receive the updated name. |
| 3388 // Check that it can reference the child frame by its new name. | 3375 // Check that it can reference the child frame by its new name. |
| 3389 bool success = false; | 3376 bool success = false; |
| 3390 EXPECT_TRUE( | 3377 EXPECT_TRUE( |
| 3391 ExecuteScriptAndExtractBool(shell()->web_contents(), | 3378 ExecuteScriptAndExtractBool(shell(), |
| 3392 "window.domAutomationController.send(" | 3379 "window.domAutomationController.send(" |
| 3393 "frames['updated-name'] == frames[0]);", | 3380 " frames['updated-name'] == frames[0]);", |
| 3394 &success)); | 3381 &success)); |
| 3395 EXPECT_TRUE(success); | 3382 EXPECT_TRUE(success); |
| 3396 | 3383 |
| 3397 // Issue a renderer-initiated navigation from the root frame to the child | 3384 // Issue a renderer-initiated navigation from the root frame to the child |
| 3398 // frame using the frame's name. Make sure correct frame is navigated. | 3385 // frame using the frame's name. Make sure correct frame is navigated. |
| 3399 // | 3386 // |
| 3400 // TODO(alexmos): When blink::createWindow is refactored to handle | 3387 // TODO(alexmos): When blink::createWindow is refactored to handle |
| 3401 // RemoteFrames, this should also be tested via window.open(url, frame_name) | 3388 // RemoteFrames, this should also be tested via window.open(url, frame_name) |
| 3402 // and a more complicated frame hierarchy (https://crbug.com/463742) | 3389 // and a more complicated frame hierarchy (https://crbug.com/463742) |
| 3403 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 3390 TestFrameNavigationObserver frame_observer(root->child_at(0)); |
| 3404 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); | 3391 GURL foo_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); |
| 3405 std::string script = base::StringPrintf( | 3392 EXPECT_TRUE(ExecuteScript( |
| 3406 "window.domAutomationController.send(" | 3393 shell(), |
| 3407 "frames['updated-name'].location.href = '%s');", | 3394 base::StringPrintf("frames['updated-name'].location.href = '%s';", |
| 3408 foo_url.spec().c_str()); | 3395 foo_url.spec().c_str()))); |
| 3409 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
| 3410 frame_observer.Wait(); | 3396 frame_observer.Wait(); |
| 3411 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); | 3397 EXPECT_EQ(foo_url, root->child_at(0)->current_url()); |
| 3412 } | 3398 } |
| 3413 | 3399 |
| 3414 // Verify that when a frame is navigated to a new origin, the origin update | 3400 // Verify that when a frame is navigated to a new origin, the origin update |
| 3415 // propagates to the frame's proxies. | 3401 // propagates to the frame's proxies. |
| 3416 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginUpdatesReachProxies) { | 3402 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginUpdatesReachProxies) { |
| 3417 GURL main_url( | 3403 GURL main_url( |
| 3418 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); | 3404 embedded_test_server()->GetURL("/frame_tree/page_with_two_frames.html")); |
| 3419 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3405 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3443 // contain the second frame's updated origin (see blink::Frame::canNavigate). | 3429 // contain the second frame's updated origin (see blink::Frame::canNavigate). |
| 3444 std::unique_ptr<ConsoleObserverDelegate> console_delegate( | 3430 std::unique_ptr<ConsoleObserverDelegate> console_delegate( |
| 3445 new ConsoleObserverDelegate( | 3431 new ConsoleObserverDelegate( |
| 3446 shell()->web_contents(), | 3432 shell()->web_contents(), |
| 3447 "Unsafe JavaScript attempt to initiate navigation*")); | 3433 "Unsafe JavaScript attempt to initiate navigation*")); |
| 3448 shell()->web_contents()->SetDelegate(console_delegate.get()); | 3434 shell()->web_contents()->SetDelegate(console_delegate.get()); |
| 3449 | 3435 |
| 3450 // frames[1] can't be used due to a bug where RemoteFrames are created out of | 3436 // frames[1] can't be used due to a bug where RemoteFrames are created out of |
| 3451 // order (https://crbug.com/478792). Instead, target second frame by name. | 3437 // order (https://crbug.com/478792). Instead, target second frame by name. |
| 3452 EXPECT_TRUE(ExecuteScript( | 3438 EXPECT_TRUE(ExecuteScript( |
| 3453 root->child_at(0)->current_frame_host(), | 3439 root->child_at(0), |
| 3454 "window.domAutomationController.send(" | 3440 "parent.frames['frame2'].location.href = 'data:text/html,foo'")); |
| 3455 " parent.frames['frame2'].location.href = 'data:text/html,foo');")); | |
| 3456 console_delegate->Wait(); | 3441 console_delegate->Wait(); |
| 3457 | 3442 |
| 3458 std::string frame_origin = root->child_at(1)->current_origin().Serialize(); | 3443 std::string frame_origin = root->child_at(1)->current_origin().Serialize(); |
| 3459 EXPECT_EQ(frame_origin + "/", frame_url.GetOrigin().spec()); | 3444 EXPECT_EQ(frame_origin + "/", frame_url.GetOrigin().spec()); |
| 3460 EXPECT_TRUE( | 3445 EXPECT_TRUE( |
| 3461 base::MatchPattern(console_delegate->message(), "*" + frame_origin + "*")) | 3446 base::MatchPattern(console_delegate->message(), "*" + frame_origin + "*")) |
| 3462 << "Error message does not contain the frame's latest origin (" | 3447 << "Error message does not contain the frame's latest origin (" |
| 3463 << frame_origin << ")"; | 3448 << frame_origin << ")"; |
| 3464 } | 3449 } |
| 3465 | 3450 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3665 GURL interstitial_url("http://interstitial"); | 3650 GURL interstitial_url("http://interstitial"); |
| 3666 InterstitialPageImpl* interstitial = new InterstitialPageImpl( | 3651 InterstitialPageImpl* interstitial = new InterstitialPageImpl( |
| 3667 opener_contents, static_cast<RenderWidgetHostDelegate*>(opener_contents), | 3652 opener_contents, static_cast<RenderWidgetHostDelegate*>(opener_contents), |
| 3668 true, interstitial_url, delegate); | 3653 true, interstitial_url, delegate); |
| 3669 interstitial->Show(); | 3654 interstitial->Show(); |
| 3670 WaitForInterstitialAttach(opener_contents); | 3655 WaitForInterstitialAttach(opener_contents); |
| 3671 | 3656 |
| 3672 // Now, navigate the opener cross-process using the popup while it still has | 3657 // Now, navigate the opener cross-process using the popup while it still has |
| 3673 // an interstitial. This should not crash. | 3658 // an interstitial. This should not crash. |
| 3674 TestNavigationObserver navigation_observer(opener_contents); | 3659 TestNavigationObserver navigation_observer(opener_contents); |
| 3675 EXPECT_TRUE( | 3660 EXPECT_TRUE(ExecuteScript(popup, "navigateOpener();")); |
| 3676 ExecuteScript(popup->web_contents(), | |
| 3677 "window.domAutomationController.send(navigateOpener());")); | |
| 3678 navigation_observer.Wait(); | 3661 navigation_observer.Wait(); |
| 3679 } | 3662 } |
| 3680 | 3663 |
| 3681 // Check that postMessage can be sent from a subframe on a cross-process opener | 3664 // Check that postMessage can be sent from a subframe on a cross-process opener |
| 3682 // tab, and that its event.source points to a valid proxy. | 3665 // tab, and that its event.source points to a valid proxy. |
| 3683 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 3666 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 3684 PostMessageWithSubframeOnOpenerChain) { | 3667 PostMessageWithSubframeOnOpenerChain) { |
| 3685 GURL main_url(embedded_test_server()->GetURL( | 3668 GURL main_url(embedded_test_server()->GetURL( |
| 3686 "a.com", "/frame_tree/page_with_post_message_frames.html")); | 3669 "a.com", "/frame_tree/page_with_post_message_frames.html")); |
| 3687 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3670 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3688 | 3671 |
| 3689 // It is safe to obtain the root frame tree node here, as it doesn't change. | 3672 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 3690 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 3673 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 3691 | 3674 |
| 3692 ASSERT_EQ(2U, root->child_count()); | 3675 ASSERT_EQ(2U, root->child_count()); |
| 3693 | 3676 |
| 3694 // Verify the initial state of the world. First frame should be same-site; | 3677 // Verify the initial state of the world. First frame should be same-site; |
| 3695 // second frame should be cross-site. | 3678 // second frame should be cross-site. |
| 3696 EXPECT_EQ( | 3679 EXPECT_EQ( |
| 3697 " Site A ------------ proxies for B\n" | 3680 " Site A ------------ proxies for B\n" |
| 3698 " |--Site A ------- proxies for B\n" | 3681 " |--Site A ------- proxies for B\n" |
| 3699 " +--Site B ------- proxies for A\n" | 3682 " +--Site B ------- proxies for A\n" |
| 3700 "Where A = http://a.com/\n" | 3683 "Where A = http://a.com/\n" |
| 3701 " B = http://foo.com/", | 3684 " B = http://foo.com/", |
| 3702 DepictFrameTree(root)); | 3685 DepictFrameTree(root)); |
| 3703 | 3686 |
| 3704 // Open a popup from the first subframe (so that popup's window.opener points | 3687 // Open a popup from the first subframe (so that popup's window.opener points |
| 3705 // to the subframe) and navigate it to bar.com. | 3688 // to the subframe) and navigate it to bar.com. |
| 3706 ShellAddedObserver new_shell_observer; | 3689 ShellAddedObserver new_shell_observer; |
| 3707 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), | 3690 EXPECT_TRUE(ExecuteScript(root->child_at(0), "openPopup('about:blank');")); |
| 3708 "openPopup('about:blank');")); | |
| 3709 Shell* popup = new_shell_observer.GetShell(); | 3691 Shell* popup = new_shell_observer.GetShell(); |
| 3710 GURL popup_url( | 3692 GURL popup_url( |
| 3711 embedded_test_server()->GetURL("bar.com", "/post_message.html")); | 3693 embedded_test_server()->GetURL("bar.com", "/post_message.html")); |
| 3712 EXPECT_TRUE(NavigateToURL(popup, popup_url)); | 3694 EXPECT_TRUE(NavigateToURL(popup, popup_url)); |
| 3713 | 3695 |
| 3714 // From the popup, open another popup for baz.com. This will be used to | 3696 // From the popup, open another popup for baz.com. This will be used to |
| 3715 // check that the whole opener chain is processed when creating proxies and | 3697 // check that the whole opener chain is processed when creating proxies and |
| 3716 // not just an immediate opener. | 3698 // not just an immediate opener. |
| 3717 ShellAddedObserver new_shell_observer2; | 3699 ShellAddedObserver new_shell_observer2; |
| 3718 EXPECT_TRUE( | 3700 EXPECT_TRUE(ExecuteScript(popup, "openPopup('about:blank');")); |
| 3719 ExecuteScript(popup->web_contents(), "openPopup('about:blank');")); | |
| 3720 Shell* popup2 = new_shell_observer2.GetShell(); | 3701 Shell* popup2 = new_shell_observer2.GetShell(); |
| 3721 GURL popup2_url( | 3702 GURL popup2_url( |
| 3722 embedded_test_server()->GetURL("baz.com", "/post_message.html")); | 3703 embedded_test_server()->GetURL("baz.com", "/post_message.html")); |
| 3723 EXPECT_TRUE(NavigateToURL(popup2, popup2_url)); | 3704 EXPECT_TRUE(NavigateToURL(popup2, popup2_url)); |
| 3724 | 3705 |
| 3725 // Ensure that we've created proxies for SiteInstances of both popups (C, D) | 3706 // Ensure that we've created proxies for SiteInstances of both popups (C, D) |
| 3726 // in the main window's frame tree. | 3707 // in the main window's frame tree. |
| 3727 EXPECT_EQ( | 3708 EXPECT_EQ( |
| 3728 " Site A ------------ proxies for B C D\n" | 3709 " Site A ------------ proxies for B C D\n" |
| 3729 " |--Site A ------- proxies for B C D\n" | 3710 " |--Site A ------- proxies for B C D\n" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3752 // Send a message from first subframe on main page to the first popup and | 3733 // Send a message from first subframe on main page to the first popup and |
| 3753 // wait for a reply back. The reply verifies that the proxy for the opener | 3734 // wait for a reply back. The reply verifies that the proxy for the opener |
| 3754 // tab's subframe is targeted properly. | 3735 // tab's subframe is targeted properly. |
| 3755 PostMessageAndWaitForReply(root->child_at(0), "postToPopup('subframe-msg')", | 3736 PostMessageAndWaitForReply(root->child_at(0), "postToPopup('subframe-msg')", |
| 3756 "\"done-subframe1\""); | 3737 "\"done-subframe1\""); |
| 3757 | 3738 |
| 3758 // Send a postMessage from the popup to window.opener and ensure that it | 3739 // Send a postMessage from the popup to window.opener and ensure that it |
| 3759 // reaches subframe1. This verifies that the subframe opener information | 3740 // reaches subframe1. This verifies that the subframe opener information |
| 3760 // propagated to the popup's RenderFrame. Wait for subframe1 to send a reply | 3741 // propagated to the popup's RenderFrame. Wait for subframe1 to send a reply |
| 3761 // message to the popup. | 3742 // message to the popup. |
| 3762 EXPECT_TRUE(ExecuteScript(popup->web_contents(), "window.name = 'popup';")); | 3743 EXPECT_TRUE(ExecuteScript(popup, "window.name = 'popup';")); |
| 3763 PostMessageAndWaitForReply(popup_root, "postToOpener('subframe-msg', '*')", | 3744 PostMessageAndWaitForReply(popup_root, "postToOpener('subframe-msg', '*')", |
| 3764 "\"done-popup\""); | 3745 "\"done-popup\""); |
| 3765 | 3746 |
| 3766 // Second a postMessage from popup2 to window.opener.opener, which should | 3747 // Second a postMessage from popup2 to window.opener.opener, which should |
| 3767 // resolve to subframe1. This tests opener chains of length greater than 1. | 3748 // resolve to subframe1. This tests opener chains of length greater than 1. |
| 3768 // As before, subframe1 will send a reply to popup2. | 3749 // As before, subframe1 will send a reply to popup2. |
| 3769 FrameTreeNode* popup2_root = | 3750 FrameTreeNode* popup2_root = |
| 3770 static_cast<WebContentsImpl*>(popup2->web_contents()) | 3751 static_cast<WebContentsImpl*>(popup2->web_contents()) |
| 3771 ->GetFrameTree() | 3752 ->GetFrameTree() |
| 3772 ->root(); | 3753 ->root(); |
| 3773 EXPECT_TRUE(ExecuteScript(popup2->web_contents(), "window.name = 'popup2';")); | 3754 EXPECT_TRUE(ExecuteScript(popup2, "window.name = 'popup2';")); |
| 3774 PostMessageAndWaitForReply(popup2_root, | 3755 PostMessageAndWaitForReply(popup2_root, |
| 3775 "postToOpenerOfOpener('subframe-msg', '*')", | 3756 "postToOpenerOfOpener('subframe-msg', '*')", |
| 3776 "\"done-popup2\""); | 3757 "\"done-popup2\""); |
| 3777 | 3758 |
| 3778 // Verify the total number of received messages for each subframe: | 3759 // Verify the total number of received messages for each subframe: |
| 3779 // - 3 for first subframe (two from first popup, one from second popup) | 3760 // - 3 for first subframe (two from first popup, one from second popup) |
| 3780 // - 2 for popup (both from first subframe) | 3761 // - 2 for popup (both from first subframe) |
| 3781 // - 1 for popup2 (reply from first subframe) | 3762 // - 1 for popup2 (reply from first subframe) |
| 3782 // - 0 for other frames | 3763 // - 0 for other frames |
| 3783 EXPECT_EQ(0, GetReceivedMessages(root)); | 3764 EXPECT_EQ(0, GetReceivedMessages(root)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3819 " +--Site D ------- proxies for A B C\n" | 3800 " +--Site D ------- proxies for A B C\n" |
| 3820 "Where A = http://a.com/\n" | 3801 "Where A = http://a.com/\n" |
| 3821 " B = http://b.com/\n" | 3802 " B = http://b.com/\n" |
| 3822 " C = http://c.com/\n" | 3803 " C = http://c.com/\n" |
| 3823 " D = http://d.com/", | 3804 " D = http://d.com/", |
| 3824 DepictFrameTree(root)); | 3805 DepictFrameTree(root)); |
| 3825 | 3806 |
| 3826 // Check that each subframe sees itself at correct index in parent.frames. | 3807 // Check that each subframe sees itself at correct index in parent.frames. |
| 3827 bool success = false; | 3808 bool success = false; |
| 3828 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3809 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3829 child0->current_frame_host(), | 3810 child0, |
| 3830 "window.domAutomationController.send(window === parent.frames[0]);", | 3811 "window.domAutomationController.send(window === parent.frames[0]);", |
| 3831 &success)); | 3812 &success)); |
| 3832 EXPECT_TRUE(success); | 3813 EXPECT_TRUE(success); |
| 3833 | 3814 |
| 3834 success = false; | 3815 success = false; |
| 3835 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3816 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3836 child1->current_frame_host(), | 3817 child1, |
| 3837 "window.domAutomationController.send(window === parent.frames[1]);", | 3818 "window.domAutomationController.send(window === parent.frames[1]);", |
| 3838 &success)); | 3819 &success)); |
| 3839 EXPECT_TRUE(success); | 3820 EXPECT_TRUE(success); |
| 3840 | 3821 |
| 3841 success = false; | 3822 success = false; |
| 3842 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3823 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3843 child2->current_frame_host(), | 3824 child2, |
| 3844 "window.domAutomationController.send(window === parent.frames[2]);", | 3825 "window.domAutomationController.send(window === parent.frames[2]);", |
| 3845 &success)); | 3826 &success)); |
| 3846 EXPECT_TRUE(success); | 3827 EXPECT_TRUE(success); |
| 3847 | 3828 |
| 3848 // Send a postMessage from B to parent.frames[1], which should go to C, and | 3829 // Send a postMessage from B to parent.frames[1], which should go to C, and |
| 3849 // wait for reply. | 3830 // wait for reply. |
| 3850 PostMessageAndWaitForReply(child0, "postToSibling('subframe-msg', 1)", | 3831 PostMessageAndWaitForReply(child0, "postToSibling('subframe-msg', 1)", |
| 3851 "\"done-1-1-name\""); | 3832 "\"done-1-1-name\""); |
| 3852 | 3833 |
| 3853 // Send a postMessage from C to parent.frames[2], which should go to D, and | 3834 // Send a postMessage from C to parent.frames[2], which should go to D, and |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3929 NavigateToURL(shell(), main_url); | 3910 NavigateToURL(shell(), main_url); |
| 3930 | 3911 |
| 3931 // It is safe to obtain the root frame tree node here, as it doesn't change. | 3912 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 3932 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 3913 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 3933 | 3914 |
| 3934 // Navigate first child cross-site. | 3915 // Navigate first child cross-site. |
| 3935 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 3916 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 3936 NavigateFrameToURL(root->child_at(0), frame_url); | 3917 NavigateFrameToURL(root->child_at(0), frame_url); |
| 3937 | 3918 |
| 3938 // Open a popup from the first child. | 3919 // Open a popup from the first child. |
| 3939 Shell* new_shell = OpenPopup(root->child_at(0)->current_frame_host(), | 3920 Shell* new_shell = |
| 3940 GURL(url::kAboutBlankURL), ""); | 3921 OpenPopup(root->child_at(0), GURL(url::kAboutBlankURL), ""); |
| 3941 EXPECT_TRUE(new_shell); | 3922 EXPECT_TRUE(new_shell); |
| 3942 | 3923 |
| 3943 // Check that the popup's opener is correct on both the browser and renderer | 3924 // Check that the popup's opener is correct on both the browser and renderer |
| 3944 // sides. | 3925 // sides. |
| 3945 FrameTreeNode* popup_root = | 3926 FrameTreeNode* popup_root = |
| 3946 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 3927 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
| 3947 ->GetFrameTree() | 3928 ->GetFrameTree() |
| 3948 ->root(); | 3929 ->root(); |
| 3949 EXPECT_EQ(root->child_at(0), popup_root->opener()); | 3930 EXPECT_EQ(root->child_at(0), popup_root->opener()); |
| 3950 | 3931 |
| 3951 std::string opener_url; | 3932 std::string opener_url; |
| 3952 EXPECT_TRUE(ExecuteScriptAndExtractString( | 3933 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 3953 popup_root->current_frame_host(), | 3934 popup_root, |
| 3954 "window.domAutomationController.send(window.opener.location.href);", | 3935 "window.domAutomationController.send(window.opener.location.href);", |
| 3955 &opener_url)); | 3936 &opener_url)); |
| 3956 EXPECT_EQ(frame_url.spec(), opener_url); | 3937 EXPECT_EQ(frame_url.spec(), opener_url); |
| 3957 | 3938 |
| 3958 // Now try the same with a cross-site popup and make sure it ends up in a new | 3939 // Now try the same with a cross-site popup and make sure it ends up in a new |
| 3959 // process and with a correct opener. | 3940 // process and with a correct opener. |
| 3960 GURL popup_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 3941 GURL popup_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 3961 Shell* cross_site_popup = | 3942 Shell* cross_site_popup = OpenPopup(root->child_at(0), popup_url, ""); |
| 3962 OpenPopup(root->child_at(0)->current_frame_host(), popup_url, ""); | |
| 3963 EXPECT_TRUE(cross_site_popup); | 3943 EXPECT_TRUE(cross_site_popup); |
| 3964 | 3944 |
| 3965 FrameTreeNode* cross_site_popup_root = | 3945 FrameTreeNode* cross_site_popup_root = |
| 3966 static_cast<WebContentsImpl*>(cross_site_popup->web_contents()) | 3946 static_cast<WebContentsImpl*>(cross_site_popup->web_contents()) |
| 3967 ->GetFrameTree() | 3947 ->GetFrameTree() |
| 3968 ->root(); | 3948 ->root(); |
| 3969 EXPECT_EQ(cross_site_popup_root->current_url(), popup_url); | 3949 EXPECT_EQ(cross_site_popup_root->current_url(), popup_url); |
| 3970 | 3950 |
| 3971 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 3951 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 3972 cross_site_popup->web_contents()->GetSiteInstance()); | 3952 cross_site_popup->web_contents()->GetSiteInstance()); |
| 3973 EXPECT_NE(root->child_at(0)->current_frame_host()->GetSiteInstance(), | 3953 EXPECT_NE(root->child_at(0)->current_frame_host()->GetSiteInstance(), |
| 3974 cross_site_popup->web_contents()->GetSiteInstance()); | 3954 cross_site_popup->web_contents()->GetSiteInstance()); |
| 3975 | 3955 |
| 3976 EXPECT_EQ(root->child_at(0), cross_site_popup_root->opener()); | 3956 EXPECT_EQ(root->child_at(0), cross_site_popup_root->opener()); |
| 3977 | 3957 |
| 3978 // Ensure the popup's window.opener points to the right subframe. Note that | 3958 // Ensure the popup's window.opener points to the right subframe. Note that |
| 3979 // we can't check the opener's location as above since it's cross-origin. | 3959 // we can't check the opener's location as above since it's cross-origin. |
| 3980 bool success = false; | 3960 bool success = false; |
| 3981 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3961 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3982 cross_site_popup_root->current_frame_host(), | 3962 cross_site_popup_root, |
| 3983 "window.domAutomationController.send(" | 3963 "window.domAutomationController.send(" |
| 3984 " window.opener === window.opener.top.frames[0]);", | 3964 " window.opener === window.opener.top.frames[0]);", |
| 3985 &success)); | 3965 &success)); |
| 3986 EXPECT_TRUE(success); | 3966 EXPECT_TRUE(success); |
| 3987 } | 3967 } |
| 3988 | 3968 |
| 3989 // Test that cross-process popups can't be navigated to disallowed URLs by | 3969 // Test that cross-process popups can't be navigated to disallowed URLs by |
| 3990 // their opener. This ensures that proper URL validation is performed when | 3970 // their opener. This ensures that proper URL validation is performed when |
| 3991 // RenderFrameProxyHosts are navigated. See https://crbug.com/595339. | 3971 // RenderFrameProxyHosts are navigated. See https://crbug.com/595339. |
| 3992 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigatePopupToIllegalURL) { | 3972 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigatePopupToIllegalURL) { |
| 3993 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | 3973 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 3994 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 3974 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3995 | 3975 |
| 3996 // Open a cross-site popup. | 3976 // Open a cross-site popup. |
| 3997 GURL popup_url(embedded_test_server()->GetURL("b.com", "/title2.html")); | 3977 GURL popup_url(embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 3998 Shell* popup = OpenPopup(shell()->web_contents(), popup_url, "foo"); | 3978 Shell* popup = OpenPopup(shell(), popup_url, "foo"); |
| 3999 EXPECT_TRUE(popup); | 3979 EXPECT_TRUE(popup); |
| 4000 EXPECT_NE(popup->web_contents()->GetSiteInstance(), | 3980 EXPECT_NE(popup->web_contents()->GetSiteInstance(), |
| 4001 shell()->web_contents()->GetSiteInstance()); | 3981 shell()->web_contents()->GetSiteInstance()); |
| 4002 | 3982 |
| 4003 // From the opener, navigate the popup to a file:/// URL. This should be | 3983 // From the opener, navigate the popup to a file:/// URL. This should be |
| 4004 // disallowed and result in an about:blank navigation. | 3984 // disallowed and result in an about:blank navigation. |
| 4005 GURL file_url("file:///"); | 3985 GURL file_url("file:///"); |
| 4006 NavigateNamedFrame(shell()->web_contents(), file_url, "foo"); | 3986 NavigateNamedFrame(shell(), file_url, "foo"); |
| 4007 EXPECT_TRUE(WaitForLoadStop(popup->web_contents())); | 3987 EXPECT_TRUE(WaitForLoadStop(popup->web_contents())); |
| 4008 EXPECT_EQ(GURL(url::kAboutBlankURL), | 3988 EXPECT_EQ(GURL(url::kAboutBlankURL), |
| 4009 popup->web_contents()->GetLastCommittedURL()); | 3989 popup->web_contents()->GetLastCommittedURL()); |
| 4010 | 3990 |
| 4011 // Navigate popup back to a cross-site URL. | 3991 // Navigate popup back to a cross-site URL. |
| 4012 EXPECT_TRUE(NavigateToURL(popup, popup_url)); | 3992 EXPECT_TRUE(NavigateToURL(popup, popup_url)); |
| 4013 EXPECT_NE(popup->web_contents()->GetSiteInstance(), | 3993 EXPECT_NE(popup->web_contents()->GetSiteInstance(), |
| 4014 shell()->web_contents()->GetSiteInstance()); | 3994 shell()->web_contents()->GetSiteInstance()); |
| 4015 | 3995 |
| 4016 // Now try the same test with a chrome:// URL. | 3996 // Now try the same test with a chrome:// URL. |
| 4017 GURL chrome_url(std::string(kChromeUIScheme) + "://" + | 3997 GURL chrome_url(std::string(kChromeUIScheme) + "://" + |
| 4018 std::string(kChromeUIGpuHost)); | 3998 std::string(kChromeUIGpuHost)); |
| 4019 NavigateNamedFrame(shell()->web_contents(), chrome_url, "foo"); | 3999 NavigateNamedFrame(shell(), chrome_url, "foo"); |
| 4020 EXPECT_TRUE(WaitForLoadStop(popup->web_contents())); | 4000 EXPECT_TRUE(WaitForLoadStop(popup->web_contents())); |
| 4021 EXPECT_EQ(GURL(url::kAboutBlankURL), | 4001 EXPECT_EQ(GURL(url::kAboutBlankURL), |
| 4022 popup->web_contents()->GetLastCommittedURL()); | 4002 popup->web_contents()->GetLastCommittedURL()); |
| 4023 } | 4003 } |
| 4024 | 4004 |
| 4025 // Verify that named frames are discoverable from their opener's ancestors. | 4005 // Verify that named frames are discoverable from their opener's ancestors. |
| 4026 // See https://crbug.com/511474. | 4006 // See https://crbug.com/511474. |
| 4027 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 4007 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 4028 DiscoverNamedFrameFromAncestorOfOpener) { | 4008 DiscoverNamedFrameFromAncestorOfOpener) { |
| 4029 GURL main_url( | 4009 GURL main_url( |
| 4030 embedded_test_server()->GetURL("a.com", "/site_per_process_main.html")); | 4010 embedded_test_server()->GetURL("a.com", "/site_per_process_main.html")); |
| 4031 NavigateToURL(shell(), main_url); | 4011 NavigateToURL(shell(), main_url); |
| 4032 | 4012 |
| 4033 // It is safe to obtain the root frame tree node here, as it doesn't change. | 4013 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 4034 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 4014 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 4035 | 4015 |
| 4036 // Navigate first child cross-site. | 4016 // Navigate first child cross-site. |
| 4037 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 4017 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 4038 NavigateFrameToURL(root->child_at(0), frame_url); | 4018 NavigateFrameToURL(root->child_at(0), frame_url); |
| 4039 | 4019 |
| 4040 // Open a popup named "foo" from the first child. | 4020 // Open a popup named "foo" from the first child. |
| 4041 Shell* foo_shell = OpenPopup(root->child_at(0)->current_frame_host(), | 4021 Shell* foo_shell = |
| 4042 GURL(url::kAboutBlankURL), "foo"); | 4022 OpenPopup(root->child_at(0), GURL(url::kAboutBlankURL), "foo"); |
| 4043 EXPECT_TRUE(foo_shell); | 4023 EXPECT_TRUE(foo_shell); |
| 4044 | 4024 |
| 4045 // Check that a proxy was created for the "foo" popup in a.com. | 4025 // Check that a proxy was created for the "foo" popup in a.com. |
| 4046 FrameTreeNode* foo_root = | 4026 FrameTreeNode* foo_root = |
| 4047 static_cast<WebContentsImpl*>(foo_shell->web_contents()) | 4027 static_cast<WebContentsImpl*>(foo_shell->web_contents()) |
| 4048 ->GetFrameTree() | 4028 ->GetFrameTree() |
| 4049 ->root(); | 4029 ->root(); |
| 4050 SiteInstance* site_instance_a = root->current_frame_host()->GetSiteInstance(); | 4030 SiteInstance* site_instance_a = root->current_frame_host()->GetSiteInstance(); |
| 4051 RenderFrameProxyHost* popup_rfph_for_a = | 4031 RenderFrameProxyHost* popup_rfph_for_a = |
| 4052 foo_root->render_manager()->GetRenderFrameProxyHost(site_instance_a); | 4032 foo_root->render_manager()->GetRenderFrameProxyHost(site_instance_a); |
| 4053 EXPECT_TRUE(popup_rfph_for_a); | 4033 EXPECT_TRUE(popup_rfph_for_a); |
| 4054 | 4034 |
| 4055 // Verify that the main frame can find the "foo" popup by name. If | 4035 // Verify that the main frame can find the "foo" popup by name. If |
| 4056 // window.open targets the correct frame, the "foo" popup's current URL | 4036 // window.open targets the correct frame, the "foo" popup's current URL |
| 4057 // should be updated to |named_frame_url|. | 4037 // should be updated to |named_frame_url|. |
| 4058 GURL named_frame_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 4038 GURL named_frame_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 4059 NavigateNamedFrame(shell()->web_contents(), named_frame_url, "foo"); | 4039 NavigateNamedFrame(shell(), named_frame_url, "foo"); |
| 4060 EXPECT_TRUE(WaitForLoadStop(foo_shell->web_contents())); | 4040 EXPECT_TRUE(WaitForLoadStop(foo_shell->web_contents())); |
| 4061 EXPECT_EQ(named_frame_url, foo_root->current_url()); | 4041 EXPECT_EQ(named_frame_url, foo_root->current_url()); |
| 4062 | 4042 |
| 4063 // Navigate the popup cross-site and ensure it's still reachable via | 4043 // Navigate the popup cross-site and ensure it's still reachable via |
| 4064 // window.open from the main frame. | 4044 // window.open from the main frame. |
| 4065 GURL d_url(embedded_test_server()->GetURL("d.com", "/title3.html")); | 4045 GURL d_url(embedded_test_server()->GetURL("d.com", "/title3.html")); |
| 4066 NavigateToURL(foo_shell, d_url); | 4046 NavigateToURL(foo_shell, d_url); |
| 4067 EXPECT_EQ(d_url, foo_root->current_url()); | 4047 EXPECT_EQ(d_url, foo_root->current_url()); |
| 4068 NavigateNamedFrame(shell()->web_contents(), named_frame_url, "foo"); | 4048 NavigateNamedFrame(shell(), named_frame_url, "foo"); |
| 4069 EXPECT_TRUE(WaitForLoadStop(foo_shell->web_contents())); | 4049 EXPECT_TRUE(WaitForLoadStop(foo_shell->web_contents())); |
| 4070 EXPECT_EQ(named_frame_url, foo_root->current_url()); | 4050 EXPECT_EQ(named_frame_url, foo_root->current_url()); |
| 4071 } | 4051 } |
| 4072 | 4052 |
| 4073 // Similar to DiscoverNamedFrameFromAncestorOfOpener, but check that if a | 4053 // Similar to DiscoverNamedFrameFromAncestorOfOpener, but check that if a |
| 4074 // window is created without a name and acquires window.name later, it will | 4054 // window is created without a name and acquires window.name later, it will |
| 4075 // still be discoverable from its opener's ancestors. Also, instead of using | 4055 // still be discoverable from its opener's ancestors. Also, instead of using |
| 4076 // an opener's ancestor, this test uses a popup with same origin as that | 4056 // an opener's ancestor, this test uses a popup with same origin as that |
| 4077 // ancestor. See https://crbug.com/511474. | 4057 // ancestor. See https://crbug.com/511474. |
| 4078 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 4058 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 4079 DiscoverFrameAfterSettingWindowName) { | 4059 DiscoverFrameAfterSettingWindowName) { |
| 4080 GURL main_url( | 4060 GURL main_url( |
| 4081 embedded_test_server()->GetURL("a.com", "/site_per_process_main.html")); | 4061 embedded_test_server()->GetURL("a.com", "/site_per_process_main.html")); |
| 4082 NavigateToURL(shell(), main_url); | 4062 NavigateToURL(shell(), main_url); |
| 4083 | 4063 |
| 4084 // It is safe to obtain the root frame tree node here, as it doesn't change. | 4064 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 4085 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 4065 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 4086 | 4066 |
| 4087 // Open a same-site popup from the main frame. | 4067 // Open a same-site popup from the main frame. |
| 4088 GURL a_com_url(embedded_test_server()->GetURL("a.com", "/title3.html")); | 4068 GURL a_com_url(embedded_test_server()->GetURL("a.com", "/title3.html")); |
| 4089 Shell* a_com_shell = | 4069 Shell* a_com_shell = OpenPopup(root->child_at(0), a_com_url, ""); |
| 4090 OpenPopup(root->child_at(0)->current_frame_host(), a_com_url, ""); | |
| 4091 EXPECT_TRUE(a_com_shell); | 4070 EXPECT_TRUE(a_com_shell); |
| 4092 | 4071 |
| 4093 // Navigate first child on main frame cross-site. | 4072 // Navigate first child on main frame cross-site. |
| 4094 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 4073 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 4095 NavigateFrameToURL(root->child_at(0), frame_url); | 4074 NavigateFrameToURL(root->child_at(0), frame_url); |
| 4096 | 4075 |
| 4097 // Open an unnamed popup from the first child frame. | 4076 // Open an unnamed popup from the first child frame. |
| 4098 Shell* foo_shell = OpenPopup(root->child_at(0)->current_frame_host(), | 4077 Shell* foo_shell = |
| 4099 GURL(url::kAboutBlankURL), ""); | 4078 OpenPopup(root->child_at(0), GURL(url::kAboutBlankURL), ""); |
| 4100 EXPECT_TRUE(foo_shell); | 4079 EXPECT_TRUE(foo_shell); |
| 4101 | 4080 |
| 4102 // There should be no proxy created for the "foo" popup in a.com, since | 4081 // There should be no proxy created for the "foo" popup in a.com, since |
| 4103 // there's no way for the two a.com frames to access it yet. | 4082 // there's no way for the two a.com frames to access it yet. |
| 4104 FrameTreeNode* foo_root = | 4083 FrameTreeNode* foo_root = |
| 4105 static_cast<WebContentsImpl*>(foo_shell->web_contents()) | 4084 static_cast<WebContentsImpl*>(foo_shell->web_contents()) |
| 4106 ->GetFrameTree() | 4085 ->GetFrameTree() |
| 4107 ->root(); | 4086 ->root(); |
| 4108 SiteInstance* site_instance_a = root->current_frame_host()->GetSiteInstance(); | 4087 SiteInstance* site_instance_a = root->current_frame_host()->GetSiteInstance(); |
| 4109 EXPECT_FALSE( | 4088 EXPECT_FALSE( |
| 4110 foo_root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); | 4089 foo_root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); |
| 4111 | 4090 |
| 4112 // Set window.name in the popup's frame. | 4091 // Set window.name in the popup's frame. |
| 4113 EXPECT_TRUE(ExecuteScript(foo_shell->web_contents(), "window.name = 'foo'")); | 4092 EXPECT_TRUE(ExecuteScript(foo_shell, "window.name = 'foo'")); |
| 4114 | 4093 |
| 4115 // A proxy for the popup should now exist in a.com. | 4094 // A proxy for the popup should now exist in a.com. |
| 4116 EXPECT_TRUE( | 4095 EXPECT_TRUE( |
| 4117 foo_root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); | 4096 foo_root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); |
| 4118 | 4097 |
| 4119 // Verify that the a.com popup can now find the "foo" popup by name. | 4098 // Verify that the a.com popup can now find the "foo" popup by name. |
| 4120 GURL named_frame_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 4099 GURL named_frame_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
| 4121 NavigateNamedFrame(a_com_shell->web_contents(), named_frame_url, "foo"); | 4100 NavigateNamedFrame(a_com_shell, named_frame_url, "foo"); |
| 4122 EXPECT_TRUE(WaitForLoadStop(foo_shell->web_contents())); | 4101 EXPECT_TRUE(WaitForLoadStop(foo_shell->web_contents())); |
| 4123 EXPECT_EQ(named_frame_url, foo_root->current_url()); | 4102 EXPECT_EQ(named_frame_url, foo_root->current_url()); |
| 4124 } | 4103 } |
| 4125 | 4104 |
| 4126 // Check that frame opener updates work with subframes. Set up a window with a | 4105 // Check that frame opener updates work with subframes. Set up a window with a |
| 4127 // popup and update openers for the popup's main frame and subframe to | 4106 // popup and update openers for the popup's main frame and subframe to |
| 4128 // subframes on first window, as follows: | 4107 // subframes on first window, as follows: |
| 4129 // | 4108 // |
| 4130 // foo +---- bar | 4109 // foo +---- bar |
| 4131 // / \ | / \ . | 4110 // / \ | / \ . |
| 4132 // bar foo <-+ bar foo | 4111 // bar foo <-+ bar foo |
| 4133 // ^ | | 4112 // ^ | |
| 4134 // +--------------------+ | 4113 // +--------------------+ |
| 4135 // | 4114 // |
| 4136 // The sites are carefully set up so that both opener updates are cross-process | 4115 // The sites are carefully set up so that both opener updates are cross-process |
| 4137 // but still allowed by Blink's navigation checks. | 4116 // but still allowed by Blink's navigation checks. |
| 4138 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, UpdateSubframeOpener) { | 4117 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, UpdateSubframeOpener) { |
| 4139 GURL main_url = embedded_test_server()->GetURL( | 4118 GURL main_url = embedded_test_server()->GetURL( |
| 4140 "foo.com", "/frame_tree/page_with_two_frames.html"); | 4119 "foo.com", "/frame_tree/page_with_two_frames.html"); |
| 4141 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 4120 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 4142 | 4121 |
| 4143 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 4122 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 4144 EXPECT_EQ(2U, root->child_count()); | 4123 EXPECT_EQ(2U, root->child_count()); |
| 4145 | 4124 |
| 4146 // From the top frame, open a popup and navigate it to a cross-site page with | 4125 // From the top frame, open a popup and navigate it to a cross-site page with |
| 4147 // two subframes. | 4126 // two subframes. |
| 4148 Shell* popup_shell = | 4127 Shell* popup_shell = OpenPopup(shell(), GURL(url::kAboutBlankURL), "popup"); |
| 4149 OpenPopup(shell()->web_contents(), GURL(url::kAboutBlankURL), "popup"); | |
| 4150 EXPECT_TRUE(popup_shell); | 4128 EXPECT_TRUE(popup_shell); |
| 4151 GURL popup_url(embedded_test_server()->GetURL( | 4129 GURL popup_url(embedded_test_server()->GetURL( |
| 4152 "bar.com", "/frame_tree/page_with_post_message_frames.html")); | 4130 "bar.com", "/frame_tree/page_with_post_message_frames.html")); |
| 4153 NavigateToURL(popup_shell, popup_url); | 4131 NavigateToURL(popup_shell, popup_url); |
| 4154 | 4132 |
| 4155 FrameTreeNode* popup_root = | 4133 FrameTreeNode* popup_root = |
| 4156 static_cast<WebContentsImpl*>(popup_shell->web_contents()) | 4134 static_cast<WebContentsImpl*>(popup_shell->web_contents()) |
| 4157 ->GetFrameTree() | 4135 ->GetFrameTree() |
| 4158 ->root(); | 4136 ->root(); |
| 4159 EXPECT_EQ(2U, popup_root->child_count()); | 4137 EXPECT_EQ(2U, popup_root->child_count()); |
| 4160 | 4138 |
| 4161 // Popup's opener should point to main frame to start with. | 4139 // Popup's opener should point to main frame to start with. |
| 4162 EXPECT_EQ(root, popup_root->opener()); | 4140 EXPECT_EQ(root, popup_root->opener()); |
| 4163 | 4141 |
| 4164 // Update the popup's opener to the second subframe on the main page (which | 4142 // Update the popup's opener to the second subframe on the main page (which |
| 4165 // is same-origin with the top frame, i.e., foo.com). | 4143 // is same-origin with the top frame, i.e., foo.com). |
| 4166 bool success = false; | 4144 bool success = false; |
| 4167 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4145 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4168 root->child_at(1)->current_frame_host(), | 4146 root->child_at(1), |
| 4169 "window.domAutomationController.send(!!window.open('','popup'));", | 4147 "window.domAutomationController.send(!!window.open('','popup'));", |
| 4170 &success)); | 4148 &success)); |
| 4171 EXPECT_TRUE(success); | 4149 EXPECT_TRUE(success); |
| 4172 | 4150 |
| 4173 // Check that updated opener propagated to the browser process and the | 4151 // Check that updated opener propagated to the browser process and the |
| 4174 // popup's bar.com process. | 4152 // popup's bar.com process. |
| 4175 EXPECT_EQ(root->child_at(1), popup_root->opener()); | 4153 EXPECT_EQ(root->child_at(1), popup_root->opener()); |
| 4176 | 4154 |
| 4177 success = false; | 4155 success = false; |
| 4178 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4156 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4179 popup_shell->web_contents(), | 4157 popup_shell, |
| 4180 "window.domAutomationController.send(" | 4158 "window.domAutomationController.send(" |
| 4181 " window.opener === window.opener.parent.frames['frame2']);", | 4159 " window.opener === window.opener.parent.frames['frame2']);", |
| 4182 &success)); | 4160 &success)); |
| 4183 EXPECT_TRUE(success); | 4161 EXPECT_TRUE(success); |
| 4184 | 4162 |
| 4185 // Now update opener on the popup's second subframe (foo.com) to the main | 4163 // Now update opener on the popup's second subframe (foo.com) to the main |
| 4186 // page's first subframe (bar.com). | 4164 // page's first subframe (bar.com). |
| 4187 success = false; | 4165 success = false; |
| 4188 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4166 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4189 root->child_at(0)->current_frame_host(), | 4167 root->child_at(0), |
| 4190 "window.domAutomationController.send(!!window.open('','subframe2'));", | 4168 "window.domAutomationController.send(!!window.open('','subframe2'));", |
| 4191 &success)); | 4169 &success)); |
| 4192 EXPECT_TRUE(success); | 4170 EXPECT_TRUE(success); |
| 4193 | 4171 |
| 4194 // Check that updated opener propagated to the browser process and the | 4172 // Check that updated opener propagated to the browser process and the |
| 4195 // foo.com process. | 4173 // foo.com process. |
| 4196 EXPECT_EQ(root->child_at(0), popup_root->child_at(1)->opener()); | 4174 EXPECT_EQ(root->child_at(0), popup_root->child_at(1)->opener()); |
| 4197 | 4175 |
| 4198 success = false; | 4176 success = false; |
| 4199 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4177 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4200 popup_root->child_at(1)->current_frame_host(), | 4178 popup_root->child_at(1), |
| 4201 "window.domAutomationController.send(" | 4179 "window.domAutomationController.send(" |
| 4202 " window.opener === window.opener.parent.frames['frame1']);", | 4180 " window.opener === window.opener.parent.frames['frame1']);", |
| 4203 &success)); | 4181 &success)); |
| 4204 EXPECT_TRUE(success); | 4182 EXPECT_TRUE(success); |
| 4205 } | 4183 } |
| 4206 | 4184 |
| 4207 // Check that when a subframe navigates to a new SiteInstance, the new | 4185 // Check that when a subframe navigates to a new SiteInstance, the new |
| 4208 // SiteInstance will get a proxy for the opener of subframe's parent. I.e., | 4186 // SiteInstance will get a proxy for the opener of subframe's parent. I.e., |
| 4209 // accessing parent.opener from the subframe should still work after a | 4187 // accessing parent.opener from the subframe should still work after a |
| 4210 // cross-process navigation. | 4188 // cross-process navigation. |
| 4211 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 4189 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 4212 NavigatingSubframePreservesOpenerInParent) { | 4190 NavigatingSubframePreservesOpenerInParent) { |
| 4213 GURL main_url = embedded_test_server()->GetURL("a.com", "/post_message.html"); | 4191 GURL main_url = embedded_test_server()->GetURL("a.com", "/post_message.html"); |
| 4214 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 4192 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 4215 | 4193 |
| 4216 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 4194 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 4217 | 4195 |
| 4218 // Open a popup with a cross-site page that has a subframe. | 4196 // Open a popup with a cross-site page that has a subframe. |
| 4219 GURL popup_url(embedded_test_server()->GetURL( | 4197 GURL popup_url(embedded_test_server()->GetURL( |
| 4220 "b.com", "/cross_site_iframe_factory.html?b(b)")); | 4198 "b.com", "/cross_site_iframe_factory.html?b(b)")); |
| 4221 Shell* popup_shell = OpenPopup(shell()->web_contents(), popup_url, "popup"); | 4199 Shell* popup_shell = OpenPopup(shell(), popup_url, "popup"); |
| 4222 EXPECT_TRUE(popup_shell); | 4200 EXPECT_TRUE(popup_shell); |
| 4223 FrameTreeNode* popup_root = | 4201 FrameTreeNode* popup_root = |
| 4224 static_cast<WebContentsImpl*>(popup_shell->web_contents()) | 4202 static_cast<WebContentsImpl*>(popup_shell->web_contents()) |
| 4225 ->GetFrameTree() | 4203 ->GetFrameTree() |
| 4226 ->root(); | 4204 ->root(); |
| 4227 EXPECT_EQ(1U, popup_root->child_count()); | 4205 EXPECT_EQ(1U, popup_root->child_count()); |
| 4228 | 4206 |
| 4229 // Check that the popup's opener is correct in the browser process. | 4207 // Check that the popup's opener is correct in the browser process. |
| 4230 EXPECT_EQ(root, popup_root->opener()); | 4208 EXPECT_EQ(root, popup_root->opener()); |
| 4231 | 4209 |
| 4232 // Navigate popup's subframe to another site. | 4210 // Navigate popup's subframe to another site. |
| 4233 GURL frame_url(embedded_test_server()->GetURL("c.com", "/post_message.html")); | 4211 GURL frame_url(embedded_test_server()->GetURL("c.com", "/post_message.html")); |
| 4234 NavigateFrameToURL(popup_root->child_at(0), frame_url); | 4212 NavigateFrameToURL(popup_root->child_at(0), frame_url); |
| 4235 | 4213 |
| 4236 // Check that the new subframe process still sees correct opener for its | 4214 // Check that the new subframe process still sees correct opener for its |
| 4237 // parent by sending a postMessage to subframe's parent.opener. | 4215 // parent by sending a postMessage to subframe's parent.opener. |
| 4238 bool success = false; | 4216 bool success = false; |
| 4239 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4217 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4240 popup_root->child_at(0)->current_frame_host(), | 4218 popup_root->child_at(0), |
| 4241 "window.domAutomationController.send(!!parent.opener);", &success)); | 4219 "window.domAutomationController.send(!!parent.opener);", &success)); |
| 4242 EXPECT_TRUE(success); | 4220 EXPECT_TRUE(success); |
| 4243 | 4221 |
| 4244 base::string16 expected_title = base::ASCIIToUTF16("msg"); | 4222 base::string16 expected_title = base::ASCIIToUTF16("msg"); |
| 4245 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 4223 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 4246 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4224 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4247 popup_root->child_at(0)->current_frame_host(), | 4225 popup_root->child_at(0), |
| 4248 "window.domAutomationController.send(postToOpenerOfParent('msg','*'));", | 4226 "window.domAutomationController.send(postToOpenerOfParent('msg','*'));", |
| 4249 &success)); | 4227 &success)); |
| 4250 EXPECT_TRUE(success); | 4228 EXPECT_TRUE(success); |
| 4251 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 4229 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 4252 } | 4230 } |
| 4253 | 4231 |
| 4254 // Check that if a subframe has an opener, that opener is preserved when the | 4232 // Check that if a subframe has an opener, that opener is preserved when the |
| 4255 // subframe navigates cross-site. | 4233 // subframe navigates cross-site. |
| 4256 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateSubframeWithOpener) { | 4234 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateSubframeWithOpener) { |
| 4257 GURL main_url(embedded_test_server()->GetURL( | 4235 GURL main_url(embedded_test_server()->GetURL( |
| 4258 "foo.com", "/frame_tree/page_with_two_frames.html")); | 4236 "foo.com", "/frame_tree/page_with_two_frames.html")); |
| 4259 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 4237 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 4260 | 4238 |
| 4261 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 4239 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 4262 EXPECT_EQ( | 4240 EXPECT_EQ( |
| 4263 " Site A ------------ proxies for B\n" | 4241 " Site A ------------ proxies for B\n" |
| 4264 " |--Site B ------- proxies for A\n" | 4242 " |--Site B ------- proxies for A\n" |
| 4265 " +--Site A ------- proxies for B\n" | 4243 " +--Site A ------- proxies for B\n" |
| 4266 "Where A = http://foo.com/\n" | 4244 "Where A = http://foo.com/\n" |
| 4267 " B = http://bar.com/", | 4245 " B = http://bar.com/", |
| 4268 DepictFrameTree(root)); | 4246 DepictFrameTree(root)); |
| 4269 | 4247 |
| 4270 // Update the first (cross-site) subframe's opener to root frame. | 4248 // Update the first (cross-site) subframe's opener to root frame. |
| 4271 bool success = false; | 4249 bool success = false; |
| 4272 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4250 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4273 root->current_frame_host(), | 4251 root, "window.domAutomationController.send(!!window.open('','frame1'));", |
| 4274 "window.domAutomationController.send(!!window.open('','frame1'));", | |
| 4275 &success)); | 4252 &success)); |
| 4276 EXPECT_TRUE(success); | 4253 EXPECT_TRUE(success); |
| 4277 | 4254 |
| 4278 // Check that updated opener propagated to the browser process and subframe's | 4255 // Check that updated opener propagated to the browser process and subframe's |
| 4279 // process. | 4256 // process. |
| 4280 EXPECT_EQ(root, root->child_at(0)->opener()); | 4257 EXPECT_EQ(root, root->child_at(0)->opener()); |
| 4281 | 4258 |
| 4282 success = false; | 4259 success = false; |
| 4283 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4260 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4284 root->child_at(0)->current_frame_host(), | 4261 root->child_at(0), |
| 4285 "window.domAutomationController.send(window.opener === window.parent);", | 4262 "window.domAutomationController.send(window.opener === window.parent);", |
| 4286 &success)); | 4263 &success)); |
| 4287 EXPECT_TRUE(success); | 4264 EXPECT_TRUE(success); |
| 4288 | 4265 |
| 4289 // Navigate the subframe with opener to another site. | 4266 // Navigate the subframe with opener to another site. |
| 4290 GURL frame_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); | 4267 GURL frame_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); |
| 4291 NavigateFrameToURL(root->child_at(0), frame_url); | 4268 NavigateFrameToURL(root->child_at(0), frame_url); |
| 4292 | 4269 |
| 4293 // Check that the subframe still sees correct opener in its new process. | 4270 // Check that the subframe still sees correct opener in its new process. |
| 4294 success = false; | 4271 success = false; |
| 4295 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4272 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4296 root->child_at(0)->current_frame_host(), | 4273 root->child_at(0), |
| 4297 "window.domAutomationController.send(window.opener === window.parent);", | 4274 "window.domAutomationController.send(window.opener === window.parent);", |
| 4298 &success)); | 4275 &success)); |
| 4299 EXPECT_TRUE(success); | 4276 EXPECT_TRUE(success); |
| 4300 | 4277 |
| 4301 // Navigate second subframe to a new site. Check that the proxy that's | 4278 // Navigate second subframe to a new site. Check that the proxy that's |
| 4302 // created for the first subframe in the new SiteInstance has correct opener. | 4279 // created for the first subframe in the new SiteInstance has correct opener. |
| 4303 GURL frame2_url(embedded_test_server()->GetURL("qux.com", "/title1.html")); | 4280 GURL frame2_url(embedded_test_server()->GetURL("qux.com", "/title1.html")); |
| 4304 NavigateFrameToURL(root->child_at(1), frame2_url); | 4281 NavigateFrameToURL(root->child_at(1), frame2_url); |
| 4305 | 4282 |
| 4306 success = false; | 4283 success = false; |
| 4307 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4284 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4308 root->child_at(1)->current_frame_host(), | 4285 root->child_at(1), |
| 4309 "window.domAutomationController.send(" | 4286 "window.domAutomationController.send(" |
| 4310 " parent.frames['frame1'].opener === parent);", | 4287 " parent.frames['frame1'].opener === parent);", |
| 4311 &success)); | 4288 &success)); |
| 4312 EXPECT_TRUE(success); | 4289 EXPECT_TRUE(success); |
| 4313 } | 4290 } |
| 4314 | 4291 |
| 4315 // Check that if a subframe has an opener, that opener is preserved when a new | 4292 // Check that if a subframe has an opener, that opener is preserved when a new |
| 4316 // RenderFrameProxy is created for that subframe in another renderer process. | 4293 // RenderFrameProxy is created for that subframe in another renderer process. |
| 4317 // Similar to NavigateSubframeWithOpener, but this test verifies the subframe | 4294 // Similar to NavigateSubframeWithOpener, but this test verifies the subframe |
| 4318 // opener plumbing for FrameMsg_NewFrameProxy, whereas | 4295 // opener plumbing for FrameMsg_NewFrameProxy, whereas |
| 4319 // NavigateSubframeWithOpener targets FrameMsg_NewFrame. | 4296 // NavigateSubframeWithOpener targets FrameMsg_NewFrame. |
| 4320 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 4297 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 4321 NewRenderFrameProxyPreservesOpener) { | 4298 NewRenderFrameProxyPreservesOpener) { |
| 4322 GURL main_url( | 4299 GURL main_url( |
| 4323 embedded_test_server()->GetURL("foo.com", "/post_message.html")); | 4300 embedded_test_server()->GetURL("foo.com", "/post_message.html")); |
| 4324 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 4301 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 4325 | 4302 |
| 4326 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 4303 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 4327 | 4304 |
| 4328 // Open a popup with a cross-site page that has two subframes. | 4305 // Open a popup with a cross-site page that has two subframes. |
| 4329 GURL popup_url(embedded_test_server()->GetURL( | 4306 GURL popup_url(embedded_test_server()->GetURL( |
| 4330 "bar.com", "/frame_tree/page_with_post_message_frames.html")); | 4307 "bar.com", "/frame_tree/page_with_post_message_frames.html")); |
| 4331 Shell* popup_shell = OpenPopup(shell()->web_contents(), popup_url, "popup"); | 4308 Shell* popup_shell = OpenPopup(shell(), popup_url, "popup"); |
| 4332 EXPECT_TRUE(popup_shell); | 4309 EXPECT_TRUE(popup_shell); |
| 4333 FrameTreeNode* popup_root = | 4310 FrameTreeNode* popup_root = |
| 4334 static_cast<WebContentsImpl*>(popup_shell->web_contents()) | 4311 static_cast<WebContentsImpl*>(popup_shell->web_contents()) |
| 4335 ->GetFrameTree() | 4312 ->GetFrameTree() |
| 4336 ->root(); | 4313 ->root(); |
| 4337 EXPECT_EQ( | 4314 EXPECT_EQ( |
| 4338 " Site A ------------ proxies for B\n" | 4315 " Site A ------------ proxies for B\n" |
| 4339 " |--Site A ------- proxies for B\n" | 4316 " |--Site A ------- proxies for B\n" |
| 4340 " +--Site B ------- proxies for A\n" | 4317 " +--Site B ------- proxies for A\n" |
| 4341 "Where A = http://bar.com/\n" | 4318 "Where A = http://bar.com/\n" |
| 4342 " B = http://foo.com/", | 4319 " B = http://foo.com/", |
| 4343 DepictFrameTree(popup_root)); | 4320 DepictFrameTree(popup_root)); |
| 4344 | 4321 |
| 4345 // Update the popup's second subframe's opener to root frame. This is | 4322 // Update the popup's second subframe's opener to root frame. This is |
| 4346 // allowed because that subframe is in the same foo.com SiteInstance as the | 4323 // allowed because that subframe is in the same foo.com SiteInstance as the |
| 4347 // root frame. | 4324 // root frame. |
| 4348 bool success = false; | 4325 bool success = false; |
| 4349 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4326 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4350 root->current_frame_host(), | 4327 root, |
| 4351 "window.domAutomationController.send(!!window.open('','subframe2'));", | 4328 "window.domAutomationController.send(!!window.open('','subframe2'));", |
| 4352 &success)); | 4329 &success)); |
| 4353 EXPECT_TRUE(success); | 4330 EXPECT_TRUE(success); |
| 4354 | 4331 |
| 4355 // Check that the opener update propagated to the browser process and bar.com | 4332 // Check that the opener update propagated to the browser process and bar.com |
| 4356 // process. | 4333 // process. |
| 4357 EXPECT_EQ(root, popup_root->child_at(1)->opener()); | 4334 EXPECT_EQ(root, popup_root->child_at(1)->opener()); |
| 4358 success = false; | 4335 success = false; |
| 4359 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4336 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4360 popup_root->child_at(0)->current_frame_host(), | 4337 popup_root->child_at(0), |
| 4361 "window.domAutomationController.send(" | 4338 "window.domAutomationController.send(" |
| 4362 " parent.frames['subframe2'].opener && " | 4339 " parent.frames['subframe2'].opener && " |
| 4363 " parent.frames['subframe2'].opener === parent.opener);", | 4340 " parent.frames['subframe2'].opener === parent.opener);", |
| 4364 &success)); | 4341 &success)); |
| 4365 EXPECT_TRUE(success); | 4342 EXPECT_TRUE(success); |
| 4366 | 4343 |
| 4367 // Navigate the popup's first subframe to another site. | 4344 // Navigate the popup's first subframe to another site. |
| 4368 GURL frame_url( | 4345 GURL frame_url( |
| 4369 embedded_test_server()->GetURL("baz.com", "/post_message.html")); | 4346 embedded_test_server()->GetURL("baz.com", "/post_message.html")); |
| 4370 NavigateFrameToURL(popup_root->child_at(0), frame_url); | 4347 NavigateFrameToURL(popup_root->child_at(0), frame_url); |
| 4371 | 4348 |
| 4372 // Check that the second subframe's opener is still correct in the first | 4349 // Check that the second subframe's opener is still correct in the first |
| 4373 // subframe's new process. Verify it both in JS and with a postMessage. | 4350 // subframe's new process. Verify it both in JS and with a postMessage. |
| 4374 success = false; | 4351 success = false; |
| 4375 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4352 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4376 popup_root->child_at(0)->current_frame_host(), | 4353 popup_root->child_at(0), |
| 4377 "window.domAutomationController.send(" | 4354 "window.domAutomationController.send(" |
| 4378 " parent.frames['subframe2'].opener && " | 4355 " parent.frames['subframe2'].opener && " |
| 4379 " parent.frames['subframe2'].opener === parent.opener);", | 4356 " parent.frames['subframe2'].opener === parent.opener);", |
| 4380 &success)); | 4357 &success)); |
| 4381 EXPECT_TRUE(success); | 4358 EXPECT_TRUE(success); |
| 4382 | 4359 |
| 4383 base::string16 expected_title = base::ASCIIToUTF16("msg"); | 4360 base::string16 expected_title = base::ASCIIToUTF16("msg"); |
| 4384 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 4361 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 4385 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 4362 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 4386 popup_root->child_at(0)->current_frame_host(), | 4363 popup_root->child_at(0), |
| 4387 "window.domAutomationController.send(" | 4364 "window.domAutomationController.send(" |
| 4388 " postToOpenerOfSibling('subframe2', 'msg', '*'));", | 4365 " postToOpenerOfSibling('subframe2', 'msg', '*'));", |
| 4389 &success)); | 4366 &success)); |
| 4390 EXPECT_TRUE(success); | 4367 EXPECT_TRUE(success); |
| 4391 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 4368 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 4392 } | 4369 } |
| 4393 | 4370 |
| 4394 // Test for https://crbug.com/515302. Perform two navigations, A->B->A, and | 4371 // Test for https://crbug.com/515302. Perform two navigations, A->B->A, and |
| 4395 // drop the SwapOut ACK from the A->B navigation, so that the second B->A | 4372 // drop the SwapOut ACK from the A->B navigation, so that the second B->A |
| 4396 // navigation is initiated before the first page receives the SwapOut ACK. | 4373 // navigation is initiated before the first page receives the SwapOut ACK. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4467 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 4444 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 4468 ReusePendingDeleteRenderViewHostForSubframe) { | 4445 ReusePendingDeleteRenderViewHostForSubframe) { |
| 4469 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | 4446 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 4470 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 4447 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 4471 | 4448 |
| 4472 std::string script = | 4449 std::string script = |
| 4473 "window.onunload = function() { " | 4450 "window.onunload = function() { " |
| 4474 " var start = Date.now();" | 4451 " var start = Date.now();" |
| 4475 " while (Date.now() - start < 1000);" | 4452 " while (Date.now() - start < 1000);" |
| 4476 "}"; | 4453 "}"; |
| 4477 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 4454 EXPECT_TRUE(ExecuteScript(shell(), script)); |
| 4478 | 4455 |
| 4479 // Navigating cross-site with an iframe to the original site shouldn't crash. | 4456 // Navigating cross-site with an iframe to the original site shouldn't crash. |
| 4480 GURL second_url(embedded_test_server()->GetURL( | 4457 GURL second_url(embedded_test_server()->GetURL( |
| 4481 "b.com", "/cross_site_iframe_factory.html?b(a)")); | 4458 "b.com", "/cross_site_iframe_factory.html?b(a)")); |
| 4482 EXPECT_TRUE(NavigateToURL(shell(), second_url)); | 4459 EXPECT_TRUE(NavigateToURL(shell(), second_url)); |
| 4483 | 4460 |
| 4484 // If the subframe is created while the main frame is pending deletion, then | 4461 // If the subframe is created while the main frame is pending deletion, then |
| 4485 // the RVH will be reused. The main frame should've been swapped with a | 4462 // the RVH will be reused. The main frame should've been swapped with a |
| 4486 // proxy despite being the last active frame in the progress (see | 4463 // proxy despite being the last active frame in the progress (see |
| 4487 // https://crbug.com/568836), and this proxy should also be reused by the new | 4464 // https://crbug.com/568836), and this proxy should also be reused by the new |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4506 EXPECT_EQ( | 4483 EXPECT_EQ( |
| 4507 " Site A ------------ proxies for B\n" | 4484 " Site A ------------ proxies for B\n" |
| 4508 " +--Site B ------- proxies for A\n" | 4485 " +--Site B ------- proxies for A\n" |
| 4509 "Where A = http://a.com/\n" | 4486 "Where A = http://a.com/\n" |
| 4510 " B = http://b.com/", | 4487 " B = http://b.com/", |
| 4511 DepictFrameTree(root)); | 4488 DepictFrameTree(root)); |
| 4512 | 4489 |
| 4513 // Focus the main frame's text field. The return value "input-focus" | 4490 // Focus the main frame's text field. The return value "input-focus" |
| 4514 // indicates that the focus event was fired correctly. | 4491 // indicates that the focus event was fired correctly. |
| 4515 std::string result; | 4492 std::string result; |
| 4516 EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(), | 4493 EXPECT_TRUE( |
| 4517 "focusInputField()", &result)); | 4494 ExecuteScriptAndExtractString(shell(), "focusInputField()", &result)); |
| 4518 EXPECT_EQ(result, "input-focus"); | 4495 EXPECT_EQ(result, "input-focus"); |
| 4519 | 4496 |
| 4520 // The main frame should be focused. | 4497 // The main frame should be focused. |
| 4521 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 4498 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
| 4522 | 4499 |
| 4523 DOMMessageQueue msg_queue; | 4500 DOMMessageQueue msg_queue; |
| 4524 | 4501 |
| 4525 // Click on the cross-process subframe. | 4502 // Click on the cross-process subframe. |
| 4526 SimulateMouseClick( | 4503 SimulateMouseClick( |
| 4527 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); | 4504 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4657 const char kSetupFocusEvents[] = | 4634 const char kSetupFocusEvents[] = |
| 4658 "window.addEventListener('focus', function() {" | 4635 "window.addEventListener('focus', function() {" |
| 4659 " domAutomationController.setAutomationId(0);" | 4636 " domAutomationController.setAutomationId(0);" |
| 4660 " domAutomationController.send('%s-got-focus');" | 4637 " domAutomationController.send('%s-got-focus');" |
| 4661 "});" | 4638 "});" |
| 4662 "window.addEventListener('blur', function() {" | 4639 "window.addEventListener('blur', function() {" |
| 4663 " domAutomationController.setAutomationId(0);" | 4640 " domAutomationController.setAutomationId(0);" |
| 4664 " domAutomationController.send('%s-lost-focus');" | 4641 " domAutomationController.send('%s-lost-focus');" |
| 4665 "});"; | 4642 "});"; |
| 4666 std::string script = base::StringPrintf(kSetupFocusEvents, "main", "main"); | 4643 std::string script = base::StringPrintf(kSetupFocusEvents, "main", "main"); |
| 4667 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 4644 EXPECT_TRUE(ExecuteScript(shell(), script)); |
| 4668 script = base::StringPrintf(kSetupFocusEvents, "child1", "child1"); | 4645 script = base::StringPrintf(kSetupFocusEvents, "child1", "child1"); |
| 4669 EXPECT_TRUE(ExecuteScript(child1->current_frame_host(), script)); | 4646 EXPECT_TRUE(ExecuteScript(child1, script)); |
| 4670 script = base::StringPrintf(kSetupFocusEvents, "child2", "child2"); | 4647 script = base::StringPrintf(kSetupFocusEvents, "child2", "child2"); |
| 4671 EXPECT_TRUE(ExecuteScript(child2->current_frame_host(), script)); | 4648 EXPECT_TRUE(ExecuteScript(child2, script)); |
| 4672 | 4649 |
| 4673 // Execute window.focus on the B subframe from the A main frame. | 4650 // Execute window.focus on the B subframe from the A main frame. |
| 4674 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "frames[0].focus()")); | 4651 EXPECT_TRUE(ExecuteScript(root, "frames[0].focus()")); |
| 4675 | 4652 |
| 4676 // Helper to wait for two specified messages to arrive on the specified | 4653 // Helper to wait for two specified messages to arrive on the specified |
| 4677 // DOMMessageQueue, assuming that the two messages can arrive in any order. | 4654 // DOMMessageQueue, assuming that the two messages can arrive in any order. |
| 4678 auto wait_for_two_messages = [](DOMMessageQueue* msg_queue, | 4655 auto wait_for_two_messages = [](DOMMessageQueue* msg_queue, |
| 4679 const std::string& msg1, | 4656 const std::string& msg1, |
| 4680 const std::string& msg2) { | 4657 const std::string& msg2) { |
| 4681 bool msg1_received = false; | 4658 bool msg1_received = false; |
| 4682 bool msg2_received = false; | 4659 bool msg2_received = false; |
| 4683 std::string status; | 4660 std::string status; |
| 4684 while (msg_queue->WaitForMessage(&status)) { | 4661 while (msg_queue->WaitForMessage(&status)) { |
| 4685 if (status == msg1) | 4662 if (status == msg1) |
| 4686 msg1_received = true; | 4663 msg1_received = true; |
| 4687 if (status == msg2) | 4664 if (status == msg2) |
| 4688 msg2_received = true; | 4665 msg2_received = true; |
| 4689 if (msg1_received && msg2_received) | 4666 if (msg1_received && msg2_received) |
| 4690 break; | 4667 break; |
| 4691 } | 4668 } |
| 4692 }; | 4669 }; |
| 4693 | 4670 |
| 4694 // Process A should fire a blur event, and process B should fire a focus | 4671 // Process A should fire a blur event, and process B should fire a focus |
| 4695 // event. Wait for both events. | 4672 // event. Wait for both events. |
| 4696 wait_for_two_messages(&msg_queue, "\"main-lost-focus\"", | 4673 wait_for_two_messages(&msg_queue, "\"main-lost-focus\"", |
| 4697 "\"child1-got-focus\""); | 4674 "\"child1-got-focus\""); |
| 4698 | 4675 |
| 4699 // The B subframe should now be focused in the browser process. | 4676 // The B subframe should now be focused in the browser process. |
| 4700 EXPECT_EQ(child1, root->frame_tree()->GetFocusedFrame()); | 4677 EXPECT_EQ(child1, root->frame_tree()->GetFocusedFrame()); |
| 4701 | 4678 |
| 4702 // Now, execute window.focus on the C subframe from A main frame. This | 4679 // Now, execute window.focus on the C subframe from A main frame. This |
| 4703 // checks that we can shift focus from one remote frame to another. | 4680 // checks that we can shift focus from one remote frame to another. |
| 4704 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "frames[1].focus()")); | 4681 EXPECT_TRUE(ExecuteScript(root, "frames[1].focus()")); |
| 4705 | 4682 |
| 4706 // Wait for the two subframes (B and C) to fire blur and focus events. | 4683 // Wait for the two subframes (B and C) to fire blur and focus events. |
| 4707 wait_for_two_messages(&msg_queue, "\"child1-lost-focus\"", | 4684 wait_for_two_messages(&msg_queue, "\"child1-lost-focus\"", |
| 4708 "\"child2-got-focus\""); | 4685 "\"child2-got-focus\""); |
| 4709 | 4686 |
| 4710 // The C subframe should now be focused. | 4687 // The C subframe should now be focused. |
| 4711 EXPECT_EQ(child2, root->frame_tree()->GetFocusedFrame()); | 4688 EXPECT_EQ(child2, root->frame_tree()->GetFocusedFrame()); |
| 4712 | 4689 |
| 4713 // window.focus the main frame from the C subframe. | 4690 // window.focus the main frame from the C subframe. |
| 4714 EXPECT_TRUE(ExecuteScript(child2->current_frame_host(), "parent.focus()")); | 4691 EXPECT_TRUE(ExecuteScript(child2, "parent.focus()")); |
| 4715 | 4692 |
| 4716 // Wait for the C subframe to blur and main frame to focus. | 4693 // Wait for the C subframe to blur and main frame to focus. |
| 4717 wait_for_two_messages(&msg_queue, "\"child2-lost-focus\"", | 4694 wait_for_two_messages(&msg_queue, "\"child2-lost-focus\"", |
| 4718 "\"main-got-focus\""); | 4695 "\"main-got-focus\""); |
| 4719 | 4696 |
| 4720 // The main frame should now be focused. | 4697 // The main frame should now be focused. |
| 4721 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 4698 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
| 4722 } | 4699 } |
| 4723 | 4700 |
| 4724 // There are no cursors on Android. | 4701 // There are no cursors on Android. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4803 // Tests that we are using the correct RenderFrameProxy when navigating an | 4780 // Tests that we are using the correct RenderFrameProxy when navigating an |
| 4804 // opener window. | 4781 // opener window. |
| 4805 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OpenerSetLocation) { | 4782 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OpenerSetLocation) { |
| 4806 // Navigate the main window. | 4783 // Navigate the main window. |
| 4807 GURL main_url(embedded_test_server()->GetURL("/title1.html")); | 4784 GURL main_url(embedded_test_server()->GetURL("/title1.html")); |
| 4808 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 4785 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 4809 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), main_url); | 4786 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), main_url); |
| 4810 | 4787 |
| 4811 // Load cross-site page into a new window. | 4788 // Load cross-site page into a new window. |
| 4812 GURL cross_url = embedded_test_server()->GetURL("foo.com", "/title1.html"); | 4789 GURL cross_url = embedded_test_server()->GetURL("foo.com", "/title1.html"); |
| 4813 Shell* popup = OpenPopup(shell()->web_contents(), cross_url, ""); | 4790 Shell* popup = OpenPopup(shell(), cross_url, ""); |
| 4814 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); | 4791 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); |
| 4815 | 4792 |
| 4816 // Use new window to navigate main window. | 4793 // Use new window to navigate main window. |
| 4817 std::string script = | 4794 std::string script = |
| 4818 "window.opener.location.href = '" + cross_url.spec() + "'"; | 4795 "window.opener.location.href = '" + cross_url.spec() + "'"; |
| 4819 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); | 4796 EXPECT_TRUE(ExecuteScript(popup, script)); |
| 4820 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 4797 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4821 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); | 4798 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); |
| 4822 } | 4799 } |
| 4823 | 4800 |
| 4824 // Ensure that a cross-process subframe with a touch-handler can receive touch | 4801 // Ensure that a cross-process subframe with a touch-handler can receive touch |
| 4825 // events. | 4802 // events. |
| 4826 #if defined(USE_AURA) | 4803 #if defined(USE_AURA) |
| 4827 // Browser process hit testing is not implemented on Android, and this test | 4804 // Browser process hit testing is not implemented on Android, and this test |
| 4828 // requires Aura for RenderWidgetHostViewAura::OnTouchEvent(). | 4805 // requires Aura for RenderWidgetHostViewAura::OnTouchEvent(). |
| 4829 // https://crbug.com/491334 | 4806 // https://crbug.com/491334 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4853 gfx::Point child_center(150, 150); | 4830 gfx::Point child_center(150, 150); |
| 4854 auto rwhv = static_cast<RenderWidgetHostViewAura*>( | 4831 auto rwhv = static_cast<RenderWidgetHostViewAura*>( |
| 4855 contents->GetRenderWidgetHostView()); | 4832 contents->GetRenderWidgetHostView()); |
| 4856 ui::TouchEvent touch_event(ui::ET_TOUCH_PRESSED, child_center, 0, 0, | 4833 ui::TouchEvent touch_event(ui::ET_TOUCH_PRESSED, child_center, 0, 0, |
| 4857 ui::EventTimeForNow(), 30.f, 30.f, 0.f, 0.f); | 4834 ui::EventTimeForNow(), 30.f, 30.f, 0.f, 0.f); |
| 4858 rwhv->OnTouchEvent(&touch_event); | 4835 rwhv->OnTouchEvent(&touch_event); |
| 4859 | 4836 |
| 4860 // Verify touch handler in subframe was invoked | 4837 // Verify touch handler in subframe was invoked |
| 4861 std::string result; | 4838 std::string result; |
| 4862 EXPECT_TRUE(ExecuteScriptAndExtractString( | 4839 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 4863 root->child_at(0)->current_frame_host(), | 4840 root->child_at(0), |
| 4864 "window.domAutomationController.send(getLastTouchEvent());", &result)); | 4841 "window.domAutomationController.send(getLastTouchEvent());", &result)); |
| 4865 EXPECT_EQ("touchstart", result); | 4842 EXPECT_EQ("touchstart", result); |
| 4866 } | 4843 } |
| 4867 | 4844 |
| 4868 namespace { | 4845 namespace { |
| 4869 | 4846 |
| 4870 // Declared here to be close to the SubframeGestureEventRouting test. | 4847 // Declared here to be close to the SubframeGestureEventRouting test. |
| 4871 void OnSyntheticGestureCompleted(scoped_refptr<MessageLoopRunner> runner, | 4848 void OnSyntheticGestureCompleted(scoped_refptr<MessageLoopRunner> runner, |
| 4872 SyntheticGesture::Result result) { | 4849 SyntheticGesture::Result result) { |
| 4873 EXPECT_EQ(SyntheticGesture::GESTURE_FINISHED, result); | 4850 EXPECT_EQ(SyntheticGesture::GESTURE_FINISHED, result); |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5450 // the script command that changes it, we need to wait for it to change | 5427 // the script command that changes it, we need to wait for it to change |
| 5451 // before attempting to create the popup widget again. | 5428 // before attempting to create the popup widget again. |
| 5452 gfx::Rect last_b_node_bounds_rect = | 5429 gfx::Rect last_b_node_bounds_rect = |
| 5453 b_node->current_frame_host()->GetView()->GetViewBounds(); | 5430 b_node->current_frame_host()->GetView()->GetViewBounds(); |
| 5454 | 5431 |
| 5455 std::string script = | 5432 std::string script = |
| 5456 "var iframe = document.querySelector('iframe');" | 5433 "var iframe = document.querySelector('iframe');" |
| 5457 "iframe.style.position = 'absolute';" | 5434 "iframe.style.position = 'absolute';" |
| 5458 "iframe.style.left = 150;" | 5435 "iframe.style.left = 150;" |
| 5459 "iframe.style.top = 150;"; | 5436 "iframe.style.top = 150;"; |
| 5460 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); | 5437 EXPECT_TRUE(ExecuteScript(root, script)); |
| 5461 | 5438 |
| 5462 filter->Reset(); | 5439 filter->Reset(); |
| 5463 | 5440 |
| 5464 // Busy loop to wait for b_node's screen rect to get updated. There | 5441 // Busy loop to wait for b_node's screen rect to get updated. There |
| 5465 // doesn't seem to be any better way to find out when this happens. | 5442 // doesn't seem to be any better way to find out when this happens. |
| 5466 while (last_b_node_bounds_rect.x() == | 5443 while (last_b_node_bounds_rect.x() == |
| 5467 b_node->current_frame_host()->GetView()->GetViewBounds().x() && | 5444 b_node->current_frame_host()->GetView()->GetViewBounds().x() && |
| 5468 last_b_node_bounds_rect.y() == | 5445 last_b_node_bounds_rect.y() == |
| 5469 b_node->current_frame_host()->GetView()->GetViewBounds().y()) { | 5446 b_node->current_frame_host()->GetView()->GetViewBounds().y()) { |
| 5470 base::RunLoop run_loop; | 5447 base::RunLoop run_loop; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5511 static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root(); | 5488 static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root(); |
| 5512 EXPECT_EQ(2U, root->child_count()); | 5489 EXPECT_EQ(2U, root->child_count()); |
| 5513 | 5490 |
| 5514 // Navigate the first child frame to 'about:blank' (which is a | 5491 // Navigate the first child frame to 'about:blank' (which is a |
| 5515 // remote-to-local transition), and then detach it. | 5492 // remote-to-local transition), and then detach it. |
| 5516 FrameDeletedObserver observer(root->child_at(0)); | 5493 FrameDeletedObserver observer(root->child_at(0)); |
| 5517 std::string script = | 5494 std::string script = |
| 5518 "var f = document.querySelector('iframe');" | 5495 "var f = document.querySelector('iframe');" |
| 5519 "f.contentWindow.location.href = 'about:blank';" | 5496 "f.contentWindow.location.href = 'about:blank';" |
| 5520 "setTimeout(function() { document.body.removeChild(f); }, 0);"; | 5497 "setTimeout(function() { document.body.removeChild(f); }, 0);"; |
| 5521 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), script)); | 5498 EXPECT_TRUE(ExecuteScript(root, script)); |
| 5522 observer.Wait(); | 5499 observer.Wait(); |
| 5523 EXPECT_EQ(1U, root->child_count()); | 5500 EXPECT_EQ(1U, root->child_count()); |
| 5524 | 5501 |
| 5525 // Make sure the main frame renderer does not crash and ignores the | 5502 // Make sure the main frame renderer does not crash and ignores the |
| 5526 // navigation to the frame that's already been deleted. | 5503 // navigation to the frame that's already been deleted. |
| 5527 int child_count = 0; | 5504 int child_count = 0; |
| 5528 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 5505 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 5529 root->current_frame_host(), | 5506 root, "domAutomationController.send(frames.length)", &child_count)); |
| 5530 "domAutomationController.send(frames.length)", | |
| 5531 &child_count)); | |
| 5532 EXPECT_EQ(1, child_count); | 5507 EXPECT_EQ(1, child_count); |
| 5533 } | 5508 } |
| 5534 | 5509 |
| 5535 // Test for a variation of https://crbug.com/526304, where a child frame does a | 5510 // Test for a variation of https://crbug.com/526304, where a child frame does a |
| 5536 // remote-to-local navigation, and the parent frame removes that child frame | 5511 // remote-to-local navigation, and the parent frame removes that child frame |
| 5537 // after the provisional local frame is created and starts to navigate, but | 5512 // after the provisional local frame is created and starts to navigate, but |
| 5538 // before it commits. | 5513 // before it commits. |
| 5539 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 5514 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 5540 NavigateProxyAndDetachBeforeCommit) { | 5515 NavigateProxyAndDetachBeforeCommit) { |
| 5541 GURL main_url(embedded_test_server()->GetURL( | 5516 GURL main_url(embedded_test_server()->GetURL( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5553 GURL same_site_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | 5528 GURL same_site_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 5554 NavigationController::LoadURLParams params(same_site_url); | 5529 NavigationController::LoadURLParams params(same_site_url); |
| 5555 params.transition_type = ui::PAGE_TRANSITION_LINK; | 5530 params.transition_type = ui::PAGE_TRANSITION_LINK; |
| 5556 params.frame_tree_node_id = child->frame_tree_node_id(); | 5531 params.frame_tree_node_id = child->frame_tree_node_id(); |
| 5557 child->navigator()->GetController()->LoadURLWithParams(params); | 5532 child->navigator()->GetController()->LoadURLWithParams(params); |
| 5558 | 5533 |
| 5559 // Tell parent to remove the first child. This should happen after the | 5534 // Tell parent to remove the first child. This should happen after the |
| 5560 // previous navigation starts but before it commits. | 5535 // previous navigation starts but before it commits. |
| 5561 FrameDeletedObserver observer(child); | 5536 FrameDeletedObserver observer(child); |
| 5562 EXPECT_TRUE(ExecuteScript( | 5537 EXPECT_TRUE(ExecuteScript( |
| 5563 root->current_frame_host(), | 5538 root, "document.body.removeChild(document.querySelector('iframe'));")); |
| 5564 "document.body.removeChild(document.querySelector('iframe'));")); | |
| 5565 observer.Wait(); | 5539 observer.Wait(); |
| 5566 EXPECT_EQ(1U, root->child_count()); | 5540 EXPECT_EQ(1U, root->child_count()); |
| 5567 | 5541 |
| 5568 // Make sure the a.com renderer does not crash. | 5542 // Make sure the a.com renderer does not crash. |
| 5569 int child_count = 0; | 5543 int child_count = 0; |
| 5570 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 5544 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 5571 root->current_frame_host(), | 5545 root, "domAutomationController.send(frames.length)", &child_count)); |
| 5572 "domAutomationController.send(frames.length)", | |
| 5573 &child_count)); | |
| 5574 EXPECT_EQ(1, child_count); | 5546 EXPECT_EQ(1, child_count); |
| 5575 } | 5547 } |
| 5576 | 5548 |
| 5577 // Similar to NavigateProxyAndDetachBeforeCommit, but uses a synchronous | 5549 // Similar to NavigateProxyAndDetachBeforeCommit, but uses a synchronous |
| 5578 // navigation to about:blank and the parent removes the child frame in a load | 5550 // navigation to about:blank and the parent removes the child frame in a load |
| 5579 // event handler for the subframe. | 5551 // event handler for the subframe. |
| 5580 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateAboutBlankAndDetach) { | 5552 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateAboutBlankAndDetach) { |
| 5581 GURL main_url( | 5553 GURL main_url( |
| 5582 embedded_test_server()->GetURL("a.com", "/remove_frame_on_load.html")); | 5554 embedded_test_server()->GetURL("a.com", "/remove_frame_on_load.html")); |
| 5583 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 5555 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 5584 | 5556 |
| 5585 WebContents* contents = shell()->web_contents(); | 5557 WebContents* contents = shell()->web_contents(); |
| 5586 FrameTreeNode* root = | 5558 FrameTreeNode* root = |
| 5587 static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root(); | 5559 static_cast<WebContentsImpl*>(contents)->GetFrameTree()->root(); |
| 5588 EXPECT_EQ(1U, root->child_count()); | 5560 EXPECT_EQ(1U, root->child_count()); |
| 5589 FrameTreeNode* child = root->child_at(0); | 5561 FrameTreeNode* child = root->child_at(0); |
| 5590 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), | 5562 EXPECT_NE(shell()->web_contents()->GetSiteInstance(), |
| 5591 child->current_frame_host()->GetSiteInstance()); | 5563 child->current_frame_host()->GetSiteInstance()); |
| 5592 | 5564 |
| 5593 // Navigate the child frame to "about:blank" from the parent document. | 5565 // Navigate the child frame to "about:blank" from the parent document. |
| 5594 TestNavigationObserver observer(shell()->web_contents()); | 5566 TestNavigationObserver observer(shell()->web_contents()); |
| 5595 EXPECT_TRUE( | 5567 EXPECT_TRUE(ExecuteScript( |
| 5596 ExecuteScript(root->current_frame_host(), | 5568 root, base::StringPrintf("f.src = '%s'", url::kAboutBlankURL))); |
| 5597 base::StringPrintf("f.src = '%s'", url::kAboutBlankURL))); | |
| 5598 observer.Wait(); | 5569 observer.Wait(); |
| 5599 | 5570 |
| 5600 // Make sure the a.com renderer does not crash and the frame is removed. | 5571 // Make sure the a.com renderer does not crash and the frame is removed. |
| 5601 int child_count = 0; | 5572 int child_count = 0; |
| 5602 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 5573 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 5603 root->current_frame_host(), "domAutomationController.send(frames.length)", | 5574 root, "domAutomationController.send(frames.length)", &child_count)); |
| 5604 &child_count)); | |
| 5605 EXPECT_EQ(0, child_count); | 5575 EXPECT_EQ(0, child_count); |
| 5606 } | 5576 } |
| 5607 | 5577 |
| 5608 // Test for https://crbug.com/568670. In A-embed-B, simultaneously have B | 5578 // Test for https://crbug.com/568670. In A-embed-B, simultaneously have B |
| 5609 // create a new (local) child frame, and have A detach B's proxy. The child | 5579 // create a new (local) child frame, and have A detach B's proxy. The child |
| 5610 // frame creation sends an IPC to create a new proxy in A's process, and if | 5580 // frame creation sends an IPC to create a new proxy in A's process, and if |
| 5611 // that IPC arrives after the detach, the new frame's parent (a proxy) won't be | 5581 // that IPC arrives after the detach, the new frame's parent (a proxy) won't be |
| 5612 // available, and this shouldn't cause RenderFrameProxy::CreateFrameProxy to | 5582 // available, and this shouldn't cause RenderFrameProxy::CreateFrameProxy to |
| 5613 // crash. | 5583 // crash. |
| 5614 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 5584 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5632 root->render_manager()->current_frame_host()->GetProcess(); | 5602 root->render_manager()->current_frame_host()->GetProcess(); |
| 5633 int new_routing_id = process_a->GetNextRoutingID(); | 5603 int new_routing_id = process_a->GetNextRoutingID(); |
| 5634 int view_routing_id = | 5604 int view_routing_id = |
| 5635 root->frame_tree()->GetRenderViewHost(site_instance_a)->GetRoutingID(); | 5605 root->frame_tree()->GetRenderViewHost(site_instance_a)->GetRoutingID(); |
| 5636 int parent_routing_id = | 5606 int parent_routing_id = |
| 5637 root->child_at(0)->render_manager()->GetProxyToParent()->GetRoutingID(); | 5607 root->child_at(0)->render_manager()->GetProxyToParent()->GetRoutingID(); |
| 5638 | 5608 |
| 5639 // Tell main frame A to delete its subframe B. | 5609 // Tell main frame A to delete its subframe B. |
| 5640 FrameDeletedObserver observer(root->child_at(0)); | 5610 FrameDeletedObserver observer(root->child_at(0)); |
| 5641 EXPECT_TRUE(ExecuteScript( | 5611 EXPECT_TRUE(ExecuteScript( |
| 5642 root->current_frame_host(), | 5612 root, "document.body.removeChild(document.querySelector('iframe'));")); |
| 5643 "document.body.removeChild(document.querySelector('iframe'));")); | |
| 5644 | 5613 |
| 5645 // Send the message to create a proxy for B's new child frame in A. This | 5614 // Send the message to create a proxy for B's new child frame in A. This |
| 5646 // used to crash, as parent_routing_id refers to a proxy that doesn't exist | 5615 // used to crash, as parent_routing_id refers to a proxy that doesn't exist |
| 5647 // anymore. | 5616 // anymore. |
| 5648 process_a->Send(new FrameMsg_NewFrameProxy( | 5617 process_a->Send(new FrameMsg_NewFrameProxy( |
| 5649 new_routing_id, view_routing_id, MSG_ROUTING_NONE, parent_routing_id, | 5618 new_routing_id, view_routing_id, MSG_ROUTING_NONE, parent_routing_id, |
| 5650 FrameReplicationState())); | 5619 FrameReplicationState())); |
| 5651 | 5620 |
| 5652 // Ensure the subframe is detached in the browser process. | 5621 // Ensure the subframe is detached in the browser process. |
| 5653 observer.Wait(); | 5622 observer.Wait(); |
| 5654 EXPECT_EQ(0U, root->child_count()); | 5623 EXPECT_EQ(0U, root->child_count()); |
| 5655 | 5624 |
| 5656 // Make sure process A did not crash. | 5625 // Make sure process A did not crash. |
| 5657 int child_count = 0; | 5626 int child_count = 0; |
| 5658 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 5627 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 5659 root->current_frame_host(), | 5628 root, "domAutomationController.send(frames.length)", &child_count)); |
| 5660 "domAutomationController.send(frames.length)", | |
| 5661 &child_count)); | |
| 5662 EXPECT_EQ(0, child_count); | 5629 EXPECT_EQ(0, child_count); |
| 5663 } | 5630 } |
| 5664 | 5631 |
| 5665 // This test ensures that the RenderFrame isn't leaked in the renderer process | 5632 // This test ensures that the RenderFrame isn't leaked in the renderer process |
| 5666 // if a pending cross-process navigation is cancelled. The test works by trying | 5633 // if a pending cross-process navigation is cancelled. The test works by trying |
| 5667 // to create a new RenderFrame with the same routing id. If there is an | 5634 // to create a new RenderFrame with the same routing id. If there is an |
| 5668 // entry with the same routing ID, a CHECK is hit and the process crashes. | 5635 // entry with the same routing ID, a CHECK is hit and the process crashes. |
| 5669 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 5636 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 5670 SubframePendingAndBackToSameSiteInstance) { | 5637 SubframePendingAndBackToSameSiteInstance) { |
| 5671 GURL main_url(embedded_test_server()->GetURL( | 5638 GURL main_url(embedded_test_server()->GetURL( |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5823 EXPECT_FALSE(render_widget_host->is_hidden()); | 5790 EXPECT_FALSE(render_widget_host->is_hidden()); |
| 5824 | 5791 |
| 5825 std::string show_script = | 5792 std::string show_script = |
| 5826 "document.querySelector('iframe').style.visibility = 'visible';"; | 5793 "document.querySelector('iframe').style.visibility = 'visible';"; |
| 5827 std::string hide_script = | 5794 std::string hide_script = |
| 5828 "document.querySelector('iframe').style.visibility = 'hidden';"; | 5795 "document.querySelector('iframe').style.visibility = 'hidden';"; |
| 5829 | 5796 |
| 5830 // Verify that hiding leads to a notification from RenderWidgetHost. | 5797 // Verify that hiding leads to a notification from RenderWidgetHost. |
| 5831 RenderWidgetHostVisibilityObserver hide_observer( | 5798 RenderWidgetHostVisibilityObserver hide_observer( |
| 5832 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), false); | 5799 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), false); |
| 5833 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), hide_script)); | 5800 EXPECT_TRUE(ExecuteScript(shell(), hide_script)); |
| 5834 EXPECT_TRUE(hide_observer.WaitUntilSatisfied()); | 5801 EXPECT_TRUE(hide_observer.WaitUntilSatisfied()); |
| 5835 | 5802 |
| 5836 // Verify showing leads to a notification as well. | 5803 // Verify showing leads to a notification as well. |
| 5837 RenderWidgetHostVisibilityObserver show_observer( | 5804 RenderWidgetHostVisibilityObserver show_observer( |
| 5838 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), true); | 5805 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), true); |
| 5839 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), show_script)); | 5806 EXPECT_TRUE(ExecuteScript(shell(), show_script)); |
| 5840 EXPECT_TRUE(show_observer.WaitUntilSatisfied()); | 5807 EXPECT_TRUE(show_observer.WaitUntilSatisfied()); |
| 5841 } | 5808 } |
| 5842 | 5809 |
| 5843 // Verify that sandbox flags inheritance works across multiple levels of | 5810 // Verify that sandbox flags inheritance works across multiple levels of |
| 5844 // frames. See https://crbug.com/576845. | 5811 // frames. See https://crbug.com/576845. |
| 5845 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SandboxFlagsInheritance) { | 5812 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SandboxFlagsInheritance) { |
| 5846 GURL main_url(embedded_test_server()->GetURL( | 5813 GURL main_url(embedded_test_server()->GetURL( |
| 5847 "a.com", "/cross_site_iframe_factory.html?a(a)")); | 5814 "a.com", "/cross_site_iframe_factory.html?a(a)")); |
| 5848 NavigateToURL(shell(), main_url); | 5815 NavigateToURL(shell(), main_url); |
| 5849 | 5816 |
| 5850 // It is safe to obtain the root frame tree node here, as it doesn't change. | 5817 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 5851 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 5818 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 5852 | 5819 |
| 5853 // Set sandbox flags for child frame. | 5820 // Set sandbox flags for child frame. |
| 5854 EXPECT_TRUE(ExecuteScript( | 5821 EXPECT_TRUE(ExecuteScript( |
| 5855 root->current_frame_host(), | 5822 root, "document.querySelector('iframe').sandbox = 'allow-scripts';")); |
| 5856 "document.querySelector('iframe').sandbox = 'allow-scripts';")); | |
| 5857 | 5823 |
| 5858 // Calculate expected flags. Note that "allow-scripts" resets both | 5824 // Calculate expected flags. Note that "allow-scripts" resets both |
| 5859 // WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits per | 5825 // WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits per |
| 5860 // blink::parseSandboxPolicy(). | 5826 // blink::parseSandboxPolicy(). |
| 5861 blink::WebSandboxFlags expected_flags = | 5827 blink::WebSandboxFlags expected_flags = |
| 5862 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 5828 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 5863 ~blink::WebSandboxFlags::AutomaticFeatures; | 5829 ~blink::WebSandboxFlags::AutomaticFeatures; |
| 5864 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 5830 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 5865 EXPECT_EQ(blink::WebSandboxFlags::None, | 5831 EXPECT_EQ(blink::WebSandboxFlags::None, |
| 5866 root->child_at(0)->effective_sandbox_flags()); | 5832 root->child_at(0)->effective_sandbox_flags()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5898 SandboxFlagsNotInheritedBeforeNavigation) { | 5864 SandboxFlagsNotInheritedBeforeNavigation) { |
| 5899 GURL main_url(embedded_test_server()->GetURL( | 5865 GURL main_url(embedded_test_server()->GetURL( |
| 5900 "a.com", "/cross_site_iframe_factory.html?a(a)")); | 5866 "a.com", "/cross_site_iframe_factory.html?a(a)")); |
| 5901 NavigateToURL(shell(), main_url); | 5867 NavigateToURL(shell(), main_url); |
| 5902 | 5868 |
| 5903 // It is safe to obtain the root frame tree node here, as it doesn't change. | 5869 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 5904 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 5870 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 5905 | 5871 |
| 5906 // Set sandbox flags for child frame. | 5872 // Set sandbox flags for child frame. |
| 5907 EXPECT_TRUE(ExecuteScript( | 5873 EXPECT_TRUE(ExecuteScript( |
| 5908 root->current_frame_host(), | 5874 root, "document.querySelector('iframe').sandbox = 'allow-scripts';")); |
| 5909 "document.querySelector('iframe').sandbox = 'allow-scripts';")); | |
| 5910 | 5875 |
| 5911 // These flags should be pending but not take effect, since there's been no | 5876 // These flags should be pending but not take effect, since there's been no |
| 5912 // navigation. | 5877 // navigation. |
| 5913 blink::WebSandboxFlags expected_flags = | 5878 blink::WebSandboxFlags expected_flags = |
| 5914 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 5879 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 5915 ~blink::WebSandboxFlags::AutomaticFeatures; | 5880 ~blink::WebSandboxFlags::AutomaticFeatures; |
| 5916 FrameTreeNode* child = root->child_at(0); | 5881 FrameTreeNode* child = root->child_at(0); |
| 5917 EXPECT_EQ(expected_flags, child->pending_sandbox_flags()); | 5882 EXPECT_EQ(expected_flags, child->pending_sandbox_flags()); |
| 5918 EXPECT_EQ(blink::WebSandboxFlags::None, child->effective_sandbox_flags()); | 5883 EXPECT_EQ(blink::WebSandboxFlags::None, child->effective_sandbox_flags()); |
| 5919 | 5884 |
| 5920 // Add a new grandchild frame and navigate it cross-site. | 5885 // Add a new grandchild frame and navigate it cross-site. |
| 5921 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); | 5886 RenderFrameHostCreatedObserver frame_observer(shell()->web_contents(), 1); |
| 5922 EXPECT_TRUE(ExecuteScript( | 5887 EXPECT_TRUE(ExecuteScript( |
| 5923 child->current_frame_host(), | 5888 child, "document.body.appendChild(document.createElement('iframe'));")); |
| 5924 "document.body.appendChild(document.createElement('iframe'));")); | |
| 5925 frame_observer.Wait(); | 5889 frame_observer.Wait(); |
| 5926 | 5890 |
| 5927 FrameTreeNode* grandchild = child->child_at(0); | 5891 FrameTreeNode* grandchild = child->child_at(0); |
| 5928 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 5892 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 5929 TestFrameNavigationObserver navigation_observer(grandchild); | 5893 TestFrameNavigationObserver navigation_observer(grandchild); |
| 5930 NavigateFrameToURL(grandchild, frame_url); | 5894 NavigateFrameToURL(grandchild, frame_url); |
| 5931 navigation_observer.Wait(); | 5895 navigation_observer.Wait(); |
| 5932 | 5896 |
| 5933 // Since the update flags haven't yet taken effect in its parent, this | 5897 // Since the update flags haven't yet taken effect in its parent, this |
| 5934 // grandchild frame should not be sandboxed. | 5898 // grandchild frame should not be sandboxed. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5947 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 5911 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 5948 NewPopupInheritsSandboxFlagsFromOpener) { | 5912 NewPopupInheritsSandboxFlagsFromOpener) { |
| 5949 GURL main_url(embedded_test_server()->GetURL( | 5913 GURL main_url(embedded_test_server()->GetURL( |
| 5950 "a.com", "/cross_site_iframe_factory.html?a(a)")); | 5914 "a.com", "/cross_site_iframe_factory.html?a(a)")); |
| 5951 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 5915 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 5952 | 5916 |
| 5953 // It is safe to obtain the root frame tree node here, as it doesn't change. | 5917 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 5954 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 5918 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 5955 | 5919 |
| 5956 // Set sandbox flags for child frame. | 5920 // Set sandbox flags for child frame. |
| 5957 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), | 5921 EXPECT_TRUE(ExecuteScript(root, |
| 5958 "document.querySelector('iframe').sandbox = " | 5922 "document.querySelector('iframe').sandbox = " |
| 5959 " 'allow-scripts allow-popups';")); | 5923 " 'allow-scripts allow-popups';")); |
| 5960 | 5924 |
| 5961 // Calculate expected flags. Note that "allow-scripts" resets both | 5925 // Calculate expected flags. Note that "allow-scripts" resets both |
| 5962 // WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits per | 5926 // WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits per |
| 5963 // blink::parseSandboxPolicy(). | 5927 // blink::parseSandboxPolicy(). |
| 5964 blink::WebSandboxFlags expected_flags = | 5928 blink::WebSandboxFlags expected_flags = |
| 5965 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 5929 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 5966 ~blink::WebSandboxFlags::AutomaticFeatures & | 5930 ~blink::WebSandboxFlags::AutomaticFeatures & |
| 5967 ~blink::WebSandboxFlags::Popups; | 5931 ~blink::WebSandboxFlags::Popups; |
| 5968 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 5932 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 5969 | 5933 |
| 5970 // Navigate child frame cross-site. The sandbox flags should take effect. | 5934 // Navigate child frame cross-site. The sandbox flags should take effect. |
| 5971 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 5935 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 5972 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 5936 TestFrameNavigationObserver frame_observer(root->child_at(0)); |
| 5973 NavigateFrameToURL(root->child_at(0), frame_url); | 5937 NavigateFrameToURL(root->child_at(0), frame_url); |
| 5974 frame_observer.Wait(); | 5938 frame_observer.Wait(); |
| 5975 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 5939 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| 5976 | 5940 |
| 5977 // Verify that they've also taken effect on the renderer side. The sandboxed | 5941 // Verify that they've also taken effect on the renderer side. The sandboxed |
| 5978 // frame's origin should be unique. | 5942 // frame's origin should be unique. |
| 5979 EXPECT_EQ("null", GetDocumentOrigin(root->child_at(0))); | 5943 EXPECT_EQ("null", GetDocumentOrigin(root->child_at(0))); |
| 5980 | 5944 |
| 5981 // Open a popup named "foo" from the sandboxed child frame. | 5945 // Open a popup named "foo" from the sandboxed child frame. |
| 5982 Shell* foo_shell = OpenPopup(root->child_at(0)->current_frame_host(), | 5946 Shell* foo_shell = |
| 5983 GURL(url::kAboutBlankURL), "foo"); | 5947 OpenPopup(root->child_at(0), GURL(url::kAboutBlankURL), "foo"); |
| 5984 EXPECT_TRUE(foo_shell); | 5948 EXPECT_TRUE(foo_shell); |
| 5985 | 5949 |
| 5986 FrameTreeNode* foo_root = | 5950 FrameTreeNode* foo_root = |
| 5987 static_cast<WebContentsImpl*>(foo_shell->web_contents()) | 5951 static_cast<WebContentsImpl*>(foo_shell->web_contents()) |
| 5988 ->GetFrameTree() | 5952 ->GetFrameTree() |
| 5989 ->root(); | 5953 ->root(); |
| 5990 | 5954 |
| 5991 // Check that the sandbox flags for new popup are correct in the browser | 5955 // Check that the sandbox flags for new popup are correct in the browser |
| 5992 // process. | 5956 // process. |
| 5993 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); | 5957 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); |
| 5994 | 5958 |
| 5995 // The popup's origin should be unique, since it's sandboxed. | 5959 // The popup's origin should be unique, since it's sandboxed. |
| 5996 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); | 5960 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); |
| 5997 | 5961 |
| 5998 // Navigate the popup cross-site. This should keep the unique origin and the | 5962 // Navigate the popup cross-site. This should keep the unique origin and the |
| 5999 // inherited sandbox flags. | 5963 // inherited sandbox flags. |
| 6000 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 5964 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 6001 TestFrameNavigationObserver popup_observer(foo_root); | 5965 TestFrameNavigationObserver popup_observer(foo_root); |
| 6002 EXPECT_TRUE(ExecuteScript(foo_root->current_frame_host(), | 5966 EXPECT_TRUE( |
| 6003 "location.href = '" + c_url.spec() + "';")); | 5967 ExecuteScript(foo_root, "location.href = '" + c_url.spec() + "';")); |
| 6004 popup_observer.Wait(); | 5968 popup_observer.Wait(); |
| 6005 EXPECT_EQ(c_url, foo_shell->web_contents()->GetLastCommittedURL()); | 5969 EXPECT_EQ(c_url, foo_shell->web_contents()->GetLastCommittedURL()); |
| 6006 | 5970 |
| 6007 // Confirm that the popup is still sandboxed, both on browser and renderer | 5971 // Confirm that the popup is still sandboxed, both on browser and renderer |
| 6008 // sides. | 5972 // sides. |
| 6009 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); | 5973 EXPECT_EQ(expected_flags, foo_root->effective_sandbox_flags()); |
| 6010 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); | 5974 EXPECT_EQ("null", GetDocumentOrigin(foo_root)); |
| 6011 } | 5975 } |
| 6012 | 5976 |
| 6013 // Verify that popups opened from frames sandboxed with the | 5977 // Verify that popups opened from frames sandboxed with the |
| 6014 // "allow-popups-to-escape-sandbox" directive do *not* inherit sandbox flags | 5978 // "allow-popups-to-escape-sandbox" directive do *not* inherit sandbox flags |
| 6015 // from their opener. | 5979 // from their opener. |
| 6016 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 5980 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 6017 OpenUnsandboxedPopupFromSandboxedFrame) { | 5981 OpenUnsandboxedPopupFromSandboxedFrame) { |
| 6018 GURL main_url(embedded_test_server()->GetURL( | 5982 GURL main_url(embedded_test_server()->GetURL( |
| 6019 "a.com", "/cross_site_iframe_factory.html?a(a)")); | 5983 "a.com", "/cross_site_iframe_factory.html?a(a)")); |
| 6020 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 5984 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 6021 | 5985 |
| 6022 // It is safe to obtain the root frame tree node here, as it doesn't change. | 5986 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 6023 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 5987 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 6024 | 5988 |
| 6025 // Set sandbox flags for child frame, specifying that popups opened from it | 5989 // Set sandbox flags for child frame, specifying that popups opened from it |
| 6026 // should not be sandboxed. | 5990 // should not be sandboxed. |
| 6027 EXPECT_TRUE(ExecuteScript( | 5991 EXPECT_TRUE(ExecuteScript( |
| 6028 root->current_frame_host(), | 5992 root, |
| 6029 "document.querySelector('iframe').sandbox = " | 5993 "document.querySelector('iframe').sandbox = " |
| 6030 " 'allow-scripts allow-popups allow-popups-to-escape-sandbox';")); | 5994 " 'allow-scripts allow-popups allow-popups-to-escape-sandbox';")); |
| 6031 | 5995 |
| 6032 // Set expected flags for the child frame. Note that "allow-scripts" resets | 5996 // Set expected flags for the child frame. Note that "allow-scripts" resets |
| 6033 // both WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits | 5997 // both WebSandboxFlags::Scripts and WebSandboxFlags::AutomaticFeatures bits |
| 6034 // per blink::parseSandboxPolicy(). | 5998 // per blink::parseSandboxPolicy(). |
| 6035 blink::WebSandboxFlags expected_flags = | 5999 blink::WebSandboxFlags expected_flags = |
| 6036 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & | 6000 blink::WebSandboxFlags::All & ~blink::WebSandboxFlags::Scripts & |
| 6037 ~blink::WebSandboxFlags::AutomaticFeatures & | 6001 ~blink::WebSandboxFlags::AutomaticFeatures & |
| 6038 ~blink::WebSandboxFlags::Popups & | 6002 ~blink::WebSandboxFlags::Popups & |
| 6039 ~blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts; | 6003 ~blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts; |
| 6040 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); | 6004 EXPECT_EQ(expected_flags, root->child_at(0)->pending_sandbox_flags()); |
| 6041 | 6005 |
| 6042 // Navigate child frame cross-site. The sandbox flags should take effect. | 6006 // Navigate child frame cross-site. The sandbox flags should take effect. |
| 6043 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 6007 GURL frame_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 6044 TestFrameNavigationObserver frame_observer(root->child_at(0)); | 6008 TestFrameNavigationObserver frame_observer(root->child_at(0)); |
| 6045 NavigateFrameToURL(root->child_at(0), frame_url); | 6009 NavigateFrameToURL(root->child_at(0), frame_url); |
| 6046 frame_observer.Wait(); | 6010 frame_observer.Wait(); |
| 6047 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); | 6011 EXPECT_EQ(expected_flags, root->child_at(0)->effective_sandbox_flags()); |
| 6048 | 6012 |
| 6049 // Open a cross-site popup named "foo" from the child frame. | 6013 // Open a cross-site popup named "foo" from the child frame. |
| 6050 GURL b_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 6014 GURL b_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 6051 Shell* foo_shell = | 6015 Shell* foo_shell = OpenPopup(root->child_at(0), b_url, "foo"); |
| 6052 OpenPopup(root->child_at(0)->current_frame_host(), b_url, "foo"); | |
| 6053 EXPECT_TRUE(foo_shell); | 6016 EXPECT_TRUE(foo_shell); |
| 6054 | 6017 |
| 6055 FrameTreeNode* foo_root = | 6018 FrameTreeNode* foo_root = |
| 6056 static_cast<WebContentsImpl*>(foo_shell->web_contents()) | 6019 static_cast<WebContentsImpl*>(foo_shell->web_contents()) |
| 6057 ->GetFrameTree() | 6020 ->GetFrameTree() |
| 6058 ->root(); | 6021 ->root(); |
| 6059 | 6022 |
| 6060 // Check that the sandbox flags for new popup are correct in the browser | 6023 // Check that the sandbox flags for new popup are correct in the browser |
| 6061 // process. They should not have been inherited. | 6024 // process. They should not have been inherited. |
| 6062 EXPECT_EQ(blink::WebSandboxFlags::None, foo_root->effective_sandbox_flags()); | 6025 EXPECT_EQ(blink::WebSandboxFlags::None, foo_root->effective_sandbox_flags()); |
| 6063 | 6026 |
| 6064 // The popup's origin should match |b_url|, since it's not sandboxed. | 6027 // The popup's origin should match |b_url|, since it's not sandboxed. |
| 6065 std::string popup_origin; | 6028 std::string popup_origin; |
| 6066 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6029 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6067 foo_root->current_frame_host(), | 6030 foo_root, "domAutomationController.send(document.origin)", |
| 6068 "domAutomationController.send(document.origin)", | |
| 6069 &popup_origin)); | 6031 &popup_origin)); |
| 6070 EXPECT_EQ(b_url.GetOrigin().spec(), popup_origin + "/"); | 6032 EXPECT_EQ(b_url.GetOrigin().spec(), popup_origin + "/"); |
| 6071 } | 6033 } |
| 6072 | 6034 |
| 6073 // Tests that the WebContents is notified when passive mixed content is | 6035 // Tests that the WebContents is notified when passive mixed content is |
| 6074 // displayed in an OOPIF. The test ignores cert errors so that an HTTPS | 6036 // displayed in an OOPIF. The test ignores cert errors so that an HTTPS |
| 6075 // iframe can be loaded from a site other than localhost (the | 6037 // iframe can be loaded from a site other than localhost (the |
| 6076 // EmbeddedTestServer serves a certificate that is valid for localhost). | 6038 // EmbeddedTestServer serves a certificate that is valid for localhost). |
| 6077 // This test crashes on Windows under Dr. Memory, see https://crbug.com/600942. | 6039 // This test crashes on Windows under Dr. Memory, see https://crbug.com/600942. |
| 6078 #if defined(OS_WIN) | 6040 #if defined(OS_WIN) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6241 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframeDisplayNone) { | 6203 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CrossSiteIframeDisplayNone) { |
| 6242 GURL main_url(embedded_test_server()->GetURL( | 6204 GURL main_url(embedded_test_server()->GetURL( |
| 6243 "a.com", "/cross_site_iframe_factory.html?a(b)")); | 6205 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
| 6244 NavigateToURL(shell(), main_url); | 6206 NavigateToURL(shell(), main_url); |
| 6245 | 6207 |
| 6246 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 6208 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 6247 RenderWidgetHost* root_render_widget_host = | 6209 RenderWidgetHost* root_render_widget_host = |
| 6248 root->current_frame_host()->GetRenderWidgetHost(); | 6210 root->current_frame_host()->GetRenderWidgetHost(); |
| 6249 | 6211 |
| 6250 // Set the iframe to display: none. | 6212 // Set the iframe to display: none. |
| 6251 EXPECT_TRUE( | 6213 EXPECT_TRUE(ExecuteScript( |
| 6252 ExecuteScript(shell()->web_contents(), | 6214 shell(), "document.querySelector('iframe').style.display = 'none'")); |
| 6253 "document.querySelector('iframe').style.display = 'none'")); | |
| 6254 | 6215 |
| 6255 // Waits until pending frames are done. | 6216 // Waits until pending frames are done. |
| 6256 std::unique_ptr<MainThreadFrameObserver> observer( | 6217 std::unique_ptr<MainThreadFrameObserver> observer( |
| 6257 new MainThreadFrameObserver(root_render_widget_host)); | 6218 new MainThreadFrameObserver(root_render_widget_host)); |
| 6258 observer->Wait(); | 6219 observer->Wait(); |
| 6259 | 6220 |
| 6260 // Force the renderer to generate a new frame. | 6221 // Force the renderer to generate a new frame. |
| 6261 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 6222 EXPECT_TRUE( |
| 6262 "document.body.style.background = 'black'")); | 6223 ExecuteScript(shell(), "document.body.style.background = 'black'")); |
| 6263 | 6224 |
| 6264 // Waits for the next frame. | 6225 // Waits for the next frame. |
| 6265 observer->Wait(); | 6226 observer->Wait(); |
| 6266 } | 6227 } |
| 6267 | 6228 |
| 6268 // Test that a cross-origin iframe can be blocked by X-Frame-Options and CSP | 6229 // Test that a cross-origin iframe can be blocked by X-Frame-Options and CSP |
| 6269 // frame-ancestors. | 6230 // frame-ancestors. |
| 6270 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 6231 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 6271 CrossSiteIframeBlockedByXFrameOptionsOrCSP) { | 6232 CrossSiteIframeBlockedByXFrameOptionsOrCSP) { |
| 6272 GURL main_url(embedded_test_server()->GetURL( | 6233 GURL main_url(embedded_test_server()->GetURL( |
| 6273 "a.com", "/cross_site_iframe_factory.html?a(a)")); | 6234 "a.com", "/cross_site_iframe_factory.html?a(a)")); |
| 6274 NavigateToURL(shell(), main_url); | 6235 NavigateToURL(shell(), main_url); |
| 6275 | 6236 |
| 6276 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 6237 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 6277 | 6238 |
| 6278 // Add a load event handler for the iframe element. | 6239 // Add a load event handler for the iframe element. |
| 6279 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 6240 EXPECT_TRUE(ExecuteScript(shell(), |
| 6280 "document.querySelector('iframe').onload = " | 6241 "document.querySelector('iframe').onload = " |
| 6281 " function() { document.title = 'loaded'; };")); | 6242 " function() { document.title = 'loaded'; };")); |
| 6282 | 6243 |
| 6283 GURL blocked_urls[] = { | 6244 GURL blocked_urls[] = { |
| 6284 embedded_test_server()->GetURL("b.com", "/frame-ancestors-none.html"), | 6245 embedded_test_server()->GetURL("b.com", "/frame-ancestors-none.html"), |
| 6285 embedded_test_server()->GetURL("b.com", "/x-frame-options-deny.html") | 6246 embedded_test_server()->GetURL("b.com", "/x-frame-options-deny.html") |
| 6286 }; | 6247 }; |
| 6287 | 6248 |
| 6288 for (size_t i = 0; i < arraysize(blocked_urls); ++i) { | 6249 for (size_t i = 0; i < arraysize(blocked_urls); ++i) { |
| 6289 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 6250 EXPECT_TRUE(ExecuteScript(shell(), "document.title = 'not loaded';")); |
| 6290 "document.title = 'not loaded';")); | |
| 6291 base::string16 expected_title(base::UTF8ToUTF16("loaded")); | 6251 base::string16 expected_title(base::UTF8ToUTF16("loaded")); |
| 6292 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 6252 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 6293 | 6253 |
| 6294 // Navigate the subframe to a blocked URL. | 6254 // Navigate the subframe to a blocked URL. |
| 6295 TestNavigationObserver load_observer(shell()->web_contents()); | 6255 TestNavigationObserver load_observer(shell()->web_contents()); |
| 6296 EXPECT_TRUE(ExecuteScript( | 6256 EXPECT_TRUE(ExecuteScript(shell(), "frames[0].location.href = '" + |
| 6297 shell()->web_contents(), | 6257 blocked_urls[i].spec() + "';")); |
| 6298 "frames[0].location.href = '" + blocked_urls[i].spec() + "';")); | |
| 6299 load_observer.Wait(); | 6258 load_observer.Wait(); |
| 6300 | 6259 |
| 6301 // The blocked frame's origin should become unique. | 6260 // The blocked frame's origin should become unique. |
| 6302 EXPECT_EQ("null", root->child_at(0)->current_origin().Serialize()); | 6261 EXPECT_EQ("null", root->child_at(0)->current_origin().Serialize()); |
| 6303 | 6262 |
| 6304 // The blocked frame should still fire a load event in its parent's process. | 6263 // The blocked frame should still fire a load event in its parent's process. |
| 6305 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 6264 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 6306 | 6265 |
| 6307 // Check that the current RenderFrameHost has stopped loading. | 6266 // Check that the current RenderFrameHost has stopped loading. |
| 6308 EXPECT_FALSE(root->child_at(0)->current_frame_host()->is_loading()); | 6267 EXPECT_FALSE(root->child_at(0)->current_frame_host()->is_loading()); |
| 6309 | 6268 |
| 6310 // The blocked navigation should behave like an empty 200 response. Make | 6269 // The blocked navigation should behave like an empty 200 response. Make |
| 6311 // sure that the frame's document.title is empty: this double-checks both | 6270 // sure that the frame's document.title is empty: this double-checks both |
| 6312 // that the blocked URL's contents wasn't loaded, and that the old page | 6271 // that the blocked URL's contents wasn't loaded, and that the old page |
| 6313 // isn't active anymore (both of these pages have non-empty titles). | 6272 // isn't active anymore (both of these pages have non-empty titles). |
| 6314 std::string frame_title; | 6273 std::string frame_title; |
| 6315 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6274 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6316 root->child_at(0)->current_frame_host(), | 6275 root->child_at(0), "domAutomationController.send(document.title)", |
| 6317 "domAutomationController.send(document.title)", &frame_title)); | 6276 &frame_title)); |
| 6318 EXPECT_EQ("", frame_title); | 6277 EXPECT_EQ("", frame_title); |
| 6319 | 6278 |
| 6320 // Navigate the subframe to another cross-origin page and ensure that this | 6279 // Navigate the subframe to another cross-origin page and ensure that this |
| 6321 // navigation succeeds. Use a renderer-initiated navigation to test the | 6280 // navigation succeeds. Use a renderer-initiated navigation to test the |
| 6322 // transfer logic, which used to have some issues with this. | 6281 // transfer logic, which used to have some issues with this. |
| 6323 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 6282 GURL c_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 6324 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "child-0", c_url)); | 6283 EXPECT_TRUE(NavigateIframeToURL(shell()->web_contents(), "child-0", c_url)); |
| 6325 EXPECT_EQ(c_url, root->child_at(0)->current_url()); | 6284 EXPECT_EQ(c_url, root->child_at(0)->current_url()); |
| 6326 | 6285 |
| 6327 // When a page gets blocked due to XFO or CSP, it is sandboxed with the | 6286 // When a page gets blocked due to XFO or CSP, it is sandboxed with the |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6350 GURL old_subframe_url( | 6309 GURL old_subframe_url( |
| 6351 embedded_test_server()->GetURL("b.com", "/title2.html")); | 6310 embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 6352 EXPECT_FALSE(root->child_at(0)->HasSameOrigin(*root)); | 6311 EXPECT_FALSE(root->child_at(0)->HasSameOrigin(*root)); |
| 6353 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); | 6312 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); |
| 6354 const std::vector<ContentSecurityPolicyHeader>& root_csp = | 6313 const std::vector<ContentSecurityPolicyHeader>& root_csp = |
| 6355 root->current_replication_state().accumulated_csp_headers; | 6314 root->current_replication_state().accumulated_csp_headers; |
| 6356 EXPECT_EQ(1u, root_csp.size()); | 6315 EXPECT_EQ(1u, root_csp.size()); |
| 6357 EXPECT_EQ("frame-src 'self' http://b.com:*", root_csp[0].header_value); | 6316 EXPECT_EQ("frame-src 'self' http://b.com:*", root_csp[0].header_value); |
| 6358 | 6317 |
| 6359 // Monitor subframe's load events via main frame's title. | 6318 // Monitor subframe's load events via main frame's title. |
| 6360 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 6319 EXPECT_TRUE(ExecuteScript(shell(), |
| 6361 "document.querySelector('iframe').onload = " | 6320 "document.querySelector('iframe').onload = " |
| 6362 " function() { document.title = 'loaded'; };")); | 6321 " function() { document.title = 'loaded'; };")); |
| 6363 EXPECT_TRUE( | 6322 EXPECT_TRUE(ExecuteScript(shell(), "document.title = 'not loaded';")); |
| 6364 ExecuteScript(shell()->web_contents(), "document.title = 'not loaded';")); | |
| 6365 base::string16 expected_title(base::UTF8ToUTF16("loaded")); | 6323 base::string16 expected_title(base::UTF8ToUTF16("loaded")); |
| 6366 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 6324 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 6367 | 6325 |
| 6368 // Try to navigate the subframe to a blocked URL. | 6326 // Try to navigate the subframe to a blocked URL. |
| 6369 TestNavigationObserver load_observer(shell()->web_contents()); | 6327 TestNavigationObserver load_observer(shell()->web_contents()); |
| 6370 GURL blocked_url = embedded_test_server()->GetURL("c.com", "/title3.html"); | 6328 GURL blocked_url = embedded_test_server()->GetURL("c.com", "/title3.html"); |
| 6371 EXPECT_TRUE( | 6329 EXPECT_TRUE(ExecuteScript(root->child_at(0), "window.location.href = '" + |
| 6372 ExecuteScript(root->child_at(0)->current_frame_host(), | 6330 blocked_url.spec() + "';")); |
| 6373 "window.location.href = '" + blocked_url.spec() + "';")); | |
| 6374 | 6331 |
| 6375 // The blocked frame should still fire a load event in its parent's process. | 6332 // The blocked frame should still fire a load event in its parent's process. |
| 6376 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 6333 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 6377 | 6334 |
| 6378 // Check that the current RenderFrameHost has stopped loading. | 6335 // Check that the current RenderFrameHost has stopped loading. |
| 6379 if (root->child_at(0)->current_frame_host()->is_loading()) { | 6336 if (root->child_at(0)->current_frame_host()->is_loading()) { |
| 6380 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 6337 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
| 6381 load_observer.Wait(); | 6338 load_observer.Wait(); |
| 6382 } | 6339 } |
| 6383 | 6340 |
| 6384 // The blocked frame should commit to |kBlockedURL| | 6341 // The blocked frame should commit to |kBlockedURL| |
| 6385 EXPECT_EQ(kBlockedURL, root->child_at(0)->current_url()); | 6342 EXPECT_EQ(kBlockedURL, root->child_at(0)->current_url()); |
| 6386 | 6343 |
| 6387 std::string frame_title; | 6344 std::string frame_title; |
| 6388 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6345 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6389 root->child_at(0)->current_frame_host(), | 6346 root->child_at(0), "domAutomationController.send(document.title)", |
| 6390 "domAutomationController.send(document.title)", &frame_title)); | 6347 &frame_title)); |
| 6391 EXPECT_EQ("", frame_title); | 6348 EXPECT_EQ("", frame_title); |
| 6392 | 6349 |
| 6393 // Navigate to a URL without CSP. | 6350 // Navigate to a URL without CSP. |
| 6394 EXPECT_TRUE(NavigateToURL( | 6351 EXPECT_TRUE(NavigateToURL( |
| 6395 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); | 6352 shell(), embedded_test_server()->GetURL("a.com", "/title1.html"))); |
| 6396 | 6353 |
| 6397 // Verify that the frame's CSP got correctly reset to an empty set. | 6354 // Verify that the frame's CSP got correctly reset to an empty set. |
| 6398 EXPECT_EQ(0u, | 6355 EXPECT_EQ(0u, |
| 6399 root->current_replication_state().accumulated_csp_headers.size()); | 6356 root->current_replication_state().accumulated_csp_headers.size()); |
| 6400 } | 6357 } |
| 6401 | 6358 |
| 6402 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. | 6359 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. |
| 6403 // In this version of a test, CSP comes from a <meta> element added after the | 6360 // In this version of a test, CSP comes from a <meta> element added after the |
| 6404 // page has already loaded. | 6361 // page has already loaded. |
| 6405 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 6362 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 6406 CrossSiteIframeBlockedByParentCSPFromMeta) { | 6363 CrossSiteIframeBlockedByParentCSPFromMeta) { |
| 6407 GURL main_url(embedded_test_server()->GetURL( | 6364 GURL main_url(embedded_test_server()->GetURL( |
| 6408 "a.com", "/cross_site_iframe_factory.html?a(a)")); | 6365 "a.com", "/cross_site_iframe_factory.html?a(a)")); |
| 6409 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 6366 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 6410 | 6367 |
| 6411 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 6368 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 6412 | 6369 |
| 6413 // Navigate the subframe to a location we will disallow in the future. | 6370 // Navigate the subframe to a location we will disallow in the future. |
| 6414 GURL old_subframe_url( | 6371 GURL old_subframe_url( |
| 6415 embedded_test_server()->GetURL("b.com", "/title2.html")); | 6372 embedded_test_server()->GetURL("b.com", "/title2.html")); |
| 6416 NavigateFrameToURL(root->child_at(0), old_subframe_url); | 6373 NavigateFrameToURL(root->child_at(0), old_subframe_url); |
| 6417 | 6374 |
| 6418 // Add frame-src CSP via a new <meta> element. | 6375 // Add frame-src CSP via a new <meta> element. |
| 6419 EXPECT_TRUE(ExecuteScript( | 6376 EXPECT_TRUE(ExecuteScript( |
| 6420 shell()->web_contents(), | 6377 shell(), |
| 6421 "var meta = document.createElement('meta');" | 6378 "var meta = document.createElement('meta');" |
| 6422 "meta.httpEquiv = 'Content-Security-Policy';" | 6379 "meta.httpEquiv = 'Content-Security-Policy';" |
| 6423 "meta.content = 'frame-src https://a.com:*';" | 6380 "meta.content = 'frame-src https://a.com:*';" |
| 6424 "document.getElementsByTagName('head')[0].appendChild(meta);")); | 6381 "document.getElementsByTagName('head')[0].appendChild(meta);")); |
| 6425 | 6382 |
| 6426 // Sanity-check that the test page has the expected shape for testing. | 6383 // Sanity-check that the test page has the expected shape for testing. |
| 6427 // (the CSP should not have an effect on the already loaded frames). | 6384 // (the CSP should not have an effect on the already loaded frames). |
| 6428 EXPECT_FALSE(root->child_at(0)->HasSameOrigin(*root)); | 6385 EXPECT_FALSE(root->child_at(0)->HasSameOrigin(*root)); |
| 6429 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); | 6386 EXPECT_EQ(old_subframe_url, root->child_at(0)->current_url()); |
| 6430 const std::vector<ContentSecurityPolicyHeader>& root_csp = | 6387 const std::vector<ContentSecurityPolicyHeader>& root_csp = |
| 6431 root->current_replication_state().accumulated_csp_headers; | 6388 root->current_replication_state().accumulated_csp_headers; |
| 6432 EXPECT_EQ(1u, root_csp.size()); | 6389 EXPECT_EQ(1u, root_csp.size()); |
| 6433 EXPECT_EQ("frame-src https://a.com:*", root_csp[0].header_value); | 6390 EXPECT_EQ("frame-src https://a.com:*", root_csp[0].header_value); |
| 6434 | 6391 |
| 6435 // Monitor subframe's load events via main frame's title. | 6392 // Monitor subframe's load events via main frame's title. |
| 6436 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 6393 EXPECT_TRUE(ExecuteScript(shell(), |
| 6437 "document.querySelector('iframe').onload = " | 6394 "document.querySelector('iframe').onload = " |
| 6438 " function() { document.title = 'loaded'; };")); | 6395 " function() { document.title = 'loaded'; };")); |
| 6439 EXPECT_TRUE( | 6396 EXPECT_TRUE(ExecuteScript(shell(), "document.title = 'not loaded';")); |
| 6440 ExecuteScript(shell()->web_contents(), "document.title = 'not loaded';")); | |
| 6441 base::string16 expected_title(base::UTF8ToUTF16("loaded")); | 6397 base::string16 expected_title(base::UTF8ToUTF16("loaded")); |
| 6442 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 6398 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 6443 | 6399 |
| 6444 // Try to navigate the subframe to a blocked URL. | 6400 // Try to navigate the subframe to a blocked URL. |
| 6445 TestNavigationObserver load_observer2(shell()->web_contents()); | 6401 TestNavigationObserver load_observer2(shell()->web_contents()); |
| 6446 GURL blocked_url = embedded_test_server()->GetURL("c.com", "/title3.html"); | 6402 GURL blocked_url = embedded_test_server()->GetURL("c.com", "/title3.html"); |
| 6447 EXPECT_TRUE( | 6403 EXPECT_TRUE(ExecuteScript(root->child_at(0), "window.location.href = '" + |
| 6448 ExecuteScript(root->child_at(0)->current_frame_host(), | 6404 blocked_url.spec() + "';")); |
| 6449 "window.location.href = '" + blocked_url.spec() + "';")); | |
| 6450 | 6405 |
| 6451 // The blocked frame should still fire a load event in its parent's process. | 6406 // The blocked frame should still fire a load event in its parent's process. |
| 6452 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 6407 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 6453 | 6408 |
| 6454 // Check that the current RenderFrameHost has stopped loading. | 6409 // Check that the current RenderFrameHost has stopped loading. |
| 6455 if (root->child_at(0)->current_frame_host()->is_loading()) { | 6410 if (root->child_at(0)->current_frame_host()->is_loading()) { |
| 6456 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 6411 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
| 6457 load_observer2.Wait(); | 6412 load_observer2.Wait(); |
| 6458 } | 6413 } |
| 6459 | 6414 |
| 6460 // The blocked frame should commit to |kBlockedURL| | 6415 // The blocked frame should commit to |kBlockedURL| |
| 6461 EXPECT_EQ(kBlockedURL, root->child_at(0)->current_url()); | 6416 EXPECT_EQ(kBlockedURL, root->child_at(0)->current_url()); |
| 6462 | 6417 |
| 6463 std::string frame_title; | 6418 std::string frame_title; |
| 6464 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6419 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6465 root->child_at(0)->current_frame_host(), | 6420 root->child_at(0), "domAutomationController.send(document.title)", |
| 6466 "domAutomationController.send(document.title)", &frame_title)); | 6421 &frame_title)); |
| 6467 EXPECT_EQ("", frame_title); | 6422 EXPECT_EQ("", frame_title); |
| 6468 } | 6423 } |
| 6469 | 6424 |
| 6470 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. | 6425 // Test that a cross-origin frame's navigation can be blocked by CSP frame-src. |
| 6471 // In this version of a test, CSP is inherited by srcdoc iframe from a parent | 6426 // In this version of a test, CSP is inherited by srcdoc iframe from a parent |
| 6472 // that declared CSP via HTTP headers. Cross-origin frame navigating to a | 6427 // that declared CSP via HTTP headers. Cross-origin frame navigating to a |
| 6473 // blocked location is a child of the srcdoc iframe. | 6428 // blocked location is a child of the srcdoc iframe. |
| 6474 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 6429 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 6475 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { | 6430 CrossSiteIframeBlockedByCSPInheritedBySrcDocParent) { |
| 6476 GURL main_url( | 6431 GURL main_url( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6491 EXPECT_FALSE(srcdoc_frame->HasSameOrigin(*navigating_frame)); | 6446 EXPECT_FALSE(srcdoc_frame->HasSameOrigin(*navigating_frame)); |
| 6492 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); | 6447 EXPECT_EQ(old_subframe_url, navigating_frame->current_url()); |
| 6493 const std::vector<ContentSecurityPolicyHeader>& srcdoc_csp = | 6448 const std::vector<ContentSecurityPolicyHeader>& srcdoc_csp = |
| 6494 srcdoc_frame->current_replication_state().accumulated_csp_headers; | 6449 srcdoc_frame->current_replication_state().accumulated_csp_headers; |
| 6495 EXPECT_EQ(1u, srcdoc_csp.size()); | 6450 EXPECT_EQ(1u, srcdoc_csp.size()); |
| 6496 EXPECT_EQ("frame-src 'self' http://b.com:*", srcdoc_csp[0].header_value); | 6451 EXPECT_EQ("frame-src 'self' http://b.com:*", srcdoc_csp[0].header_value); |
| 6497 | 6452 |
| 6498 // Monitor navigating_frame's load events via srcdoc_frame posting | 6453 // Monitor navigating_frame's load events via srcdoc_frame posting |
| 6499 // a message to the parent frame. | 6454 // a message to the parent frame. |
| 6500 EXPECT_TRUE( | 6455 EXPECT_TRUE( |
| 6501 ExecuteScript(root->current_frame_host(), | 6456 ExecuteScript(root, |
| 6502 "window.addEventListener('message', function(event) {" | 6457 "window.addEventListener('message', function(event) {" |
| 6503 " document.title = event.data;" | 6458 " document.title = event.data;" |
| 6504 "});")); | 6459 "});")); |
| 6505 EXPECT_TRUE(ExecuteScript( | 6460 EXPECT_TRUE(ExecuteScript( |
| 6506 srcdoc_frame->current_frame_host(), | 6461 srcdoc_frame, |
| 6507 "document.querySelector('iframe').onload = " | 6462 "document.querySelector('iframe').onload = " |
| 6508 " function() { window.top.postMessage('loaded', '*'); };")); | 6463 " function() { window.top.postMessage('loaded', '*'); };")); |
| 6509 EXPECT_TRUE( | 6464 EXPECT_TRUE(ExecuteScript(shell(), "document.title = 'not loaded';")); |
| 6510 ExecuteScript(shell()->web_contents(), "document.title = 'not loaded';")); | |
| 6511 base::string16 expected_title(base::UTF8ToUTF16("loaded")); | 6465 base::string16 expected_title(base::UTF8ToUTF16("loaded")); |
| 6512 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 6466 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 6513 | 6467 |
| 6514 // Try to navigate the subframe to a blocked URL. | 6468 // Try to navigate the subframe to a blocked URL. |
| 6515 TestNavigationObserver load_observer2(shell()->web_contents()); | 6469 TestNavigationObserver load_observer2(shell()->web_contents()); |
| 6516 GURL blocked_url = embedded_test_server()->GetURL("c.com", "/title3.html"); | 6470 GURL blocked_url = embedded_test_server()->GetURL("c.com", "/title3.html"); |
| 6517 EXPECT_TRUE( | 6471 EXPECT_TRUE(ExecuteScript(navigating_frame, "window.location.href = '" + |
| 6518 ExecuteScript(navigating_frame->current_frame_host(), | 6472 blocked_url.spec() + "';")); |
| 6519 "window.location.href = '" + blocked_url.spec() + "';")); | |
| 6520 | 6473 |
| 6521 // The blocked frame should still fire a load event in its parent's process. | 6474 // The blocked frame should still fire a load event in its parent's process. |
| 6522 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 6475 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 6523 | 6476 |
| 6524 // Check that the current RenderFrameHost has stopped loading. | 6477 // Check that the current RenderFrameHost has stopped loading. |
| 6525 if (navigating_frame->current_frame_host()->is_loading()) { | 6478 if (navigating_frame->current_frame_host()->is_loading()) { |
| 6526 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; | 6479 ADD_FAILURE() << "Blocked RenderFrameHost shouldn't be loading anything"; |
| 6527 load_observer2.Wait(); | 6480 load_observer2.Wait(); |
| 6528 } | 6481 } |
| 6529 | 6482 |
| 6530 // The blocked frame should commit to |kBlockedURL| | 6483 // The blocked frame should commit to |kBlockedURL| |
| 6531 EXPECT_EQ(kBlockedURL, navigating_frame->current_url()); | 6484 EXPECT_EQ(kBlockedURL, navigating_frame->current_url()); |
| 6532 | 6485 |
| 6533 std::string frame_title; | 6486 std::string frame_title; |
| 6534 EXPECT_TRUE(ExecuteScriptAndExtractString( | 6487 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 6535 navigating_frame->current_frame_host(), | 6488 navigating_frame, "domAutomationController.send(document.title)", |
| 6536 "domAutomationController.send(document.title)", &frame_title)); | 6489 &frame_title)); |
| 6537 EXPECT_EQ("", frame_title); | 6490 EXPECT_EQ("", frame_title); |
| 6538 | 6491 |
| 6539 // Navigate the subframe to a URL without CSP. | 6492 // Navigate the subframe to a URL without CSP. |
| 6540 NavigateFrameToURL(srcdoc_frame, | 6493 NavigateFrameToURL(srcdoc_frame, |
| 6541 embedded_test_server()->GetURL("a.com", "/title1.html")); | 6494 embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 6542 | 6495 |
| 6543 // Verify that the frame's CSP got correctly reset to an empty set. | 6496 // Verify that the frame's CSP got correctly reset to an empty set. |
| 6544 EXPECT_EQ( | 6497 EXPECT_EQ( |
| 6545 0u, | 6498 0u, |
| 6546 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); | 6499 srcdoc_frame->current_replication_state().accumulated_csp_headers.size()); |
| 6547 } | 6500 } |
| 6548 | 6501 |
| 6549 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, ScreenCoordinates) { | 6502 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, ScreenCoordinates) { |
| 6550 GURL main_url(embedded_test_server()->GetURL( | 6503 GURL main_url(embedded_test_server()->GetURL( |
| 6551 "a.com", "/cross_site_iframe_factory.html?a(b)")); | 6504 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
| 6552 NavigateToURL(shell(), main_url); | 6505 NavigateToURL(shell(), main_url); |
| 6553 | 6506 |
| 6554 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | 6507 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
| 6555 FrameTreeNode* child = root->child_at(0); | 6508 FrameTreeNode* child = root->child_at(0); |
| 6556 | 6509 |
| 6557 const char* properties[] = {"screenX", "screenY", "outerWidth", | 6510 const char* properties[] = {"screenX", "screenY", "outerWidth", |
| 6558 "outerHeight"}; | 6511 "outerHeight"}; |
| 6559 | 6512 |
| 6560 for (const char* property : properties) { | 6513 for (const char* property : properties) { |
| 6561 std::string script = "window.domAutomationController.send(window."; | 6514 std::string script = "window.domAutomationController.send(window."; |
| 6562 script += property; | 6515 script += property; |
| 6563 script += ");"; | 6516 script += ");"; |
| 6564 int root_value = 1; | 6517 int root_value = 1; |
| 6565 int child_value = 2; | 6518 int child_value = 2; |
| 6566 EXPECT_TRUE(ExecuteScriptAndExtractInt(root->current_frame_host(), | 6519 EXPECT_TRUE(ExecuteScriptAndExtractInt(root, script.c_str(), &root_value)); |
| 6567 script.c_str(), &root_value)); | |
| 6568 | 6520 |
| 6569 EXPECT_TRUE(ExecuteScriptAndExtractInt(child->current_frame_host(), | 6521 EXPECT_TRUE( |
| 6570 script.c_str(), &child_value)); | 6522 ExecuteScriptAndExtractInt(child, script.c_str(), &child_value)); |
| 6571 | 6523 |
| 6572 EXPECT_EQ(root_value, child_value); | 6524 EXPECT_EQ(root_value, child_value); |
| 6573 } | 6525 } |
| 6574 } | 6526 } |
| 6575 | 6527 |
| 6576 // Tests that the certificate store is updated during a cross-site | 6528 // Tests that the certificate store is updated during a cross-site |
| 6577 // redirect navigation. (See https://crbug.com/561754.) Ignores | 6529 // redirect navigation. (See https://crbug.com/561754.) Ignores |
| 6578 // certificate errors so that it can use the cross-site redirector to | 6530 // certificate errors so that it can use the cross-site redirector to |
| 6579 // redirect from HTTPS to HTTPS. | 6531 // redirect from HTTPS to HTTPS. |
| 6580 IN_PROC_BROWSER_TEST_F(SitePerProcessIgnoreCertErrorsBrowserTest, | 6532 IN_PROC_BROWSER_TEST_F(SitePerProcessIgnoreCertErrorsBrowserTest, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6646 EXPECT_TRUE(rvh->is_swapped_out_); | 6598 EXPECT_TRUE(rvh->is_swapped_out_); |
| 6647 | 6599 |
| 6648 // Have the child frame navigate its parent to its SiteInstance. | 6600 // Have the child frame navigate its parent to its SiteInstance. |
| 6649 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 6601 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 6650 std::string script = base::StringPrintf( | 6602 std::string script = base::StringPrintf( |
| 6651 "window.domAutomationController.send(" | 6603 "window.domAutomationController.send(" |
| 6652 "parent.location = '%s');", | 6604 "parent.location = '%s');", |
| 6653 b_url.spec().c_str()); | 6605 b_url.spec().c_str()); |
| 6654 | 6606 |
| 6655 TestFrameNavigationObserver frame_observer(root); | 6607 TestFrameNavigationObserver frame_observer(root); |
| 6656 EXPECT_TRUE(ExecuteScript(root->child_at(0)->current_frame_host(), script)); | 6608 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
| 6657 frame_observer.Wait(); | 6609 frame_observer.Wait(); |
| 6658 EXPECT_EQ(b_url, root->current_url()); | 6610 EXPECT_EQ(b_url, root->current_url()); |
| 6659 | 6611 |
| 6660 // Verify that the same RenderViewHost is preserved and that it is no longer | 6612 // Verify that the same RenderViewHost is preserved and that it is no longer |
| 6661 // in swapped out state. | 6613 // in swapped out state. |
| 6662 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( | 6614 EXPECT_EQ(rvh, contents->GetFrameTree()->GetRenderViewHost( |
| 6663 root->current_frame_host()->GetSiteInstance())); | 6615 root->current_frame_host()->GetSiteInstance())); |
| 6664 EXPECT_FALSE(rvh->is_swapped_out_); | 6616 EXPECT_FALSE(rvh->is_swapped_out_); |
| 6665 } | 6617 } |
| 6666 | 6618 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6887 EXPECT_EQ( | 6839 EXPECT_EQ( |
| 6888 " Site A ------------ proxies for B\n" | 6840 " Site A ------------ proxies for B\n" |
| 6889 " +--Site B ------- proxies for A\n" | 6841 " +--Site B ------- proxies for A\n" |
| 6890 " +--Site B -- proxies for A\n" | 6842 " +--Site B -- proxies for A\n" |
| 6891 "Where A = http://a.com/\n" | 6843 "Where A = http://a.com/\n" |
| 6892 " B = http://b.com/", | 6844 " B = http://b.com/", |
| 6893 DepictFrameTree(root)); | 6845 DepictFrameTree(root)); |
| 6894 | 6846 |
| 6895 int child_count = 0; | 6847 int child_count = 0; |
| 6896 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 6848 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 6897 root->child_at(0)->current_frame_host(), | 6849 root->child_at(0), "window.domAutomationController.send(frames.length);", |
| 6898 "window.domAutomationController.send(frames.length);", &child_count)); | 6850 &child_count)); |
| 6899 EXPECT_EQ(1, child_count); | 6851 EXPECT_EQ(1, child_count); |
| 6900 | 6852 |
| 6901 RenderFrameDeletedObserver deleted_observer( | 6853 RenderFrameDeletedObserver deleted_observer( |
| 6902 root->child_at(0)->child_at(0)->current_frame_host()); | 6854 root->child_at(0)->child_at(0)->current_frame_host()); |
| 6903 | 6855 |
| 6904 // Add an unload handler to the grandchild that causes it to be synchronously | 6856 // Add an unload handler to the grandchild that causes it to be synchronously |
| 6905 // detached, then navigate it. | 6857 // detached, then navigate it. |
| 6906 EXPECT_TRUE(ExecuteScript( | 6858 EXPECT_TRUE(ExecuteScript( |
| 6907 root->child_at(0)->child_at(0)->current_frame_host(), | 6859 root->child_at(0)->child_at(0), |
| 6908 "window.onunload=function(e){\n" | 6860 "window.onunload=function(e){\n" |
| 6909 " window.parent.document.getElementById('child-0').remove();\n" | 6861 " window.parent.document.getElementById('child-0').remove();\n" |
| 6910 "};\n")); | 6862 "};\n")); |
| 6911 std::string script = | 6863 std::string script = |
| 6912 std::string("window.document.getElementById('child-0').src = \"") + | 6864 std::string("window.document.getElementById('child-0').src = \"") + |
| 6913 embedded_test_server() | 6865 embedded_test_server() |
| 6914 ->GetURL("c.com", "/cross_site_iframe_factory.html?c") | 6866 ->GetURL("c.com", "/cross_site_iframe_factory.html?c") |
| 6915 .spec() + | 6867 .spec() + |
| 6916 "\""; | 6868 "\""; |
| 6917 EXPECT_TRUE( | 6869 EXPECT_TRUE(ExecuteScript(root->child_at(0), script.c_str())); |
| 6918 ExecuteScript(root->child_at(0)->current_frame_host(), script.c_str())); | |
| 6919 | 6870 |
| 6920 deleted_observer.WaitUntilDeleted(); | 6871 deleted_observer.WaitUntilDeleted(); |
| 6921 | 6872 |
| 6922 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 6873 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 6923 root->child_at(0)->current_frame_host(), | 6874 root->child_at(0), "window.domAutomationController.send(frames.length);", |
| 6924 "window.domAutomationController.send(frames.length);", &child_count)); | 6875 &child_count)); |
| 6925 EXPECT_EQ(0, child_count); | 6876 EXPECT_EQ(0, child_count); |
| 6926 | 6877 |
| 6927 EXPECT_EQ( | 6878 EXPECT_EQ( |
| 6928 " Site A ------------ proxies for B\n" | 6879 " Site A ------------ proxies for B\n" |
| 6929 " +--Site B ------- proxies for A\n" | 6880 " +--Site B ------- proxies for A\n" |
| 6930 "Where A = http://a.com/\n" | 6881 "Where A = http://a.com/\n" |
| 6931 " B = http://b.com/", | 6882 " B = http://b.com/", |
| 6932 DepictFrameTree(root)); | 6883 DepictFrameTree(root)); |
| 6933 } | 6884 } |
| 6934 | 6885 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7009 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess(); | 6960 RenderProcessHost* process1 = child1->current_frame_host()->GetProcess(); |
| 7010 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess(); | 6961 RenderProcessHost* process2 = child2->current_frame_host()->GetProcess(); |
| 7011 | 6962 |
| 7012 // Call window.open simultaneously in both subframes to create two popups. | 6963 // Call window.open simultaneously in both subframes to create two popups. |
| 7013 // Wait for and then drop both ViewHostMsg_ShowView messages. This will | 6964 // Wait for and then drop both ViewHostMsg_ShowView messages. This will |
| 7014 // ensure that both CreateNewWindow calls happen before either | 6965 // ensure that both CreateNewWindow calls happen before either |
| 7015 // ShowCreatedWindow call. | 6966 // ShowCreatedWindow call. |
| 7016 scoped_refptr<PendingWidgetMessageFilter> filter1 = | 6967 scoped_refptr<PendingWidgetMessageFilter> filter1 = |
| 7017 new PendingWidgetMessageFilter(); | 6968 new PendingWidgetMessageFilter(); |
| 7018 process1->AddFilter(filter1.get()); | 6969 process1->AddFilter(filter1.get()); |
| 7019 EXPECT_TRUE(ExecuteScript(child1->current_frame_host(), "window.open();")); | 6970 EXPECT_TRUE(ExecuteScript(child1, "window.open();")); |
| 7020 filter1->Wait(); | 6971 filter1->Wait(); |
| 7021 | 6972 |
| 7022 scoped_refptr<PendingWidgetMessageFilter> filter2 = | 6973 scoped_refptr<PendingWidgetMessageFilter> filter2 = |
| 7023 new PendingWidgetMessageFilter(); | 6974 new PendingWidgetMessageFilter(); |
| 7024 process2->AddFilter(filter2.get()); | 6975 process2->AddFilter(filter2.get()); |
| 7025 EXPECT_TRUE(ExecuteScript(child2->current_frame_host(), "window.open();")); | 6976 EXPECT_TRUE(ExecuteScript(child2, "window.open();")); |
| 7026 filter2->Wait(); | 6977 filter2->Wait(); |
| 7027 | 6978 |
| 7028 // At this point, we should have two pending WebContents. | 6979 // At this point, we should have two pending WebContents. |
| 7029 EXPECT_TRUE( | 6980 EXPECT_TRUE( |
| 7030 ContainsKey(web_contents()->pending_contents_, | 6981 ContainsKey(web_contents()->pending_contents_, |
| 7031 std::make_pair(process1->GetID(), filter1->routing_id()))); | 6982 std::make_pair(process1->GetID(), filter1->routing_id()))); |
| 7032 EXPECT_TRUE( | 6983 EXPECT_TRUE( |
| 7033 ContainsKey(web_contents()->pending_contents_, | 6984 ContainsKey(web_contents()->pending_contents_, |
| 7034 std::make_pair(process2->GetID(), filter2->routing_id()))); | 6985 std::make_pair(process2->GetID(), filter2->routing_id()))); |
| 7035 | 6986 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7075 "b.com", "/site_isolation/page-with-select.html")); | 7026 "b.com", "/site_isolation/page-with-select.html")); |
| 7076 NavigateFrameToURL(child2, embedded_test_server()->GetURL( | 7027 NavigateFrameToURL(child2, embedded_test_server()->GetURL( |
| 7077 "c.com", "/site_isolation/page-with-select.html")); | 7028 "c.com", "/site_isolation/page-with-select.html")); |
| 7078 | 7029 |
| 7079 // Open both <select> menus. This creates a popup widget in both processes. | 7030 // Open both <select> menus. This creates a popup widget in both processes. |
| 7080 // Wait for and then drop the ViewHostMsg_ShowWidget messages, so that both | 7031 // Wait for and then drop the ViewHostMsg_ShowWidget messages, so that both |
| 7081 // widgets are left in pending-but-not-shown state. | 7032 // widgets are left in pending-but-not-shown state. |
| 7082 scoped_refptr<PendingWidgetMessageFilter> filter1 = | 7033 scoped_refptr<PendingWidgetMessageFilter> filter1 = |
| 7083 new PendingWidgetMessageFilter(); | 7034 new PendingWidgetMessageFilter(); |
| 7084 process1->AddFilter(filter1.get()); | 7035 process1->AddFilter(filter1.get()); |
| 7085 EXPECT_TRUE(ExecuteScript(child1->current_frame_host(), "openSelectMenu();")); | 7036 EXPECT_TRUE(ExecuteScript(child1, "openSelectMenu();")); |
| 7086 filter1->Wait(); | 7037 filter1->Wait(); |
| 7087 | 7038 |
| 7088 scoped_refptr<PendingWidgetMessageFilter> filter2 = | 7039 scoped_refptr<PendingWidgetMessageFilter> filter2 = |
| 7089 new PendingWidgetMessageFilter(); | 7040 new PendingWidgetMessageFilter(); |
| 7090 process2->AddFilter(filter2.get()); | 7041 process2->AddFilter(filter2.get()); |
| 7091 EXPECT_TRUE(ExecuteScript(child2->current_frame_host(), "openSelectMenu();")); | 7042 EXPECT_TRUE(ExecuteScript(child2, "openSelectMenu();")); |
| 7092 filter2->Wait(); | 7043 filter2->Wait(); |
| 7093 | 7044 |
| 7094 // At this point, we should have two pending widgets. | 7045 // At this point, we should have two pending widgets. |
| 7095 EXPECT_TRUE( | 7046 EXPECT_TRUE( |
| 7096 ContainsKey(web_contents()->pending_widget_views_, | 7047 ContainsKey(web_contents()->pending_widget_views_, |
| 7097 std::make_pair(process1->GetID(), filter1->routing_id()))); | 7048 std::make_pair(process1->GetID(), filter1->routing_id()))); |
| 7098 EXPECT_TRUE( | 7049 EXPECT_TRUE( |
| 7099 ContainsKey(web_contents()->pending_widget_views_, | 7050 ContainsKey(web_contents()->pending_widget_views_, |
| 7100 std::make_pair(process2->GetID(), filter2->routing_id()))); | 7051 std::make_pair(process2->GetID(), filter2->routing_id()))); |
| 7101 | 7052 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7137 EXPECT_TRUE(NavigateToURL(shell(), url_1)); | 7088 EXPECT_TRUE(NavigateToURL(shell(), url_1)); |
| 7138 | 7089 |
| 7139 WebContentsImpl* contents = web_contents(); | 7090 WebContentsImpl* contents = web_contents(); |
| 7140 FrameTreeNode* root = contents->GetFrameTree()->root(); | 7091 FrameTreeNode* root = contents->GetFrameTree()->root(); |
| 7141 | 7092 |
| 7142 // Helper to check if a frame is allowed to go fullscreen on the renderer | 7093 // Helper to check if a frame is allowed to go fullscreen on the renderer |
| 7143 // side. | 7094 // side. |
| 7144 auto is_fullscreen_allowed = [](FrameTreeNode* ftn) { | 7095 auto is_fullscreen_allowed = [](FrameTreeNode* ftn) { |
| 7145 bool fullscreen_allowed = false; | 7096 bool fullscreen_allowed = false; |
| 7146 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 7097 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 7147 ftn->current_frame_host(), | 7098 ftn, |
| 7148 "window.domAutomationController.send(document.webkitFullscreenEnabled)", | 7099 "window.domAutomationController.send(document.webkitFullscreenEnabled)", |
| 7149 &fullscreen_allowed)); | 7100 &fullscreen_allowed)); |
| 7150 return fullscreen_allowed; | 7101 return fullscreen_allowed; |
| 7151 }; | 7102 }; |
| 7152 | 7103 |
| 7153 EXPECT_TRUE(is_fullscreen_allowed(root)); | 7104 EXPECT_TRUE(is_fullscreen_allowed(root)); |
| 7154 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0))); | 7105 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0))); |
| 7155 EXPECT_TRUE(root->child_at(0)->frame_owner_properties().allowFullscreen); | 7106 EXPECT_TRUE(root->child_at(0)->frame_owner_properties().allowFullscreen); |
| 7156 | 7107 |
| 7157 // Now navigate to a page with two <iframe>'s, both without allowFullscreen. | 7108 // Now navigate to a page with two <iframe>'s, both without allowFullscreen. |
| 7158 GURL url_2(embedded_test_server()->GetURL( | 7109 GURL url_2(embedded_test_server()->GetURL( |
| 7159 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); | 7110 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); |
| 7160 EXPECT_TRUE(NavigateToURL(shell(), url_2)); | 7111 EXPECT_TRUE(NavigateToURL(shell(), url_2)); |
| 7161 EXPECT_FALSE(root->child_at(0)->frame_owner_properties().allowFullscreen); | 7112 EXPECT_FALSE(root->child_at(0)->frame_owner_properties().allowFullscreen); |
| 7162 EXPECT_FALSE(root->child_at(1)->frame_owner_properties().allowFullscreen); | 7113 EXPECT_FALSE(root->child_at(1)->frame_owner_properties().allowFullscreen); |
| 7163 | 7114 |
| 7164 EXPECT_TRUE(is_fullscreen_allowed(root)); | 7115 EXPECT_TRUE(is_fullscreen_allowed(root)); |
| 7165 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0))); | 7116 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0))); |
| 7166 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(1))); | 7117 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(1))); |
| 7167 | 7118 |
| 7168 // Dynamically enable fullscreen for first subframe and check that the | 7119 // Dynamically enable fullscreen for first subframe and check that the |
| 7169 // fullscreen property was updated on the FrameTreeNode. | 7120 // fullscreen property was updated on the FrameTreeNode. |
| 7170 EXPECT_TRUE(ExecuteScript( | 7121 EXPECT_TRUE(ExecuteScript( |
| 7171 root->current_frame_host(), | 7122 root, "document.getElementById('child-0').allowFullscreen='true'")); |
| 7172 "document.getElementById('child-0').allowFullscreen='true'")); | |
| 7173 EXPECT_TRUE(root->child_at(0)->frame_owner_properties().allowFullscreen); | 7123 EXPECT_TRUE(root->child_at(0)->frame_owner_properties().allowFullscreen); |
| 7174 | 7124 |
| 7175 // Check that the first subframe is now allowed to go fullscreen. Other | 7125 // Check that the first subframe is now allowed to go fullscreen. Other |
| 7176 // frames shouldn't be affected. | 7126 // frames shouldn't be affected. |
| 7177 EXPECT_TRUE(is_fullscreen_allowed(root)); | 7127 EXPECT_TRUE(is_fullscreen_allowed(root)); |
| 7178 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0))); | 7128 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0))); |
| 7179 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(1))); | 7129 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(1))); |
| 7180 | 7130 |
| 7181 // Now navigate to a page with two levels of nesting. | 7131 // Now navigate to a page with two levels of nesting. |
| 7182 GURL url_3(embedded_test_server()->GetURL( | 7132 GURL url_3(embedded_test_server()->GetURL( |
| 7183 "a.com", "/cross_site_iframe_factory.html?a(b(c))")); | 7133 "a.com", "/cross_site_iframe_factory.html?a(b(c))")); |
| 7184 EXPECT_TRUE(NavigateToURL(shell(), url_3)); | 7134 EXPECT_TRUE(NavigateToURL(shell(), url_3)); |
| 7185 | 7135 |
| 7186 EXPECT_TRUE(is_fullscreen_allowed(root)); | 7136 EXPECT_TRUE(is_fullscreen_allowed(root)); |
| 7187 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0))); | 7137 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0))); |
| 7188 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); | 7138 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); |
| 7189 | 7139 |
| 7190 // Dynamically enable fullscreen for bottom subframe. | 7140 // Dynamically enable fullscreen for bottom subframe. |
| 7191 EXPECT_TRUE(ExecuteScript( | 7141 EXPECT_TRUE(ExecuteScript( |
| 7192 root->child_at(0)->current_frame_host(), | 7142 root->child_at(0), |
| 7193 "document.getElementById('child-0').allowFullscreen='true'")); | 7143 "document.getElementById('child-0').allowFullscreen='true'")); |
| 7194 | 7144 |
| 7195 // This still shouldn't allow the bottom child to go fullscreen, since the | 7145 // This still shouldn't allow the bottom child to go fullscreen, since the |
| 7196 // top frame hasn't allowed fullscreen for the middle frame. | 7146 // top frame hasn't allowed fullscreen for the middle frame. |
| 7197 EXPECT_TRUE(is_fullscreen_allowed(root)); | 7147 EXPECT_TRUE(is_fullscreen_allowed(root)); |
| 7198 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0))); | 7148 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0))); |
| 7199 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); | 7149 EXPECT_FALSE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); |
| 7200 | 7150 |
| 7201 // Now allow fullscreen for the middle frame. | 7151 // Now allow fullscreen for the middle frame. |
| 7202 EXPECT_TRUE(ExecuteScript( | 7152 EXPECT_TRUE(ExecuteScript( |
| 7203 root->current_frame_host(), | 7153 root, "document.getElementById('child-0').allowFullscreen='true'")); |
| 7204 "document.getElementById('child-0').allowFullscreen='true'")); | |
| 7205 | 7154 |
| 7206 // All frames should be allowed to go fullscreen now. | 7155 // All frames should be allowed to go fullscreen now. |
| 7207 EXPECT_TRUE(is_fullscreen_allowed(root)); | 7156 EXPECT_TRUE(is_fullscreen_allowed(root)); |
| 7208 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0))); | 7157 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0))); |
| 7209 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); | 7158 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); |
| 7210 | 7159 |
| 7211 // Cross-site navigation should preserve the fullscreen flags. | 7160 // Cross-site navigation should preserve the fullscreen flags. |
| 7212 NavigateFrameToURL(root->child_at(0)->child_at(0), | 7161 NavigateFrameToURL(root->child_at(0)->child_at(0), |
| 7213 embedded_test_server()->GetURL("d.com", "/title1.html")); | 7162 embedded_test_server()->GetURL("d.com", "/title1.html")); |
| 7214 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); | 7163 EXPECT_TRUE(is_fullscreen_allowed(root->child_at(0)->child_at(0))); |
| 7215 } | 7164 } |
| 7216 | 7165 |
| 7217 } // namespace content | 7166 } // namespace content |
| OLD | NEW |