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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "content/public/test/mock_render_process_host.h" | 37 #include "content/public/test/mock_render_process_host.h" |
38 #include "content/public/test/test_notification_tracker.h" | 38 #include "content/public/test/test_notification_tracker.h" |
39 #include "content/public/test/test_utils.h" | 39 #include "content/public/test/test_utils.h" |
40 #include "content/test/test_content_browser_client.h" | 40 #include "content/test/test_content_browser_client.h" |
41 #include "content/test/test_content_client.h" | 41 #include "content/test/test_content_client.h" |
42 #include "content/test/test_render_frame_host.h" | 42 #include "content/test/test_render_frame_host.h" |
43 #include "content/test/test_render_view_host.h" | 43 #include "content/test/test_render_view_host.h" |
44 #include "content/test/test_web_contents.h" | 44 #include "content/test/test_web_contents.h" |
45 #include "net/base/load_flags.h" | 45 #include "net/base/load_flags.h" |
46 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 47 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" |
47 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 48 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
48 #include "ui/base/page_transition_types.h" | 49 #include "ui/base/page_transition_types.h" |
49 | 50 |
50 namespace content { | 51 namespace content { |
51 namespace { | 52 namespace { |
52 | 53 |
53 class RenderFrameHostManagerTestWebUIControllerFactory | 54 class RenderFrameHostManagerTestWebUIControllerFactory |
54 : public WebUIControllerFactory { | 55 : public WebUIControllerFactory { |
55 public: | 56 public: |
56 RenderFrameHostManagerTestWebUIControllerFactory() | 57 RenderFrameHostManagerTestWebUIControllerFactory() |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 } | 677 } |
677 | 678 |
678 // Navigate to the first site. | 679 // Navigate to the first site. |
679 NavigateActiveAndCommit(kUrl1); | 680 NavigateActiveAndCommit(kUrl1); |
680 TestRenderFrameHost* initial_rfh = contents()->GetMainFrame(); | 681 TestRenderFrameHost* initial_rfh = contents()->GetMainFrame(); |
681 { | 682 { |
682 RenderFrameHostCreatedObserver observer(contents()); | 683 RenderFrameHostCreatedObserver observer(contents()); |
683 initial_rfh->OnCreateChildFrame( | 684 initial_rfh->OnCreateChildFrame( |
684 initial_rfh->GetProcess()->GetNextRoutingID(), | 685 initial_rfh->GetProcess()->GetNextRoutingID(), |
685 blink::WebTreeScopeType::Document, std::string(), | 686 blink::WebTreeScopeType::Document, std::string(), |
686 blink::WebSandboxFlags::None); | 687 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
687 EXPECT_TRUE(observer.created()); | 688 EXPECT_TRUE(observer.created()); |
688 } | 689 } |
689 | 690 |
690 // Create one more frame in the same SiteInstance where initial_rfh | 691 // Create one more frame in the same SiteInstance where initial_rfh |
691 // exists so that initial_rfh doesn't get deleted on navigation to another | 692 // exists so that initial_rfh doesn't get deleted on navigation to another |
692 // site. | 693 // site. |
693 initial_rfh->GetSiteInstance()->increment_active_frame_count(); | 694 initial_rfh->GetSiteInstance()->increment_active_frame_count(); |
694 | 695 |
695 // Navigate to a cross-site URL. | 696 // Navigate to a cross-site URL. |
696 NavigateActiveAndCommit(kUrl2); | 697 NavigateActiveAndCommit(kUrl2); |
697 EXPECT_TRUE(initial_rfh->is_swapped_out()); | 698 EXPECT_TRUE(initial_rfh->is_swapped_out()); |
698 | 699 |
699 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame(); | 700 TestRenderFrameHost* dest_rfh = contents()->GetMainFrame(); |
700 ASSERT_TRUE(dest_rfh); | 701 ASSERT_TRUE(dest_rfh); |
701 EXPECT_NE(initial_rfh, dest_rfh); | 702 EXPECT_NE(initial_rfh, dest_rfh); |
702 | 703 |
703 { | 704 { |
704 // Since the old RFH is now swapped out, it shouldn't process any messages | 705 // Since the old RFH is now swapped out, it shouldn't process any messages |
705 // to create child frames. | 706 // to create child frames. |
706 RenderFrameHostCreatedObserver observer(contents()); | 707 RenderFrameHostCreatedObserver observer(contents()); |
707 initial_rfh->OnCreateChildFrame( | 708 initial_rfh->OnCreateChildFrame( |
708 initial_rfh->GetProcess()->GetNextRoutingID(), | 709 initial_rfh->GetProcess()->GetNextRoutingID(), |
709 blink::WebTreeScopeType::Document, std::string(), | 710 blink::WebTreeScopeType::Document, std::string(), |
710 blink::WebSandboxFlags::None); | 711 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
711 EXPECT_FALSE(observer.created()); | 712 EXPECT_FALSE(observer.created()); |
712 } | 713 } |
713 } | 714 } |
714 | 715 |
715 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { | 716 TEST_F(RenderFrameHostManagerTest, WhiteListSwapCompositorFrame) { |
716 // TODO(nasko): Check with kenrb whether this test can be rewritten and | 717 // TODO(nasko): Check with kenrb whether this test can be rewritten and |
717 // whether it makes sense when swapped out is replaced with proxies. | 718 // whether it makes sense when swapped out is replaced with proxies. |
718 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { | 719 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { |
719 return; | 720 return; |
720 } | 721 } |
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 // http://crbug.com/444955. | 2075 // http://crbug.com/444955. |
2075 TEST_F(RenderFrameHostManagerTestWithSiteIsolation, DetachPendingChild) { | 2076 TEST_F(RenderFrameHostManagerTestWithSiteIsolation, DetachPendingChild) { |
2076 const GURL kUrlA("http://www.google.com/"); | 2077 const GURL kUrlA("http://www.google.com/"); |
2077 const GURL kUrlB("http://webkit.org/"); | 2078 const GURL kUrlB("http://webkit.org/"); |
2078 | 2079 |
2079 // Create a page with two child frames. | 2080 // Create a page with two child frames. |
2080 contents()->NavigateAndCommit(kUrlA); | 2081 contents()->NavigateAndCommit(kUrlA); |
2081 contents()->GetMainFrame()->OnCreateChildFrame( | 2082 contents()->GetMainFrame()->OnCreateChildFrame( |
2082 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 2083 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
2083 blink::WebTreeScopeType::Document, "frame_name", | 2084 blink::WebTreeScopeType::Document, "frame_name", |
2084 blink::WebSandboxFlags::None); | 2085 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
2085 contents()->GetMainFrame()->OnCreateChildFrame( | 2086 contents()->GetMainFrame()->OnCreateChildFrame( |
2086 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 2087 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
2087 blink::WebTreeScopeType::Document, "frame_name", | 2088 blink::WebTreeScopeType::Document, "frame_name", |
2088 blink::WebSandboxFlags::None); | 2089 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
2089 RenderFrameHostManager* root_manager = | 2090 RenderFrameHostManager* root_manager = |
2090 contents()->GetFrameTree()->root()->render_manager(); | 2091 contents()->GetFrameTree()->root()->render_manager(); |
2091 RenderFrameHostManager* iframe1 = | 2092 RenderFrameHostManager* iframe1 = |
2092 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 2093 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
2093 RenderFrameHostManager* iframe2 = | 2094 RenderFrameHostManager* iframe2 = |
2094 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); | 2095 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); |
2095 | 2096 |
2096 // 1) The first navigation. | 2097 // 1) The first navigation. |
2097 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, | 2098 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, |
2098 Referrer(), base::string16() /* title */, | 2099 Referrer(), base::string16() /* title */, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 // Reload |contents1|. | 2216 // Reload |contents1|. |
2216 contents1->NavigateAndCommit(kUrl1); | 2217 contents1->NavigateAndCommit(kUrl1); |
2217 EXPECT_TRUE(contents1->GetMainFrame()->IsRenderFrameLive()); | 2218 EXPECT_TRUE(contents1->GetMainFrame()->IsRenderFrameLive()); |
2218 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2219 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2219 EXPECT_EQ(contents1->GetSiteInstance(), contents2->GetSiteInstance()); | 2220 EXPECT_EQ(contents1->GetSiteInstance(), contents2->GetSiteInstance()); |
2220 | 2221 |
2221 // |contents1| creates an out of process iframe. | 2222 // |contents1| creates an out of process iframe. |
2222 contents1->GetMainFrame()->OnCreateChildFrame( | 2223 contents1->GetMainFrame()->OnCreateChildFrame( |
2223 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 2224 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
2224 blink::WebTreeScopeType::Document, "frame_name", | 2225 blink::WebTreeScopeType::Document, "frame_name", |
2225 blink::WebSandboxFlags::None); | 2226 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
2226 RenderFrameHostManager* iframe = | 2227 RenderFrameHostManager* iframe = |
2227 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 2228 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
2228 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, | 2229 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, |
2229 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 2230 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
2230 base::string16() /* title */, | 2231 base::string16() /* title */, |
2231 ui::PAGE_TRANSITION_LINK, | 2232 ui::PAGE_TRANSITION_LINK, |
2232 false /* is_renderer_init */); | 2233 false /* is_renderer_init */); |
2233 RenderFrameHostImpl* cross_site = NavigateToEntry(iframe, entry); | 2234 RenderFrameHostImpl* cross_site = NavigateToEntry(iframe, entry); |
2234 iframe->DidNavigateFrame(cross_site, true); | 2235 iframe->DidNavigateFrame(cross_site, true); |
2235 | 2236 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 // The test starts traversing openers from root1 and expects to discover all | 2422 // The test starts traversing openers from root1 and expects to discover all |
2422 // four FrameTrees. Nodes 13 (with cycle to itself) and 42 (with back link to | 2423 // four FrameTrees. Nodes 13 (with cycle to itself) and 42 (with back link to |
2423 // root3) should be put on the list of nodes that will need their frame openers | 2424 // root3) should be put on the list of nodes that will need their frame openers |
2424 // set separately in a second pass, since their opener routing IDs won't be | 2425 // set separately in a second pass, since their opener routing IDs won't be |
2425 // available during the first pass of CreateOpenerProxies. | 2426 // available during the first pass of CreateOpenerProxies. |
2426 TEST_F(RenderFrameHostManagerTest, TraverseComplexOpenerChain) { | 2427 TEST_F(RenderFrameHostManagerTest, TraverseComplexOpenerChain) { |
2427 FrameTree* tree1 = contents()->GetFrameTree(); | 2428 FrameTree* tree1 = contents()->GetFrameTree(); |
2428 FrameTreeNode* root1 = tree1->root(); | 2429 FrameTreeNode* root1 = tree1->root(); |
2429 int process_id = root1->current_frame_host()->GetProcess()->GetID(); | 2430 int process_id = root1->current_frame_host()->GetProcess()->GetID(); |
2430 tree1->AddFrame(root1, process_id, 12, blink::WebTreeScopeType::Document, | 2431 tree1->AddFrame(root1, process_id, 12, blink::WebTreeScopeType::Document, |
2431 std::string(), blink::WebSandboxFlags::None); | 2432 std::string(), blink::WebSandboxFlags::None, |
| 2433 blink::WebFrameOwnerProperties()); |
2432 tree1->AddFrame(root1, process_id, 13, blink::WebTreeScopeType::Document, | 2434 tree1->AddFrame(root1, process_id, 13, blink::WebTreeScopeType::Document, |
2433 std::string(), blink::WebSandboxFlags::None); | 2435 std::string(), blink::WebSandboxFlags::None, |
| 2436 blink::WebFrameOwnerProperties()); |
2434 | 2437 |
2435 scoped_ptr<TestWebContents> tab2( | 2438 scoped_ptr<TestWebContents> tab2( |
2436 TestWebContents::Create(browser_context(), nullptr)); | 2439 TestWebContents::Create(browser_context(), nullptr)); |
2437 FrameTree* tree2 = tab2->GetFrameTree(); | 2440 FrameTree* tree2 = tab2->GetFrameTree(); |
2438 FrameTreeNode* root2 = tree2->root(); | 2441 FrameTreeNode* root2 = tree2->root(); |
2439 process_id = root2->current_frame_host()->GetProcess()->GetID(); | 2442 process_id = root2->current_frame_host()->GetProcess()->GetID(); |
2440 tree2->AddFrame(root2, process_id, 22, blink::WebTreeScopeType::Document, | 2443 tree2->AddFrame(root2, process_id, 22, blink::WebTreeScopeType::Document, |
2441 std::string(), blink::WebSandboxFlags::None); | 2444 std::string(), blink::WebSandboxFlags::None, |
| 2445 blink::WebFrameOwnerProperties()); |
2442 tree2->AddFrame(root2, process_id, 23, blink::WebTreeScopeType::Document, | 2446 tree2->AddFrame(root2, process_id, 23, blink::WebTreeScopeType::Document, |
2443 std::string(), blink::WebSandboxFlags::None); | 2447 std::string(), blink::WebSandboxFlags::None, |
| 2448 blink::WebFrameOwnerProperties()); |
2444 | 2449 |
2445 scoped_ptr<TestWebContents> tab3( | 2450 scoped_ptr<TestWebContents> tab3( |
2446 TestWebContents::Create(browser_context(), nullptr)); | 2451 TestWebContents::Create(browser_context(), nullptr)); |
2447 FrameTree* tree3 = tab3->GetFrameTree(); | 2452 FrameTree* tree3 = tab3->GetFrameTree(); |
2448 FrameTreeNode* root3 = tree3->root(); | 2453 FrameTreeNode* root3 = tree3->root(); |
2449 | 2454 |
2450 scoped_ptr<TestWebContents> tab4( | 2455 scoped_ptr<TestWebContents> tab4( |
2451 TestWebContents::Create(browser_context(), nullptr)); | 2456 TestWebContents::Create(browser_context(), nullptr)); |
2452 FrameTree* tree4 = tab4->GetFrameTree(); | 2457 FrameTree* tree4 = tab4->GetFrameTree(); |
2453 FrameTreeNode* root4 = tree4->root(); | 2458 FrameTreeNode* root4 = tree4->root(); |
2454 process_id = root4->current_frame_host()->GetProcess()->GetID(); | 2459 process_id = root4->current_frame_host()->GetProcess()->GetID(); |
2455 tree4->AddFrame(root4, process_id, 42, blink::WebTreeScopeType::Document, | 2460 tree4->AddFrame(root4, process_id, 42, blink::WebTreeScopeType::Document, |
2456 std::string(), blink::WebSandboxFlags::None); | 2461 std::string(), blink::WebSandboxFlags::None, |
| 2462 blink::WebFrameOwnerProperties()); |
2457 | 2463 |
2458 root1->child_at(1)->SetOpener(root1->child_at(1)); | 2464 root1->child_at(1)->SetOpener(root1->child_at(1)); |
2459 root1->SetOpener(root2->child_at(1)); | 2465 root1->SetOpener(root2->child_at(1)); |
2460 root2->SetOpener(root3); | 2466 root2->SetOpener(root3); |
2461 root2->child_at(0)->SetOpener(root4); | 2467 root2->child_at(0)->SetOpener(root4); |
2462 root2->child_at(1)->SetOpener(root4); | 2468 root2->child_at(1)->SetOpener(root4); |
2463 root4->child_at(0)->SetOpener(root3); | 2469 root4->child_at(0)->SetOpener(root3); |
2464 | 2470 |
2465 std::vector<FrameTree*> opener_frame_trees; | 2471 std::vector<FrameTree*> opener_frame_trees; |
2466 base::hash_set<FrameTreeNode*> nodes_with_back_links; | 2472 base::hash_set<FrameTreeNode*> nodes_with_back_links; |
2467 | 2473 |
2468 CollectOpenerFrameTrees(root1, &opener_frame_trees, &nodes_with_back_links); | 2474 CollectOpenerFrameTrees(root1, &opener_frame_trees, &nodes_with_back_links); |
2469 | 2475 |
2470 EXPECT_EQ(4U, opener_frame_trees.size()); | 2476 EXPECT_EQ(4U, opener_frame_trees.size()); |
2471 EXPECT_EQ(tree1, opener_frame_trees[0]); | 2477 EXPECT_EQ(tree1, opener_frame_trees[0]); |
2472 EXPECT_EQ(tree2, opener_frame_trees[1]); | 2478 EXPECT_EQ(tree2, opener_frame_trees[1]); |
2473 EXPECT_EQ(tree3, opener_frame_trees[2]); | 2479 EXPECT_EQ(tree3, opener_frame_trees[2]); |
2474 EXPECT_EQ(tree4, opener_frame_trees[3]); | 2480 EXPECT_EQ(tree4, opener_frame_trees[3]); |
2475 | 2481 |
2476 EXPECT_EQ(2U, nodes_with_back_links.size()); | 2482 EXPECT_EQ(2U, nodes_with_back_links.size()); |
2477 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != | 2483 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != |
2478 nodes_with_back_links.end()); | 2484 nodes_with_back_links.end()); |
2479 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != | 2485 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != |
2480 nodes_with_back_links.end()); | 2486 nodes_with_back_links.end()); |
2481 } | 2487 } |
2482 | 2488 |
2483 } // namespace content | 2489 } // namespace content |
OLD | NEW |