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

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

Issue 1268153002: Refactor CreateOpenerProxies to support updates to frame openers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Charlie's comments Created 5 years, 4 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // PlzNavigate: returns the speculative RenderFrameHost. 415 // PlzNavigate: returns the speculative RenderFrameHost.
416 RenderFrameHostImpl* GetPendingFrameHost( 416 RenderFrameHostImpl* GetPendingFrameHost(
417 RenderFrameHostManager* manager) { 417 RenderFrameHostManager* manager) {
418 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 418 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
419 switches::kEnableBrowserSideNavigation)) { 419 switches::kEnableBrowserSideNavigation)) {
420 return manager->speculative_render_frame_host_.get(); 420 return manager->speculative_render_frame_host_.get();
421 } 421 }
422 return manager->pending_frame_host(); 422 return manager->pending_frame_host();
423 } 423 }
424 424
425 // Traverse the opener chain and populate |opener_frame_trees| with all
426 // FrameTrees accessible by following frame openers of nodes in the given
427 // |node|'s FrameTree. Also collect nodes with openers in FrameTrees
428 // that have already been traversed (such as when there's a cycle) in
429 // |nodes_with_back_links|.
Charlie Reis 2015/08/06 17:35:06 It'd be ok to just say "Exposes CollectOpenerFrame
alexmos 2015/08/06 17:42:57 Done.
430 void CollectOpenerFrameTrees(
431 FrameTreeNode* node,
432 std::vector<FrameTree*>* opener_frame_trees,
433 base::hash_set<FrameTreeNode*>* nodes_with_back_links) {
434 node->render_manager()->CollectOpenerFrameTrees(opener_frame_trees,
435 nodes_with_back_links);
436 }
437
425 private: 438 private:
426 RenderFrameHostManagerTestWebUIControllerFactory factory_; 439 RenderFrameHostManagerTestWebUIControllerFactory factory_;
427 }; 440 };
428 441
429 // Tests that when you navigate from a chrome:// url to another page, and 442 // Tests that when you navigate from a chrome:// url to another page, and
430 // then do that same thing in another tab, that the two resulting pages have 443 // then do that same thing in another tab, that the two resulting pages have
431 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 444 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
432 // a regression test for bug 9364. 445 // a regression test for bug 9364.
433 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { 446 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) {
434 set_should_create_webui(true); 447 set_should_create_webui(true);
(...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 // |contents1| -- that was http://crbug.com/473714. 2244 // |contents1| -- that was http://crbug.com/473714.
2232 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); 2245 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive());
2233 contents2->NavigateAndCommit(kUrl3); 2246 contents2->NavigateAndCommit(kUrl3);
2234 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); 2247 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive());
2235 EXPECT_NE(nullptr, 2248 EXPECT_NE(nullptr,
2236 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); 2249 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance()));
2237 EXPECT_EQ(nullptr, 2250 EXPECT_EQ(nullptr,
2238 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); 2251 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance()));
2239 } 2252 }
2240 2253
2254 // Test that opener proxies are created properly with a cycle on the opener
2255 // chain.
2256 TEST_F(RenderFrameHostManagerTest, CreateOpenerProxiesWithCycleOnOpenerChain) {
2257 const GURL kUrl1("http://www.google.com/");
2258 const GURL kUrl2("http://www.chromium.org/");
2259
2260 // Navigate to an initial URL.
2261 contents()->NavigateAndCommit(kUrl1);
2262 TestRenderFrameHost* rfh1 = main_test_rfh();
2263 scoped_refptr<SiteInstanceImpl> site_instance1 = rfh1->GetSiteInstance();
2264
2265 // Create 2 new tabs and construct the opener chain as follows:
2266 //
2267 // tab2 <--- tab1 <---- contents()
2268 // | ^
2269 // +-------+
2270 //
2271 scoped_ptr<TestWebContents> tab1(
2272 TestWebContents::Create(browser_context(), site_instance1.get()));
2273 RenderFrameHostManager* tab1_manager = tab1->GetRenderManagerForTesting();
2274 scoped_ptr<TestWebContents> tab2(
2275 TestWebContents::Create(browser_context(), site_instance1.get()));
2276 RenderFrameHostManager* tab2_manager = tab2->GetRenderManagerForTesting();
2277
2278 contents()->SetOpener(tab1.get());
2279 tab1->SetOpener(tab2.get());
2280 tab2->SetOpener(tab1.get());
2281
2282 // Navigate main window to a cross-site URL. This will call
2283 // CreateOpenerProxies() to create proxies for the two opener tabs in the new
2284 // SiteInstance.
2285 contents()->NavigateAndCommit(kUrl2);
2286 TestRenderFrameHost* rfh2 = main_test_rfh();
2287 EXPECT_NE(site_instance1, rfh2->GetSiteInstance());
2288
2289 // Check that each tab now has a proxy in the new SiteInstance.
2290 RenderFrameProxyHost* tab1_proxy =
2291 tab1_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance());
2292 EXPECT_TRUE(tab1_proxy);
2293 RenderFrameProxyHost* tab2_proxy =
2294 tab2_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance());
2295 EXPECT_TRUE(tab2_proxy);
2296
2297 // Verify that the proxies' openers point to each other.
2298 int tab1_opener_routing_id =
2299 tab1_manager->GetOpenerRoutingID(rfh2->GetSiteInstance());
2300 int tab2_opener_routing_id =
2301 tab2_manager->GetOpenerRoutingID(rfh2->GetSiteInstance());
2302 EXPECT_EQ(tab2_proxy->GetRoutingID(), tab1_opener_routing_id);
2303 EXPECT_EQ(tab1_proxy->GetRoutingID(), tab2_opener_routing_id);
2304
2305 // TODO(alexmos): Because of the cycle, tab2 will require a separate opener
2306 // update IPC. Verify that this IPC is sent once it's implemented.
2307 }
2308
2309 // Test that opener proxies are created properly when the opener points
2310 // to itself.
2311 TEST_F(RenderFrameHostManagerTest, CreateOpenerProxiesWhenOpenerPointsToSelf) {
2312 const GURL kUrl1("http://www.google.com/");
2313 const GURL kUrl2("http://www.chromium.org/");
2314
2315 // Navigate to an initial URL.
2316 contents()->NavigateAndCommit(kUrl1);
2317 TestRenderFrameHost* rfh1 = main_test_rfh();
2318 scoped_refptr<SiteInstanceImpl> site_instance1 = rfh1->GetSiteInstance();
2319
2320 // Create an opener tab, and simulate that its opener points to itself.
2321 scoped_ptr<TestWebContents> opener(
2322 TestWebContents::Create(browser_context(), site_instance1.get()));
2323 RenderFrameHostManager* opener_manager = opener->GetRenderManagerForTesting();
2324 contents()->SetOpener(opener.get());
2325 opener->SetOpener(opener.get());
2326
2327 // Navigate main window to a cross-site URL. This will call
2328 // CreateOpenerProxies() to create proxies for the opener tab in the new
2329 // SiteInstance.
2330 contents()->NavigateAndCommit(kUrl2);
2331 TestRenderFrameHost* rfh2 = main_test_rfh();
2332 EXPECT_NE(site_instance1, rfh2->GetSiteInstance());
2333
2334 // Check that the opener now has a proxy in the new SiteInstance.
2335 RenderFrameProxyHost* opener_proxy =
2336 opener_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance());
2337 EXPECT_TRUE(opener_proxy);
2338
2339 // Verify that the proxy's opener points to itself.
2340 int opener_routing_id =
2341 opener_manager->GetOpenerRoutingID(rfh2->GetSiteInstance());
2342 EXPECT_EQ(opener_proxy->GetRoutingID(), opener_routing_id);
2343
2344 // TODO(alexmos): Because of the cycle, setting the opener in opener_proxy
2345 // will require a separate opener update IPC. Verify that this IPC is sent
2346 // once it's implemented.
2347 }
2348
2349 // Build the following frame opener graph and see that it can be properly
2350 // traversed when creating opener proxies:
2351 //
2352 // +-> root4 <--+ root3 <---- root2 +--- root1
2353 // | / | ^ / \ | / \ .
2354 // | 42 +-----|------- 22 23 <--+ 12 13
2355 // | +------------+ | | ^
2356 // +-------------------------------+ +-+
2357 //
2358 // The test starts traversing openers from root1 and expects to discover all
2359 // four FrameTrees. Nodes 13 (with cycle to itself) and 42 (with back link to
2360 // root3) should be put on the list of nodes that will need their frame openers
2361 // set separately in a second pass, since their opener routing IDs won't be
2362 // available during the first pass of CreateOpenerProxies.
2363 TEST_F(RenderFrameHostManagerTest, TraverseComplexOpenerChain) {
2364 FrameTree* tree1 = contents()->GetFrameTree();
2365 FrameTreeNode* root1 = tree1->root();
2366 int process_id = root1->current_frame_host()->GetProcess()->GetID();
2367 tree1->AddFrame(root1, process_id, 12, blink::WebTreeScopeType::Document,
2368 std::string(), blink::WebSandboxFlags::None);
2369 tree1->AddFrame(root1, process_id, 13, blink::WebTreeScopeType::Document,
2370 std::string(), blink::WebSandboxFlags::None);
2371
2372 scoped_ptr<TestWebContents> tab2(
2373 TestWebContents::Create(browser_context(), nullptr));
2374 FrameTree* tree2 = tab2->GetFrameTree();
2375 FrameTreeNode* root2 = tree2->root();
2376 process_id = root2->current_frame_host()->GetProcess()->GetID();
2377 tree2->AddFrame(root2, process_id, 22, blink::WebTreeScopeType::Document,
2378 std::string(), blink::WebSandboxFlags::None);
2379 tree2->AddFrame(root2, process_id, 23, blink::WebTreeScopeType::Document,
2380 std::string(), blink::WebSandboxFlags::None);
2381
2382 scoped_ptr<TestWebContents> tab3(
2383 TestWebContents::Create(browser_context(), nullptr));
2384 FrameTree* tree3 = tab3->GetFrameTree();
2385 FrameTreeNode* root3 = tree3->root();
2386
2387 scoped_ptr<TestWebContents> tab4(
2388 TestWebContents::Create(browser_context(), nullptr));
2389 FrameTree* tree4 = tab4->GetFrameTree();
2390 FrameTreeNode* root4 = tree4->root();
2391 process_id = root4->current_frame_host()->GetProcess()->GetID();
2392 tree4->AddFrame(root4, process_id, 42, blink::WebTreeScopeType::Document,
2393 std::string(), blink::WebSandboxFlags::None);
2394
2395 root1->child_at(1)->SetOpener(root1->child_at(1));
2396 root1->SetOpener(root2->child_at(1));
2397 root2->SetOpener(root3);
2398 root2->child_at(0)->SetOpener(root4);
2399 root2->child_at(1)->SetOpener(root4);
2400 root4->child_at(0)->SetOpener(root3);
2401
2402 std::vector<FrameTree*> opener_frame_trees;
2403 base::hash_set<FrameTreeNode*> nodes_with_back_links;
2404
2405 CollectOpenerFrameTrees(root1, &opener_frame_trees, &nodes_with_back_links);
2406
2407 EXPECT_EQ(4U, opener_frame_trees.size());
2408 EXPECT_EQ(tree1, opener_frame_trees[0]);
2409 EXPECT_EQ(tree2, opener_frame_trees[1]);
2410 EXPECT_EQ(tree3, opener_frame_trees[2]);
2411 EXPECT_EQ(tree4, opener_frame_trees[3]);
2412
2413 EXPECT_EQ(2U, nodes_with_back_links.size());
2414 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) !=
2415 nodes_with_back_links.end());
2416 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) !=
2417 nodes_with_back_links.end());
2418 }
2419
2241 } // namespace content 2420 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698