| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 NavigateToURL(shell(), frame_url); | 791 NavigateToURL(shell(), frame_url); |
| 792 | 792 |
| 793 // Give the frame an opener using window.open. | 793 // Give the frame an opener using window.open. |
| 794 EXPECT_TRUE(ExecuteScript(shell(), "window.open('about:blank','foo');")); | 794 EXPECT_TRUE(ExecuteScript(shell(), "window.open('about:blank','foo');")); |
| 795 | 795 |
| 796 // Check that the browser process updates the subframe's opener. | 796 // Check that the browser process updates the subframe's opener. |
| 797 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 797 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 798 ->GetFrameTree() | 798 ->GetFrameTree() |
| 799 ->root(); | 799 ->root(); |
| 800 EXPECT_EQ(root, root->child_at(0)->opener()); | 800 EXPECT_EQ(root, root->child_at(0)->opener()); |
| 801 EXPECT_EQ(nullptr, root->child_at(0)->original_opener()); |
| 801 | 802 |
| 802 // Now disown the frame's opener. Shouldn't crash. | 803 // Now disown the frame's opener. Shouldn't crash. |
| 803 EXPECT_TRUE(ExecuteScript(shell(), "window.frames[0].opener = null;")); | 804 EXPECT_TRUE(ExecuteScript(shell(), "window.frames[0].opener = null;")); |
| 804 | 805 |
| 805 // Check that the subframe's opener in the browser process is disowned. | 806 // Check that the subframe's opener in the browser process is disowned. |
| 806 EXPECT_EQ(nullptr, root->child_at(0)->opener()); | 807 EXPECT_EQ(nullptr, root->child_at(0)->opener()); |
| 808 EXPECT_EQ(nullptr, root->child_at(0)->original_opener()); |
| 807 } | 809 } |
| 808 | 810 |
| 809 // Check that window.name is preserved for top frames when they navigate | 811 // Check that window.name is preserved for top frames when they navigate |
| 810 // cross-process. See https://crbug.com/504164. | 812 // cross-process. See https://crbug.com/504164. |
| 811 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 813 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 812 PreserveTopFrameWindowNameOnCrossProcessNavigations) { | 814 PreserveTopFrameWindowNameOnCrossProcessNavigations) { |
| 813 StartEmbeddedServer(); | 815 StartEmbeddedServer(); |
| 814 | 816 |
| 815 GURL main_url(embedded_test_server()->GetURL("/title1.html")); | 817 GURL main_url(embedded_test_server()->GetURL("/title1.html")); |
| 816 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 818 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| (...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2266 // Initially, both popups' openers should point to main window. | 2268 // Initially, both popups' openers should point to main window. |
| 2267 FrameTreeNode* foo_root = | 2269 FrameTreeNode* foo_root = |
| 2268 static_cast<WebContentsImpl*>(foo_shell->web_contents()) | 2270 static_cast<WebContentsImpl*>(foo_shell->web_contents()) |
| 2269 ->GetFrameTree() | 2271 ->GetFrameTree() |
| 2270 ->root(); | 2272 ->root(); |
| 2271 FrameTreeNode* bar_root = | 2273 FrameTreeNode* bar_root = |
| 2272 static_cast<WebContentsImpl*>(bar_shell->web_contents()) | 2274 static_cast<WebContentsImpl*>(bar_shell->web_contents()) |
| 2273 ->GetFrameTree() | 2275 ->GetFrameTree() |
| 2274 ->root(); | 2276 ->root(); |
| 2275 EXPECT_EQ(root, foo_root->opener()); | 2277 EXPECT_EQ(root, foo_root->opener()); |
| 2278 EXPECT_EQ(root, foo_root->original_opener()); |
| 2276 EXPECT_EQ(root, bar_root->opener()); | 2279 EXPECT_EQ(root, bar_root->opener()); |
| 2280 EXPECT_EQ(root, bar_root->original_opener()); |
| 2277 | 2281 |
| 2278 // From the bar process, use window.open to update foo's opener to point to | 2282 // From the bar process, use window.open to update foo's opener to point to |
| 2279 // bar. This is allowed since bar is same-origin with foo's opener. Use | 2283 // bar. This is allowed since bar is same-origin with foo's opener. Use |
| 2280 // window.open with an empty URL, which should return a reference to the | 2284 // window.open with an empty URL, which should return a reference to the |
| 2281 // target frame without navigating it. | 2285 // target frame without navigating it. |
| 2282 bool success = false; | 2286 bool success = false; |
| 2283 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2287 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2284 bar_shell, | 2288 bar_shell, |
| 2285 "window.domAutomationController.send(!!window.open('','foo'));", | 2289 "window.domAutomationController.send(!!window.open('','foo'));", |
| 2286 &success)); | 2290 &success)); |
| 2287 EXPECT_TRUE(success); | 2291 EXPECT_TRUE(success); |
| 2288 EXPECT_FALSE(foo_shell->web_contents()->IsLoading()); | 2292 EXPECT_FALSE(foo_shell->web_contents()->IsLoading()); |
| 2289 EXPECT_EQ(foo_url, foo_root->current_url()); | 2293 EXPECT_EQ(foo_url, foo_root->current_url()); |
| 2290 | 2294 |
| 2291 // Check that updated opener propagated to the browser process. | 2295 // Check that updated opener propagated to the browser process. |
| 2292 EXPECT_EQ(bar_root, foo_root->opener()); | 2296 EXPECT_EQ(bar_root, foo_root->opener()); |
| 2297 EXPECT_EQ(root, foo_root->original_opener()); |
| 2293 | 2298 |
| 2294 // Check that foo's opener was updated in foo's process. Send a postMessage | 2299 // Check that foo's opener was updated in foo's process. Send a postMessage |
| 2295 // to the opener and check that the right window (bar_shell) receives it. | 2300 // to the opener and check that the right window (bar_shell) receives it. |
| 2296 base::string16 expected_title = ASCIIToUTF16("opener-msg"); | 2301 base::string16 expected_title = ASCIIToUTF16("opener-msg"); |
| 2297 TitleWatcher title_watcher(bar_shell->web_contents(), expected_title); | 2302 TitleWatcher title_watcher(bar_shell->web_contents(), expected_title); |
| 2298 success = false; | 2303 success = false; |
| 2299 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 2304 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 2300 foo_shell, | 2305 foo_shell, |
| 2301 "window.domAutomationController.send(postToOpener('opener-msg', '*'));", | 2306 "window.domAutomationController.send(postToOpener('opener-msg', '*'));", |
| 2302 &success)); | 2307 &success)); |
| 2303 EXPECT_TRUE(success); | 2308 EXPECT_TRUE(success); |
| 2304 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 2309 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 2305 | 2310 |
| 2306 // Check that a non-null assignment to the opener doesn't change the opener | 2311 // Check that a non-null assignment to the opener doesn't change the opener |
| 2307 // in the browser process. | 2312 // in the browser process. |
| 2308 EXPECT_TRUE(ExecuteScript(foo_shell, "window.opener = window;")); | 2313 EXPECT_TRUE(ExecuteScript(foo_shell, "window.opener = window;")); |
| 2309 EXPECT_EQ(bar_root, foo_root->opener()); | 2314 EXPECT_EQ(bar_root, foo_root->opener()); |
| 2315 EXPECT_EQ(root, foo_root->original_opener()); |
| 2310 } | 2316 } |
| 2311 | 2317 |
| 2312 // Tests that when a popup is opened, which is then navigated cross-process and | 2318 // Tests that when a popup is opened, which is then navigated cross-process and |
| 2313 // back, it can be still accessed through the original window reference in | 2319 // back, it can be still accessed through the original window reference in |
| 2314 // JavaScript. See https://crbug.com/537657 | 2320 // JavaScript. See https://crbug.com/537657 |
| 2315 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, | 2321 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, |
| 2316 PopupKeepsWindowReferenceCrossProcesAndBack) { | 2322 PopupKeepsWindowReferenceCrossProcesAndBack) { |
| 2317 StartEmbeddedServer(); | 2323 StartEmbeddedServer(); |
| 2318 | 2324 |
| 2319 // Load a page with links that open in a new window. | 2325 // Load a page with links that open in a new window. |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3025 // the iframe's old RFH still has correct origin, even though it's pending | 3031 // the iframe's old RFH still has correct origin, even though it's pending |
| 3026 // deletion. | 3032 // deletion. |
| 3027 if (AreAllSitesIsolatedForTesting()) { | 3033 if (AreAllSitesIsolatedForTesting()) { |
| 3028 EXPECT_FALSE(child_rfh_b->is_active()); | 3034 EXPECT_FALSE(child_rfh_b->is_active()); |
| 3029 EXPECT_NE(child_rfh_b, child->current_frame_host()); | 3035 EXPECT_NE(child_rfh_b, child->current_frame_host()); |
| 3030 EXPECT_EQ(url::Origin(url_b), child_rfh_b->GetLastCommittedOrigin()); | 3036 EXPECT_EQ(url::Origin(url_b), child_rfh_b->GetLastCommittedOrigin()); |
| 3031 } | 3037 } |
| 3032 } | 3038 } |
| 3033 | 3039 |
| 3034 } // namespace content | 3040 } // namespace content |
| OLD | NEW |