OLD | NEW |
---|---|
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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
716 FrameNavigateParamsCapturer capturer(root); | 716 FrameNavigateParamsCapturer capturer(root); |
717 GURL frame_url(embedded_test_server()->GetURL( | 717 GURL frame_url(embedded_test_server()->GetURL( |
718 "/navigation_controller/simple_page_1.html")); | 718 "/navigation_controller/simple_page_1.html")); |
719 std::string script = "location.replace('" + frame_url.spec() + "')"; | 719 std::string script = "location.replace('" + frame_url.spec() + "')"; |
720 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 720 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
721 capturer.Wait(); | 721 capturer.Wait(); |
722 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 722 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
723 capturer.params().transition); | 723 capturer.params().transition); |
724 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 724 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
725 } | 725 } |
726 | |
727 { | |
728 // Cross-site location.replace(). | |
729 FrameNavigateParamsCapturer capturer(root); | |
730 GURL frame_url(embedded_test_server()->GetURL( | |
731 "foo.com", "/navigation_controller/simple_page_1.html")); | |
732 std::string script = "location.replace('" + frame_url.spec() + "')"; | |
733 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
734 capturer.Wait(); | |
735 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | |
736 capturer.params().transition); | |
737 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
Charlie Reis
2015/07/09 17:40:11
We were treating this as NEW_PAGE before, with |re
Avi (use Gerrit)
2015/07/09 19:05:53
Acknowledged. It's nice that it classifies just li
| |
738 } | |
726 } | 739 } |
727 | 740 |
728 // Verify that navigations for NAVIGATION_TYPE_SAME_PAGE are correctly | 741 // Verify that navigations for NAVIGATION_TYPE_SAME_PAGE are correctly |
729 // classified. | 742 // classified. |
730 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 743 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
731 NavigationTypeClassification_SamePage) { | 744 NavigationTypeClassification_SamePage) { |
732 GURL url1(embedded_test_server()->GetURL( | 745 GURL url1(embedded_test_server()->GetURL( |
733 "/navigation_controller/simple_page_1.html")); | 746 "/navigation_controller/simple_page_1.html")); |
734 NavigateToURL(shell(), url1); | 747 NavigateToURL(shell(), url1); |
735 | 748 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 GURL frame_url(embedded_test_server()->GetURL( | 951 GURL frame_url(embedded_test_server()->GetURL( |
939 "/navigation_controller/simple_page_2.html")); | 952 "/navigation_controller/simple_page_2.html")); |
940 std::string script = "location.replace('" + frame_url.spec() + "')"; | 953 std::string script = "location.replace('" + frame_url.spec() + "')"; |
941 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 954 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
942 script)); | 955 script)); |
943 capturer.Wait(); | 956 capturer.Wait(); |
944 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 957 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
945 } | 958 } |
946 | 959 |
947 { | 960 { |
961 // Cross-site location.replace(). | |
962 LoadCommittedCapturer capturer(root->child_at(0)); | |
963 GURL frame_url(embedded_test_server()->GetURL( | |
964 "foo.com", "/navigation_controller/simple_page_2.html")); | |
965 std::string script = "location.replace('" + frame_url.spec() + "')"; | |
966 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | |
967 script)); | |
968 capturer.Wait(); | |
969 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
Charlie Reis
2015/07/09 17:40:11
We were treating this as NEW_SUBFRAME, which didn'
Avi (use Gerrit)
2015/07/09 19:05:53
Same as above; it's nice to see that this classifi
| |
970 } | |
971 | |
972 { | |
948 // history.pushState(). | 973 // history.pushState(). |
949 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 974 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
950 std::string script = | 975 std::string script = |
951 "history.pushState({}, 'page 1', 'simple_page_1.html')"; | 976 "history.pushState({}, 'page 1', 'simple_page_1.html')"; |
952 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 977 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
953 script)); | 978 script)); |
954 capturer.Wait(); | 979 capturer.Wait(); |
955 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 980 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
956 capturer.params().transition); | 981 capturer.params().transition); |
957 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 982 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1354 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1379 ASSERT_EQ(2U, entry->root_node()->children.size()); |
1355 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); | 1380 ASSERT_EQ(1U, entry->root_node()->children[1]->children.size()); |
1356 FrameNavigationEntry* frame_entry = | 1381 FrameNavigationEntry* frame_entry = |
1357 entry->root_node()->children[1]->children[0]->frame_entry.get(); | 1382 entry->root_node()->children[1]->children[0]->frame_entry.get(); |
1358 EXPECT_EQ(foo_url, frame_entry->url()); | 1383 EXPECT_EQ(foo_url, frame_entry->url()); |
1359 } else { | 1384 } else { |
1360 // There are no subframe FrameNavigationEntries by default. | 1385 // There are no subframe FrameNavigationEntries by default. |
1361 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1386 EXPECT_EQ(0U, entry->root_node()->children.size()); |
1362 } | 1387 } |
1363 | 1388 |
1364 // TODO(creis): Add tests for another subframe on B, and for a subframe on A | 1389 // 4. Create a third iframe on the same site as the second. This ensures that |
1365 // within it. Both are currently broken. | 1390 // the commit type is correct even when the subframe process already exists. |
1391 { | |
1392 LoadCommittedCapturer capturer(shell()->web_contents()); | |
1393 std::string script = "var iframe = document.createElement('iframe');" | |
1394 "iframe.src = '" + foo_url.spec() + "';" | |
1395 "document.body.appendChild(iframe);"; | |
1396 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
1397 capturer.Wait(); | |
1398 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
1399 } | |
1400 | |
1401 // The last committed NavigationEntry shouldn't have changed. | |
1402 EXPECT_EQ(1, controller.GetEntryCount()); | |
1403 entry = controller.GetLastCommittedEntry(); | |
1404 EXPECT_EQ(main_url, entry->GetURL()); | |
1405 root_entry = entry->root_node()->frame_entry.get(); | |
1406 EXPECT_EQ(main_url, root_entry->url()); | |
1407 | |
1408 // Verify subframe entries if we're in --site-per-process mode. | |
1409 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1410 switches::kSitePerProcess)) { | |
1411 // The entry should now have 3 subframe FrameNavigationEntries. | |
1412 ASSERT_EQ(3U, entry->root_node()->children.size()); | |
1413 FrameNavigationEntry* frame_entry = | |
1414 entry->root_node()->children[2]->frame_entry.get(); | |
1415 EXPECT_EQ(foo_url, frame_entry->url()); | |
1416 } else { | |
1417 // There are no subframe FrameNavigationEntries by default. | |
1418 EXPECT_EQ(0U, entry->root_node()->children.size()); | |
1419 } | |
1420 | |
1421 // 5. Create a nested iframe on the original site (A-B-A). | |
1422 { | |
1423 LoadCommittedCapturer capturer(shell()->web_contents()); | |
1424 std::string script = "var iframe = document.createElement('iframe');" | |
1425 "iframe.src = '" + frame_url.spec() + "';" | |
1426 "document.body.appendChild(iframe);"; | |
1427 FrameTreeNode* child = root->child_at(2); | |
1428 EXPECT_TRUE(content::ExecuteScript(child->current_frame_host(), script)); | |
1429 capturer.Wait(); | |
1430 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
1431 } | |
1432 | |
1433 // The last committed NavigationEntry shouldn't have changed. | |
1434 EXPECT_EQ(1, controller.GetEntryCount()); | |
1435 entry = controller.GetLastCommittedEntry(); | |
1436 EXPECT_EQ(main_url, entry->GetURL()); | |
1437 root_entry = entry->root_node()->frame_entry.get(); | |
1438 EXPECT_EQ(main_url, root_entry->url()); | |
1439 | |
1440 // Verify subframe entries if we're in --site-per-process mode. | |
1441 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1442 switches::kSitePerProcess)) { | |
1443 // There should be a corresponding FrameNavigationEntry. | |
1444 ASSERT_EQ(1U, entry->root_node()->children[2]->children.size()); | |
1445 FrameNavigationEntry* frame_entry = | |
1446 entry->root_node()->children[2]->children[0]->frame_entry.get(); | |
1447 EXPECT_EQ(frame_url, frame_entry->url()); | |
1448 } else { | |
1449 // There are no subframe FrameNavigationEntries by default. | |
1450 EXPECT_EQ(0U, entry->root_node()->children.size()); | |
1451 } | |
1366 | 1452 |
1367 // Check the end result of the frame tree. | 1453 // Check the end result of the frame tree. |
1368 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1454 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1369 switches::kSitePerProcess)) { | 1455 switches::kSitePerProcess)) { |
1370 FrameTreeVisualizer visualizer; | 1456 FrameTreeVisualizer visualizer; |
1371 EXPECT_EQ( | 1457 EXPECT_EQ( |
1372 " Site A ------------ proxies for B\n" | 1458 " Site A ------------ proxies for B\n" |
1373 " |--Site A ------- proxies for B\n" | 1459 " |--Site A ------- proxies for B\n" |
1460 " |--Site B ------- proxies for A\n" | |
1461 " | +--Site B -- proxies for A\n" | |
1374 " +--Site B ------- proxies for A\n" | 1462 " +--Site B ------- proxies for A\n" |
1375 " +--Site B -- proxies for A\n" | 1463 " +--Site A -- proxies for B\n" |
1376 "Where A = http://127.0.0.1/\n" | 1464 "Where A = http://127.0.0.1/\n" |
1377 " B = http://foo.com/", | 1465 " B = http://foo.com/", |
1378 visualizer.DepictFrameTree(root)); | 1466 visualizer.DepictFrameTree(root)); |
1379 } | 1467 } |
1380 } | 1468 } |
1381 | 1469 |
1382 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME | 1470 // Verify the tree of FrameNavigationEntries after NAVIGATION_TYPE_NEW_SUBFRAME |
1383 // commits. | 1471 // commits. |
1384 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1472 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
1385 FrameNavigationEntry_NewSubframe) { | 1473 FrameNavigationEntry_NewSubframe) { |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2119 // tricky. | 2207 // tricky. |
2120 EXPECT_EQ(nullptr, controller.GetPendingEntry()); | 2208 EXPECT_EQ(nullptr, controller.GetPendingEntry()); |
2121 shell()->web_contents()->Stop(); | 2209 shell()->web_contents()->Stop(); |
2122 watcher.Wait(); | 2210 watcher.Wait(); |
2123 } | 2211 } |
2124 | 2212 |
2125 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 2213 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
2126 } | 2214 } |
2127 | 2215 |
2128 } // namespace content | 2216 } // namespace content |
OLD | NEW |