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