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

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

Powered by Google App Engine
This is Rietveld 408576698