Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 3029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3040 base::string16 expected_title = base::ASCIIToUTF16("msg"); | 3040 base::string16 expected_title = base::ASCIIToUTF16("msg"); |
| 3041 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 3041 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 3042 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3042 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3043 popup_root->child_at(0)->current_frame_host(), | 3043 popup_root->child_at(0)->current_frame_host(), |
| 3044 "window.domAutomationController.send(postToOpenerOfParent('msg','*'));", | 3044 "window.domAutomationController.send(postToOpenerOfParent('msg','*'));", |
| 3045 &success)); | 3045 &success)); |
| 3046 EXPECT_TRUE(success); | 3046 EXPECT_TRUE(success); |
| 3047 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 3047 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 3048 } | 3048 } |
| 3049 | 3049 |
| 3050 // Check that if a subframe has an opener, that opener is preserved when the | |
| 3051 // subframe navigates cross-site. | |
| 3052 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateSubframeWithOpener) { | |
| 3053 GURL main_url = embedded_test_server()->GetURL( | |
| 3054 "foo.com", "/frame_tree/page_with_two_frames.html"); | |
|
Charlie Reis
2015/08/28 23:27:38
nit: Let's use Nick's new cross_site_iframe_factor
alexmos
2015/08/31 23:54:28
I hit a problem with this in that I need the subfr
Charlie Reis
2015/09/01 22:04:26
Ah, no need, then. We can change it if the factor
| |
| 3055 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 3056 | |
| 3057 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 3058 ->GetFrameTree() | |
| 3059 ->root(); | |
| 3060 EXPECT_EQ( | |
| 3061 " Site A ------------ proxies for B\n" | |
| 3062 " |--Site B ------- proxies for A\n" | |
| 3063 " +--Site A ------- proxies for B\n" | |
| 3064 "Where A = http://foo.com/\n" | |
| 3065 " B = http://bar.com/", | |
| 3066 DepictFrameTree(root)); | |
| 3067 | |
| 3068 // Update the first (cross-site) subframe's opener to root frame. | |
| 3069 bool success = false; | |
| 3070 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 3071 root->current_frame_host(), | |
| 3072 "window.domAutomationController.send(!!window.open('','frame1'));", | |
| 3073 &success)); | |
| 3074 EXPECT_TRUE(success); | |
| 3075 | |
| 3076 // Check that updated opener propagated to the browser process and subframe's | |
| 3077 // process. | |
| 3078 EXPECT_EQ(root, root->child_at(0)->opener()); | |
| 3079 | |
| 3080 success = false; | |
| 3081 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 3082 root->child_at(0)->current_frame_host(), | |
| 3083 "window.domAutomationController.send(window.opener === window.parent);", | |
| 3084 &success)); | |
| 3085 EXPECT_TRUE(success); | |
| 3086 | |
| 3087 // Navigate the subframe with opener to another site. | |
| 3088 GURL frame_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); | |
| 3089 NavigateFrameToURL(root->child_at(0), frame_url); | |
| 3090 | |
| 3091 // Check that the subframe still sees correct opener in its new process. | |
| 3092 success = false; | |
| 3093 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 3094 root->child_at(0)->current_frame_host(), | |
| 3095 "window.domAutomationController.send(window.opener === window.parent);", | |
| 3096 &success)); | |
| 3097 EXPECT_TRUE(success); | |
| 3098 | |
| 3099 // Navigate second subframe to a new site. Check that the proxy that's | |
| 3100 // created for the first subframe in the new SiteInstance has correct opener. | |
| 3101 GURL frame2_url(embedded_test_server()->GetURL("qux.com", "/title1.html")); | |
| 3102 NavigateFrameToURL(root->child_at(1), frame2_url); | |
| 3103 | |
| 3104 success = false; | |
| 3105 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 3106 root->child_at(1)->current_frame_host(), | |
| 3107 "window.domAutomationController.send(" | |
| 3108 " parent.frames['frame1'].opener === parent);", | |
| 3109 &success)); | |
| 3110 EXPECT_TRUE(success); | |
| 3111 } | |
| 3112 | |
| 3113 // Check that if a subframe has an opener, that opener is preserved when a new | |
| 3114 // RenderFrameProxy is created for that subframe in another renderer process. | |
| 3115 // Similar to NavigateSubframeWithOpener, but this test verifies the subframe | |
| 3116 // opener plumbing for FrameMsg_NewFrameProxy, whereas | |
| 3117 // NavigateSubframeWithOpener targets FrameMsg_NewFrame. | |
| 3118 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 3119 NewRenderFrameProxyPreservesOpener) { | |
| 3120 GURL main_url = | |
| 3121 embedded_test_server()->GetURL("foo.com", "/post_message.html"); | |
| 3122 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 3123 | |
| 3124 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 3125 ->GetFrameTree() | |
| 3126 ->root(); | |
| 3127 | |
| 3128 // Open a popup with a cross-site page that has two subframes. | |
| 3129 GURL popup_url(embedded_test_server()->GetURL( | |
| 3130 "bar.com", "/frame_tree/page_with_post_message_frames.html")); | |
| 3131 Shell* popup_shell = OpenPopup(shell()->web_contents(), popup_url, "popup"); | |
| 3132 EXPECT_TRUE(popup_shell); | |
| 3133 FrameTreeNode* popup_root = | |
| 3134 static_cast<WebContentsImpl*>(popup_shell->web_contents()) | |
| 3135 ->GetFrameTree() | |
| 3136 ->root(); | |
| 3137 EXPECT_EQ( | |
| 3138 " Site A ------------ proxies for B\n" | |
| 3139 " |--Site A ------- proxies for B\n" | |
| 3140 " +--Site B ------- proxies for A\n" | |
| 3141 "Where A = http://bar.com/\n" | |
| 3142 " B = http://foo.com/", | |
| 3143 DepictFrameTree(popup_root)); | |
| 3144 | |
| 3145 // Update the popup's second subframe's opener to root frame. This is | |
| 3146 // allowed because that subframe is in the same foo.com SiteInstance as the | |
| 3147 // root frame. | |
| 3148 bool success = false; | |
| 3149 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 3150 root->current_frame_host(), | |
| 3151 "window.domAutomationController.send(!!window.open('','subframe2'));", | |
| 3152 &success)); | |
| 3153 EXPECT_TRUE(success); | |
| 3154 | |
| 3155 // Check that the opener update propagated to the browser process and bar.com | |
| 3156 // process. | |
| 3157 EXPECT_EQ(root, popup_root->child_at(1)->opener()); | |
| 3158 success = false; | |
| 3159 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 3160 popup_root->child_at(0)->current_frame_host(), | |
| 3161 "window.domAutomationController.send(" | |
| 3162 " parent.frames['subframe2'].opener && " | |
| 3163 " parent.frames['subframe2'].opener === parent.opener);", | |
| 3164 &success)); | |
| 3165 EXPECT_TRUE(success); | |
| 3166 | |
| 3167 // Navigate the popup's first subframe to another site. | |
| 3168 GURL frame_url( | |
| 3169 embedded_test_server()->GetURL("baz.com", "/post_message.html")); | |
| 3170 NavigateFrameToURL(popup_root->child_at(0), frame_url); | |
| 3171 EXPECT_TRUE( | |
| 3172 WaitForRenderFrameReady(popup_root->child_at(0)->current_frame_host())); | |
| 3173 | |
| 3174 // Check that the second subframe's opener is still correct in the first | |
| 3175 // subframe's new process. Verify it both in JS and with a postMessage. | |
| 3176 success = false; | |
| 3177 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 3178 popup_root->child_at(0)->current_frame_host(), | |
| 3179 "window.domAutomationController.send(" | |
| 3180 " parent.frames['subframe2'].opener && " | |
| 3181 " parent.frames['subframe2'].opener === parent.opener);", | |
| 3182 &success)); | |
| 3183 EXPECT_TRUE(success); | |
| 3184 | |
| 3185 base::string16 expected_title = base::ASCIIToUTF16("msg"); | |
| 3186 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | |
| 3187 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 3188 popup_root->child_at(0)->current_frame_host(), | |
| 3189 "window.domAutomationController.send(" | |
| 3190 " postToOpenerOfSibling('subframe2', 'msg', '*'));", | |
| 3191 &success)); | |
| 3192 EXPECT_TRUE(success); | |
| 3193 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
| 3194 } | |
| 3195 | |
| 3050 } // namespace content | 3196 } // namespace content |
| OLD | NEW |