Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(926)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 1307013004: Propagate scrolling/marginwidth/marginheight property values to child frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after
2067 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess()); 2068 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess());
2068 2069
2069 const GURL kUrlA("http://www.google.com/"); 2070 const GURL kUrlA("http://www.google.com/");
2070 const GURL kUrlB("http://webkit.org/"); 2071 const GURL kUrlB("http://webkit.org/");
2071 2072
2072 // Create a page with two child frames. 2073 // Create a page with two child frames.
2073 contents()->NavigateAndCommit(kUrlA); 2074 contents()->NavigateAndCommit(kUrlA);
2074 contents()->GetMainFrame()->OnCreateChildFrame( 2075 contents()->GetMainFrame()->OnCreateChildFrame(
2075 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), 2076 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(),
2076 blink::WebTreeScopeType::Document, "frame_name", 2077 blink::WebTreeScopeType::Document, "frame_name",
2077 blink::WebSandboxFlags::None); 2078 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties());
2078 contents()->GetMainFrame()->OnCreateChildFrame( 2079 contents()->GetMainFrame()->OnCreateChildFrame(
2079 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(), 2080 contents()->GetMainFrame()->GetProcess()->GetNextRoutingID(),
2080 blink::WebTreeScopeType::Document, "frame_name", 2081 blink::WebTreeScopeType::Document, "frame_name",
2081 blink::WebSandboxFlags::None); 2082 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties());
2082 RenderFrameHostManager* root_manager = 2083 RenderFrameHostManager* root_manager =
2083 contents()->GetFrameTree()->root()->render_manager(); 2084 contents()->GetFrameTree()->root()->render_manager();
2084 RenderFrameHostManager* iframe1 = 2085 RenderFrameHostManager* iframe1 =
2085 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); 2086 contents()->GetFrameTree()->root()->child_at(0)->render_manager();
2086 RenderFrameHostManager* iframe2 = 2087 RenderFrameHostManager* iframe2 =
2087 contents()->GetFrameTree()->root()->child_at(1)->render_manager(); 2088 contents()->GetFrameTree()->root()->child_at(1)->render_manager();
2088 2089
2089 // 1) The first navigation. 2090 // 1) The first navigation.
2090 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA, 2091 NavigationEntryImpl entryA(NULL /* instance */, -1 /* page_id */, kUrlA,
2091 Referrer(), base::string16() /* title */, 2092 Referrer(), base::string16() /* title */,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 // Reload |contents1|. 2210 // Reload |contents1|.
2210 contents1->NavigateAndCommit(kUrl1); 2211 contents1->NavigateAndCommit(kUrl1);
2211 EXPECT_TRUE(contents1->GetMainFrame()->IsRenderFrameLive()); 2212 EXPECT_TRUE(contents1->GetMainFrame()->IsRenderFrameLive());
2212 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); 2213 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive());
2213 EXPECT_EQ(contents1->GetSiteInstance(), contents2->GetSiteInstance()); 2214 EXPECT_EQ(contents1->GetSiteInstance(), contents2->GetSiteInstance());
2214 2215
2215 // |contents1| creates an out of process iframe. 2216 // |contents1| creates an out of process iframe.
2216 contents1->GetMainFrame()->OnCreateChildFrame( 2217 contents1->GetMainFrame()->OnCreateChildFrame(
2217 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(), 2218 contents1->GetMainFrame()->GetProcess()->GetNextRoutingID(),
2218 blink::WebTreeScopeType::Document, "frame_name", 2219 blink::WebTreeScopeType::Document, "frame_name",
2219 blink::WebSandboxFlags::None); 2220 blink::WebSandboxFlags::None, blink::WebFrameOwnerProperties());
2220 RenderFrameHostManager* iframe = 2221 RenderFrameHostManager* iframe =
2221 contents()->GetFrameTree()->root()->child_at(0)->render_manager(); 2222 contents()->GetFrameTree()->root()->child_at(0)->render_manager();
2222 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2, 2223 NavigationEntryImpl entry(NULL /* instance */, -1 /* page_id */, kUrl2,
2223 Referrer(kUrl1, blink::WebReferrerPolicyDefault), 2224 Referrer(kUrl1, blink::WebReferrerPolicyDefault),
2224 base::string16() /* title */, 2225 base::string16() /* title */,
2225 ui::PAGE_TRANSITION_LINK, 2226 ui::PAGE_TRANSITION_LINK,
2226 false /* is_renderer_init */); 2227 false /* is_renderer_init */);
2227 RenderFrameHostImpl* cross_site = NavigateToEntry(iframe, entry); 2228 RenderFrameHostImpl* cross_site = NavigateToEntry(iframe, entry);
2228 iframe->DidNavigateFrame(cross_site, true); 2229 iframe->DidNavigateFrame(cross_site, true);
2229 2230
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 // The test starts traversing openers from root1 and expects to discover all 2370 // The test starts traversing openers from root1 and expects to discover all
2370 // four FrameTrees. Nodes 13 (with cycle to itself) and 42 (with back link to 2371 // four FrameTrees. Nodes 13 (with cycle to itself) and 42 (with back link to
2371 // root3) should be put on the list of nodes that will need their frame openers 2372 // root3) should be put on the list of nodes that will need their frame openers
2372 // set separately in a second pass, since their opener routing IDs won't be 2373 // set separately in a second pass, since their opener routing IDs won't be
2373 // available during the first pass of CreateOpenerProxies. 2374 // available during the first pass of CreateOpenerProxies.
2374 TEST_F(RenderFrameHostManagerTest, TraverseComplexOpenerChain) { 2375 TEST_F(RenderFrameHostManagerTest, TraverseComplexOpenerChain) {
2375 FrameTree* tree1 = contents()->GetFrameTree(); 2376 FrameTree* tree1 = contents()->GetFrameTree();
2376 FrameTreeNode* root1 = tree1->root(); 2377 FrameTreeNode* root1 = tree1->root();
2377 int process_id = root1->current_frame_host()->GetProcess()->GetID(); 2378 int process_id = root1->current_frame_host()->GetProcess()->GetID();
2378 tree1->AddFrame(root1, process_id, 12, blink::WebTreeScopeType::Document, 2379 tree1->AddFrame(root1, process_id, 12, blink::WebTreeScopeType::Document,
2379 std::string(), blink::WebSandboxFlags::None); 2380 std::string(), blink::WebSandboxFlags::None,
2381 blink::WebFrameOwnerProperties());
2380 tree1->AddFrame(root1, process_id, 13, blink::WebTreeScopeType::Document, 2382 tree1->AddFrame(root1, process_id, 13, blink::WebTreeScopeType::Document,
2381 std::string(), blink::WebSandboxFlags::None); 2383 std::string(), blink::WebSandboxFlags::None,
2384 blink::WebFrameOwnerProperties());
2382 2385
2383 scoped_ptr<TestWebContents> tab2( 2386 scoped_ptr<TestWebContents> tab2(
2384 TestWebContents::Create(browser_context(), nullptr)); 2387 TestWebContents::Create(browser_context(), nullptr));
2385 FrameTree* tree2 = tab2->GetFrameTree(); 2388 FrameTree* tree2 = tab2->GetFrameTree();
2386 FrameTreeNode* root2 = tree2->root(); 2389 FrameTreeNode* root2 = tree2->root();
2387 process_id = root2->current_frame_host()->GetProcess()->GetID(); 2390 process_id = root2->current_frame_host()->GetProcess()->GetID();
2388 tree2->AddFrame(root2, process_id, 22, blink::WebTreeScopeType::Document, 2391 tree2->AddFrame(root2, process_id, 22, blink::WebTreeScopeType::Document,
2389 std::string(), blink::WebSandboxFlags::None); 2392 std::string(), blink::WebSandboxFlags::None,
2393 blink::WebFrameOwnerProperties());
2390 tree2->AddFrame(root2, process_id, 23, blink::WebTreeScopeType::Document, 2394 tree2->AddFrame(root2, process_id, 23, blink::WebTreeScopeType::Document,
2391 std::string(), blink::WebSandboxFlags::None); 2395 std::string(), blink::WebSandboxFlags::None,
2396 blink::WebFrameOwnerProperties());
2392 2397
2393 scoped_ptr<TestWebContents> tab3( 2398 scoped_ptr<TestWebContents> tab3(
2394 TestWebContents::Create(browser_context(), nullptr)); 2399 TestWebContents::Create(browser_context(), nullptr));
2395 FrameTree* tree3 = tab3->GetFrameTree(); 2400 FrameTree* tree3 = tab3->GetFrameTree();
2396 FrameTreeNode* root3 = tree3->root(); 2401 FrameTreeNode* root3 = tree3->root();
2397 2402
2398 scoped_ptr<TestWebContents> tab4( 2403 scoped_ptr<TestWebContents> tab4(
2399 TestWebContents::Create(browser_context(), nullptr)); 2404 TestWebContents::Create(browser_context(), nullptr));
2400 FrameTree* tree4 = tab4->GetFrameTree(); 2405 FrameTree* tree4 = tab4->GetFrameTree();
2401 FrameTreeNode* root4 = tree4->root(); 2406 FrameTreeNode* root4 = tree4->root();
2402 process_id = root4->current_frame_host()->GetProcess()->GetID(); 2407 process_id = root4->current_frame_host()->GetProcess()->GetID();
2403 tree4->AddFrame(root4, process_id, 42, blink::WebTreeScopeType::Document, 2408 tree4->AddFrame(root4, process_id, 42, blink::WebTreeScopeType::Document,
2404 std::string(), blink::WebSandboxFlags::None); 2409 std::string(), blink::WebSandboxFlags::None,
2410 blink::WebFrameOwnerProperties());
2405 2411
2406 root1->child_at(1)->SetOpener(root1->child_at(1)); 2412 root1->child_at(1)->SetOpener(root1->child_at(1));
2407 root1->SetOpener(root2->child_at(1)); 2413 root1->SetOpener(root2->child_at(1));
2408 root2->SetOpener(root3); 2414 root2->SetOpener(root3);
2409 root2->child_at(0)->SetOpener(root4); 2415 root2->child_at(0)->SetOpener(root4);
2410 root2->child_at(1)->SetOpener(root4); 2416 root2->child_at(1)->SetOpener(root4);
2411 root4->child_at(0)->SetOpener(root3); 2417 root4->child_at(0)->SetOpener(root3);
2412 2418
2413 std::vector<FrameTree*> opener_frame_trees; 2419 std::vector<FrameTree*> opener_frame_trees;
2414 base::hash_set<FrameTreeNode*> nodes_with_back_links; 2420 base::hash_set<FrameTreeNode*> nodes_with_back_links;
2415 2421
2416 CollectOpenerFrameTrees(root1, &opener_frame_trees, &nodes_with_back_links); 2422 CollectOpenerFrameTrees(root1, &opener_frame_trees, &nodes_with_back_links);
2417 2423
2418 EXPECT_EQ(4U, opener_frame_trees.size()); 2424 EXPECT_EQ(4U, opener_frame_trees.size());
2419 EXPECT_EQ(tree1, opener_frame_trees[0]); 2425 EXPECT_EQ(tree1, opener_frame_trees[0]);
2420 EXPECT_EQ(tree2, opener_frame_trees[1]); 2426 EXPECT_EQ(tree2, opener_frame_trees[1]);
2421 EXPECT_EQ(tree3, opener_frame_trees[2]); 2427 EXPECT_EQ(tree3, opener_frame_trees[2]);
2422 EXPECT_EQ(tree4, opener_frame_trees[3]); 2428 EXPECT_EQ(tree4, opener_frame_trees[3]);
2423 2429
2424 EXPECT_EQ(2U, nodes_with_back_links.size()); 2430 EXPECT_EQ(2U, nodes_with_back_links.size());
2425 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) != 2431 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) !=
2426 nodes_with_back_links.end()); 2432 nodes_with_back_links.end());
2427 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) != 2433 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) !=
2428 nodes_with_back_links.end()); 2434 nodes_with_back_links.end());
2429 } 2435 }
2430 2436
2431 } // namespace content 2437 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698