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: 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 2220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 // |contents1| -- that was http://crbug.com/473714. 2231 // |contents1| -- that was http://crbug.com/473714.
2232 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); 2232 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive());
2233 contents2->NavigateAndCommit(kUrl3); 2233 contents2->NavigateAndCommit(kUrl3);
2234 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); 2234 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive());
2235 EXPECT_NE(nullptr, 2235 EXPECT_NE(nullptr,
2236 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); 2236 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance()));
2237 EXPECT_EQ(nullptr, 2237 EXPECT_EQ(nullptr,
2238 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); 2238 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance()));
2239 } 2239 }
2240 2240
2241 // Test that opener proxies are created properly with a cycle on the opener
2242 // chain.
2243 TEST_F(RenderFrameHostManagerTest, CreateOpenerProxiesWithCycleOnOpenerChain) {
2244 const GURL kUrl1("http://www.google.com/");
2245 const GURL kUrl2("http://www.chromium.org/");
2246
2247 // Navigate to an initial URL.
2248 contents()->NavigateAndCommit(kUrl1);
2249 TestRenderFrameHost* rfh1 = main_test_rfh();
2250 scoped_refptr<SiteInstanceImpl> site_instance1 = rfh1->GetSiteInstance();
2251
2252 // Create 2 new tabs and construct the opener chain as follows:
2253 //
2254 // tab2 <--- tab1 <---- contents()
2255 // | ^
2256 // +-------+
2257 //
2258 scoped_ptr<TestWebContents> tab1(
2259 TestWebContents::Create(browser_context(), site_instance1.get()));
2260 RenderFrameHostManager* tab1_manager = tab1->GetRenderManagerForTesting();
2261 scoped_ptr<TestWebContents> tab2(
2262 TestWebContents::Create(browser_context(), site_instance1.get()));
2263 RenderFrameHostManager* tab2_manager = tab2->GetRenderManagerForTesting();
2264
2265 contents()->SetOpener(tab1.get());
2266 tab1->SetOpener(tab2.get());
2267 tab2->SetOpener(tab1.get());
2268
2269 // Navigate main window to a cross-site URL. This will call
2270 // CreateOpenerProxies() to create proxies for the two opener tabs in the new
2271 // SiteInstance.
2272 contents()->NavigateAndCommit(kUrl2);
2273 TestRenderFrameHost* rfh2 = main_test_rfh();
2274 EXPECT_NE(site_instance1, rfh2->GetSiteInstance());
2275
2276 // Check that each tab now has a proxy in the new SiteInstance.
2277 RenderFrameProxyHost* tab1_proxy =
2278 tab1_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance());
2279 EXPECT_TRUE(tab1_proxy);
2280 RenderFrameProxyHost* tab2_proxy =
2281 tab2_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance());
2282 EXPECT_TRUE(tab2_proxy);
2283
2284 // Verify that the proxies' openers point to each other.
2285 int tab1_opener_routing_id =
2286 tab1_manager->GetOpenerRoutingID(rfh2->GetSiteInstance());
2287 int tab2_opener_routing_id =
2288 tab2_manager->GetOpenerRoutingID(rfh2->GetSiteInstance());
2289 EXPECT_EQ(tab2_proxy->GetRoutingID(), tab1_opener_routing_id);
2290 EXPECT_EQ(tab1_proxy->GetRoutingID(), tab2_opener_routing_id);
2291
2292 // TODO(alexmos): Because of the cycle, tab2 will require a separate opener
2293 // update IPC. Verify that this IPC is sent once it's implemented.
2294 }
2295
2296 // Test that opener proxies are created properly when the opener points
2297 // to itself.
2298 TEST_F(RenderFrameHostManagerTest, CreateOpenerProxiesWhenOpenerPointsToSelf) {
2299 const GURL kUrl1("http://www.google.com/");
2300 const GURL kUrl2("http://www.chromium.org/");
2301
2302 // Navigate to an initial URL.
2303 contents()->NavigateAndCommit(kUrl1);
2304 TestRenderFrameHost* rfh1 = main_test_rfh();
2305 scoped_refptr<SiteInstanceImpl> site_instance1 = rfh1->GetSiteInstance();
2306
2307 // Create an opener tab, and simulate that its opener points to itself.
Charlie Reis 2015/08/05 23:59:10 Sigh, the things the web platform can do...
alexmos 2015/08/06 17:05:40 Acknowledged. :)
2308 scoped_ptr<TestWebContents> opener(
2309 TestWebContents::Create(browser_context(), site_instance1.get()));
2310 RenderFrameHostManager* opener_manager = opener->GetRenderManagerForTesting();
2311 contents()->SetOpener(opener.get());
2312 opener->SetOpener(opener.get());
2313
2314 // Navigate main window to a cross-site URL. This will call
2315 // CreateOpenerProxies() to create proxies for the opener tab in the new
2316 // SiteInstance.
2317 contents()->NavigateAndCommit(kUrl2);
2318 TestRenderFrameHost* rfh2 = main_test_rfh();
2319 EXPECT_NE(site_instance1, rfh2->GetSiteInstance());
2320
2321 // Check that the opener now has a proxy in the new SiteInstance.
2322 RenderFrameProxyHost* opener_proxy =
2323 opener_manager->GetRenderFrameProxyHost(rfh2->GetSiteInstance());
2324 EXPECT_TRUE(opener_proxy);
2325
2326 // Verify that the proxy' opener points to itself.
Charlie Reis 2015/08/05 23:59:10 nit: proxy's
alexmos 2015/08/06 17:05:39 Done.
2327 int opener_routing_id =
2328 opener_manager->GetOpenerRoutingID(rfh2->GetSiteInstance());
2329 EXPECT_EQ(opener_proxy->GetRoutingID(), opener_routing_id);
2330
2331 // TODO(alexmos): Because of the cycle, setting the opener in opener_proxy
2332 // will require a separate opener update IPC. Verify that this IPC is sent
2333 // once it's implemented.
2334 }
2335
2336 // Build the following frame opener graph and see that it can be properly
2337 // traversed when creating opener proxies:
2338 //
2339 // +-> root4 <--+ root3 <---- root2 +--- root1
2340 // | / | ^ / \ | / \ .
2341 // | 42 +-----|------- 22 23 <--+ 12 13
2342 // | +------------+ | | ^
2343 // +-------------------------------+ +-+
2344 //
2345 // The test starts traversing openers from root1 and expects to discover all
2346 // four FrameTrees. Nodes 13 (with cycle to itself) and 42 (with back link to
2347 // root3) should be put on the list of nodes that will need their frame openers
2348 // set separately in a second pass, since their opener routing IDs won't be
2349 // available during the first pass of CreateOpenerProxies.
Charlie Reis 2015/08/05 23:59:10 Wow, this is a well-constructed test case, and it'
2350 TEST_F(RenderFrameHostManagerTest, TraverseComplexOpenerChain) {
2351 FrameTree* tree1 = contents()->GetFrameTree();
2352 FrameTreeNode* root1 = tree1->root();
2353 int process_id = root1->current_frame_host()->GetProcess()->GetID();
2354 tree1->AddFrame(root1, process_id, 12, blink::WebTreeScopeType::Document,
2355 std::string(), blink::WebSandboxFlags::None);
2356 tree1->AddFrame(root1, process_id, 13, blink::WebTreeScopeType::Document,
2357 std::string(), blink::WebSandboxFlags::None);
2358
2359 scoped_ptr<TestWebContents> tab2(
2360 TestWebContents::Create(browser_context(), nullptr));
2361 FrameTree* tree2 = tab2->GetFrameTree();
2362 FrameTreeNode* root2 = tree2->root();
2363 process_id = root2->current_frame_host()->GetProcess()->GetID();
2364 tree2->AddFrame(root2, process_id, 22, blink::WebTreeScopeType::Document,
2365 std::string(), blink::WebSandboxFlags::None);
2366 tree2->AddFrame(root2, process_id, 23, blink::WebTreeScopeType::Document,
2367 std::string(), blink::WebSandboxFlags::None);
2368
2369 scoped_ptr<TestWebContents> tab3(
2370 TestWebContents::Create(browser_context(), nullptr));
2371 FrameTree* tree3 = tab3->GetFrameTree();
2372 FrameTreeNode* root3 = tree3->root();
2373
2374 scoped_ptr<TestWebContents> tab4(
2375 TestWebContents::Create(browser_context(), nullptr));
2376 FrameTree* tree4 = tab4->GetFrameTree();
2377 FrameTreeNode* root4 = tree4->root();
2378 process_id = root4->current_frame_host()->GetProcess()->GetID();
2379 tree4->AddFrame(root4, process_id, 42, blink::WebTreeScopeType::Document,
2380 std::string(), blink::WebSandboxFlags::None);
2381
2382 root1->child_at(1)->SetOpener(root1->child_at(1));
2383 root1->SetOpener(root2->child_at(1));
2384 root2->SetOpener(root3);
2385 root2->child_at(0)->SetOpener(root4);
2386 root2->child_at(1)->SetOpener(root4);
2387 root4->child_at(0)->SetOpener(root3);
2388
2389 std::vector<FrameTree*> opener_frame_trees;
2390 base::hash_set<FrameTreeNode*> nodes_with_back_links;
2391
2392 root1->render_manager()->CollectOpenerFrameTrees(&opener_frame_trees,
2393 &nodes_with_back_links);
2394
2395 EXPECT_EQ(4U, opener_frame_trees.size());
2396 EXPECT_EQ(tree1, opener_frame_trees[0]);
2397 EXPECT_EQ(tree2, opener_frame_trees[1]);
2398 EXPECT_EQ(tree3, opener_frame_trees[2]);
2399 EXPECT_EQ(tree4, opener_frame_trees[3]);
2400
2401 EXPECT_EQ(2U, nodes_with_back_links.size());
2402 EXPECT_TRUE(nodes_with_back_links.find(root1->child_at(1)) !=
2403 nodes_with_back_links.end());
2404 EXPECT_TRUE(nodes_with_back_links.find(root4->child_at(0)) !=
2405 nodes_with_back_links.end());
2406 }
2407
2241 } // namespace content 2408 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698