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 3073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3084 base::string16 expected_title = base::ASCIIToUTF16("msg"); | 3084 base::string16 expected_title = base::ASCIIToUTF16("msg"); |
3085 TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 3085 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
3086 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 3086 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
3087 popup_root->child_at(0)->current_frame_host(), | 3087 popup_root->child_at(0)->current_frame_host(), |
3088 "window.domAutomationController.send(postToOpenerOfParent('msg','*'));", | 3088 "window.domAutomationController.send(postToOpenerOfParent('msg','*'));", |
3089 &success)); | 3089 &success)); |
3090 EXPECT_TRUE(success); | 3090 EXPECT_TRUE(success); |
3091 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 3091 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
3092 } | 3092 } |
3093 | 3093 |
| 3094 // Check that if a subframe has an opener, that opener is preserved when the |
| 3095 // subframe navigates cross-site. |
| 3096 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, NavigateSubframeWithOpener) { |
| 3097 GURL main_url(embedded_test_server()->GetURL( |
| 3098 "foo.com", "/frame_tree/page_with_two_frames.html")); |
| 3099 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3100 |
| 3101 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 3102 ->GetFrameTree() |
| 3103 ->root(); |
| 3104 EXPECT_EQ( |
| 3105 " Site A ------------ proxies for B\n" |
| 3106 " |--Site B ------- proxies for A\n" |
| 3107 " +--Site A ------- proxies for B\n" |
| 3108 "Where A = http://foo.com/\n" |
| 3109 " B = http://bar.com/", |
| 3110 DepictFrameTree(root)); |
| 3111 |
| 3112 // Update the first (cross-site) subframe's opener to root frame. |
| 3113 bool success = false; |
| 3114 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3115 root->current_frame_host(), |
| 3116 "window.domAutomationController.send(!!window.open('','frame1'));", |
| 3117 &success)); |
| 3118 EXPECT_TRUE(success); |
| 3119 |
| 3120 // Check that updated opener propagated to the browser process and subframe's |
| 3121 // process. |
| 3122 EXPECT_EQ(root, root->child_at(0)->opener()); |
| 3123 |
| 3124 success = false; |
| 3125 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3126 root->child_at(0)->current_frame_host(), |
| 3127 "window.domAutomationController.send(window.opener === window.parent);", |
| 3128 &success)); |
| 3129 EXPECT_TRUE(success); |
| 3130 |
| 3131 // Navigate the subframe with opener to another site. |
| 3132 GURL frame_url(embedded_test_server()->GetURL("baz.com", "/title1.html")); |
| 3133 NavigateFrameToURL(root->child_at(0), frame_url); |
| 3134 |
| 3135 // Check that the subframe still sees correct opener in its new process. |
| 3136 success = false; |
| 3137 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3138 root->child_at(0)->current_frame_host(), |
| 3139 "window.domAutomationController.send(window.opener === window.parent);", |
| 3140 &success)); |
| 3141 EXPECT_TRUE(success); |
| 3142 |
| 3143 // Navigate second subframe to a new site. Check that the proxy that's |
| 3144 // created for the first subframe in the new SiteInstance has correct opener. |
| 3145 GURL frame2_url(embedded_test_server()->GetURL("qux.com", "/title1.html")); |
| 3146 NavigateFrameToURL(root->child_at(1), frame2_url); |
| 3147 |
| 3148 success = false; |
| 3149 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3150 root->child_at(1)->current_frame_host(), |
| 3151 "window.domAutomationController.send(" |
| 3152 " parent.frames['frame1'].opener === parent);", |
| 3153 &success)); |
| 3154 EXPECT_TRUE(success); |
| 3155 } |
| 3156 |
| 3157 // Check that if a subframe has an opener, that opener is preserved when a new |
| 3158 // RenderFrameProxy is created for that subframe in another renderer process. |
| 3159 // Similar to NavigateSubframeWithOpener, but this test verifies the subframe |
| 3160 // opener plumbing for FrameMsg_NewFrameProxy, whereas |
| 3161 // NavigateSubframeWithOpener targets FrameMsg_NewFrame. |
| 3162 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 3163 NewRenderFrameProxyPreservesOpener) { |
| 3164 GURL main_url( |
| 3165 embedded_test_server()->GetURL("foo.com", "/post_message.html")); |
| 3166 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 3167 |
| 3168 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 3169 ->GetFrameTree() |
| 3170 ->root(); |
| 3171 |
| 3172 // Open a popup with a cross-site page that has two subframes. |
| 3173 GURL popup_url(embedded_test_server()->GetURL( |
| 3174 "bar.com", "/frame_tree/page_with_post_message_frames.html")); |
| 3175 Shell* popup_shell = OpenPopup(shell()->web_contents(), popup_url, "popup"); |
| 3176 EXPECT_TRUE(popup_shell); |
| 3177 FrameTreeNode* popup_root = |
| 3178 static_cast<WebContentsImpl*>(popup_shell->web_contents()) |
| 3179 ->GetFrameTree() |
| 3180 ->root(); |
| 3181 EXPECT_EQ( |
| 3182 " Site A ------------ proxies for B\n" |
| 3183 " |--Site A ------- proxies for B\n" |
| 3184 " +--Site B ------- proxies for A\n" |
| 3185 "Where A = http://bar.com/\n" |
| 3186 " B = http://foo.com/", |
| 3187 DepictFrameTree(popup_root)); |
| 3188 |
| 3189 // Update the popup's second subframe's opener to root frame. This is |
| 3190 // allowed because that subframe is in the same foo.com SiteInstance as the |
| 3191 // root frame. |
| 3192 bool success = false; |
| 3193 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3194 root->current_frame_host(), |
| 3195 "window.domAutomationController.send(!!window.open('','subframe2'));", |
| 3196 &success)); |
| 3197 EXPECT_TRUE(success); |
| 3198 |
| 3199 // Check that the opener update propagated to the browser process and bar.com |
| 3200 // process. |
| 3201 EXPECT_EQ(root, popup_root->child_at(1)->opener()); |
| 3202 success = false; |
| 3203 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3204 popup_root->child_at(0)->current_frame_host(), |
| 3205 "window.domAutomationController.send(" |
| 3206 " parent.frames['subframe2'].opener && " |
| 3207 " parent.frames['subframe2'].opener === parent.opener);", |
| 3208 &success)); |
| 3209 EXPECT_TRUE(success); |
| 3210 |
| 3211 // Navigate the popup's first subframe to another site. |
| 3212 GURL frame_url( |
| 3213 embedded_test_server()->GetURL("baz.com", "/post_message.html")); |
| 3214 NavigateFrameToURL(popup_root->child_at(0), frame_url); |
| 3215 EXPECT_TRUE( |
| 3216 WaitForRenderFrameReady(popup_root->child_at(0)->current_frame_host())); |
| 3217 |
| 3218 // Check that the second subframe's opener is still correct in the first |
| 3219 // subframe's new process. Verify it both in JS and with a postMessage. |
| 3220 success = false; |
| 3221 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3222 popup_root->child_at(0)->current_frame_host(), |
| 3223 "window.domAutomationController.send(" |
| 3224 " parent.frames['subframe2'].opener && " |
| 3225 " parent.frames['subframe2'].opener === parent.opener);", |
| 3226 &success)); |
| 3227 EXPECT_TRUE(success); |
| 3228 |
| 3229 base::string16 expected_title = base::ASCIIToUTF16("msg"); |
| 3230 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 3231 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 3232 popup_root->child_at(0)->current_frame_host(), |
| 3233 "window.domAutomationController.send(" |
| 3234 " postToOpenerOfSibling('subframe2', 'msg', '*'));", |
| 3235 &success)); |
| 3236 EXPECT_TRUE(success); |
| 3237 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 3238 } |
| 3239 |
3094 } // namespace content | 3240 } // namespace content |
OLD | NEW |