OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "content/browser/frame_host/frame_tree.h" | 6 #include "content/browser/frame_host/frame_tree.h" |
7 #include "content/browser/frame_host/frame_tree_node.h" | 7 #include "content/browser/frame_host/frame_tree_node.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 192 |
193 // Load a same-site page into iframe and it should still be live. | 193 // Load a same-site page into iframe and it should still be live. |
194 GURL http_url(test_server()->GetURL("files/title1.html")); | 194 GURL http_url(test_server()->GetURL("files/title1.html")); |
195 NavigateFrameToURL(root->child_at(0), http_url); | 195 NavigateFrameToURL(root->child_at(0), http_url); |
196 EXPECT_TRUE( | 196 EXPECT_TRUE( |
197 root->current_frame_host()->render_view_host()->IsRenderViewLive()); | 197 root->current_frame_host()->render_view_host()->IsRenderViewLive()); |
198 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 198 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
199 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); | 199 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); |
200 } | 200 } |
201 | 201 |
| 202 // Ensure that origins are correctly set on navigations. |
| 203 IN_PROC_BROWSER_TEST_F(FrameTreeBrowserTest, OriginSetOnNavigation) { |
| 204 host_resolver()->AddRule("*", "127.0.0.1"); |
| 205 ASSERT_TRUE(test_server()->Start()); |
| 206 GURL main_url(test_server()->GetURL("files/frame_tree/top.html")); |
| 207 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 208 |
| 209 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 210 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 211 ->GetFrameTree()->root(); |
| 212 |
| 213 // Extra '/' is added because the replicated origin is serialized in RFC 6454 |
| 214 // format, which dictates no trailing '/', whereas GURL::GetOrigin does put a |
| 215 // '/' at the end. |
| 216 EXPECT_EQ(root->current_replication_state().origin.string() + '/', |
| 217 main_url.GetOrigin().spec()); |
| 218 |
| 219 GURL frame_url(test_server()->GetURL("files/title1.html")); |
| 220 NavigateFrameToURL(root->child_at(0), frame_url); |
| 221 |
| 222 EXPECT_EQ( |
| 223 root->child_at(0)->current_replication_state().origin.string() + '/', |
| 224 frame_url.GetOrigin().spec()); |
| 225 |
| 226 GURL data_url("data:text/html,foo"); |
| 227 EXPECT_TRUE(NavigateToURL(shell(), data_url)); |
| 228 |
| 229 // Navigating to a data URL should set a unique origin. This is represented |
| 230 // as "null" per RFC 6454. |
| 231 EXPECT_EQ(root->current_replication_state().origin.string(), "null"); |
| 232 |
| 233 // Re-navigating to a normal URL should update the origin. |
| 234 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 235 EXPECT_EQ(root->current_replication_state().origin.string() + '/', |
| 236 main_url.GetOrigin().spec()); |
| 237 } |
| 238 |
202 class CrossProcessFrameTreeBrowserTest : public ContentBrowserTest { | 239 class CrossProcessFrameTreeBrowserTest : public ContentBrowserTest { |
203 public: | 240 public: |
204 CrossProcessFrameTreeBrowserTest() {} | 241 CrossProcessFrameTreeBrowserTest() {} |
205 | 242 |
206 void SetUpCommandLine(base::CommandLine* command_line) override { | 243 void SetUpCommandLine(base::CommandLine* command_line) override { |
207 command_line->AppendSwitch(switches::kSitePerProcess); | 244 command_line->AppendSwitch(switches::kSitePerProcess); |
208 } | 245 } |
209 | 246 |
210 private: | 247 private: |
211 DISALLOW_COPY_AND_ASSIGN(CrossProcessFrameTreeBrowserTest); | 248 DISALLOW_COPY_AND_ASSIGN(CrossProcessFrameTreeBrowserTest); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 307 |
271 // Ensure that the RenderViews and RenderFrames are all live. | 308 // Ensure that the RenderViews and RenderFrames are all live. |
272 EXPECT_TRUE( | 309 EXPECT_TRUE( |
273 root->current_frame_host()->render_view_host()->IsRenderViewLive()); | 310 root->current_frame_host()->render_view_host()->IsRenderViewLive()); |
274 EXPECT_TRUE( | 311 EXPECT_TRUE( |
275 child->current_frame_host()->render_view_host()->IsRenderViewLive()); | 312 child->current_frame_host()->render_view_host()->IsRenderViewLive()); |
276 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 313 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
277 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); | 314 EXPECT_TRUE(root->child_at(0)->current_frame_host()->IsRenderFrameLive()); |
278 } | 315 } |
279 | 316 |
| 317 IN_PROC_BROWSER_TEST_F(CrossProcessFrameTreeBrowserTest, |
| 318 OriginSetOnCrossProcessNavigations) { |
| 319 host_resolver()->AddRule("*", "127.0.0.1"); |
| 320 ASSERT_TRUE(test_server()->Start()); |
| 321 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); |
| 322 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 323 |
| 324 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 325 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 326 ->GetFrameTree()->root(); |
| 327 |
| 328 EXPECT_EQ(root->current_replication_state().origin.string() + '/', |
| 329 main_url.GetOrigin().spec()); |
| 330 |
| 331 // First frame is an about:blank frame. Check that its origin is correctly |
| 332 // inherited from the parent. |
| 333 EXPECT_EQ( |
| 334 root->child_at(0)->current_replication_state().origin.string() + '/', |
| 335 main_url.GetOrigin().spec()); |
| 336 |
| 337 // Second frame loads a same-site page. Its origin should also be the same |
| 338 // as the parent. |
| 339 EXPECT_EQ( |
| 340 root->child_at(1)->current_replication_state().origin.string() + '/', |
| 341 main_url.GetOrigin().spec()); |
| 342 |
| 343 // These must stay in scope with replace_host. |
| 344 GURL::Replacements replace_host; |
| 345 std::string foo_com("foo.com"); |
| 346 |
| 347 // Load cross-site page into the first frame. |
| 348 GURL cross_site_url(test_server()->GetURL("files/title2.html")); |
| 349 replace_host.SetHostStr(foo_com); |
| 350 cross_site_url = cross_site_url.ReplaceComponents(replace_host); |
| 351 NavigateFrameToURL(root->child_at(0), cross_site_url); |
| 352 |
| 353 EXPECT_EQ( |
| 354 root->child_at(0)->current_replication_state().origin.string() + '/', |
| 355 cross_site_url.GetOrigin().spec()); |
| 356 |
| 357 // The root's origin shouldn't have changed. |
| 358 EXPECT_EQ(root->current_replication_state().origin.string() + '/', |
| 359 main_url.GetOrigin().spec()); |
| 360 |
| 361 GURL data_url("data:text/html,foo"); |
| 362 NavigateFrameToURL(root->child_at(1), data_url); |
| 363 |
| 364 // Navigating to a data URL should set a unique origin. This is represented |
| 365 // as "null" per RFC 6454. |
| 366 EXPECT_EQ(root->child_at(1)->current_replication_state().origin.string(), |
| 367 "null"); |
| 368 } |
| 369 |
280 } // namespace content | 370 } // namespace content |
OLD | NEW |