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 1352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2073 // http://crbug.com/444955. | 2074 // http://crbug.com/444955. |
2074 TEST_F(RenderFrameHostManagerTestWithSiteIsolation, DetachPendingChild) { | 2075 TEST_F(RenderFrameHostManagerTestWithSiteIsolation, DetachPendingChild) { |
2075 const GURL kUrlA("http://www.google.com/"); | 2076 const GURL kUrlA("http://www.google.com/"); |
2076 const GURL kUrlB("http://webkit.org/"); | 2077 const GURL kUrlB("http://webkit.org/"); |
2077 | 2078 |
2078 // Create a page with two child frames. | 2079 // Create a page with two child frames. |
2079 contents()->NavigateAndCommit(kUrlA); | 2080 contents()->NavigateAndCommit(kUrlA); |
2080 contents()->GetMainFrame()->OnCreateChildFrame( | 2081 contents()->GetMainFrame()->OnCreateChildFrame( |
2081 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 2082 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
2082 blink::WebTreeScopeType::Document, "frame_name", | 2083 blink::WebTreeScopeType::Document, "frame_name", |
2083 blink::WebSandboxFlags::None); | 2084 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
2084 contents()->GetMainFrame()->OnCreateChildFrame( | 2085 contents()->GetMainFrame()->OnCreateChildFrame( |
2085 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 2086 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
2086 blink::WebTreeScopeType::Document, "frame_name", | 2087 blink::WebTreeScopeType::Document, "frame_name", |
2087 blink::WebSandboxFlags::None); | 2088 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
2088 RenderFrameHostManager* root_manager = | 2089 RenderFrameHostManager* root_manager = |
2089 contents()->GetFrameTree()->root()->render_manager(); | 2090 contents()->GetFrameTree()->root()->render_manager(); |
2090 RenderFrameHostManager* iframe1 = | 2091 RenderFrameHostManager* iframe1 = |
2091 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 2092 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
2092 RenderFrameHostManager* iframe2 = | 2093 RenderFrameHostManager* iframe2 = |
2093 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); | 2094 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); |
2094 | 2095 |
2095 // 1) The first navigation. | 2096 // 1) The first navigation. |
2096 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, | 2097 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, |
2097 Referrer(), base::string16() /* title */, | 2098 Referrer(), base::string16() /* title */, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2214 // Reload |contents1|. | 2215 // Reload |contents1|. |
2215 contents1->NavigateAndCommit(kUrl1); | 2216 contents1->NavigateAndCommit(kUrl1); |
2216 EXPECT_TRUE(contents1->GetMainFrame()->IsRenderFrameLive()); | 2217 EXPECT_TRUE(contents1->GetMainFrame()->IsRenderFrameLive()); |
2217 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2218 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2218 EXPECT_EQ(contents1->GetSiteInstance(), contents2->GetSiteInstance()); | 2219 EXPECT_EQ(contents1->GetSiteInstance(), contents2->GetSiteInstance()); |
2219 | 2220 |
2220 // |contents1| creates an out of process iframe. | 2221 // |contents1| creates an out of process iframe. |
2221 contents1->GetMainFrame()->OnCreateChildFrame( | 2222 contents1->GetMainFrame()->OnCreateChildFrame( |
2222 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), | 2223 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), |
2223 blink::WebTreeScopeType::Document, "frame_name", | 2224 blink::WebTreeScopeType::Document, "frame_name", |
2224 blink::WebSandboxFlags::None); | 2225 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties()); |
2225 RenderFrameHostManager* iframe = | 2226 RenderFrameHostManager* iframe = |
2226 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); | 2227 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); |
2227 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, | 2228 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, |
2228 Referrer(kUrl1, blink::WebReferrerPolicyDefault), | 2229 Referrer(kUrl1, blink::WebReferrerPolicyDefault), |
2229 base::string16() /* title */, | 2230 base::string16() /* title */, |
2230 ui::PAGE_TRANSITION_LINK, | 2231 ui::PAGE_TRANSITION_LINK, |
2231 false /* is_renderer_init */); | 2232 false /* is_renderer_init */); |
2232 RenderFrameHostImpl* cross_site = NavigateToEntry(iframe, entry); | 2233 RenderFrameHostImpl* cross_site = NavigateToEntry(iframe, entry); |
2233 iframe->DidNavigateFrame(cross_site, true); | 2234 iframe->DidNavigateFrame(cross_site, true); |
2234 | 2235 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 // The test starts traversing openers from root1 and expects to discover all | 2375 // The test starts traversing openers from root1 and expects to discover all |
2375 // four FrameTrees. Nodes 13 (with cycle to itself) and 42 (with back link to | 2376 // four FrameTrees. Nodes 13 (with cycle to itself) and 42 (with back link to |
2376 // root3) should be put on the list of nodes that will need their frame openers | 2377 // root3) should be put on the list of nodes that will need their frame openers |
2377 // set separately in a second pass, since their opener routing IDs won't be | 2378 // set separately in a second pass, since their opener routing IDs won't be |
2378 // available during the first pass of CreateOpenerProxies. | 2379 // available during the first pass of CreateOpenerProxies. |
2379 TEST_F(RenderFrameHostManagerTest, TraverseComplexOpenerChain) { | 2380 TEST_F(RenderFrameHostManagerTest, TraverseComplexOpenerChain) { |
2380 FrameTree* tree1 = contents()->GetFrameTree(); | 2381 FrameTree* tree1 = contents()->GetFrameTree(); |
2381 FrameTreeNode* root1 = tree1->root(); | 2382 FrameTreeNode* root1 = tree1->root(); |
2382 int process_id = root1->current_frame_host()->GetProcess()->GetID(); | 2383 int process_id = root1->current_frame_host()->GetProcess()->GetID(); |
2383 tree1->AddFrame(root1, process_id, 12, blink::WebTreeScopeType::Document, | 2384 tree1->AddFrame(root1, process_id, 12, blink::WebTreeScopeType::Document, |
2384 std::string(), blink::WebSandboxFlags::None); | 2385 std::string(), blink::WebSandboxFlags::None, |
| 2386 blink::WebFrameOwnerProperties()); |
2385 tree1->AddFrame(root1, process_id, 13, blink::WebTreeScopeType::Document, | 2387 tree1->AddFrame(root1, process_id, 13, blink::WebTreeScopeType::Document, |
2386 std::string(), blink::WebSandboxFlags::None); | 2388 std::string(), blink::WebSandboxFlags::None, |
| 2389 blink::WebFrameOwnerProperties()); |
2387 | 2390 |
2388 scoped_ptr<TestWebContents> tab2( | 2391 scoped_ptr<TestWebContents> tab2( |
2389 TestWebContents::Create(browser_context(), nullptr)); | 2392 TestWebContents::Create(browser_context(), nullptr)); |
2390 FrameTree* tree2 = tab2->GetFrameTree(); | 2393 FrameTree* tree2 = tab2->GetFrameTree(); |
2391 FrameTreeNode* root2 = tree2->root(); | 2394 FrameTreeNode* root2 = tree2->root(); |
2392 process_id = root2->current_frame_host()->GetProcess()->GetID(); | 2395 process_id = root2->current_frame_host()->GetProcess()->GetID(); |
2393 tree2->AddFrame(root2, process_id, 22, blink::WebTreeScopeType::Document, | 2396 tree2->AddFrame(root2, process_id, 22, blink::WebTreeScopeType::Document, |
2394 std::string(), blink::WebSandboxFlags::None); | 2397 std::string(), blink::WebSandboxFlags::None, |
| 2398 blink::WebFrameOwnerProperties()); |
2395 tree2->AddFrame(root2, process_id, 23, blink::WebTreeScopeType::Document, | 2399 tree2->AddFrame(root2, process_id, 23, blink::WebTreeScopeType::Document, |
2396 std::string(), blink::WebSandboxFlags::None); | 2400 std::string(), blink::WebSandboxFlags::None, |
| 2401 blink::WebFrameOwnerProperties()); |
2397 | 2402 |
2398 scoped_ptr<TestWebContents> tab3( | 2403 scoped_ptr<TestWebContents> tab3( |
2399 TestWebContents::Create(browser_context(), nullptr)); | 2404 TestWebContents::Create(browser_context(), nullptr)); |
2400 FrameTree* tree3 = tab3->GetFrameTree(); | 2405 FrameTree* tree3 = tab3->GetFrameTree(); |
2401 FrameTreeNode* root3 = tree3->root(); | 2406 FrameTreeNode* root3 = tree3->root(); |
2402 | 2407 |
2403 scoped_ptr<TestWebContents> tab4( | 2408 scoped_ptr<TestWebContents> tab4( |
2404 TestWebContents::Create(browser_context(), nullptr)); | 2409 TestWebContents::Create(browser_context(), nullptr)); |
2405 FrameTree* tree4 = tab4->GetFrameTree(); | 2410 FrameTree* tree4 = tab4->GetFrameTree(); |
2406 FrameTreeNode* root4 = tree4->root(); | 2411 FrameTreeNode* root4 = tree4->root(); |
2407 process_id = root4->current_frame_host()->GetProcess()->GetID(); | 2412 process_id = root4->current_frame_host()->GetProcess()->GetID(); |
2408 tree4->AddFrame(root4, process_id, 42, blink::WebTreeScopeType::Document, | 2413 tree4->AddFrame(root4, process_id, 42, blink::WebTreeScopeType::Document, |
2409 std::string(), blink::WebSandboxFlags::None); | 2414 std::string(), blink::WebSandboxFlags::None, |
| 2415 blink::WebFrameOwnerProperties()); |
2410 | 2416 |
2411 root1->child_at(1)->SetOpener(root1->child_at(1)); | 2417 root1->child_at(1)->SetOpener(root1->child_at(1)); |
2412 root1->SetOpener(root2->child_at(1)); | 2418 root1->SetOpener(root2->child_at(1)); |
2413 root2->SetOpener(root3); | 2419 root2->SetOpener(root3); |
2414 root2->child_at(0)->SetOpener(root4); | 2420 root2->child_at(0)->SetOpener(root4); |
2415 root2->child_at(1)->SetOpener(root4); | 2421 root2->child_at(1)->SetOpener(root4); |
2416 root4->child_at(0)->SetOpener(root3); | 2422 root4->child_at(0)->SetOpener(root3); |
2417 | 2423 |
2418 std::vector<FrameTree*> opener_frame_trees; | 2424 std::vector<FrameTree*> opener_frame_trees; |
2419 base::hash_set<FrameTreeNode*> nodes_with_back_links; | 2425 base::hash_set<FrameTreeNode*> nodes_with_back_links; |
2420 | 2426 |
2421 CollectOpenerFrameTrees(root1, &opener_frame_trees, &nodes_with_back_links); | 2427 CollectOpenerFrameTrees(root1, &opener_frame_trees, &nodes_with_back_links); |
2422 | 2428 |
2423 EXPECT_EQ(4U, opener_frame_trees.size()); | 2429 EXPECT_EQ(4U, opener_frame_trees.size()); |
2424 EXPECT_EQ(tree1, opener_frame_trees[0]); | 2430 EXPECT_EQ(tree1, opener_frame_trees[0]); |
2425 EXPECT_EQ(tree2, opener_frame_trees[1]); | 2431 EXPECT_EQ(tree2, opener_frame_trees[1]); |
2426 EXPECT_EQ(tree3, opener_frame_trees[2]); | 2432 EXPECT_EQ(tree3, opener_frame_trees[2]); |
2427 EXPECT_EQ(tree4, opener_frame_trees[3]); | 2433 EXPECT_EQ(tree4, opener_frame_trees[3]); |
2428 | 2434 |
2429 EXPECT_EQ(2U, nodes_with_back_links.size()); | 2435 EXPECT_EQ(2U, nodes_with_back_links.size()); |
2430 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != | 2436 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != |
2431 nodes_with_back_links.end()); | 2437 nodes_with_back_links.end()); |
2432 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != | 2438 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != |
2433 nodes_with_back_links.end()); | 2439 nodes_with_back_links.end()); |
2434 } | 2440 } |
2435 | 2441 |
2436 } // namespace content | 2442 } // namespace content |
OLD | NEW |