| 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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 shell()->LoadDataWithBaseURL(history_url, data, base_url); | 297 shell()->LoadDataWithBaseURL(history_url, data, base_url); |
| 298 same_tab_observer.Wait(); | 298 same_tab_observer.Wait(); |
| 299 EXPECT_EQ(1, controller.GetEntryCount()); | 299 EXPECT_EQ(1, controller.GetEntryCount()); |
| 300 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | 300 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 301 EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); | 301 EXPECT_EQ(base_url, entry->GetBaseURLForDataURL()); |
| 302 EXPECT_EQ(history_url, entry->GetVirtualURL()); | 302 EXPECT_EQ(history_url, entry->GetVirtualURL()); |
| 303 EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); | 303 EXPECT_EQ(history_url, entry->GetHistoryURLForDataURL()); |
| 304 EXPECT_EQ(data_url, entry->GetURL()); | 304 EXPECT_EQ(data_url, entry->GetURL()); |
| 305 } | 305 } |
| 306 | 306 |
| 307 // TODO(boliu): Add test for in-page fragment navigation. See | 307 // TODO(boliu): Add test for same document fragment navigation. See |
| 308 // crbug.com/561034. | 308 // crbug.com/561034. |
| 309 | 309 |
| 310 // Navigate with Javascript. | 310 // Navigate with Javascript. |
| 311 { | 311 { |
| 312 GURL navigate_url = embedded_test_server()->base_url(); | 312 GURL navigate_url = embedded_test_server()->base_url(); |
| 313 std::string script = "document.location = '" + | 313 std::string script = "document.location = '" + |
| 314 navigate_url.spec() + "';"; | 314 navigate_url.spec() + "';"; |
| 315 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); | 315 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); |
| 316 EXPECT_TRUE(ExecuteScript(shell(), script)); | 316 EXPECT_TRUE(ExecuteScript(shell(), script)); |
| 317 same_tab_observer.Wait(); | 317 same_tab_observer.Wait(); |
| 318 EXPECT_EQ(2, controller.GetEntryCount()); | 318 EXPECT_EQ(2, controller.GetEntryCount()); |
| 319 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | 319 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 320 EXPECT_TRUE(entry->GetBaseURLForDataURL().is_empty()); | 320 EXPECT_TRUE(entry->GetBaseURLForDataURL().is_empty()); |
| 321 EXPECT_TRUE(entry->GetHistoryURLForDataURL().is_empty()); | 321 EXPECT_TRUE(entry->GetHistoryURLForDataURL().is_empty()); |
| 322 EXPECT_EQ(navigate_url, entry->GetVirtualURL()); | 322 EXPECT_EQ(navigate_url, entry->GetVirtualURL()); |
| 323 EXPECT_EQ(navigate_url, entry->GetURL()); | 323 EXPECT_EQ(navigate_url, entry->GetURL()); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 327 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 328 FragmentNavigateFromLoadDataWithBaseURL) { | 328 FragmentNavigateFromLoadDataWithBaseURL) { |
| 329 const GURL base_url("http://baseurl"); | 329 const GURL base_url("http://baseurl"); |
| 330 const GURL history_url("http://historyurl"); | 330 const GURL history_url("http://historyurl"); |
| 331 const std::string data = | 331 const std::string data = |
| 332 "<html><body>" | 332 "<html><body>" |
| 333 " <p id=\"frag\"><a id=\"fraglink\" href=\"#frag\">in-page nav</a></p>" | 333 " <p id=\"frag\">" |
| 334 " <a id=\"fraglink\" href=\"#frag\">same document nav</a>" |
| 335 " </p>" |
| 334 "</body></html>"; | 336 "</body></html>"; |
| 335 | 337 |
| 336 const NavigationControllerImpl& controller = | 338 const NavigationControllerImpl& controller = |
| 337 static_cast<const NavigationControllerImpl&>( | 339 static_cast<const NavigationControllerImpl&>( |
| 338 shell()->web_contents()->GetController()); | 340 shell()->web_contents()->GetController()); |
| 339 | 341 |
| 340 // Load data and commit. | 342 // Load data and commit. |
| 341 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); | 343 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); |
| 342 #if defined(OS_ANDROID) | 344 #if defined(OS_ANDROID) |
| 343 shell()->LoadDataAsStringWithBaseURL(history_url, data, base_url); | 345 shell()->LoadDataAsStringWithBaseURL(history_url, data, base_url); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 ui::PageTransition transition() { | 618 ui::PageTransition transition() { |
| 617 EXPECT_EQ(1U, transitions_.size()); | 619 EXPECT_EQ(1U, transitions_.size()); |
| 618 return transitions_[0]; | 620 return transitions_[0]; |
| 619 } | 621 } |
| 620 | 622 |
| 621 NavigationType navigation_type() { | 623 NavigationType navigation_type() { |
| 622 EXPECT_EQ(1U, navigation_types_.size()); | 624 EXPECT_EQ(1U, navigation_types_.size()); |
| 623 return navigation_types_[0]; | 625 return navigation_types_[0]; |
| 624 } | 626 } |
| 625 | 627 |
| 626 bool is_in_page() { | 628 bool is_same_document() { |
| 627 EXPECT_EQ(1U, is_in_pages_.size()); | 629 EXPECT_EQ(1U, is_same_documents_.size()); |
| 628 return is_in_pages_[0]; | 630 return is_same_documents_[0]; |
| 629 } | 631 } |
| 630 | 632 |
| 631 const std::vector<ui::PageTransition>& transitions() { return transitions_; } | 633 const std::vector<ui::PageTransition>& transitions() { return transitions_; } |
| 632 const std::vector<GURL>& urls() { return urls_; } | 634 const std::vector<GURL>& urls() { return urls_; } |
| 633 const std::vector<NavigationType>& navigation_types() { | 635 const std::vector<NavigationType>& navigation_types() { |
| 634 return navigation_types_; | 636 return navigation_types_; |
| 635 } | 637 } |
| 636 const std::vector<bool>& is_in_pages() { return is_in_pages_; } | 638 const std::vector<bool>& is_same_documents() { return is_same_documents_; } |
| 637 | 639 |
| 638 private: | 640 private: |
| 639 void DidFinishNavigation(NavigationHandle* navigation_handle) override { | 641 void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
| 640 if (!navigation_handle->HasCommitted()) | 642 if (!navigation_handle->HasCommitted()) |
| 641 return; | 643 return; |
| 642 | 644 |
| 643 if (navigation_handle->GetFrameTreeNodeId() != frame_tree_node_id_) | 645 if (navigation_handle->GetFrameTreeNodeId() != frame_tree_node_id_) |
| 644 return; | 646 return; |
| 645 | 647 |
| 646 --navigations_remaining_; | 648 --navigations_remaining_; |
| 647 transitions_.push_back(navigation_handle->GetPageTransition()); | 649 transitions_.push_back(navigation_handle->GetPageTransition()); |
| 648 urls_.push_back(navigation_handle->GetURL()); | 650 urls_.push_back(navigation_handle->GetURL()); |
| 649 navigation_types_.push_back( | 651 navigation_types_.push_back( |
| 650 static_cast<NavigationHandleImpl*>(navigation_handle) | 652 static_cast<NavigationHandleImpl*>(navigation_handle) |
| 651 ->navigation_type()); | 653 ->navigation_type()); |
| 652 is_in_pages_.push_back(navigation_handle->IsSameDocument()); | 654 is_same_documents_.push_back(navigation_handle->IsSameDocument()); |
| 653 if (!navigations_remaining_ && | 655 if (!navigations_remaining_ && |
| 654 (!web_contents()->IsLoading() || !wait_for_load_)) | 656 (!web_contents()->IsLoading() || !wait_for_load_)) |
| 655 message_loop_runner_->Quit(); | 657 message_loop_runner_->Quit(); |
| 656 } | 658 } |
| 657 | 659 |
| 658 void DidStopLoading() override { | 660 void DidStopLoading() override { |
| 659 if (!navigations_remaining_) | 661 if (!navigations_remaining_) |
| 660 message_loop_runner_->Quit(); | 662 message_loop_runner_->Quit(); |
| 661 } | 663 } |
| 662 | 664 |
| 663 // The id of the FrameTreeNode whose navigations to observe. | 665 // The id of the FrameTreeNode whose navigations to observe. |
| 664 int frame_tree_node_id_; | 666 int frame_tree_node_id_; |
| 665 | 667 |
| 666 // How many navigations remain to capture. | 668 // How many navigations remain to capture. |
| 667 int navigations_remaining_; | 669 int navigations_remaining_; |
| 668 | 670 |
| 669 // Whether to also wait for the load to complete. | 671 // Whether to also wait for the load to complete. |
| 670 bool wait_for_load_; | 672 bool wait_for_load_; |
| 671 | 673 |
| 672 std::vector<ui::PageTransition> transitions_; | 674 std::vector<ui::PageTransition> transitions_; |
| 673 std::vector<GURL> urls_; | 675 std::vector<GURL> urls_; |
| 674 std::vector<NavigationType> navigation_types_; | 676 std::vector<NavigationType> navigation_types_; |
| 675 std::vector<bool> is_in_pages_; | 677 std::vector<bool> is_same_documents_; |
| 676 | 678 |
| 677 // The MessageLoopRunner used to spin the message loop. | 679 // The MessageLoopRunner used to spin the message loop. |
| 678 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 680 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 679 }; | 681 }; |
| 680 | 682 |
| 681 class LoadCommittedCapturer : public WebContentsObserver { | 683 class LoadCommittedCapturer : public WebContentsObserver { |
| 682 public: | 684 public: |
| 683 // Observes the load commit for the specified |node|. | 685 // Observes the load commit for the specified |node|. |
| 684 explicit LoadCommittedCapturer(FrameTreeNode* node) | 686 explicit LoadCommittedCapturer(FrameTreeNode* node) |
| 685 : WebContentsObserver( | 687 : WebContentsObserver( |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 FrameNavigateParamsCapturer capturer(root); | 1005 FrameNavigateParamsCapturer capturer(root); |
| 1004 GURL frame_url(embedded_test_server()->GetURL( | 1006 GURL frame_url(embedded_test_server()->GetURL( |
| 1005 "/navigation_controller/page_with_links.html")); | 1007 "/navigation_controller/page_with_links.html")); |
| 1006 NavigateFrameToURL(root, frame_url); | 1008 NavigateFrameToURL(root, frame_url); |
| 1007 capturer.Wait(); | 1009 capturer.Wait(); |
| 1008 // TODO(avi,creis): Why is this (and quite a few others below) a "link" | 1010 // TODO(avi,creis): Why is this (and quite a few others below) a "link" |
| 1009 // transition? Lots of these transitions should be cleaned up. | 1011 // transition? Lots of these transitions should be cleaned up. |
| 1010 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1012 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1011 capturer.transition(), ui::PAGE_TRANSITION_LINK)); | 1013 capturer.transition(), ui::PAGE_TRANSITION_LINK)); |
| 1012 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1014 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1013 EXPECT_FALSE(capturer.is_in_page()); | 1015 EXPECT_FALSE(capturer.is_same_document()); |
| 1014 } | 1016 } |
| 1015 | 1017 |
| 1016 { | 1018 { |
| 1017 // Load via a fragment link click. | 1019 // Load via a fragment link click. |
| 1018 FrameNavigateParamsCapturer capturer(root); | 1020 FrameNavigateParamsCapturer capturer(root); |
| 1019 std::string script = "document.getElementById('fraglink').click()"; | 1021 std::string script = "document.getElementById('fraglink').click()"; |
| 1020 EXPECT_TRUE(ExecuteScript(root, script)); | 1022 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1021 capturer.Wait(); | 1023 capturer.Wait(); |
| 1022 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1024 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1023 capturer.transition(), ui::PAGE_TRANSITION_LINK)); | 1025 capturer.transition(), ui::PAGE_TRANSITION_LINK)); |
| 1024 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1026 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1025 EXPECT_TRUE(capturer.is_in_page()); | 1027 EXPECT_TRUE(capturer.is_same_document()); |
| 1026 } | 1028 } |
| 1027 | 1029 |
| 1028 { | 1030 { |
| 1029 // Load via link click. | 1031 // Load via link click. |
| 1030 FrameNavigateParamsCapturer capturer(root); | 1032 FrameNavigateParamsCapturer capturer(root); |
| 1031 std::string script = "document.getElementById('thelink').click()"; | 1033 std::string script = "document.getElementById('thelink').click()"; |
| 1032 EXPECT_TRUE(ExecuteScript(root, script)); | 1034 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1033 capturer.Wait(); | 1035 capturer.Wait(); |
| 1034 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1036 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1035 capturer.transition(), ui::PAGE_TRANSITION_LINK)); | 1037 capturer.transition(), ui::PAGE_TRANSITION_LINK)); |
| 1036 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1038 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1037 EXPECT_FALSE(capturer.is_in_page()); | 1039 EXPECT_FALSE(capturer.is_same_document()); |
| 1038 } | 1040 } |
| 1039 | 1041 |
| 1040 { | 1042 { |
| 1041 // location.assign(). | 1043 // location.assign(). |
| 1042 FrameNavigateParamsCapturer capturer(root); | 1044 FrameNavigateParamsCapturer capturer(root); |
| 1043 GURL frame_url(embedded_test_server()->GetURL( | 1045 GURL frame_url(embedded_test_server()->GetURL( |
| 1044 "/navigation_controller/simple_page_2.html")); | 1046 "/navigation_controller/simple_page_2.html")); |
| 1045 std::string script = "location.assign('" + frame_url.spec() + "')"; | 1047 std::string script = "location.assign('" + frame_url.spec() + "')"; |
| 1046 EXPECT_TRUE(ExecuteScript(root, script)); | 1048 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1047 capturer.Wait(); | 1049 capturer.Wait(); |
| 1048 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1050 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1049 capturer.transition(), | 1051 capturer.transition(), |
| 1050 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1052 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1051 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); | 1053 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); |
| 1052 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1054 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1053 EXPECT_FALSE(capturer.is_in_page()); | 1055 EXPECT_FALSE(capturer.is_same_document()); |
| 1054 } | 1056 } |
| 1055 | 1057 |
| 1056 { | 1058 { |
| 1057 // history.pushState(). | 1059 // history.pushState(). |
| 1058 FrameNavigateParamsCapturer capturer(root); | 1060 FrameNavigateParamsCapturer capturer(root); |
| 1059 std::string script = | 1061 std::string script = |
| 1060 "history.pushState({}, 'page 1', 'simple_page_1.html')"; | 1062 "history.pushState({}, 'page 1', 'simple_page_1.html')"; |
| 1061 EXPECT_TRUE(ExecuteScript(root, script)); | 1063 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1062 capturer.Wait(); | 1064 capturer.Wait(); |
| 1063 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1065 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1064 capturer.transition(), | 1066 capturer.transition(), |
| 1065 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1067 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1066 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); | 1068 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); |
| 1067 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1069 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1068 EXPECT_TRUE(capturer.is_in_page()); | 1070 EXPECT_TRUE(capturer.is_same_document()); |
| 1069 } | 1071 } |
| 1070 | 1072 |
| 1071 if (AreAllSitesIsolatedForTesting()) { | 1073 if (AreAllSitesIsolatedForTesting()) { |
| 1072 // Cross-process location.replace(). | 1074 // Cross-process location.replace(). |
| 1073 FrameNavigateParamsCapturer capturer(root); | 1075 FrameNavigateParamsCapturer capturer(root); |
| 1074 GURL frame_url(embedded_test_server()->GetURL( | 1076 GURL frame_url(embedded_test_server()->GetURL( |
| 1075 "foo.com", "/navigation_controller/simple_page_1.html")); | 1077 "foo.com", "/navigation_controller/simple_page_1.html")); |
| 1076 std::string script = "location.replace('" + frame_url.spec() + "')"; | 1078 std::string script = "location.replace('" + frame_url.spec() + "')"; |
| 1077 EXPECT_TRUE(ExecuteScript(root, script)); | 1079 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1078 capturer.Wait(); | 1080 capturer.Wait(); |
| 1079 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1081 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1080 capturer.transition(), | 1082 capturer.transition(), |
| 1081 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1083 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1082 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); | 1084 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); |
| 1083 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1085 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1084 EXPECT_FALSE(capturer.is_in_page()); | 1086 EXPECT_FALSE(capturer.is_same_document()); |
| 1085 } | 1087 } |
| 1086 } | 1088 } |
| 1087 | 1089 |
| 1088 // Verify that navigations for NAVIGATION_TYPE_EXISTING_PAGE are correctly | 1090 // Verify that navigations for NAVIGATION_TYPE_EXISTING_PAGE are correctly |
| 1089 // classified. | 1091 // classified. |
| 1090 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1092 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1091 NavigationTypeClassification_ExistingPage) { | 1093 NavigationTypeClassification_ExistingPage) { |
| 1092 GURL url1(embedded_test_server()->GetURL( | 1094 GURL url1(embedded_test_server()->GetURL( |
| 1093 "/navigation_controller/simple_page_1.html")); | 1095 "/navigation_controller/simple_page_1.html")); |
| 1094 EXPECT_TRUE(NavigateToURL(shell(), url1)); | 1096 EXPECT_TRUE(NavigateToURL(shell(), url1)); |
| 1095 GURL url2(embedded_test_server()->GetURL( | 1097 GURL url2(embedded_test_server()->GetURL( |
| 1096 "/navigation_controller/simple_page_2.html")); | 1098 "/navigation_controller/simple_page_2.html")); |
| 1097 EXPECT_TRUE(NavigateToURL(shell(), url2)); | 1099 EXPECT_TRUE(NavigateToURL(shell(), url2)); |
| 1098 | 1100 |
| 1099 FrameTreeNode* root = | 1101 FrameTreeNode* root = |
| 1100 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1102 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1101 GetFrameTree()->root(); | 1103 GetFrameTree()->root(); |
| 1102 | 1104 |
| 1103 { | 1105 { |
| 1104 // Back from the browser side. | 1106 // Back from the browser side. |
| 1105 FrameNavigateParamsCapturer capturer(root); | 1107 FrameNavigateParamsCapturer capturer(root); |
| 1106 shell()->web_contents()->GetController().GoBack(); | 1108 shell()->web_contents()->GetController().GoBack(); |
| 1107 capturer.Wait(); | 1109 capturer.Wait(); |
| 1108 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1110 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1109 capturer.transition(), | 1111 capturer.transition(), |
| 1110 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 1112 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 1111 ui::PAGE_TRANSITION_FORWARD_BACK | | 1113 ui::PAGE_TRANSITION_FORWARD_BACK | |
| 1112 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); | 1114 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); |
| 1113 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1115 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1114 EXPECT_FALSE(capturer.is_in_page()); | 1116 EXPECT_FALSE(capturer.is_same_document()); |
| 1115 } | 1117 } |
| 1116 | 1118 |
| 1117 { | 1119 { |
| 1118 // Forward from the browser side. | 1120 // Forward from the browser side. |
| 1119 FrameNavigateParamsCapturer capturer(root); | 1121 FrameNavigateParamsCapturer capturer(root); |
| 1120 shell()->web_contents()->GetController().GoForward(); | 1122 shell()->web_contents()->GetController().GoForward(); |
| 1121 capturer.Wait(); | 1123 capturer.Wait(); |
| 1122 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1124 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1123 capturer.transition(), | 1125 capturer.transition(), |
| 1124 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 1126 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 1125 ui::PAGE_TRANSITION_FORWARD_BACK | | 1127 ui::PAGE_TRANSITION_FORWARD_BACK | |
| 1126 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); | 1128 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); |
| 1127 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1129 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1128 EXPECT_FALSE(capturer.is_in_page()); | 1130 EXPECT_FALSE(capturer.is_same_document()); |
| 1129 } | 1131 } |
| 1130 | 1132 |
| 1131 { | 1133 { |
| 1132 // Back from the renderer side. | 1134 // Back from the renderer side. |
| 1133 FrameNavigateParamsCapturer capturer(root); | 1135 FrameNavigateParamsCapturer capturer(root); |
| 1134 EXPECT_TRUE(ExecuteScript(root, "history.back()")); | 1136 EXPECT_TRUE(ExecuteScript(root, "history.back()")); |
| 1135 capturer.Wait(); | 1137 capturer.Wait(); |
| 1136 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1138 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1137 capturer.transition(), | 1139 capturer.transition(), |
| 1138 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 1140 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 1139 ui::PAGE_TRANSITION_FORWARD_BACK | | 1141 ui::PAGE_TRANSITION_FORWARD_BACK | |
| 1140 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); | 1142 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); |
| 1141 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1143 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1142 EXPECT_FALSE(capturer.is_in_page()); | 1144 EXPECT_FALSE(capturer.is_same_document()); |
| 1143 } | 1145 } |
| 1144 | 1146 |
| 1145 { | 1147 { |
| 1146 // Forward from the renderer side. | 1148 // Forward from the renderer side. |
| 1147 FrameNavigateParamsCapturer capturer(root); | 1149 FrameNavigateParamsCapturer capturer(root); |
| 1148 EXPECT_TRUE(ExecuteScript(root, "history.forward()")); | 1150 EXPECT_TRUE(ExecuteScript(root, "history.forward()")); |
| 1149 capturer.Wait(); | 1151 capturer.Wait(); |
| 1150 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1152 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1151 capturer.transition(), | 1153 capturer.transition(), |
| 1152 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 1154 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 1153 ui::PAGE_TRANSITION_FORWARD_BACK | | 1155 ui::PAGE_TRANSITION_FORWARD_BACK | |
| 1154 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); | 1156 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); |
| 1155 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1157 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1156 EXPECT_FALSE(capturer.is_in_page()); | 1158 EXPECT_FALSE(capturer.is_same_document()); |
| 1157 } | 1159 } |
| 1158 | 1160 |
| 1159 { | 1161 { |
| 1160 // Back from the renderer side via history.go(). | 1162 // Back from the renderer side via history.go(). |
| 1161 FrameNavigateParamsCapturer capturer(root); | 1163 FrameNavigateParamsCapturer capturer(root); |
| 1162 EXPECT_TRUE(ExecuteScript(root, "history.go(-1)")); | 1164 EXPECT_TRUE(ExecuteScript(root, "history.go(-1)")); |
| 1163 capturer.Wait(); | 1165 capturer.Wait(); |
| 1164 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1166 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1165 capturer.transition(), | 1167 capturer.transition(), |
| 1166 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 1168 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 1167 ui::PAGE_TRANSITION_FORWARD_BACK | | 1169 ui::PAGE_TRANSITION_FORWARD_BACK | |
| 1168 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); | 1170 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); |
| 1169 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1171 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1170 EXPECT_FALSE(capturer.is_in_page()); | 1172 EXPECT_FALSE(capturer.is_same_document()); |
| 1171 } | 1173 } |
| 1172 | 1174 |
| 1173 { | 1175 { |
| 1174 // Forward from the renderer side via history.go(). | 1176 // Forward from the renderer side via history.go(). |
| 1175 FrameNavigateParamsCapturer capturer(root); | 1177 FrameNavigateParamsCapturer capturer(root); |
| 1176 EXPECT_TRUE(ExecuteScript(root, "history.go(1)")); | 1178 EXPECT_TRUE(ExecuteScript(root, "history.go(1)")); |
| 1177 capturer.Wait(); | 1179 capturer.Wait(); |
| 1178 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1180 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1179 capturer.transition(), | 1181 capturer.transition(), |
| 1180 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 1182 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 1181 ui::PAGE_TRANSITION_FORWARD_BACK | | 1183 ui::PAGE_TRANSITION_FORWARD_BACK | |
| 1182 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); | 1184 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); |
| 1183 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1185 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1184 EXPECT_FALSE(capturer.is_in_page()); | 1186 EXPECT_FALSE(capturer.is_same_document()); |
| 1185 } | 1187 } |
| 1186 | 1188 |
| 1187 { | 1189 { |
| 1188 // Reload from the browser side. | 1190 // Reload from the browser side. |
| 1189 FrameNavigateParamsCapturer capturer(root); | 1191 FrameNavigateParamsCapturer capturer(root); |
| 1190 shell()->web_contents()->GetController().Reload(ReloadType::NORMAL, false); | 1192 shell()->web_contents()->GetController().Reload(ReloadType::NORMAL, false); |
| 1191 capturer.Wait(); | 1193 capturer.Wait(); |
| 1192 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1194 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1193 capturer.transition(), ui::PAGE_TRANSITION_RELOAD)); | 1195 capturer.transition(), ui::PAGE_TRANSITION_RELOAD)); |
| 1194 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1196 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1195 EXPECT_FALSE(capturer.is_in_page()); | 1197 EXPECT_FALSE(capturer.is_same_document()); |
| 1196 } | 1198 } |
| 1197 | 1199 |
| 1198 { | 1200 { |
| 1199 // Reload from the renderer side. | 1201 // Reload from the renderer side. |
| 1200 FrameNavigateParamsCapturer capturer(root); | 1202 FrameNavigateParamsCapturer capturer(root); |
| 1201 EXPECT_TRUE(ExecuteScript(root, "location.reload()")); | 1203 EXPECT_TRUE(ExecuteScript(root, "location.reload()")); |
| 1202 capturer.Wait(); | 1204 capturer.Wait(); |
| 1203 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1205 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1204 capturer.transition(), | 1206 capturer.transition(), |
| 1205 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1207 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1206 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); | 1208 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); |
| 1207 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1209 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1208 EXPECT_FALSE(capturer.is_in_page()); | 1210 EXPECT_FALSE(capturer.is_same_document()); |
| 1209 } | 1211 } |
| 1210 | 1212 |
| 1211 { | 1213 { |
| 1212 // location.replace(). | 1214 // location.replace(). |
| 1213 // TODO(creis): Change this to be NEW_PAGE with replacement in | 1215 // TODO(creis): Change this to be NEW_PAGE with replacement in |
| 1214 // https://crbug.com/596707. | 1216 // https://crbug.com/596707. |
| 1215 FrameNavigateParamsCapturer capturer(root); | 1217 FrameNavigateParamsCapturer capturer(root); |
| 1216 GURL frame_url(embedded_test_server()->GetURL( | 1218 GURL frame_url(embedded_test_server()->GetURL( |
| 1217 "/navigation_controller/simple_page_1.html")); | 1219 "/navigation_controller/simple_page_1.html")); |
| 1218 std::string script = "location.replace('" + frame_url.spec() + "')"; | 1220 std::string script = "location.replace('" + frame_url.spec() + "')"; |
| 1219 EXPECT_TRUE(ExecuteScript(root, script)); | 1221 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1220 capturer.Wait(); | 1222 capturer.Wait(); |
| 1221 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1223 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1222 capturer.transition(), | 1224 capturer.transition(), |
| 1223 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1225 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1224 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); | 1226 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); |
| 1225 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1227 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1226 EXPECT_FALSE(capturer.is_in_page()); | 1228 EXPECT_FALSE(capturer.is_same_document()); |
| 1227 } | 1229 } |
| 1228 | 1230 |
| 1229 // Now, various in-page navigations. | 1231 // Now, various same document navigations. |
| 1230 | 1232 |
| 1231 { | 1233 { |
| 1232 // history.replaceState(). | 1234 // history.replaceState(). |
| 1233 FrameNavigateParamsCapturer capturer(root); | 1235 FrameNavigateParamsCapturer capturer(root); |
| 1234 std::string script = | 1236 std::string script = |
| 1235 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; | 1237 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; |
| 1236 EXPECT_TRUE(ExecuteScript(root, script)); | 1238 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1237 capturer.Wait(); | 1239 capturer.Wait(); |
| 1238 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1240 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1239 capturer.transition(), | 1241 capturer.transition(), |
| 1240 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1242 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1241 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); | 1243 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); |
| 1242 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1244 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1243 EXPECT_TRUE(capturer.is_in_page()); | 1245 EXPECT_TRUE(capturer.is_same_document()); |
| 1244 } | 1246 } |
| 1245 | 1247 |
| 1246 // Back and forward across a fragment navigation. | 1248 // Back and forward across a fragment navigation. |
| 1247 | 1249 |
| 1248 GURL url_links(embedded_test_server()->GetURL( | 1250 GURL url_links(embedded_test_server()->GetURL( |
| 1249 "/navigation_controller/page_with_links.html")); | 1251 "/navigation_controller/page_with_links.html")); |
| 1250 EXPECT_TRUE(NavigateToURL(shell(), url_links)); | 1252 EXPECT_TRUE(NavigateToURL(shell(), url_links)); |
| 1251 std::string script = "document.getElementById('fraglink').click()"; | 1253 std::string script = "document.getElementById('fraglink').click()"; |
| 1252 EXPECT_TRUE(ExecuteScript(root, script)); | 1254 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1253 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 1255 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1254 | 1256 |
| 1255 { | 1257 { |
| 1256 // Back. | 1258 // Back. |
| 1257 FrameNavigateParamsCapturer capturer(root); | 1259 FrameNavigateParamsCapturer capturer(root); |
| 1258 shell()->web_contents()->GetController().GoBack(); | 1260 shell()->web_contents()->GetController().GoBack(); |
| 1259 capturer.Wait(); | 1261 capturer.Wait(); |
| 1260 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1262 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1261 capturer.transition(), | 1263 capturer.transition(), |
| 1262 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 1264 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 1263 ui::PAGE_TRANSITION_FORWARD_BACK | | 1265 ui::PAGE_TRANSITION_FORWARD_BACK | |
| 1264 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); | 1266 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); |
| 1265 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1267 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1266 EXPECT_TRUE(capturer.is_in_page()); | 1268 EXPECT_TRUE(capturer.is_same_document()); |
| 1267 } | 1269 } |
| 1268 | 1270 |
| 1269 { | 1271 { |
| 1270 // Forward. | 1272 // Forward. |
| 1271 FrameNavigateParamsCapturer capturer(root); | 1273 FrameNavigateParamsCapturer capturer(root); |
| 1272 shell()->web_contents()->GetController().GoForward(); | 1274 shell()->web_contents()->GetController().GoForward(); |
| 1273 capturer.Wait(); | 1275 capturer.Wait(); |
| 1274 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1276 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1275 capturer.transition(), | 1277 capturer.transition(), |
| 1276 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1278 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1277 ui::PAGE_TRANSITION_FORWARD_BACK))); | 1279 ui::PAGE_TRANSITION_FORWARD_BACK))); |
| 1278 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1280 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1279 EXPECT_TRUE(capturer.is_in_page()); | 1281 EXPECT_TRUE(capturer.is_same_document()); |
| 1280 } | 1282 } |
| 1281 | 1283 |
| 1282 // Back and forward across a pushState-created navigation. | 1284 // Back and forward across a pushState-created navigation. |
| 1283 | 1285 |
| 1284 EXPECT_TRUE(NavigateToURL(shell(), url1)); | 1286 EXPECT_TRUE(NavigateToURL(shell(), url1)); |
| 1285 script = "history.pushState({}, 'page 2', 'simple_page_2.html')"; | 1287 script = "history.pushState({}, 'page 2', 'simple_page_2.html')"; |
| 1286 EXPECT_TRUE(ExecuteScript(root, script)); | 1288 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1287 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 1289 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1288 | 1290 |
| 1289 { | 1291 { |
| 1290 // Back. | 1292 // Back. |
| 1291 FrameNavigateParamsCapturer capturer(root); | 1293 FrameNavigateParamsCapturer capturer(root); |
| 1292 shell()->web_contents()->GetController().GoBack(); | 1294 shell()->web_contents()->GetController().GoBack(); |
| 1293 capturer.Wait(); | 1295 capturer.Wait(); |
| 1294 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1296 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1295 capturer.transition(), | 1297 capturer.transition(), |
| 1296 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 1298 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 1297 ui::PAGE_TRANSITION_FORWARD_BACK | | 1299 ui::PAGE_TRANSITION_FORWARD_BACK | |
| 1298 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); | 1300 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); |
| 1299 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1301 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1300 EXPECT_TRUE(capturer.is_in_page()); | 1302 EXPECT_TRUE(capturer.is_same_document()); |
| 1301 } | 1303 } |
| 1302 | 1304 |
| 1303 { | 1305 { |
| 1304 // Forward. | 1306 // Forward. |
| 1305 FrameNavigateParamsCapturer capturer(root); | 1307 FrameNavigateParamsCapturer capturer(root); |
| 1306 shell()->web_contents()->GetController().GoForward(); | 1308 shell()->web_contents()->GetController().GoForward(); |
| 1307 capturer.Wait(); | 1309 capturer.Wait(); |
| 1308 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1310 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1309 capturer.transition(), | 1311 capturer.transition(), |
| 1310 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1312 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1311 ui::PAGE_TRANSITION_FORWARD_BACK))); | 1313 ui::PAGE_TRANSITION_FORWARD_BACK))); |
| 1312 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 1314 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 1313 EXPECT_TRUE(capturer.is_in_page()); | 1315 EXPECT_TRUE(capturer.is_same_document()); |
| 1314 } | 1316 } |
| 1315 } | 1317 } |
| 1316 | 1318 |
| 1317 // Verify that navigations for NAVIGATION_TYPE_SAME_PAGE are correctly | 1319 // Verify that navigations for NAVIGATION_TYPE_SAME_PAGE are correctly |
| 1318 // classified. | 1320 // classified. |
| 1319 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1321 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1320 NavigationTypeClassification_SamePage) { | 1322 NavigationTypeClassification_SamePage) { |
| 1321 GURL url1(embedded_test_server()->GetURL( | 1323 GURL url1(embedded_test_server()->GetURL( |
| 1322 "/navigation_controller/simple_page_1.html")); | 1324 "/navigation_controller/simple_page_1.html")); |
| 1323 EXPECT_TRUE(NavigateToURL(shell(), url1)); | 1325 EXPECT_TRUE(NavigateToURL(shell(), url1)); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1597 capturer.transitions()[0], ui::PAGE_TRANSITION_LINK)); | 1599 capturer.transitions()[0], ui::PAGE_TRANSITION_LINK)); |
| 1598 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_types()[0]); | 1600 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_types()[0]); |
| 1599 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1601 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1600 capturer.transitions()[1], | 1602 capturer.transitions()[1], |
| 1601 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 1603 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
| 1602 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); | 1604 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); |
| 1603 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_types()[1]); | 1605 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_types()[1]); |
| 1604 } | 1606 } |
| 1605 } | 1607 } |
| 1606 | 1608 |
| 1607 // Verify that the LoadCommittedDetails::is_in_page value is properly set for | 1609 // Verify that the LoadCommittedDetails::is_same_document value is properly set |
| 1608 // non-IN_PAGE navigations. (It's tested for IN_PAGE navigations with the | 1610 // for non same document navigations. |
| 1609 // NavigationTypeClassification_InPage test.) | |
| 1610 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1611 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1611 LoadCommittedDetails_IsInPage) { | 1612 LoadCommittedDetails_IsSameDocument) { |
| 1612 GURL links_url(embedded_test_server()->GetURL( | 1613 GURL links_url(embedded_test_server()->GetURL( |
| 1613 "/navigation_controller/page_with_links.html")); | 1614 "/navigation_controller/page_with_links.html")); |
| 1614 EXPECT_TRUE(NavigateToURL(shell(), links_url)); | 1615 EXPECT_TRUE(NavigateToURL(shell(), links_url)); |
| 1615 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 1616 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1616 | 1617 |
| 1617 FrameTreeNode* root = | 1618 FrameTreeNode* root = |
| 1618 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1619 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1619 GetFrameTree()->root(); | 1620 GetFrameTree()->root(); |
| 1620 | 1621 |
| 1621 { | 1622 { |
| 1622 // Do a fragment link click. | 1623 // Do a fragment link click. |
| 1623 FrameNavigateParamsCapturer capturer(root); | 1624 FrameNavigateParamsCapturer capturer(root); |
| 1624 std::string script = "document.getElementById('fraglink').click()"; | 1625 std::string script = "document.getElementById('fraglink').click()"; |
| 1625 EXPECT_TRUE(ExecuteScript(root, script)); | 1626 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1626 capturer.Wait(); | 1627 capturer.Wait(); |
| 1627 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1628 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1628 capturer.transition(), ui::PAGE_TRANSITION_LINK)); | 1629 capturer.transition(), ui::PAGE_TRANSITION_LINK)); |
| 1629 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1630 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1630 EXPECT_TRUE(capturer.is_in_page()); | 1631 EXPECT_TRUE(capturer.is_same_document()); |
| 1631 } | 1632 } |
| 1632 | 1633 |
| 1633 { | 1634 { |
| 1634 // Do a non-fragment link click. | 1635 // Do a non-fragment link click. |
| 1635 FrameNavigateParamsCapturer capturer(root); | 1636 FrameNavigateParamsCapturer capturer(root); |
| 1636 std::string script = "document.getElementById('thelink').click()"; | 1637 std::string script = "document.getElementById('thelink').click()"; |
| 1637 EXPECT_TRUE(ExecuteScript(root, script)); | 1638 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1638 capturer.Wait(); | 1639 capturer.Wait(); |
| 1639 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1640 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1640 capturer.transition(), ui::PAGE_TRANSITION_LINK)); | 1641 capturer.transition(), ui::PAGE_TRANSITION_LINK)); |
| 1641 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1642 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1642 EXPECT_FALSE(capturer.is_in_page()); | 1643 EXPECT_FALSE(capturer.is_same_document()); |
| 1643 } | 1644 } |
| 1644 | 1645 |
| 1645 // Second verse, same as the first. (But in a subframe.) | 1646 // Second verse, same as the first. (But in a subframe.) |
| 1646 | 1647 |
| 1647 GURL iframe_url(embedded_test_server()->GetURL( | 1648 GURL iframe_url(embedded_test_server()->GetURL( |
| 1648 "/navigation_controller/page_with_iframe.html")); | 1649 "/navigation_controller/page_with_iframe.html")); |
| 1649 EXPECT_TRUE(NavigateToURL(shell(), iframe_url)); | 1650 EXPECT_TRUE(NavigateToURL(shell(), iframe_url)); |
| 1650 | 1651 |
| 1651 root = static_cast<WebContentsImpl*>(shell()->web_contents())-> | 1652 root = static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1652 GetFrameTree()->root(); | 1653 GetFrameTree()->root(); |
| 1653 | 1654 |
| 1654 ASSERT_EQ(1U, root->child_count()); | 1655 ASSERT_EQ(1U, root->child_count()); |
| 1655 ASSERT_NE(nullptr, root->child_at(0)); | 1656 ASSERT_NE(nullptr, root->child_at(0)); |
| 1656 | 1657 |
| 1657 NavigateFrameToURL(root->child_at(0), links_url); | 1658 NavigateFrameToURL(root->child_at(0), links_url); |
| 1658 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 1659 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1659 | 1660 |
| 1660 { | 1661 { |
| 1661 // Do a fragment link click. | 1662 // Do a fragment link click. |
| 1662 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 1663 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 1663 std::string script = "document.getElementById('fraglink').click()"; | 1664 std::string script = "document.getElementById('fraglink').click()"; |
| 1664 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); | 1665 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
| 1665 capturer.Wait(); | 1666 capturer.Wait(); |
| 1666 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1667 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1667 capturer.transition(), ui::PAGE_TRANSITION_MANUAL_SUBFRAME)); | 1668 capturer.transition(), ui::PAGE_TRANSITION_MANUAL_SUBFRAME)); |
| 1668 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.navigation_type()); | 1669 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.navigation_type()); |
| 1669 EXPECT_TRUE(capturer.is_in_page()); | 1670 EXPECT_TRUE(capturer.is_same_document()); |
| 1670 } | 1671 } |
| 1671 | 1672 |
| 1672 { | 1673 { |
| 1673 // Do a non-fragment link click. | 1674 // Do a non-fragment link click. |
| 1674 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 1675 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 1675 std::string script = "document.getElementById('thelink').click()"; | 1676 std::string script = "document.getElementById('thelink').click()"; |
| 1676 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); | 1677 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
| 1677 capturer.Wait(); | 1678 capturer.Wait(); |
| 1678 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1679 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1679 capturer.transition(), ui::PAGE_TRANSITION_MANUAL_SUBFRAME)); | 1680 capturer.transition(), ui::PAGE_TRANSITION_MANUAL_SUBFRAME)); |
| 1680 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.navigation_type()); | 1681 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.navigation_type()); |
| 1681 EXPECT_FALSE(capturer.is_in_page()); | 1682 EXPECT_FALSE(capturer.is_same_document()); |
| 1682 } | 1683 } |
| 1683 } | 1684 } |
| 1684 | 1685 |
| 1685 // Verify the tree of FrameNavigationEntries after initial about:blank commits | 1686 // Verify the tree of FrameNavigationEntries after initial about:blank commits |
| 1686 // in subframes, which should not count as real committed loads. | 1687 // in subframes, which should not count as real committed loads. |
| 1687 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1688 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1688 FrameNavigationEntry_BlankAutoSubframe) { | 1689 FrameNavigationEntry_BlankAutoSubframe) { |
| 1689 GURL about_blank_url(url::kAboutBlankURL); | 1690 GURL about_blank_url(url::kAboutBlankURL); |
| 1690 GURL main_url(embedded_test_server()->GetURL( | 1691 GURL main_url(embedded_test_server()->GetURL( |
| 1691 "/navigation_controller/simple_page_1.html")); | 1692 "/navigation_controller/simple_page_1.html")); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1937 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1938 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1938 capturer.transition_type(), ui::PAGE_TRANSITION_AUTO_SUBFRAME)); | 1939 capturer.transition_type(), ui::PAGE_TRANSITION_AUTO_SUBFRAME)); |
| 1939 } | 1940 } |
| 1940 | 1941 |
| 1941 // TODO(creis): Check subframe entries once we create them in this case. | 1942 // TODO(creis): Check subframe entries once we create them in this case. |
| 1942 // See https://crbug.com/608402. | 1943 // See https://crbug.com/608402. |
| 1943 EXPECT_EQ(foo_url, root->child_at(0)->child_at(0)->current_url()); | 1944 EXPECT_EQ(foo_url, root->child_at(0)->child_at(0)->current_url()); |
| 1944 } | 1945 } |
| 1945 | 1946 |
| 1946 // Verify the tree of FrameNavigationEntries when a nested iframe commits after | 1947 // Verify the tree of FrameNavigationEntries when a nested iframe commits after |
| 1947 // going back in-page, in which case its parent might not have been in the | 1948 // doing same document back navigation, in which case its parent might not have |
| 1948 // NavigationEntry. Prevents regression of https://crbug.com/600743. | 1949 // been in the NavigationEntry. Prevents regression of |
| 1950 // https://crbug.com/600743. |
| 1949 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1951 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1950 FrameNavigationEntry_BackNestedAutoSubframe) { | 1952 FrameNavigationEntry_BackNestedAutoSubframe) { |
| 1951 GURL main_url(embedded_test_server()->GetURL( | 1953 GURL main_url(embedded_test_server()->GetURL( |
| 1952 "/navigation_controller/simple_page_1.html")); | 1954 "/navigation_controller/simple_page_1.html")); |
| 1953 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 1955 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 1954 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 1956 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1955 ->GetFrameTree() | 1957 ->GetFrameTree() |
| 1956 ->root(); | 1958 ->root(); |
| 1957 | 1959 |
| 1958 // 1. Navigate in-page. | 1960 // 1. Perform same document navigation. |
| 1959 { | 1961 { |
| 1960 FrameNavigateParamsCapturer capturer(root); | 1962 FrameNavigateParamsCapturer capturer(root); |
| 1961 std::string script = "history.pushState({}, 'foo', 'foo')"; | 1963 std::string script = "history.pushState({}, 'foo', 'foo')"; |
| 1962 EXPECT_TRUE(ExecuteScript(root, script)); | 1964 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1963 capturer.Wait(); | 1965 capturer.Wait(); |
| 1964 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 1966 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 1965 EXPECT_TRUE(capturer.is_in_page()); | 1967 EXPECT_TRUE(capturer.is_same_document()); |
| 1966 } | 1968 } |
| 1967 | 1969 |
| 1968 // 2. Create an iframe. | 1970 // 2. Create an iframe. |
| 1969 GURL child_url(embedded_test_server()->GetURL( | 1971 GURL child_url(embedded_test_server()->GetURL( |
| 1970 "/navigation_controller/simple_page_2.html")); | 1972 "/navigation_controller/simple_page_2.html")); |
| 1971 { | 1973 { |
| 1972 LoadCommittedCapturer capturer(shell()->web_contents()); | 1974 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1973 std::string script = "var iframe = document.createElement('iframe');" | 1975 std::string script = "var iframe = document.createElement('iframe');" |
| 1974 "iframe.src = '" + child_url.spec() + "';" | 1976 "iframe.src = '" + child_url.spec() + "';" |
| 1975 "document.body.appendChild(iframe);"; | 1977 "document.body.appendChild(iframe);"; |
| 1976 EXPECT_TRUE(ExecuteScript(root, script)); | 1978 EXPECT_TRUE(ExecuteScript(root, script)); |
| 1977 capturer.Wait(); | 1979 capturer.Wait(); |
| 1978 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 1980 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 1979 capturer.transition_type(), ui::PAGE_TRANSITION_AUTO_SUBFRAME)); | 1981 capturer.transition_type(), ui::PAGE_TRANSITION_AUTO_SUBFRAME)); |
| 1980 } | 1982 } |
| 1981 | 1983 |
| 1982 // 3. Go back in-page. | 1984 // 3. Perform back same document navigation. |
| 1983 { | 1985 { |
| 1984 TestNavigationObserver back_load_observer(shell()->web_contents()); | 1986 TestNavigationObserver back_load_observer(shell()->web_contents()); |
| 1985 shell()->web_contents()->GetController().GoBack(); | 1987 shell()->web_contents()->GetController().GoBack(); |
| 1986 back_load_observer.Wait(); | 1988 back_load_observer.Wait(); |
| 1987 } | 1989 } |
| 1988 | 1990 |
| 1989 // 4. A nested iframe with a cross-site URL should be able to commit. | 1991 // 4. A nested iframe with a cross-site URL should be able to commit. |
| 1990 GURL grandchild_url(embedded_test_server()->GetURL( | 1992 GURL grandchild_url(embedded_test_server()->GetURL( |
| 1991 "foo.com", "/navigation_controller/simple_page_1.html")); | 1993 "foo.com", "/navigation_controller/simple_page_1.html")); |
| 1992 { | 1994 { |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2365 EXPECT_EQ( | 2367 EXPECT_EQ( |
| 2366 " Site A ------------ proxies for B\n" | 2368 " Site A ------------ proxies for B\n" |
| 2367 " |--Site A ------- proxies for B\n" | 2369 " |--Site A ------- proxies for B\n" |
| 2368 " +--Site B ------- proxies for A\n" | 2370 " +--Site B ------- proxies for A\n" |
| 2369 "Where A = http://127.0.0.1/\n" | 2371 "Where A = http://127.0.0.1/\n" |
| 2370 " B = http://baz.com/", | 2372 " B = http://baz.com/", |
| 2371 visualizer.DepictFrameTree(root)); | 2373 visualizer.DepictFrameTree(root)); |
| 2372 } | 2374 } |
| 2373 } | 2375 } |
| 2374 | 2376 |
| 2375 // Ensure that we don't crash when navigating subframes after in-page | 2377 // Ensure that we don't crash when navigating subframes after same document |
| 2376 // navigations. See https://crbug.com/522193. | 2378 // navigations. See https://crbug.com/522193. |
| 2377 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 2379 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 2378 FrameNavigationEntry_SubframeAfterInPage) { | 2380 FrameNavigationEntry_SubframeAfterSameDocument) { |
| 2379 // 1. Start on a page with a subframe. | 2381 // 1. Start on a page with a subframe. |
| 2380 GURL main_url(embedded_test_server()->GetURL( | 2382 GURL main_url(embedded_test_server()->GetURL( |
| 2381 "/navigation_controller/page_with_iframe.html")); | 2383 "/navigation_controller/page_with_iframe.html")); |
| 2382 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 2384 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
| 2383 const NavigationControllerImpl& controller = | 2385 const NavigationControllerImpl& controller = |
| 2384 static_cast<const NavigationControllerImpl&>( | 2386 static_cast<const NavigationControllerImpl&>( |
| 2385 shell()->web_contents()->GetController()); | 2387 shell()->web_contents()->GetController()); |
| 2386 FrameTreeNode* root = | 2388 FrameTreeNode* root = |
| 2387 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 2389 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 2388 GetFrameTree()->root(); | 2390 GetFrameTree()->root(); |
| 2389 | 2391 |
| 2390 ASSERT_EQ(1U, root->child_count()); | 2392 ASSERT_EQ(1U, root->child_count()); |
| 2391 ASSERT_NE(nullptr, root->child_at(0)); | 2393 ASSERT_NE(nullptr, root->child_at(0)); |
| 2392 | 2394 |
| 2393 // Navigate to a real page in the subframe, so that the next navigation will | 2395 // Navigate to a real page in the subframe, so that the next navigation will |
| 2394 // be MANUAL_SUBFRAME. | 2396 // be MANUAL_SUBFRAME. |
| 2395 GURL subframe_url(embedded_test_server()->GetURL( | 2397 GURL subframe_url(embedded_test_server()->GetURL( |
| 2396 "/navigation_controller/simple_page_1.html")); | 2398 "/navigation_controller/simple_page_1.html")); |
| 2397 { | 2399 { |
| 2398 LoadCommittedCapturer capturer(root->child_at(0)); | 2400 LoadCommittedCapturer capturer(root->child_at(0)); |
| 2399 NavigateFrameToURL(root->child_at(0), subframe_url); | 2401 NavigateFrameToURL(root->child_at(0), subframe_url); |
| 2400 capturer.Wait(); | 2402 capturer.Wait(); |
| 2401 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 2403 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 2402 capturer.transition_type(), ui::PAGE_TRANSITION_AUTO_SUBFRAME)); | 2404 capturer.transition_type(), ui::PAGE_TRANSITION_AUTO_SUBFRAME)); |
| 2403 } | 2405 } |
| 2404 | 2406 |
| 2405 // 2. In-page navigation in the main frame. | 2407 // 2. Same document navigation in the main frame. |
| 2406 std::string push_script = "history.pushState({}, 'page 2', 'page_2.html')"; | 2408 std::string push_script = "history.pushState({}, 'page 2', 'page_2.html')"; |
| 2407 EXPECT_TRUE(ExecuteScript(root, push_script)); | 2409 EXPECT_TRUE(ExecuteScript(root, push_script)); |
| 2408 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 2410 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 2409 | 2411 |
| 2410 // The entry should have a FrameNavigationEntry for the subframe. | 2412 // The entry should have a FrameNavigationEntry for the subframe. |
| 2411 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); | 2413 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 2412 ASSERT_EQ(1U, entry->root_node()->children.size()); | 2414 ASSERT_EQ(1U, entry->root_node()->children.size()); |
| 2413 EXPECT_EQ(subframe_url, entry->root_node()->children[0]->frame_entry->url()); | 2415 EXPECT_EQ(subframe_url, entry->root_node()->children[0]->frame_entry->url()); |
| 2414 | 2416 |
| 2415 // 3. Add a nested subframe. | 2417 // 3. Add a nested subframe. |
| (...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3988 } | 3990 } |
| 3989 | 3991 |
| 3990 // Go back. | 3992 // Go back. |
| 3991 { | 3993 { |
| 3992 TestNavigationObserver back_load_observer(new_tab.get()); | 3994 TestNavigationObserver back_load_observer(new_tab.get()); |
| 3993 new_controller.GoBack(); | 3995 new_controller.GoBack(); |
| 3994 back_load_observer.Wait(); | 3996 back_load_observer.Wait(); |
| 3995 } | 3997 } |
| 3996 } | 3998 } |
| 3997 | 3999 |
| 3998 // Ensure that going back/forward to an apparently in-page NavigationEntry works | 4000 // Ensure that going back/forward to an apparently same document |
| 3999 // when the renderer process hasn't committed anything yet. This can happen | 4001 // NavigationEntry works when the renderer process hasn't committed anything |
| 4000 // when using Ctrl+Back or after a crash. See https://crbug.com/635403. | 4002 // yet. This can happen when using Ctrl+Back or after a crash. See |
| 4003 // https://crbug.com/635403. |
| 4001 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 4004 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 4002 BackInPageInNewWindow) { | 4005 BackSameDocumentInNewWindow) { |
| 4003 // Start on an initial page. | 4006 // Start on an initial page. |
| 4004 GURL url_1(embedded_test_server()->GetURL( | 4007 GURL url_1(embedded_test_server()->GetURL( |
| 4005 "/navigation_controller/simple_page_1.html")); | 4008 "/navigation_controller/simple_page_1.html")); |
| 4006 EXPECT_TRUE(NavigateToURL(shell(), url_1)); | 4009 EXPECT_TRUE(NavigateToURL(shell(), url_1)); |
| 4007 | 4010 |
| 4008 // Navigate it in-page. | 4011 // Perform same document navigation. |
| 4009 GURL url_2(embedded_test_server()->GetURL( | 4012 GURL url_2(embedded_test_server()->GetURL( |
| 4010 "/navigation_controller/simple_page_1.html#foo")); | 4013 "/navigation_controller/simple_page_1.html#foo")); |
| 4011 EXPECT_TRUE(NavigateToURL(shell(), url_2)); | 4014 EXPECT_TRUE(NavigateToURL(shell(), url_2)); |
| 4012 | 4015 |
| 4013 // Clone the tab but don't load last committed page. | 4016 // Clone the tab but don't load last committed page. |
| 4014 std::unique_ptr<WebContentsImpl> new_tab( | 4017 std::unique_ptr<WebContentsImpl> new_tab( |
| 4015 static_cast<WebContentsImpl*>(shell()->web_contents()->Clone())); | 4018 static_cast<WebContentsImpl*>(shell()->web_contents()->Clone())); |
| 4016 NavigationController& new_controller = new_tab->GetController(); | 4019 NavigationController& new_controller = new_tab->GetController(); |
| 4017 EXPECT_TRUE(new_controller.IsInitialNavigation()); | 4020 EXPECT_TRUE(new_controller.IsInitialNavigation()); |
| 4018 EXPECT_TRUE(new_controller.NeedsReload()); | 4021 EXPECT_TRUE(new_controller.NeedsReload()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4093 EXPECT_EQ(frame_url, subframe_entry->url()); | 4096 EXPECT_EQ(frame_url, subframe_entry->url()); |
| 4094 | 4097 |
| 4095 // 3. Reload the main frame. | 4098 // 3. Reload the main frame. |
| 4096 { | 4099 { |
| 4097 FrameNavigateParamsCapturer capturer(root); | 4100 FrameNavigateParamsCapturer capturer(root); |
| 4098 controller.Reload(ReloadType::NORMAL, false); | 4101 controller.Reload(ReloadType::NORMAL, false); |
| 4099 capturer.Wait(); | 4102 capturer.Wait(); |
| 4100 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 4103 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 4101 capturer.transition(), ui::PAGE_TRANSITION_RELOAD)); | 4104 capturer.transition(), ui::PAGE_TRANSITION_RELOAD)); |
| 4102 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 4105 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 4103 EXPECT_FALSE(capturer.is_in_page()); | 4106 EXPECT_FALSE(capturer.is_same_document()); |
| 4104 } | 4107 } |
| 4105 | 4108 |
| 4106 // 4. Add the iframe again. | 4109 // 4. Add the iframe again. |
| 4107 { | 4110 { |
| 4108 LoadCommittedCapturer capturer(shell()->web_contents()); | 4111 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 4109 EXPECT_TRUE(ExecuteScript(root, script)); | 4112 EXPECT_TRUE(ExecuteScript(root, script)); |
| 4110 capturer.Wait(); | 4113 capturer.Wait(); |
| 4111 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 4114 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 4112 capturer.transition_type(), ui::PAGE_TRANSITION_AUTO_SUBFRAME)); | 4115 capturer.transition_type(), ui::PAGE_TRANSITION_AUTO_SUBFRAME)); |
| 4113 } | 4116 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4133 ->GetFrameTree() | 4136 ->GetFrameTree() |
| 4134 ->root(); | 4137 ->root(); |
| 4135 | 4138 |
| 4136 FrameNavigationEntry* frame_entry = | 4139 FrameNavigationEntry* frame_entry = |
| 4137 controller.GetLastCommittedEntry()->GetFrameEntry(root); | 4140 controller.GetLastCommittedEntry()->GetFrameEntry(root); |
| 4138 int64_t isn_1 = frame_entry->item_sequence_number(); | 4141 int64_t isn_1 = frame_entry->item_sequence_number(); |
| 4139 int64_t dsn_1 = frame_entry->document_sequence_number(); | 4142 int64_t dsn_1 = frame_entry->document_sequence_number(); |
| 4140 EXPECT_NE(-1, isn_1); | 4143 EXPECT_NE(-1, isn_1); |
| 4141 EXPECT_NE(-1, dsn_1); | 4144 EXPECT_NE(-1, dsn_1); |
| 4142 | 4145 |
| 4143 // 2. Do an in-page fragment navigation. | 4146 // 2. Do a same document fragment navigation. |
| 4144 std::string script = "document.getElementById('fraglink').click()"; | 4147 std::string script = "document.getElementById('fraglink').click()"; |
| 4145 EXPECT_TRUE(ExecuteScript(root, script)); | 4148 EXPECT_TRUE(ExecuteScript(root, script)); |
| 4146 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 4149 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4147 | 4150 |
| 4148 frame_entry = controller.GetLastCommittedEntry()->GetFrameEntry(root); | 4151 frame_entry = controller.GetLastCommittedEntry()->GetFrameEntry(root); |
| 4149 int64_t isn_2 = frame_entry->item_sequence_number(); | 4152 int64_t isn_2 = frame_entry->item_sequence_number(); |
| 4150 int64_t dsn_2 = frame_entry->document_sequence_number(); | 4153 int64_t dsn_2 = frame_entry->document_sequence_number(); |
| 4151 EXPECT_NE(-1, isn_2); | 4154 EXPECT_NE(-1, isn_2); |
| 4152 EXPECT_NE(isn_1, isn_2); | 4155 EXPECT_NE(isn_1, isn_2); |
| 4153 EXPECT_EQ(dsn_1, dsn_2); | 4156 EXPECT_EQ(dsn_1, dsn_2); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4171 // We should have a unique ISN and DSN for the subframe entry. | 4174 // We should have a unique ISN and DSN for the subframe entry. |
| 4172 FrameTreeNode* subframe = root->child_at(0); | 4175 FrameTreeNode* subframe = root->child_at(0); |
| 4173 FrameNavigationEntry* subframe_entry = | 4176 FrameNavigationEntry* subframe_entry = |
| 4174 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); | 4177 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| 4175 int64_t isn_3 = subframe_entry->item_sequence_number(); | 4178 int64_t isn_3 = subframe_entry->item_sequence_number(); |
| 4176 int64_t dsn_3 = subframe_entry->document_sequence_number(); | 4179 int64_t dsn_3 = subframe_entry->document_sequence_number(); |
| 4177 EXPECT_NE(-1, isn_2); | 4180 EXPECT_NE(-1, isn_2); |
| 4178 EXPECT_NE(isn_2, isn_3); | 4181 EXPECT_NE(isn_2, isn_3); |
| 4179 EXPECT_NE(dsn_2, dsn_3); | 4182 EXPECT_NE(dsn_2, dsn_3); |
| 4180 | 4183 |
| 4181 // 4. Do an in-page fragment navigation in the subframe. | 4184 // 4. Do a same document fragment navigation in the subframe. |
| 4182 EXPECT_TRUE(ExecuteScript(subframe, script)); | 4185 EXPECT_TRUE(ExecuteScript(subframe, script)); |
| 4183 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 4186 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4184 | 4187 |
| 4185 subframe_entry = controller.GetLastCommittedEntry()->GetFrameEntry(subframe); | 4188 subframe_entry = controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| 4186 int64_t isn_4 = subframe_entry->item_sequence_number(); | 4189 int64_t isn_4 = subframe_entry->item_sequence_number(); |
| 4187 int64_t dsn_4 = subframe_entry->document_sequence_number(); | 4190 int64_t dsn_4 = subframe_entry->document_sequence_number(); |
| 4188 EXPECT_NE(-1, isn_4); | 4191 EXPECT_NE(-1, isn_4); |
| 4189 EXPECT_NE(isn_3, isn_4); | 4192 EXPECT_NE(isn_3, isn_4); |
| 4190 EXPECT_EQ(dsn_3, dsn_4); | 4193 EXPECT_EQ(dsn_3, dsn_4); |
| 4191 } | 4194 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4378 new_root->child_at(0)->current_frame_host()->GetSiteInstance()); | 4381 new_root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 4379 } else { | 4382 } else { |
| 4380 EXPECT_EQ(new_root->current_frame_host()->GetSiteInstance(), | 4383 EXPECT_EQ(new_root->current_frame_host()->GetSiteInstance(), |
| 4381 new_root->child_at(0)->current_frame_host()->GetSiteInstance()); | 4384 new_root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 4382 } | 4385 } |
| 4383 } | 4386 } |
| 4384 | 4387 |
| 4385 namespace { | 4388 namespace { |
| 4386 | 4389 |
| 4387 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is | 4390 // Loads |start_url|, then loads |stalled_url| which stalls. While the page is |
| 4388 // stalled, an in-page navigation happens. Make sure that all the navigations | 4391 // stalled, a same document navigation happens. Make sure that all the |
| 4389 // are properly classified. | 4392 // navigations are properly classified. |
| 4390 void DoReplaceStateWhilePending(Shell* shell, | 4393 void DoReplaceStateWhilePending(Shell* shell, |
| 4391 const GURL& start_url, | 4394 const GURL& start_url, |
| 4392 const GURL& stalled_url, | 4395 const GURL& stalled_url, |
| 4393 const std::string& replace_state_filename) { | 4396 const std::string& replace_state_filename) { |
| 4394 NavigationControllerImpl& controller = | 4397 NavigationControllerImpl& controller = |
| 4395 static_cast<NavigationControllerImpl&>( | 4398 static_cast<NavigationControllerImpl&>( |
| 4396 shell->web_contents()->GetController()); | 4399 shell->web_contents()->GetController()); |
| 4397 | 4400 |
| 4398 FrameTreeNode* root = | 4401 FrameTreeNode* root = |
| 4399 static_cast<WebContentsImpl*>(shell->web_contents())-> | 4402 static_cast<WebContentsImpl*>(shell->web_contents())-> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4418 FrameNavigateParamsCapturer capturer(root); | 4421 FrameNavigateParamsCapturer capturer(root); |
| 4419 capturer.set_wait_for_load(false); | 4422 capturer.set_wait_for_load(false); |
| 4420 std::string script = | 4423 std::string script = |
| 4421 "history.replaceState({}, '', '" + replace_state_filename + "')"; | 4424 "history.replaceState({}, '', '" + replace_state_filename + "')"; |
| 4422 EXPECT_TRUE(ExecuteScript(root, script)); | 4425 EXPECT_TRUE(ExecuteScript(root, script)); |
| 4423 capturer.Wait(); | 4426 capturer.Wait(); |
| 4424 | 4427 |
| 4425 // The fact that there was a pending entry shouldn't interfere with the | 4428 // The fact that there was a pending entry shouldn't interfere with the |
| 4426 // classification. | 4429 // classification. |
| 4427 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); | 4430 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.navigation_type()); |
| 4428 EXPECT_TRUE(capturer.is_in_page()); | 4431 EXPECT_TRUE(capturer.is_same_document()); |
| 4429 } | 4432 } |
| 4430 | 4433 |
| 4431 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 4434 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
| 4432 } | 4435 } |
| 4433 | 4436 |
| 4434 } // namespace | 4437 } // namespace |
| 4435 | 4438 |
| 4436 IN_PROC_BROWSER_TEST_F( | 4439 IN_PROC_BROWSER_TEST_F( |
| 4437 NavigationControllerBrowserTest, | 4440 NavigationControllerBrowserTest, |
| 4438 NavigationTypeClassification_On1InPageToXWhile2Pending) { | 4441 NavigationTypeClassification_On1SameDocumentToXWhile2Pending) { |
| 4439 GURL url1(embedded_test_server()->GetURL( | 4442 GURL url1(embedded_test_server()->GetURL( |
| 4440 "/navigation_controller/simple_page_1.html")); | 4443 "/navigation_controller/simple_page_1.html")); |
| 4441 GURL url2(embedded_test_server()->GetURL( | 4444 GURL url2(embedded_test_server()->GetURL( |
| 4442 "/navigation_controller/simple_page_2.html")); | 4445 "/navigation_controller/simple_page_2.html")); |
| 4443 DoReplaceStateWhilePending(shell(), url1, url2, "x"); | 4446 DoReplaceStateWhilePending(shell(), url1, url2, "x"); |
| 4444 } | 4447 } |
| 4445 | 4448 |
| 4446 IN_PROC_BROWSER_TEST_F( | 4449 IN_PROC_BROWSER_TEST_F( |
| 4447 NavigationControllerBrowserTest, | 4450 NavigationControllerBrowserTest, |
| 4448 NavigationTypeClassification_On1InPageTo2While2Pending) { | 4451 NavigationTypeClassification_On1SameDocumentTo2While2Pending) { |
| 4449 GURL url1(embedded_test_server()->GetURL( | 4452 GURL url1(embedded_test_server()->GetURL( |
| 4450 "/navigation_controller/simple_page_1.html")); | 4453 "/navigation_controller/simple_page_1.html")); |
| 4451 GURL url2(embedded_test_server()->GetURL( | 4454 GURL url2(embedded_test_server()->GetURL( |
| 4452 "/navigation_controller/simple_page_2.html")); | 4455 "/navigation_controller/simple_page_2.html")); |
| 4453 DoReplaceStateWhilePending(shell(), url1, url2, "simple_page_2.html"); | 4456 DoReplaceStateWhilePending(shell(), url1, url2, "simple_page_2.html"); |
| 4454 } | 4457 } |
| 4455 | 4458 |
| 4456 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 4459 IN_PROC_BROWSER_TEST_F( |
| 4457 NavigationTypeClassification_On1InPageToXWhile1Pending) { | 4460 NavigationControllerBrowserTest, |
| 4461 NavigationTypeClassification_On1SameDocumentToXWhile1Pending) { |
| 4458 GURL url(embedded_test_server()->GetURL( | 4462 GURL url(embedded_test_server()->GetURL( |
| 4459 "/navigation_controller/simple_page_1.html")); | 4463 "/navigation_controller/simple_page_1.html")); |
| 4460 DoReplaceStateWhilePending(shell(), url, url, "x"); | 4464 DoReplaceStateWhilePending(shell(), url, url, "x"); |
| 4461 } | 4465 } |
| 4462 | 4466 |
| 4463 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 4467 IN_PROC_BROWSER_TEST_F( |
| 4464 NavigationTypeClassification_On1InPageTo1While1Pending) { | 4468 NavigationControllerBrowserTest, |
| 4469 NavigationTypeClassification_On1SameDocumentTo1While1Pending) { |
| 4465 GURL url(embedded_test_server()->GetURL( | 4470 GURL url(embedded_test_server()->GetURL( |
| 4466 "/navigation_controller/simple_page_1.html")); | 4471 "/navigation_controller/simple_page_1.html")); |
| 4467 DoReplaceStateWhilePending(shell(), url, url, "simple_page_1.html"); | 4472 DoReplaceStateWhilePending(shell(), url, url, "simple_page_1.html"); |
| 4468 } | 4473 } |
| 4469 | 4474 |
| 4470 // Ensure that a pending NavigationEntry for a different navigation doesn't | 4475 // Ensure that a pending NavigationEntry for a different navigation doesn't |
| 4471 // cause a commit to be incorrectly treated as a replacement. | 4476 // cause a commit to be incorrectly treated as a replacement. |
| 4472 // See https://crbug.com/593153. | 4477 // See https://crbug.com/593153. |
| 4473 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 4478 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 4474 OtherCommitDuringPendingEntryWithReplacement) { | 4479 OtherCommitDuringPendingEntryWithReplacement) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4504 | 4509 |
| 4505 { | 4510 { |
| 4506 // Now the existing page uses history.pushState() while the pending entry | 4511 // Now the existing page uses history.pushState() while the pending entry |
| 4507 // for the other navigation still exists. | 4512 // for the other navigation still exists. |
| 4508 FrameNavigateParamsCapturer capturer(root); | 4513 FrameNavigateParamsCapturer capturer(root); |
| 4509 capturer.set_wait_for_load(false); | 4514 capturer.set_wait_for_load(false); |
| 4510 std::string script = "history.pushState({}, '', 'pushed')"; | 4515 std::string script = "history.pushState({}, '', 'pushed')"; |
| 4511 EXPECT_TRUE(ExecuteScript(root, script)); | 4516 EXPECT_TRUE(ExecuteScript(root, script)); |
| 4512 capturer.Wait(); | 4517 capturer.Wait(); |
| 4513 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); | 4518 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.navigation_type()); |
| 4514 EXPECT_TRUE(capturer.is_in_page()); | 4519 EXPECT_TRUE(capturer.is_same_document()); |
| 4515 } | 4520 } |
| 4516 | 4521 |
| 4517 // The in-page navigation should not have replaced the previous entry. | 4522 // The same document navigation should not have replaced the previous entry. |
| 4518 GURL push_state_url( | 4523 GURL push_state_url( |
| 4519 embedded_test_server()->GetURL("/navigation_controller/pushed")); | 4524 embedded_test_server()->GetURL("/navigation_controller/pushed")); |
| 4520 EXPECT_EQ(entry_count + 1, controller.GetEntryCount()); | 4525 EXPECT_EQ(entry_count + 1, controller.GetEntryCount()); |
| 4521 EXPECT_EQ(push_state_url, controller.GetLastCommittedEntry()->GetURL()); | 4526 EXPECT_EQ(push_state_url, controller.GetLastCommittedEntry()->GetURL()); |
| 4522 EXPECT_EQ(start_url, controller.GetEntryAtIndex(0)->GetURL()); | 4527 EXPECT_EQ(start_url, controller.GetEntryAtIndex(0)->GetURL()); |
| 4523 | 4528 |
| 4524 ResourceDispatcherHost::Get()->SetDelegate(nullptr); | 4529 ResourceDispatcherHost::Get()->SetDelegate(nullptr); |
| 4525 } | 4530 } |
| 4526 | 4531 |
| 4527 // This test ensures that if we go back from a page that has a replaceState() | 4532 // This test ensures that if we go back from a page that has a replaceState() |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4815 | 4820 |
| 4816 void RenderProcessGone(base::TerminationStatus status) override { | 4821 void RenderProcessGone(base::TerminationStatus status) override { |
| 4817 CHECK_NE(status, | 4822 CHECK_NE(status, |
| 4818 base::TerminationStatus::TERMINATION_STATUS_PROCESS_WAS_KILLED); | 4823 base::TerminationStatus::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
| 4819 } | 4824 } |
| 4820 }; | 4825 }; |
| 4821 } | 4826 } |
| 4822 | 4827 |
| 4823 // This tests a race in Reload with ReloadType::ORIGINAL_REQUEST_URL, where a | 4828 // This tests a race in Reload with ReloadType::ORIGINAL_REQUEST_URL, where a |
| 4824 // cross-origin reload was causing an in-flight replaceState to look like a | 4829 // cross-origin reload was causing an in-flight replaceState to look like a |
| 4825 // cross-origin navigation, even though it's in-page. (The reload should not | 4830 // cross-origin navigation, even though it's same document. (The reload should |
| 4826 // modify the underlying last committed entry.) Not crashing means that the | 4831 // not modify the underlying last committed entry.) Not crashing means that |
| 4827 // test is successful. | 4832 // the test is successful. |
| 4828 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) { | 4833 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) { |
| 4829 GURL original_url(embedded_test_server()->GetURL( | 4834 GURL original_url(embedded_test_server()->GetURL( |
| 4830 "/navigation_controller/simple_page_1.html")); | 4835 "/navigation_controller/simple_page_1.html")); |
| 4831 EXPECT_TRUE(NavigateToURL(shell(), original_url)); | 4836 EXPECT_TRUE(NavigateToURL(shell(), original_url)); |
| 4832 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 4837 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 4833 ->GetFrameTree() | 4838 ->GetFrameTree() |
| 4834 ->root(); | 4839 ->root(); |
| 4835 RenderProcessKilledObserver kill_observer(shell()->web_contents()); | 4840 RenderProcessKilledObserver kill_observer(shell()->web_contents()); |
| 4836 | 4841 |
| 4837 // Redirect so that we can use Reload with ReloadType::ORIGINAL_REQUEST_URL. | 4842 // Redirect so that we can use Reload with ReloadType::ORIGINAL_REQUEST_URL. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4880 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 4885 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
| 4881 } | 4886 } |
| 4882 | 4887 |
| 4883 // Make sure the renderer is still alive. | 4888 // Make sure the renderer is still alive. |
| 4884 EXPECT_TRUE(ExecuteScript(shell(), "console.log('Success');")); | 4889 EXPECT_TRUE(ExecuteScript(shell(), "console.log('Success');")); |
| 4885 } | 4890 } |
| 4886 | 4891 |
| 4887 // This test shows that the initial "about:blank" URL is elided from the | 4892 // This test shows that the initial "about:blank" URL is elided from the |
| 4888 // navigation history of a subframe when it is loaded. | 4893 // navigation history of a subframe when it is loaded. |
| 4889 // | 4894 // |
| 4890 // It also prevents regression for an in-page navigation renderer kill when | 4895 // It also prevents regression for an same document navigation renderer kill |
| 4891 // going back after an in-page navigation in the main frame is followed by an | 4896 // when going back after an in-page navigation in the main frame is followed by |
| 4892 // auto subframe navigation, due to a bug in HistoryEntry::CloneAndReplace. | 4897 // an auto subframe navigation, due to a bug in HistoryEntry::CloneAndReplace. |
| 4893 // See https://crbug.com/612713. | 4898 // See https://crbug.com/612713. |
| 4894 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 4899 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 4895 BackToAboutBlankIframe) { | 4900 BackToAboutBlankIframe) { |
| 4896 GURL original_url(embedded_test_server()->GetURL( | 4901 GURL original_url(embedded_test_server()->GetURL( |
| 4897 "/navigation_controller/simple_page_1.html")); | 4902 "/navigation_controller/simple_page_1.html")); |
| 4898 EXPECT_TRUE(NavigateToURL(shell(), original_url)); | 4903 EXPECT_TRUE(NavigateToURL(shell(), original_url)); |
| 4899 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 4904 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4900 | 4905 |
| 4901 NavigationController& controller = shell()->web_contents()->GetController(); | 4906 NavigationController& controller = shell()->web_contents()->GetController(); |
| 4902 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 4907 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4969 // NavigationControllerImpl::FindFramesToNavigate for more information, as | 4974 // NavigationControllerImpl::FindFramesToNavigate for more information, as |
| 4970 // well as http://crbug.com/542299, https://crbug.com/598043 (for the | 4975 // well as http://crbug.com/542299, https://crbug.com/598043 (for the |
| 4971 // regressions caused by going back), and | 4976 // regressions caused by going back), and |
| 4972 // https://github.com/whatwg/html/issues/546. | 4977 // https://github.com/whatwg/html/issues/546. |
| 4973 // TODO(avi, creis): Figure out the correct behavior to use here. | 4978 // TODO(avi, creis): Figure out the correct behavior to use here. |
| 4974 EXPECT_EQ(frame_url, frame->current_url()); | 4979 EXPECT_EQ(frame_url, frame->current_url()); |
| 4975 | 4980 |
| 4976 // Now test for https://crbug.com/612713 to prevent an NC_IN_PAGE_NAVIGATION | 4981 // Now test for https://crbug.com/612713 to prevent an NC_IN_PAGE_NAVIGATION |
| 4977 // renderer kill. | 4982 // renderer kill. |
| 4978 | 4983 |
| 4979 // Do an in-page navigation in the subframe. | 4984 // Do a same document navigation in the subframe. |
| 4980 std::string fragment_script = "location.href = \"#foo\";"; | 4985 std::string fragment_script = "location.href = \"#foo\";"; |
| 4981 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), fragment_script)); | 4986 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), fragment_script)); |
| 4982 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 4987 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 4983 | 4988 |
| 4984 EXPECT_EQ(2, controller.GetEntryCount()); | 4989 EXPECT_EQ(2, controller.GetEntryCount()); |
| 4985 EXPECT_EQ(2, RendererHistoryLength(shell())); | 4990 EXPECT_EQ(2, RendererHistoryLength(shell())); |
| 4986 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 4991 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 4987 | 4992 |
| 4988 GURL frame_url_2 = embedded_test_server()->GetURL( | 4993 GURL frame_url_2 = embedded_test_server()->GetURL( |
| 4989 "foo.com", "/navigation_controller/simple_page_2.html#foo"); | 4994 "foo.com", "/navigation_controller/simple_page_2.html#foo"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5003 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 5008 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 5004 | 5009 |
| 5005 // TODO(creis): We should probably go back to frame_url here instead of the | 5010 // TODO(creis): We should probably go back to frame_url here instead of the |
| 5006 // initial blank page. That might require updating all relevant NavEntries to | 5011 // initial blank page. That might require updating all relevant NavEntries to |
| 5007 // know what the first committed URL is, so that we really elide the initial | 5012 // know what the first committed URL is, so that we really elide the initial |
| 5008 // blank page from history. | 5013 // blank page from history. |
| 5009 EXPECT_EQ(blank_url, frame->current_url()); | 5014 EXPECT_EQ(blank_url, frame->current_url()); |
| 5010 } | 5015 } |
| 5011 | 5016 |
| 5012 // This test is similar to "BackToAboutBlankIframe" above, except that a | 5017 // This test is similar to "BackToAboutBlankIframe" above, except that a |
| 5013 // fragment navigation is used rather than pushState (both create an in-page | 5018 // fragment navigation is used rather than pushState (both create a same |
| 5014 // navigation, so we need to test both), and an initial 'src' is given to the | 5019 // document navigation, so we need to test both), and an initial 'src' is given |
| 5015 // iframe to test proper restoration in that case. | 5020 // to the iframe to test proper restoration in that case. |
| 5016 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 5021 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 5017 BackToIframeWithContent) { | 5022 BackToIframeWithContent) { |
| 5018 GURL links_url(embedded_test_server()->GetURL( | 5023 GURL links_url(embedded_test_server()->GetURL( |
| 5019 "/navigation_controller/page_with_links.html")); | 5024 "/navigation_controller/page_with_links.html")); |
| 5020 EXPECT_TRUE(NavigateToURL(shell(), links_url)); | 5025 EXPECT_TRUE(NavigateToURL(shell(), links_url)); |
| 5021 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5026 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 5022 | 5027 |
| 5023 NavigationController& controller = shell()->web_contents()->GetController(); | 5028 NavigationController& controller = shell()->web_contents()->GetController(); |
| 5024 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 5029 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 5025 ->GetFrameTree() | 5030 ->GetFrameTree() |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5095 // NavigationControllerImpl::FindFramesToNavigate for more information, as | 5100 // NavigationControllerImpl::FindFramesToNavigate for more information, as |
| 5096 // well as http://crbug.com/542299, https://crbug.com/598043 (for the | 5101 // well as http://crbug.com/542299, https://crbug.com/598043 (for the |
| 5097 // regressions caused by going back), and | 5102 // regressions caused by going back), and |
| 5098 // https://github.com/whatwg/html/issues/546. | 5103 // https://github.com/whatwg/html/issues/546. |
| 5099 // TODO(avi, creis): Figure out the correct behavior to use here. | 5104 // TODO(avi, creis): Figure out the correct behavior to use here. |
| 5100 EXPECT_EQ(frame_url_2, frame->current_url()); | 5105 EXPECT_EQ(frame_url_2, frame->current_url()); |
| 5101 | 5106 |
| 5102 // Now test for https://crbug.com/612713 to prevent an NC_IN_PAGE_NAVIGATION | 5107 // Now test for https://crbug.com/612713 to prevent an NC_IN_PAGE_NAVIGATION |
| 5103 // renderer kill. | 5108 // renderer kill. |
| 5104 | 5109 |
| 5105 // Do an in-page navigation in the subframe. | 5110 // Do a same document navigation in the subframe. |
| 5106 std::string fragment_script = "location.href = \"#foo\";"; | 5111 std::string fragment_script = "location.href = \"#foo\";"; |
| 5107 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), fragment_script)); | 5112 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), fragment_script)); |
| 5108 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5113 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 5109 | 5114 |
| 5110 EXPECT_EQ(2, controller.GetEntryCount()); | 5115 EXPECT_EQ(2, controller.GetEntryCount()); |
| 5111 EXPECT_EQ(2, RendererHistoryLength(shell())); | 5116 EXPECT_EQ(2, RendererHistoryLength(shell())); |
| 5112 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 5117 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 5113 | 5118 |
| 5114 // Go back. | 5119 // Go back. |
| 5115 { | 5120 { |
| 5116 TestNavigationObserver observer(shell()->web_contents(), 1); | 5121 TestNavigationObserver observer(shell()->web_contents(), 1); |
| 5117 controller.GoBack(); | 5122 controller.GoBack(); |
| 5118 observer.Wait(); | 5123 observer.Wait(); |
| 5119 } | 5124 } |
| 5120 | 5125 |
| 5121 // Verify the process is still alive by running script. We can't just call | 5126 // Verify the process is still alive by running script. We can't just call |
| 5122 // IsRenderFrameLive after the navigation since it might not have disconnected | 5127 // IsRenderFrameLive after the navigation since it might not have disconnected |
| 5123 // yet. | 5128 // yet. |
| 5124 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;")); | 5129 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;")); |
| 5125 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 5130 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 5126 | 5131 |
| 5127 // TODO(creis): It's a bit surprising to go to frame_url_1 here instead of | 5132 // TODO(creis): It's a bit surprising to go to frame_url_1 here instead of |
| 5128 // frame_url_2. Perhaps we should be going back to frame_url_1 when going | 5133 // frame_url_2. Perhaps we should be going back to frame_url_1 when going |
| 5129 // back two entries above, since it's different than the initial blank case. | 5134 // back two entries above, since it's different than the initial blank case. |
| 5130 EXPECT_EQ(frame_url_1, frame->current_url()); | 5135 EXPECT_EQ(frame_url_1, frame->current_url()); |
| 5131 } | 5136 } |
| 5132 | 5137 |
| 5133 // Test for in-page navigation kills due to using the wrong history item in | 5138 // Test for same document navigation kills due to using the wrong history item |
| 5134 // HistoryController::RecursiveGoToEntry and NavigationControllerImpl:: | 5139 // in HistoryController::RecursiveGoToEntry and |
| 5135 // FindFramesToNavigate. See https://crbug.com/612713. | 5140 // NavigationControllerImpl::FindFramesToNavigate. |
| 5141 // See https://crbug.com/612713. |
| 5136 // | 5142 // |
| 5137 // TODO(creis): Enable this test when https://crbug.com/618100 is fixed. | 5143 // TODO(creis): Enable this test when https://crbug.com/618100 is fixed. |
| 5138 // Disabled for now while we switch to the new navigation path, since this kill | 5144 // Disabled for now while we switch to the new navigation path, since this kill |
| 5139 // is exceptionally rare in practice. | 5145 // is exceptionally rare in practice. |
| 5140 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 5146 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 5141 DISABLED_BackTwiceToIframeWithContent) { | 5147 DISABLED_BackTwiceToIframeWithContent) { |
| 5142 GURL links_url(embedded_test_server()->GetURL( | 5148 GURL links_url(embedded_test_server()->GetURL( |
| 5143 "/navigation_controller/page_with_links.html")); | 5149 "/navigation_controller/page_with_links.html")); |
| 5144 EXPECT_TRUE(NavigateToURL(shell(), links_url)); | 5150 EXPECT_TRUE(NavigateToURL(shell(), links_url)); |
| 5145 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5151 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 5167 EXPECT_EQ(1, controller.GetEntryCount()); | 5173 EXPECT_EQ(1, controller.GetEntryCount()); |
| 5168 EXPECT_EQ(1, RendererHistoryLength(shell())); | 5174 EXPECT_EQ(1, RendererHistoryLength(shell())); |
| 5169 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); | 5175 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); |
| 5170 | 5176 |
| 5171 ASSERT_EQ(1U, root->child_count()); | 5177 ASSERT_EQ(1U, root->child_count()); |
| 5172 FrameTreeNode* frame = root->child_at(0); | 5178 FrameTreeNode* frame = root->child_at(0); |
| 5173 ASSERT_NE(nullptr, frame); | 5179 ASSERT_NE(nullptr, frame); |
| 5174 | 5180 |
| 5175 EXPECT_EQ(frame_url_1, frame->current_url()); | 5181 EXPECT_EQ(frame_url_1, frame->current_url()); |
| 5176 | 5182 |
| 5177 // Do an in-page navigation in the subframe. | 5183 // Do a same document navigation in the subframe. |
| 5178 GURL frame_url_2 = embedded_test_server()->GetURL( | 5184 GURL frame_url_2 = embedded_test_server()->GetURL( |
| 5179 "/navigation_controller/simple_page_1.html#foo"); | 5185 "/navigation_controller/simple_page_1.html#foo"); |
| 5180 std::string fragment_script = "location.href = \"#foo\";"; | 5186 std::string fragment_script = "location.href = \"#foo\";"; |
| 5181 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), fragment_script)); | 5187 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), fragment_script)); |
| 5182 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5188 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 5183 EXPECT_EQ(2, controller.GetEntryCount()); | 5189 EXPECT_EQ(2, controller.GetEntryCount()); |
| 5184 EXPECT_EQ(2, RendererHistoryLength(shell())); | 5190 EXPECT_EQ(2, RendererHistoryLength(shell())); |
| 5185 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 5191 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 5186 EXPECT_EQ(frame_url_2, frame->current_url()); | 5192 EXPECT_EQ(frame_url_2, frame->current_url()); |
| 5187 | 5193 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5241 // yet. | 5247 // yet. |
| 5242 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;")); | 5248 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;")); |
| 5243 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 5249 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 5244 | 5250 |
| 5245 // TODO(creis): It's a bit surprising to go to frame_url_1 here instead of | 5251 // TODO(creis): It's a bit surprising to go to frame_url_1 here instead of |
| 5246 // frame_url_2. Perhaps we should be going back to frame_url_1 when going | 5252 // frame_url_2. Perhaps we should be going back to frame_url_1 when going |
| 5247 // back two entries above, since it's different than the initial blank case. | 5253 // back two entries above, since it's different than the initial blank case. |
| 5248 EXPECT_EQ(frame_url_1, frame->current_url()); | 5254 EXPECT_EQ(frame_url_1, frame->current_url()); |
| 5249 } | 5255 } |
| 5250 | 5256 |
| 5251 // Test for in-page navigation kills when going back to about:blank after a | 5257 // Test for same document navigation kills when going back to about:blank after |
| 5252 // document.write. See https://crbug.com/446959. | 5258 // a document.write. See https://crbug.com/446959. |
| 5253 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 5259 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 5254 BackAfterIframeDocumentWrite) { | 5260 BackAfterIframeDocumentWrite) { |
| 5255 GURL links_url(embedded_test_server()->GetURL( | 5261 GURL links_url(embedded_test_server()->GetURL( |
| 5256 "/navigation_controller/page_with_links.html")); | 5262 "/navigation_controller/page_with_links.html")); |
| 5257 EXPECT_TRUE(NavigateToURL(shell(), links_url)); | 5263 EXPECT_TRUE(NavigateToURL(shell(), links_url)); |
| 5258 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5264 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 5259 | 5265 |
| 5260 NavigationController& controller = shell()->web_contents()->GetController(); | 5266 NavigationController& controller = shell()->web_contents()->GetController(); |
| 5261 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 5267 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 5262 ->GetFrameTree() | 5268 ->GetFrameTree() |
| (...skipping 19 matching lines...) Expand all Loading... |
| 5282 EXPECT_EQ(blank_url, frame->current_url()); | 5288 EXPECT_EQ(blank_url, frame->current_url()); |
| 5283 | 5289 |
| 5284 // Do a document.write in the subframe to create a link to click. | 5290 // Do a document.write in the subframe to create a link to click. |
| 5285 std::string document_write_script = | 5291 std::string document_write_script = |
| 5286 "var iframe = document.getElementById('frame');" | 5292 "var iframe = document.getElementById('frame');" |
| 5287 "iframe.contentWindow.document.write(" | 5293 "iframe.contentWindow.document.write(" |
| 5288 " \"<a id='fraglink' href='#frag'>fragment link</a>\");" | 5294 " \"<a id='fraglink' href='#frag'>fragment link</a>\");" |
| 5289 "iframe.contentWindow.document.close();"; | 5295 "iframe.contentWindow.document.close();"; |
| 5290 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), document_write_script)); | 5296 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), document_write_script)); |
| 5291 | 5297 |
| 5292 // Click the link to do an in-page navigation. Due to the document.write, the | 5298 // Click the link to do a same document navigation. Due to the |
| 5293 // new URL matches the parent frame's URL. | 5299 // document.write, the new URL matches the parent frame's URL. |
| 5294 GURL frame_url_2(embedded_test_server()->GetURL( | 5300 GURL frame_url_2(embedded_test_server()->GetURL( |
| 5295 "/navigation_controller/page_with_links.html#frag")); | 5301 "/navigation_controller/page_with_links.html#frag")); |
| 5296 std::string link_script = "document.getElementById('fraglink').click()"; | 5302 std::string link_script = "document.getElementById('fraglink').click()"; |
| 5297 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), link_script)); | 5303 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), link_script)); |
| 5298 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5304 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 5299 EXPECT_EQ(2, controller.GetEntryCount()); | 5305 EXPECT_EQ(2, controller.GetEntryCount()); |
| 5300 EXPECT_EQ(2, RendererHistoryLength(shell())); | 5306 EXPECT_EQ(2, RendererHistoryLength(shell())); |
| 5301 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 5307 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 5302 EXPECT_EQ(frame_url_2, frame->current_url()); | 5308 EXPECT_EQ(frame_url_2, frame->current_url()); |
| 5303 | 5309 |
| 5304 // Go back. | 5310 // Go back. |
| 5305 { | 5311 { |
| 5306 TestNavigationObserver observer(shell()->web_contents(), 1); | 5312 TestNavigationObserver observer(shell()->web_contents(), 1); |
| 5307 controller.GoBack(); | 5313 controller.GoBack(); |
| 5308 observer.Wait(); | 5314 observer.Wait(); |
| 5309 } | 5315 } |
| 5310 | 5316 |
| 5311 // Verify the process is still alive by running script. We can't just call | 5317 // Verify the process is still alive by running script. We can't just call |
| 5312 // IsRenderFrameLive after the navigation since it might not have disconnected | 5318 // IsRenderFrameLive after the navigation since it might not have disconnected |
| 5313 // yet. | 5319 // yet. |
| 5314 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;")); | 5320 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), "true;")); |
| 5315 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); | 5321 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive()); |
| 5316 | 5322 |
| 5317 EXPECT_EQ(blank_url, frame->current_url()); | 5323 EXPECT_EQ(blank_url, frame->current_url()); |
| 5318 } | 5324 } |
| 5319 | 5325 |
| 5320 // Test for in-page navigation kills when going back to about:blank in an iframe | 5326 // Test for same document navigation kills when going back to about:blank in an |
| 5321 // of a data URL, after a document.write. This differs from | 5327 // iframe of a data URL, after a document.write. This differs from |
| 5322 // BackAfterIframeDocumentWrite because both about:blank and the data URL are | 5328 // BackAfterIframeDocumentWrite because both about:blank and the data URL are |
| 5323 // considered unique origins. See https://crbug.com/446959. | 5329 // considered unique origins. See https://crbug.com/446959. |
| 5324 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 5330 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 5325 BackAfterIframeDocumentWriteInDataURL) { | 5331 BackAfterIframeDocumentWriteInDataURL) { |
| 5326 GURL data_url("data:text/html,Top level page"); | 5332 GURL data_url("data:text/html,Top level page"); |
| 5327 EXPECT_TRUE(NavigateToURL(shell(), data_url)); | 5333 EXPECT_TRUE(NavigateToURL(shell(), data_url)); |
| 5328 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5334 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 5329 | 5335 |
| 5330 NavigationController& controller = shell()->web_contents()->GetController(); | 5336 NavigationController& controller = shell()->web_contents()->GetController(); |
| 5331 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 5337 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5352 EXPECT_EQ(blank_url, frame->current_url()); | 5358 EXPECT_EQ(blank_url, frame->current_url()); |
| 5353 | 5359 |
| 5354 // Do a document.write in the subframe to create a link to click. | 5360 // Do a document.write in the subframe to create a link to click. |
| 5355 std::string document_write_script = | 5361 std::string document_write_script = |
| 5356 "var iframe = document.getElementById('frame');" | 5362 "var iframe = document.getElementById('frame');" |
| 5357 "iframe.contentWindow.document.write(" | 5363 "iframe.contentWindow.document.write(" |
| 5358 " \"<a id='fraglink' href='#frag'>fragment link</a>\");" | 5364 " \"<a id='fraglink' href='#frag'>fragment link</a>\");" |
| 5359 "iframe.contentWindow.document.close();"; | 5365 "iframe.contentWindow.document.close();"; |
| 5360 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), document_write_script)); | 5366 EXPECT_TRUE(ExecuteScript(root->current_frame_host(), document_write_script)); |
| 5361 | 5367 |
| 5362 // Click the link to do an in-page navigation. Due to the document.write, the | 5368 // Click the link to do a same document navigation. Due to the |
| 5363 // new URL matches the parent frame's URL. | 5369 // document.write, the new URL matches the parent frame's URL. |
| 5364 GURL frame_url_2("data:text/html,Top level page#frag"); | 5370 GURL frame_url_2("data:text/html,Top level page#frag"); |
| 5365 std::string link_script = "document.getElementById('fraglink').click()"; | 5371 std::string link_script = "document.getElementById('fraglink').click()"; |
| 5366 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), link_script)); | 5372 EXPECT_TRUE(ExecuteScript(frame->current_frame_host(), link_script)); |
| 5367 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 5373 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 5368 EXPECT_EQ(2, controller.GetEntryCount()); | 5374 EXPECT_EQ(2, controller.GetEntryCount()); |
| 5369 EXPECT_EQ(2, RendererHistoryLength(shell())); | 5375 EXPECT_EQ(2, RendererHistoryLength(shell())); |
| 5370 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); | 5376 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); |
| 5371 EXPECT_EQ(frame_url_2, frame->current_url()); | 5377 EXPECT_EQ(frame_url_2, frame->current_url()); |
| 5372 | 5378 |
| 5373 // Go back. | 5379 // Go back. |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6271 "document.getElementsByTagName('pre')[1].innerText);", | 6277 "document.getElementsByTagName('pre')[1].innerText);", |
| 6272 &headers)); | 6278 &headers)); |
| 6273 | 6279 |
| 6274 // Verify the Origin and Referer headers. | 6280 // Verify the Origin and Referer headers. |
| 6275 EXPECT_THAT(headers, ::testing::HasSubstr("Origin: null")); | 6281 EXPECT_THAT(headers, ::testing::HasSubstr("Origin: null")); |
| 6276 EXPECT_THAT(headers, | 6282 EXPECT_THAT(headers, |
| 6277 ::testing::ContainsRegex( | 6283 ::testing::ContainsRegex( |
| 6278 "Referer: http://a.com:.*/form_that_posts_cross_site.html")); | 6284 "Referer: http://a.com:.*/form_that_posts_cross_site.html")); |
| 6279 } | 6285 } |
| 6280 | 6286 |
| 6281 // Check that the favicon is not cleared for navigating in-page. | 6287 // Check that the favicon is not cleared for same document navigations. |
| 6282 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 6288 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 6283 InPageNavigationDoesNotClearFavicon) { | 6289 SameDocumentNavigationDoesNotClearFavicon) { |
| 6284 // Load a page and fake a favicon for it. | 6290 // Load a page and fake a favicon for it. |
| 6285 NavigationController& controller = shell()->web_contents()->GetController(); | 6291 NavigationController& controller = shell()->web_contents()->GetController(); |
| 6286 ASSERT_TRUE(NavigateToURL( | 6292 ASSERT_TRUE(NavigateToURL( |
| 6287 shell(), embedded_test_server()->GetURL("/simple_page.html"))); | 6293 shell(), embedded_test_server()->GetURL("/simple_page.html"))); |
| 6288 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); | 6294 content::NavigationEntry* entry = controller.GetLastCommittedEntry(); |
| 6289 ASSERT_TRUE(entry); | 6295 ASSERT_TRUE(entry); |
| 6290 content::FaviconStatus& favicon_status = entry->GetFavicon(); | 6296 content::FaviconStatus& favicon_status = entry->GetFavicon(); |
| 6291 favicon_status.valid = true; | 6297 favicon_status.valid = true; |
| 6292 | 6298 |
| 6293 ASSERT_TRUE(RendererLocationReplace( | 6299 ASSERT_TRUE(RendererLocationReplace( |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6815 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | 6821 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); |
| 6816 | 6822 |
| 6817 TestNavigationObserver back_observer(shell()->web_contents()); | 6823 TestNavigationObserver back_observer(shell()->web_contents()); |
| 6818 controller.GoBack(); | 6824 controller.GoBack(); |
| 6819 back_observer.Wait(); | 6825 back_observer.Wait(); |
| 6820 | 6826 |
| 6821 EXPECT_TRUE(back_observer.last_navigation_succeeded()); | 6827 EXPECT_TRUE(back_observer.last_navigation_succeeded()); |
| 6822 } | 6828 } |
| 6823 | 6829 |
| 6824 } // namespace content | 6830 } // namespace content |
| OLD | NEW |