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

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

Issue 1143653002: Create FrameNavigationEntries for manual subframe navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "content/browser/frame_host/frame_navigation_entry.h" 8 #include "content/browser/frame_host/frame_navigation_entry.h"
9 #include "content/browser/frame_host/frame_tree.h" 9 #include "content/browser/frame_host/frame_tree.h"
10 #include "content/browser/frame_host/navigation_controller_impl.h" 10 #include "content/browser/frame_host/navigation_controller_impl.h"
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 capturer.Wait(); 807 capturer.Wait();
808 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FORWARD_BACK, 808 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_FORWARD_BACK,
809 capturer.params().transition); 809 capturer.params().transition);
810 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type); 810 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, capturer.details().type);
811 EXPECT_TRUE(capturer.details().is_in_page); 811 EXPECT_TRUE(capturer.details().is_in_page);
812 } 812 }
813 } 813 }
814 814
815 // Verify that navigations for NAVIGATION_TYPE_NEW_SUBFRAME and 815 // Verify that navigations for NAVIGATION_TYPE_NEW_SUBFRAME and
816 // NAVIGATION_TYPE_AUTO_SUBFRAME are properly classified. 816 // NAVIGATION_TYPE_AUTO_SUBFRAME are properly classified.
817 // TODO(creis): Re-enable this test when https://crbug.com/498559 is fixed. 817 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
818 IN_PROC_BROWSER_TEST_F( 818 NavigationTypeClassification_NewAndAutoSubframe) {
819 NavigationControllerBrowserTest,
820 DISABLED_NavigationTypeClassification_NewAndAutoSubframe) {
821 GURL main_url(embedded_test_server()->GetURL( 819 GURL main_url(embedded_test_server()->GetURL(
822 "/navigation_controller/page_with_iframe.html")); 820 "/navigation_controller/page_with_iframe.html"));
823 NavigateToURL(shell(), main_url); 821 NavigateToURL(shell(), main_url);
824 822
825 // It is safe to obtain the root frame tree node here, as it doesn't change. 823 // It is safe to obtain the root frame tree node here, as it doesn't change.
826 FrameTreeNode* root = 824 FrameTreeNode* root =
827 static_cast<WebContentsImpl*>(shell()->web_contents())-> 825 static_cast<WebContentsImpl*>(shell()->web_contents())->
828 GetFrameTree()->root(); 826 GetFrameTree()->root();
829 827
830 ASSERT_EQ(1U, root->child_count()); 828 ASSERT_EQ(1U, root->child_count());
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 } 1340 }
1343 } 1341 }
1344 1342
1345 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME 1343 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME
1346 // commits. 1344 // commits.
1347 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 1345 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
1348 FrameNavigationEntry_NewSubframe) { 1346 FrameNavigationEntry_NewSubframe) {
1349 GURL main_url(embedded_test_server()->GetURL( 1347 GURL main_url(embedded_test_server()->GetURL(
1350 "/navigation_controller/simple_page_1.html")); 1348 "/navigation_controller/simple_page_1.html"));
1351 NavigateToURL(shell(), main_url); 1349 NavigateToURL(shell(), main_url);
1350 const NavigationControllerImpl& controller =
1351 static_cast<const NavigationControllerImpl&>(
1352 shell()->web_contents()->GetController());
1352 FrameTreeNode* root = 1353 FrameTreeNode* root =
1353 static_cast<WebContentsImpl*>(shell()->web_contents())-> 1354 static_cast<WebContentsImpl*>(shell()->web_contents())->
1354 GetFrameTree()->root(); 1355 GetFrameTree()->root();
1355 1356
1356 // 1. Create a same-site iframe. 1357 // 1. Create a same-site iframe.
1357 GURL frame_url(embedded_test_server()->GetURL( 1358 GURL frame_url(embedded_test_server()->GetURL(
1358 "/navigation_controller/simple_page_2.html")); 1359 "/navigation_controller/simple_page_2.html"));
1359 { 1360 {
1360 LoadCommittedCapturer capturer(shell()->web_contents()); 1361 LoadCommittedCapturer capturer(shell()->web_contents());
1361 std::string script = "var iframe = document.createElement('iframe');" 1362 std::string script = "var iframe = document.createElement('iframe');"
1362 "iframe.src = '" + frame_url.spec() + "';" 1363 "iframe.src = '" + frame_url.spec() + "';"
1363 "document.body.appendChild(iframe);"; 1364 "document.body.appendChild(iframe);";
1364 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 1365 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
1365 capturer.Wait(); 1366 capturer.Wait();
1366 } 1367 }
1368 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
1367 1369
1368 // 2. Navigate in the first subframe same-site. 1370 // 2. Navigate in the subframe same-site.
1369 GURL frame_url2(embedded_test_server()->GetURL( 1371 GURL frame_url2(embedded_test_server()->GetURL(
1370 "/navigation_controller/page_with_links.html")); 1372 "/navigation_controller/page_with_links.html"));
1371 { 1373 {
1372 FrameNavigateParamsCapturer capturer(root->child_at(0)); 1374 FrameNavigateParamsCapturer capturer(root->child_at(0));
1373 NavigateFrameToURL(root->child_at(0), frame_url2); 1375 NavigateFrameToURL(root->child_at(0), frame_url2);
1374 capturer.Wait(); 1376 capturer.Wait();
1375 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, 1377 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
1376 capturer.params().transition); 1378 capturer.params().transition);
1377 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); 1379 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
1378 } 1380 }
1379 1381
1382 // We should have created a new NavigationEntry with the same main frame URL.
1383 EXPECT_EQ(2, controller.GetEntryCount());
1384 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
1385 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry();
1386 EXPECT_NE(entry, entry2);
1387 EXPECT_EQ(main_url, entry2->GetURL());
1388 FrameNavigationEntry* root_entry2 = entry2->root_node()->frame_entry.get();
1389 EXPECT_EQ(main_url, root_entry2->url());
1390
1391 // Verify subframe entries if we're in --site-per-process mode.
1392 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1393 switches::kSitePerProcess)) {
1394 // The entry should have a new FrameNavigationEntries for the subframe.
1395 ASSERT_EQ(1U, entry2->root_node()->children.size());
1396 EXPECT_EQ(frame_url2, entry2->root_node()->children[0]->frame_entry->url());
1397 } else {
1398 // There are no subframe FrameNavigationEntries by default.
1399 EXPECT_EQ(0U, entry2->root_node()->children.size());
1400 }
1401
1380 // 3. Create a second, initially cross-site iframe. 1402 // 3. Create a second, initially cross-site iframe.
1381 GURL foo_url(embedded_test_server()->GetURL( 1403 GURL foo_url(embedded_test_server()->GetURL(
1382 "foo.com", "/navigation_controller/simple_page_1.html")); 1404 "foo.com", "/navigation_controller/simple_page_1.html"));
1383 { 1405 {
1384 LoadCommittedCapturer capturer(shell()->web_contents()); 1406 LoadCommittedCapturer capturer(shell()->web_contents());
1385 std::string script = "var iframe = document.createElement('iframe');" 1407 std::string script = "var iframe = document.createElement('iframe');"
1386 "iframe.src = '" + foo_url.spec() + "';" 1408 "iframe.src = '" + foo_url.spec() + "';"
1387 "document.body.appendChild(iframe);"; 1409 "document.body.appendChild(iframe);";
1388 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 1410 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
1389 capturer.Wait(); 1411 capturer.Wait();
1390 } 1412 }
1391 1413
1392 // 4. Navigate in the second subframe cross-site. 1414 // 4. Create a nested same-site iframe in the second subframe, wait for it to
1415 // commit, then navigate it again.
1416 {
1417 LoadCommittedCapturer capturer(shell()->web_contents());
1418 std::string script = "var iframe = document.createElement('iframe');"
1419 "iframe.src = '" + foo_url.spec() + "';"
1420 "document.body.appendChild(iframe);";
1421 EXPECT_TRUE(content::ExecuteScript(root->child_at(1)->current_frame_host(),
1422 script));
1423 capturer.Wait();
1424 }
1393 GURL bar_url(embedded_test_server()->GetURL( 1425 GURL bar_url(embedded_test_server()->GetURL(
1394 "bar.com", "/navigation_controller/simple_page_1.html")); 1426 "bar.com", "/navigation_controller/simple_page_1.html"));
1395 { 1427 {
1428 FrameNavigateParamsCapturer capturer(root->child_at(1)->child_at(0));
1429 NavigateFrameToURL(root->child_at(1)->child_at(0), bar_url);
1430 capturer.Wait();
1431 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
1432 capturer.params().transition);
1433 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
1434 }
1435
1436 // We should have created a new NavigationEntry with the same main frame URL.
1437 EXPECT_EQ(3, controller.GetEntryCount());
1438 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
1439 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry();
1440 EXPECT_NE(entry, entry3);
1441 EXPECT_EQ(main_url, entry3->GetURL());
1442 FrameNavigationEntry* root_entry3 = entry3->root_node()->frame_entry.get();
1443 EXPECT_EQ(main_url, root_entry3->url());
1444
1445 // Verify subframe entries if we're in --site-per-process mode.
1446 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1447 switches::kSitePerProcess)) {
1448 // The entry should still have FrameNavigationEntries for all 3 subframes.
1449 ASSERT_EQ(2U, entry3->root_node()->children.size());
1450 EXPECT_EQ(frame_url2, entry3->root_node()->children[0]->frame_entry->url());
1451 EXPECT_EQ(foo_url, entry3->root_node()->children[1]->frame_entry->url());
1452 ASSERT_EQ(1U, entry3->root_node()->children[1]->children.size());
1453 EXPECT_EQ(
1454 bar_url,
1455 entry3->root_node()->children[1]->children[0]->frame_entry->url());
1456 } else {
1457 // There are no subframe FrameNavigationEntries by default.
1458 EXPECT_EQ(0U, entry3->root_node()->children.size());
1459 }
1460
1461 // 6. Navigate the second subframe cross-site, clearing its existing subtree.
1462 GURL baz_url(embedded_test_server()->GetURL(
1463 "baz.com", "/navigation_controller/simple_page_1.html"));
1464 {
1396 FrameNavigateParamsCapturer capturer(root->child_at(1)); 1465 FrameNavigateParamsCapturer capturer(root->child_at(1));
1397 std::string script = "var frames = document.getElementsByTagName('iframe');" 1466 std::string script = "var frames = document.getElementsByTagName('iframe');"
1398 "frames[1].src = '" + bar_url.spec() + "';"; 1467 "frames[1].src = '" + baz_url.spec() + "';";
1399 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); 1468 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script));
1400 capturer.Wait(); 1469 capturer.Wait();
1401 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, 1470 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
1402 capturer.params().transition); 1471 capturer.params().transition);
1403 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); 1472 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type);
1404 } 1473 }
1405 1474
1406 // TODO(creis): Expand this test once we clone FrameNavigationEntries for 1475 // We should have created a new NavigationEntry with the same main frame URL.
1407 // NEW_SUBFRAME navigations. 1476 EXPECT_EQ(4, controller.GetEntryCount());
1477 EXPECT_EQ(3, controller.GetLastCommittedEntryIndex());
1478 NavigationEntryImpl* entry4 = controller.GetLastCommittedEntry();
1479 EXPECT_NE(entry, entry4);
1480 EXPECT_EQ(main_url, entry4->GetURL());
1481 FrameNavigationEntry* root_entry4 = entry4->root_node()->frame_entry.get();
1482 EXPECT_EQ(main_url, root_entry4->url());
1483
1484 // Verify subframe entries if we're in --site-per-process mode.
1485 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1486 switches::kSitePerProcess)) {
1487 // The entry should still have FrameNavigationEntries for all 3 subframes.
1488 ASSERT_EQ(2U, entry4->root_node()->children.size());
1489 EXPECT_EQ(frame_url2, entry4->root_node()->children[0]->frame_entry->url());
1490 EXPECT_EQ(baz_url, entry4->root_node()->children[1]->frame_entry->url());
1491 ASSERT_EQ(0U, entry4->root_node()->children[1]->children.size());
1492 } else {
1493 // There are no subframe FrameNavigationEntries by default.
1494 EXPECT_EQ(0U, entry4->root_node()->children.size());
1495 }
1408 1496
1409 // Check the end result of the frame tree. 1497 // Check the end result of the frame tree.
1410 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1498 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1411 switches::kSitePerProcess)) { 1499 switches::kSitePerProcess)) {
1412 FrameTreeVisualizer visualizer; 1500 FrameTreeVisualizer visualizer;
1413 EXPECT_EQ( 1501 EXPECT_EQ(
1414 " Site A ------------ proxies for B\n" 1502 " Site A ------------ proxies for B\n"
1415 " |--Site A ------- proxies for B\n" 1503 " |--Site A ------- proxies for B\n"
1416 " +--Site B ------- proxies for A\n" 1504 " +--Site B ------- proxies for A\n"
1417 "Where A = http://127.0.0.1/\n" 1505 "Where A = http://127.0.0.1/\n"
1418 " B = http://bar.com/", 1506 " B = http://baz.com/",
1419 visualizer.DepictFrameTree(root)); 1507 visualizer.DepictFrameTree(root));
1420 } 1508 }
1421 } 1509 }
1422 1510
1423 namespace { 1511 namespace {
1424 1512
1425 class HttpThrottle : public ResourceThrottle { 1513 class HttpThrottle : public ResourceThrottle {
1426 public: 1514 public:
1427 // ResourceThrottle 1515 // ResourceThrottle
1428 void WillStartRequest(bool* defer) override { 1516 void WillStartRequest(bool* defer) override {
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 // tricky. 1855 // tricky.
1768 EXPECT_EQ(nullptr, controller.GetPendingEntry()); 1856 EXPECT_EQ(nullptr, controller.GetPendingEntry());
1769 shell()->web_contents()->Stop(); 1857 shell()->web_contents()->Stop();
1770 watcher.Wait(); 1858 watcher.Wait();
1771 } 1859 }
1772 1860
1773 ResourceDispatcherHost::Get()->SetDelegate(nullptr); 1861 ResourceDispatcherHost::Get()->SetDelegate(nullptr);
1774 } 1862 }
1775 1863
1776 } // namespace content 1864 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698