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 <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 NavigateToURL(shell(), main_url); | 202 NavigateToURL(shell(), main_url); |
203 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 203 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
204 ->GetFrameTree() | 204 ->GetFrameTree() |
205 ->root(); | 205 ->root(); |
206 ASSERT_EQ(1U, root->child_count()); | 206 ASSERT_EQ(1U, root->child_count()); |
207 ASSERT_NE(nullptr, root->child_at(0)); | 207 ASSERT_NE(nullptr, root->child_at(0)); |
208 | 208 |
209 // The main frame's nav_entry_id should match the last committed entry. | 209 // The main frame's nav_entry_id should match the last committed entry. |
210 int unique_id = controller.GetLastCommittedEntry()->GetUniqueID(); | 210 int unique_id = controller.GetLastCommittedEntry()->GetUniqueID(); |
211 EXPECT_EQ(unique_id, root->current_frame_host()->nav_entry_id()); | 211 EXPECT_EQ(unique_id, root->current_frame_host()->nav_entry_id()); |
| 212 EXPECT_EQ(1, controller.GetEntryCount()); |
212 | 213 |
213 // The about:blank iframe should have inherited the same nav_entry_id. | 214 // The about:blank iframe should have inherited the same nav_entry_id. |
214 EXPECT_EQ(unique_id, root->child_at(0)->current_frame_host()->nav_entry_id()); | 215 EXPECT_EQ(unique_id, root->child_at(0)->current_frame_host()->nav_entry_id()); |
215 | 216 |
216 // Use NavigateFrameToURL to go cross-site in the subframe. | 217 // Use NavigateFrameToURL to go cross-site in the subframe. |
217 GURL foo_url(embedded_test_server()->GetURL( | 218 GURL foo_url(embedded_test_server()->GetURL( |
218 "foo.com", "/navigation_controller/simple_page_1.html")); | 219 "foo.com", "/navigation_controller/simple_page_1.html")); |
219 NavigateFrameToURL(root->child_at(0), foo_url); | 220 NavigateFrameToURL(root->child_at(0), foo_url); |
220 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 221 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 222 EXPECT_EQ(1, controller.GetEntryCount()); |
221 | 223 |
222 // The unique ID should have stayed the same for the auto-subframe navigation, | 224 // The unique ID should have updated for the new subframe navigation, even |
223 // since the new page replaces the initial about:blank page in the subframe. | 225 // though new page replaces the initial about:blank page in the subframe. |
224 EXPECT_EQ(unique_id, controller.GetLastCommittedEntry()->GetUniqueID()); | 226 int unique_id2 = controller.GetLastCommittedEntry()->GetUniqueID(); |
225 EXPECT_EQ(unique_id, root->current_frame_host()->nav_entry_id()); | 227 EXPECT_NE(unique_id, unique_id2); |
226 EXPECT_EQ(unique_id, root->child_at(0)->current_frame_host()->nav_entry_id()); | 228 EXPECT_EQ(unique_id2, root->current_frame_host()->nav_entry_id()); |
| 229 EXPECT_EQ(unique_id2, |
| 230 root->child_at(0)->current_frame_host()->nav_entry_id()); |
227 | 231 |
228 // Navigating in the subframe again should create a new entry. | 232 // Navigating in the subframe again should create a new entry. |
229 GURL foo_url2(embedded_test_server()->GetURL( | 233 GURL foo_url2(embedded_test_server()->GetURL( |
230 "foo.com", "/navigation_controller/simple_page_2.html")); | 234 "foo.com", "/navigation_controller/simple_page_2.html")); |
231 NavigateFrameToURL(root->child_at(0), foo_url2); | 235 NavigateFrameToURL(root->child_at(0), foo_url2); |
232 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 236 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
233 int unique_id2 = controller.GetLastCommittedEntry()->GetUniqueID(); | 237 EXPECT_EQ(2, controller.GetEntryCount()); |
234 EXPECT_NE(unique_id, unique_id2); | 238 int unique_id3 = controller.GetLastCommittedEntry()->GetUniqueID(); |
| 239 EXPECT_NE(unique_id2, unique_id3); |
235 | 240 |
236 // The unique ID should have updated for the current RenderFrameHost in both | 241 // The unique ID should have updated for the current RenderFrameHost in both |
237 // frames, not just the subframe. | 242 // frames, not just the subframe. |
238 EXPECT_EQ(unique_id2, root->current_frame_host()->nav_entry_id()); | 243 EXPECT_EQ(unique_id3, root->current_frame_host()->nav_entry_id()); |
239 EXPECT_EQ(unique_id2, | 244 EXPECT_EQ(unique_id3, |
240 root->child_at(0)->current_frame_host()->nav_entry_id()); | 245 root->child_at(0)->current_frame_host()->nav_entry_id()); |
241 } | 246 } |
242 | 247 |
243 // This test used to make sure that a scheme used to prevent spoofs didn't ever | 248 // This test used to make sure that a scheme used to prevent spoofs didn't ever |
244 // interfere with navigations. We switched to a different scheme, so now this is | 249 // interfere with navigations. We switched to a different scheme, so now this is |
245 // just a test to make sure we can still navigate once we prune the history | 250 // just a test to make sure we can still navigate once we prune the history |
246 // list. | 251 // list. |
247 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 252 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
248 DontIgnoreBackAfterNavEntryLimit) { | 253 DontIgnoreBackAfterNavEntryLimit) { |
249 NavigationController& controller = | 254 NavigationController& controller = |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 FrameNavigateParamsCapturer capturer(root); | 632 FrameNavigateParamsCapturer capturer(root); |
628 NavigateFrameToURL(root, error_url); | 633 NavigateFrameToURL(root, error_url); |
629 capturer.Wait(); | 634 capturer.Wait(); |
630 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | 635 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
631 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 636 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
632 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | 637 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
633 EXPECT_EQ(2, controller.GetEntryCount()); | 638 EXPECT_EQ(2, controller.GetEntryCount()); |
634 } | 639 } |
635 | 640 |
636 // Navigate again to the page that fails to load. It must result in an error | 641 // Navigate again to the page that fails to load. It must result in an error |
637 // page, the EXISTING_PAGE navigation type, and no addition to the history | 642 // page, the NEW_PAGE navigation type with did_replace_entry, and no addition |
638 // list. We do not use SAME_PAGE here; that case only differs in that it | 643 // to the history list. We do not use SAME_PAGE here; that case differs in |
639 // clears the pending entry, and there is no pending entry after a load | 644 // that it clears the pending entry, and there is no pending entry after a |
640 // failure. | 645 // load failure. |
641 { | 646 { |
642 FrameNavigateParamsCapturer capturer(root); | 647 FrameNavigateParamsCapturer capturer(root); |
643 NavigateFrameToURL(root, error_url); | 648 NavigateFrameToURL(root, error_url); |
644 capturer.Wait(); | 649 capturer.Wait(); |
645 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 650 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 651 EXPECT_TRUE(capturer.details().did_replace_entry); |
646 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 652 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
647 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | 653 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
648 EXPECT_EQ(2, controller.GetEntryCount()); | 654 EXPECT_EQ(2, controller.GetEntryCount()); |
649 } | 655 } |
650 | 656 |
651 // Make a new entry ... | 657 // Make a new entry ... |
652 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | 658 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
653 EXPECT_EQ(3, controller.GetEntryCount()); | 659 EXPECT_EQ(3, controller.GetEntryCount()); |
654 | 660 |
655 // ... and replace it with a failed load. (Note that when you set the | 661 // ... and replace it with a failed load. (Note that NavigateToURLAndReplace |
656 // should_replace_current_entry flag, the navigation is classified as NEW_PAGE | 662 // sets the should_replace_current_entry flag, which propagates from the |
657 // because that is a classification of the renderer's behavior, and the flag | 663 // browser to the renderer and back.) |
658 // is a browser-side flag.) | |
659 { | 664 { |
660 FrameNavigateParamsCapturer capturer(root); | 665 FrameNavigateParamsCapturer capturer(root); |
661 NavigateToURLAndReplace(shell(), error_url); | 666 NavigateToURLAndReplace(shell(), error_url); |
662 capturer.Wait(); | 667 capturer.Wait(); |
663 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | 668 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 669 EXPECT_TRUE(capturer.details().did_replace_entry); |
664 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 670 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
665 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | 671 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
666 EXPECT_EQ(3, controller.GetEntryCount()); | 672 EXPECT_EQ(3, controller.GetEntryCount()); |
667 } | 673 } |
668 | 674 |
669 // Make a new web ui page to force a process swap ... | 675 // Make a new web ui page to force a process swap ... |
670 GURL web_ui_page(std::string(kChromeUIScheme) + "://" + | 676 GURL web_ui_page(std::string(kChromeUIScheme) + "://" + |
671 std::string(kChromeUIGpuHost)); | 677 std::string(kChromeUIGpuHost)); |
672 NavigateToURL(shell(), web_ui_page); | 678 NavigateToURL(shell(), web_ui_page); |
673 EXPECT_EQ(4, controller.GetEntryCount()); | 679 EXPECT_EQ(4, controller.GetEntryCount()); |
674 | 680 |
675 // ... and replace it with a failed load. (It is NEW_PAGE for the reason noted | 681 // ... and replace it with a failed load. |
676 // above.) | |
677 { | 682 { |
678 FrameNavigateParamsCapturer capturer(root); | 683 FrameNavigateParamsCapturer capturer(root); |
679 NavigateToURLAndReplace(shell(), error_url); | 684 NavigateToURLAndReplace(shell(), error_url); |
680 capturer.Wait(); | 685 capturer.Wait(); |
681 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | 686 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 687 EXPECT_TRUE(capturer.details().did_replace_entry); |
682 NavigationEntry* entry = controller.GetLastCommittedEntry(); | 688 NavigationEntry* entry = controller.GetLastCommittedEntry(); |
683 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | 689 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
684 EXPECT_EQ(4, controller.GetEntryCount()); | 690 EXPECT_EQ(4, controller.GetEntryCount()); |
685 } | 691 } |
686 } | 692 } |
687 | 693 |
688 // Various tests for navigation type classifications. TODO(avi): It's rather | 694 // Various tests for navigation type classifications. TODO(avi): It's rather |
689 // bogus that the same info is in two different enums; http://crbug.com/453555. | 695 // bogus that the same info is in two different enums; http://crbug.com/453555. |
690 | 696 |
691 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly | 697 // Verify that navigations for NAVIGATION_TYPE_NEW_PAGE are correctly |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 FrameNavigateParamsCapturer capturer(root); | 759 FrameNavigateParamsCapturer capturer(root); |
754 std::string script = | 760 std::string script = |
755 "history.pushState({}, 'page 1', 'simple_page_1.html')"; | 761 "history.pushState({}, 'page 1', 'simple_page_1.html')"; |
756 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 762 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
757 capturer.Wait(); | 763 capturer.Wait(); |
758 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 764 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
759 capturer.params().transition); | 765 capturer.params().transition); |
760 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); | 766 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
761 EXPECT_TRUE(capturer.details().is_in_page); | 767 EXPECT_TRUE(capturer.details().is_in_page); |
762 } | 768 } |
| 769 |
| 770 // Now test NEW_PAGE with replacement. First, go back so that we can ensure |
| 771 // location.replace leaves the forward history. |
| 772 { |
| 773 FrameNavigateParamsCapturer capturer(root); |
| 774 shell()->web_contents()->GetController().GoBack(); |
| 775 capturer.Wait(); |
| 776 EXPECT_TRUE(shell()->web_contents()->GetController().CanGoForward()); |
| 777 } |
| 778 |
| 779 { |
| 780 // location.replace(). |
| 781 FrameNavigateParamsCapturer capturer(root); |
| 782 GURL frame_url(embedded_test_server()->GetURL( |
| 783 "/navigation_controller/simple_page_1.html")); |
| 784 std::string script = "location.replace('" + frame_url.spec() + "')"; |
| 785 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 786 capturer.Wait(); |
| 787 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
| 788 capturer.params().transition); |
| 789 // Unlike replaceState, this replaces the existing entry with a new one. |
| 790 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 791 EXPECT_TRUE(capturer.details().did_replace_entry); |
| 792 EXPECT_FALSE(capturer.details().is_in_page); |
| 793 |
| 794 // Make sure the forward history did not get pruned. |
| 795 EXPECT_TRUE(shell()->web_contents()->GetController().CanGoForward()); |
| 796 } |
| 797 |
| 798 { |
| 799 // Cross-site location.replace(). |
| 800 FrameNavigateParamsCapturer capturer(root); |
| 801 GURL frame_url(embedded_test_server()->GetURL( |
| 802 "foo.com", "/navigation_controller/simple_page_1.html")); |
| 803 std::string script = "location.replace('" + frame_url.spec() + "')"; |
| 804 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 805 capturer.Wait(); |
| 806 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
| 807 capturer.params().transition); |
| 808 // Unlike replaceState, this replaces the existing entry with a new one. |
| 809 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
| 810 EXPECT_TRUE(capturer.details().did_replace_entry); |
| 811 EXPECT_FALSE(capturer.details().is_in_page); |
| 812 |
| 813 // Make sure the forward history did not get pruned. |
| 814 EXPECT_TRUE(shell()->web_contents()->GetController().CanGoForward()); |
| 815 } |
763 } | 816 } |
764 | 817 |
765 // Verify that navigations for NAVIGATION_TYPE_EXISTING_PAGE are correctly | 818 // Verify that navigations for NAVIGATION_TYPE_EXISTING_PAGE are correctly |
766 // classified. | 819 // classified. |
767 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 820 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
768 NavigationTypeClassification_ExistingPage) { | 821 NavigationTypeClassification_ExistingPage) { |
769 GURL url1(embedded_test_server()->GetURL( | 822 GURL url1(embedded_test_server()->GetURL( |
770 "/navigation_controller/simple_page_1.html")); | 823 "/navigation_controller/simple_page_1.html")); |
771 NavigateToURL(shell(), url1); | 824 NavigateToURL(shell(), url1); |
772 GURL url2(embedded_test_server()->GetURL( | 825 GURL url2(embedded_test_server()->GetURL( |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 FrameNavigateParamsCapturer capturer(root); | 927 FrameNavigateParamsCapturer capturer(root); |
875 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), | 928 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), |
876 "location.reload()")); | 929 "location.reload()")); |
877 capturer.Wait(); | 930 capturer.Wait(); |
878 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 931 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
879 capturer.params().transition); | 932 capturer.params().transition); |
880 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 933 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
881 EXPECT_FALSE(capturer.details().is_in_page); | 934 EXPECT_FALSE(capturer.details().is_in_page); |
882 } | 935 } |
883 | 936 |
884 { | |
885 // location.replace(). | |
886 FrameNavigateParamsCapturer capturer(root); | |
887 GURL frame_url(embedded_test_server()->GetURL( | |
888 "/navigation_controller/simple_page_1.html")); | |
889 std::string script = "location.replace('" + frame_url.spec() + "')"; | |
890 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
891 capturer.Wait(); | |
892 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | |
893 capturer.params().transition); | |
894 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | |
895 EXPECT_FALSE(capturer.details().is_in_page); | |
896 } | |
897 | |
898 // Now, various in-page navigations. | 937 // Now, various in-page navigations. |
899 | 938 |
900 { | 939 { |
901 // history.replaceState(). | 940 // history.replaceState(). |
902 FrameNavigateParamsCapturer capturer(root); | 941 FrameNavigateParamsCapturer capturer(root); |
903 std::string script = | 942 std::string script = |
904 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; | 943 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; |
905 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 944 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
906 capturer.Wait(); | 945 capturer.Wait(); |
907 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 946 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
908 capturer.params().transition); | 947 capturer.params().transition); |
| 948 // Unlike location.replace, this updates the existing entry. |
909 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 949 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
| 950 EXPECT_TRUE(capturer.details().did_replace_entry); |
910 EXPECT_TRUE(capturer.details().is_in_page); | 951 EXPECT_TRUE(capturer.details().is_in_page); |
911 } | 952 } |
912 | 953 |
913 // Back and forward across a fragment navigation. | 954 // Back and forward across a fragment navigation. |
914 | 955 |
915 GURL url_links(embedded_test_server()->GetURL( | 956 GURL url_links(embedded_test_server()->GetURL( |
916 "/navigation_controller/page_with_links.html")); | 957 "/navigation_controller/page_with_links.html")); |
917 NavigateToURL(shell(), url_links); | 958 NavigateToURL(shell(), url_links); |
918 std::string script = "document.getElementById('fraglink').click()"; | 959 std::string script = "document.getElementById('fraglink').click()"; |
919 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 960 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 ASSERT_EQ(1U, root->child_count()); | 1079 ASSERT_EQ(1U, root->child_count()); |
1039 ASSERT_NE(nullptr, root->child_at(0)); | 1080 ASSERT_NE(nullptr, root->child_at(0)); |
1040 | 1081 |
1041 { | 1082 { |
1042 // Initial load. | 1083 // Initial load. |
1043 LoadCommittedCapturer capturer(root->child_at(0)); | 1084 LoadCommittedCapturer capturer(root->child_at(0)); |
1044 GURL frame_url(embedded_test_server()->GetURL( | 1085 GURL frame_url(embedded_test_server()->GetURL( |
1045 "/navigation_controller/simple_page_1.html")); | 1086 "/navigation_controller/simple_page_1.html")); |
1046 NavigateFrameToURL(root->child_at(0), frame_url); | 1087 NavigateFrameToURL(root->child_at(0), frame_url); |
1047 capturer.Wait(); | 1088 capturer.Wait(); |
1048 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1089 // TODO(creis): This doesn't seem right. |
| 1090 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, capturer.transition_type()); |
1049 } | 1091 } |
1050 | 1092 |
1051 { | 1093 { |
1052 // Simple load. | 1094 // Simple load. |
1053 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 1095 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
1054 GURL frame_url(embedded_test_server()->GetURL( | 1096 GURL frame_url(embedded_test_server()->GetURL( |
1055 "/navigation_controller/simple_page_2.html")); | 1097 "/navigation_controller/simple_page_2.html")); |
1056 NavigateFrameToURL(root->child_at(0), frame_url); | 1098 NavigateFrameToURL(root->child_at(0), frame_url); |
1057 capturer.Wait(); | 1099 capturer.Wait(); |
1058 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 1100 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 "/navigation_controller/simple_page_1.html")); | 1151 "/navigation_controller/simple_page_1.html")); |
1110 std::string script = "location.assign('" + frame_url.spec() + "')"; | 1152 std::string script = "location.assign('" + frame_url.spec() + "')"; |
1111 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 1153 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
1112 script)); | 1154 script)); |
1113 capturer.Wait(); | 1155 capturer.Wait(); |
1114 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 1156 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
1115 capturer.params().transition); | 1157 capturer.params().transition); |
1116 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 1158 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
1117 } | 1159 } |
1118 | 1160 |
| 1161 // Go back so that we can ensure location.replace leaves the forward history. |
| 1162 { |
| 1163 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 1164 shell()->web_contents()->GetController().GoBack(); |
| 1165 capturer.Wait(); |
| 1166 EXPECT_TRUE(shell()->web_contents()->GetController().CanGoForward()); |
| 1167 } |
| 1168 |
1119 { | 1169 { |
1120 // location.replace(). | 1170 // location.replace(). |
1121 LoadCommittedCapturer capturer(root->child_at(0)); | 1171 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
1122 GURL frame_url(embedded_test_server()->GetURL( | 1172 GURL frame_url(embedded_test_server()->GetURL( |
1123 "/navigation_controller/simple_page_2.html")); | 1173 "/navigation_controller/simple_page_2.html")); |
1124 std::string script = "location.replace('" + frame_url.spec() + "')"; | 1174 std::string script = "location.replace('" + frame_url.spec() + "')"; |
1125 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 1175 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
1126 script)); | 1176 script)); |
1127 capturer.Wait(); | 1177 capturer.Wait(); |
1128 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1178 // Unlike replaceState, this replaces the existing entry with a new one. |
| 1179 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 1180 capturer.params().transition); |
| 1181 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 1182 EXPECT_TRUE(capturer.details().did_replace_entry); |
| 1183 |
| 1184 // Make sure the forward history did not get pruned. |
| 1185 EXPECT_TRUE(shell()->web_contents()->GetController().CanGoForward()); |
1129 } | 1186 } |
1130 | 1187 |
1131 { | 1188 { |
| 1189 // Cross-site location.replace(). |
| 1190 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| 1191 GURL frame_url(embedded_test_server()->GetURL( |
| 1192 "foo.com", "/navigation_controller/simple_page_2.html")); |
| 1193 std::string script = "location.replace('" + frame_url.spec() + "')"; |
| 1194 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| 1195 script)); |
| 1196 capturer.Wait(); |
| 1197 // Unlike replaceState, this replaces the existing entry with a new one. |
| 1198 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 1199 capturer.params().transition); |
| 1200 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 1201 EXPECT_TRUE(capturer.details().did_replace_entry); |
| 1202 |
| 1203 // Make sure the forward history did not get pruned. |
| 1204 EXPECT_TRUE(shell()->web_contents()->GetController().CanGoForward()); |
| 1205 } |
| 1206 |
| 1207 { |
1132 // history.pushState(). | 1208 // history.pushState(). |
1133 FrameNavigateParamsCapturer capturer(root->child_at(0)); | 1209 FrameNavigateParamsCapturer capturer(root->child_at(0)); |
1134 std::string script = | 1210 std::string script = |
1135 "history.pushState({}, 'page 1', 'simple_page_1.html')"; | 1211 "history.pushState({}, 'page 1', 'simple_page_1.html')"; |
1136 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 1212 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
1137 script)); | 1213 script)); |
1138 capturer.Wait(); | 1214 capturer.Wait(); |
1139 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 1215 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
1140 capturer.params().transition); | 1216 capturer.params().transition); |
1141 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); | 1217 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
1142 } | 1218 } |
1143 | 1219 |
1144 { | 1220 { |
1145 // history.replaceState(). | 1221 // history.replaceState(). |
1146 LoadCommittedCapturer capturer(root->child_at(0)); | 1222 LoadCommittedCapturer capturer(root->child_at(0)); |
1147 std::string script = | 1223 std::string script = |
1148 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; | 1224 "history.replaceState({}, 'page 2', 'simple_page_2.html')"; |
1149 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 1225 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
1150 script)); | 1226 script)); |
1151 capturer.Wait(); | 1227 capturer.Wait(); |
| 1228 // Unlike location.replace, this updates the existing entry. |
1152 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1229 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
1153 } | 1230 } |
1154 | 1231 |
1155 { | 1232 { |
1156 // Reload. | 1233 // Reload. |
1157 LoadCommittedCapturer capturer(root->child_at(0)); | 1234 LoadCommittedCapturer capturer(root->child_at(0)); |
1158 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 1235 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
1159 "location.reload()")); | 1236 "location.reload()")); |
1160 capturer.Wait(); | 1237 capturer.Wait(); |
1161 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1238 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 capturer.Wait(); | 1273 capturer.Wait(); |
1197 | 1274 |
1198 std::vector<FrameNavigateParams> params = capturer.all_params(); | 1275 std::vector<FrameNavigateParams> params = capturer.all_params(); |
1199 std::vector<LoadCommittedDetails> details = capturer.all_details(); | 1276 std::vector<LoadCommittedDetails> details = capturer.all_details(); |
1200 ASSERT_EQ(2U, params.size()); | 1277 ASSERT_EQ(2U, params.size()); |
1201 ASSERT_EQ(2U, details.size()); | 1278 ASSERT_EQ(2U, details.size()); |
1202 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); | 1279 EXPECT_EQ(ui::PAGE_TRANSITION_LINK, params[0].transition); |
1203 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); | 1280 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[0].type); |
1204 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 1281 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
1205 params[1].transition); | 1282 params[1].transition); |
1206 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, details[1].type); | 1283 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, details[1].type); |
| 1284 EXPECT_TRUE(details[1].did_replace_entry); |
1207 } | 1285 } |
1208 } | 1286 } |
1209 | 1287 |
1210 // Verify that the LoadCommittedDetails::is_in_page value is properly set for | 1288 // Verify that the LoadCommittedDetails::is_in_page value is properly set for |
1211 // non-IN_PAGE navigations. (It's tested for IN_PAGE navigations with the | 1289 // non-IN_PAGE navigations. (It's tested for IN_PAGE navigations with the |
1212 // NavigationTypeClassification_InPage test.) | 1290 // NavigationTypeClassification_InPage test.) |
1213 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1291 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
1214 LoadCommittedDetails_IsInPage) { | 1292 LoadCommittedDetails_IsInPage) { |
1215 GURL links_url(embedded_test_server()->GetURL( | 1293 GURL links_url(embedded_test_server()->GetURL( |
1216 "/navigation_controller/page_with_links.html")); | 1294 "/navigation_controller/page_with_links.html")); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1457 ASSERT_EQ(2U, entry->root_node()->children.size()); |
1380 FrameNavigationEntry* frame_entry = | 1458 FrameNavigationEntry* frame_entry = |
1381 entry->root_node()->children[1]->frame_entry.get(); | 1459 entry->root_node()->children[1]->frame_entry.get(); |
1382 EXPECT_EQ(about_blank_url, frame_entry->url()); | 1460 EXPECT_EQ(about_blank_url, frame_entry->url()); |
1383 } else { | 1461 } else { |
1384 // There are no subframe FrameNavigationEntries by default. | 1462 // There are no subframe FrameNavigationEntries by default. |
1385 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1463 EXPECT_EQ(0U, entry->root_node()->children.size()); |
1386 } | 1464 } |
1387 EXPECT_FALSE(root->child_at(1)->has_committed_real_load()); | 1465 EXPECT_FALSE(root->child_at(1)->has_committed_real_load()); |
1388 | 1466 |
1389 // 3. A real same-site navigation in the nested iframe should be AUTO. | 1467 // 3. A real same-site navigation in the nested iframe should be MANUAL with |
| 1468 // replacement. |
1390 GURL frame_url(embedded_test_server()->GetURL( | 1469 GURL frame_url(embedded_test_server()->GetURL( |
1391 "/navigation_controller/simple_page_1.html")); | 1470 "/navigation_controller/simple_page_1.html")); |
1392 { | 1471 { |
1393 LoadCommittedCapturer capturer(root->child_at(0)->child_at(0)); | 1472 LoadCommittedCapturer capturer(root->child_at(0)->child_at(0)); |
1394 std::string script = "var frames = document.getElementsByTagName('iframe');" | 1473 std::string script = "var frames = document.getElementsByTagName('iframe');" |
1395 "frames[0].src = '" + frame_url.spec() + "';"; | 1474 "frames[0].src = '" + frame_url.spec() + "';"; |
1396 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 1475 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
1397 script)); | 1476 script)); |
1398 capturer.Wait(); | 1477 capturer.Wait(); |
1399 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1478 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, capturer.transition_type()); |
1400 } | 1479 } |
1401 | 1480 |
1402 // Check last committed NavigationEntry. It should have replaced the previous | 1481 // Check last committed NavigationEntry. It should have replaced the previous |
1403 // frame entry in the original NavigationEntry. | 1482 // NavigationEntry. |
1404 EXPECT_EQ(1, controller.GetEntryCount()); | 1483 EXPECT_EQ(1, controller.GetEntryCount()); |
1405 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); | 1484 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); |
| 1485 EXPECT_NE(entry, entry2); |
1406 | 1486 |
1407 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | 1487 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
1408 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 1488 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
1409 // The entry should still have one nested subframe FrameNavigationEntry. | 1489 // The entry should still have one nested subframe FrameNavigationEntry. |
1410 ASSERT_EQ(1U, entry->root_node()->children[0]->children.size()); | 1490 ASSERT_EQ(1U, entry2->root_node()->children[0]->children.size()); |
1411 FrameNavigationEntry* frame_entry = | 1491 FrameNavigationEntry* frame_entry = |
1412 entry->root_node()->children[0]->children[0]->frame_entry.get(); | 1492 entry2->root_node()->children[0]->children[0]->frame_entry.get(); |
1413 EXPECT_EQ(frame_url, frame_entry->url()); | 1493 EXPECT_EQ(frame_url, frame_entry->url()); |
1414 } else { | 1494 } else { |
1415 // There are no subframe FrameNavigationEntries by default. | 1495 // There are no subframe FrameNavigationEntries by default. |
1416 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1496 EXPECT_EQ(0U, entry2->root_node()->children.size()); |
1417 } | 1497 } |
1418 EXPECT_FALSE(root->child_at(0)->has_committed_real_load()); | 1498 EXPECT_FALSE(root->child_at(0)->has_committed_real_load()); |
1419 EXPECT_TRUE(root->child_at(0)->child_at(0)->has_committed_real_load()); | 1499 EXPECT_TRUE(root->child_at(0)->child_at(0)->has_committed_real_load()); |
1420 EXPECT_FALSE(root->child_at(1)->has_committed_real_load()); | 1500 EXPECT_FALSE(root->child_at(1)->has_committed_real_load()); |
1421 | 1501 |
1422 // 4. A real cross-site navigation in the second iframe should be AUTO. | 1502 // 4. A real cross-site navigation in the second iframe should be MANUAL with |
| 1503 // replacement. |
1423 GURL foo_url(embedded_test_server()->GetURL( | 1504 GURL foo_url(embedded_test_server()->GetURL( |
1424 "foo.com", "/navigation_controller/simple_page_2.html")); | 1505 "foo.com", "/navigation_controller/simple_page_2.html")); |
1425 { | 1506 { |
1426 LoadCommittedCapturer capturer(root->child_at(1)); | 1507 LoadCommittedCapturer capturer(root->child_at(1)); |
1427 std::string script = "var frames = document.getElementsByTagName('iframe');" | 1508 std::string script = "var frames = document.getElementsByTagName('iframe');" |
1428 "frames[1].src = '" + foo_url.spec() + "';"; | 1509 "frames[1].src = '" + foo_url.spec() + "';"; |
1429 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 1510 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
1430 capturer.Wait(); | 1511 capturer.Wait(); |
1431 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1512 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, capturer.transition_type()); |
1432 } | 1513 } |
1433 | 1514 |
1434 // Check last committed NavigationEntry. | 1515 // Check last committed NavigationEntry. |
1435 EXPECT_EQ(1, controller.GetEntryCount()); | 1516 EXPECT_EQ(1, controller.GetEntryCount()); |
1436 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); | 1517 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry(); |
| 1518 EXPECT_NE(entry2, entry3); |
1437 | 1519 |
1438 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | 1520 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
1439 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 1521 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
1440 // The entry should still have two subframe FrameNavigationEntries. | 1522 // The entry should still have two subframe FrameNavigationEntries. |
1441 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1523 ASSERT_EQ(2U, entry3->root_node()->children.size()); |
1442 FrameNavigationEntry* frame_entry = | 1524 FrameNavigationEntry* frame_entry = |
1443 entry->root_node()->children[1]->frame_entry.get(); | 1525 entry3->root_node()->children[1]->frame_entry.get(); |
1444 EXPECT_EQ(foo_url, frame_entry->url()); | 1526 EXPECT_EQ(foo_url, frame_entry->url()); |
1445 } else { | 1527 } else { |
1446 // There are no subframe FrameNavigationEntries by default. | 1528 // There are no subframe FrameNavigationEntries by default. |
1447 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1529 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
1448 } | 1530 } |
1449 EXPECT_FALSE(root->child_at(0)->has_committed_real_load()); | 1531 EXPECT_FALSE(root->child_at(0)->has_committed_real_load()); |
1450 EXPECT_TRUE(root->child_at(0)->child_at(0)->has_committed_real_load()); | 1532 EXPECT_TRUE(root->child_at(0)->child_at(0)->has_committed_real_load()); |
1451 EXPECT_TRUE(root->child_at(1)->has_committed_real_load()); | 1533 EXPECT_TRUE(root->child_at(1)->has_committed_real_load()); |
1452 | 1534 |
1453 // 5. A new navigation to about:blank in the nested frame should count as a | 1535 // 5. A new navigation to about:blank in the nested frame should count as a |
1454 // real load, since that frame has already committed a real load and this is | 1536 // real load, since that frame has already committed a real load and this is |
1455 // not the initial blank page. | 1537 // not the initial blank page. |
1456 { | 1538 { |
1457 LoadCommittedCapturer capturer(root->child_at(0)->child_at(0)); | 1539 LoadCommittedCapturer capturer(root->child_at(0)->child_at(0)); |
1458 std::string script = "var frames = document.getElementsByTagName('iframe');" | 1540 std::string script = "var frames = document.getElementsByTagName('iframe');" |
1459 "frames[0].src = 'about:blank';"; | 1541 "frames[0].src = 'about:blank';"; |
1460 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), | 1542 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
1461 script)); | 1543 script)); |
1462 capturer.Wait(); | 1544 capturer.Wait(); |
1463 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, capturer.transition_type()); | 1545 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, capturer.transition_type()); |
1464 } | 1546 } |
1465 | 1547 |
1466 // This should have created a new NavigationEntry. | 1548 // This should have created a new NavigationEntry. |
1467 EXPECT_EQ(2, controller.GetEntryCount()); | 1549 EXPECT_EQ(2, controller.GetEntryCount()); |
1468 EXPECT_NE(entry, controller.GetLastCommittedEntry()); | 1550 NavigationEntryImpl* entry4 = controller.GetLastCommittedEntry(); |
1469 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); | 1551 EXPECT_NE(entry3, entry4); |
1470 | 1552 |
1471 // Verify subframe entries if they're enabled (e.g. in --site-per-process). | 1553 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
1472 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 1554 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
1473 ASSERT_EQ(2U, entry->root_node()->children.size()); | 1555 ASSERT_EQ(2U, entry4->root_node()->children.size()); |
1474 FrameNavigationEntry* frame_entry = | 1556 FrameNavigationEntry* frame_entry = |
1475 entry2->root_node()->children[0]->children[0]->frame_entry.get(); | 1557 entry4->root_node()->children[0]->children[0]->frame_entry.get(); |
1476 EXPECT_EQ(about_blank_url, frame_entry->url()); | 1558 EXPECT_EQ(about_blank_url, frame_entry->url()); |
1477 } else { | 1559 } else { |
1478 // There are no subframe FrameNavigationEntries by default. | 1560 // There are no subframe FrameNavigationEntries by default. |
1479 EXPECT_EQ(0U, entry->root_node()->children.size()); | 1561 EXPECT_EQ(0U, entry4->root_node()->children.size()); |
1480 } | 1562 } |
1481 EXPECT_FALSE(root->child_at(0)->has_committed_real_load()); | 1563 EXPECT_FALSE(root->child_at(0)->has_committed_real_load()); |
1482 EXPECT_TRUE(root->child_at(0)->child_at(0)->has_committed_real_load()); | 1564 EXPECT_TRUE(root->child_at(0)->child_at(0)->has_committed_real_load()); |
1483 EXPECT_TRUE(root->child_at(1)->has_committed_real_load()); | 1565 EXPECT_TRUE(root->child_at(1)->has_committed_real_load()); |
1484 | 1566 |
1485 // Check the end result of the frame tree. | 1567 // Check the end result of the frame tree. |
1486 if (AreAllSitesIsolatedForTesting()) { | 1568 if (AreAllSitesIsolatedForTesting()) { |
1487 FrameTreeVisualizer visualizer; | 1569 FrameTreeVisualizer visualizer; |
1488 EXPECT_EQ( | 1570 EXPECT_EQ( |
1489 " Site A ------------ proxies for B\n" | 1571 " Site A ------------ proxies for B\n" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 EXPECT_EQ(foo_url, entry3->root_node()->children[1]->frame_entry->url()); | 1880 EXPECT_EQ(foo_url, entry3->root_node()->children[1]->frame_entry->url()); |
1799 ASSERT_EQ(1U, entry3->root_node()->children[1]->children.size()); | 1881 ASSERT_EQ(1U, entry3->root_node()->children[1]->children.size()); |
1800 EXPECT_EQ( | 1882 EXPECT_EQ( |
1801 bar_url, | 1883 bar_url, |
1802 entry3->root_node()->children[1]->children[0]->frame_entry->url()); | 1884 entry3->root_node()->children[1]->children[0]->frame_entry->url()); |
1803 } else { | 1885 } else { |
1804 // There are no subframe FrameNavigationEntries by default. | 1886 // There are no subframe FrameNavigationEntries by default. |
1805 EXPECT_EQ(0U, entry3->root_node()->children.size()); | 1887 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
1806 } | 1888 } |
1807 | 1889 |
1808 // 6. Navigate the second subframe cross-site, clearing its existing subtree. | 1890 // 5. Navigate the second subframe cross-site, clearing its existing subtree. |
1809 GURL baz_url(embedded_test_server()->GetURL( | 1891 GURL baz_url(embedded_test_server()->GetURL( |
1810 "baz.com", "/navigation_controller/simple_page_1.html")); | 1892 "baz.com", "/navigation_controller/simple_page_1.html")); |
1811 { | 1893 { |
1812 FrameNavigateParamsCapturer capturer(root->child_at(1)); | 1894 FrameNavigateParamsCapturer capturer(root->child_at(1)); |
1813 std::string script = "var frames = document.getElementsByTagName('iframe');" | 1895 std::string script = "var frames = document.getElementsByTagName('iframe');" |
1814 "frames[1].src = '" + baz_url.spec() + "';"; | 1896 "frames[1].src = '" + baz_url.spec() + "';"; |
1815 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 1897 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
1816 capturer.Wait(); | 1898 capturer.Wait(); |
1817 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, | 1899 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
1818 capturer.params().transition); | 1900 capturer.params().transition); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 ASSERT_NE(nullptr, root->child_at(0)); | 1951 ASSERT_NE(nullptr, root->child_at(0)); |
1870 | 1952 |
1871 // Navigate to a real page in the subframe, so that the next navigation will | 1953 // Navigate to a real page in the subframe, so that the next navigation will |
1872 // be MANUAL_SUBFRAME. | 1954 // be MANUAL_SUBFRAME. |
1873 GURL subframe_url(embedded_test_server()->GetURL( | 1955 GURL subframe_url(embedded_test_server()->GetURL( |
1874 "/navigation_controller/simple_page_1.html")); | 1956 "/navigation_controller/simple_page_1.html")); |
1875 { | 1957 { |
1876 LoadCommittedCapturer capturer(root->child_at(0)); | 1958 LoadCommittedCapturer capturer(root->child_at(0)); |
1877 NavigateFrameToURL(root->child_at(0), subframe_url); | 1959 NavigateFrameToURL(root->child_at(0), subframe_url); |
1878 capturer.Wait(); | 1960 capturer.Wait(); |
1879 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 1961 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, capturer.transition_type()); |
1880 } | 1962 } |
1881 | 1963 |
1882 // 2. In-page navigation in the main frame. | 1964 // 2. In-page navigation in the main frame. |
1883 std::string push_script = "history.pushState({}, 'page 2', 'page_2.html')"; | 1965 std::string push_script = "history.pushState({}, 'page 2', 'page_2.html')"; |
1884 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), push_script)); | 1966 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), push_script)); |
1885 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 1967 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
1886 | 1968 |
1887 // TODO(creis): Verify subframe entries. https://crbug.com/522193. | 1969 // TODO(creis): Verify subframe entries. https://crbug.com/522193. |
1888 | 1970 |
1889 // 3. Add a nested subframe. | 1971 // 3. Add a nested subframe. |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3139 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) { | 3221 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) { |
3140 GURL original_url(embedded_test_server()->GetURL( | 3222 GURL original_url(embedded_test_server()->GetURL( |
3141 "/navigation_controller/simple_page_1.html")); | 3223 "/navigation_controller/simple_page_1.html")); |
3142 NavigateToURL(shell(), original_url); | 3224 NavigateToURL(shell(), original_url); |
3143 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 3225 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
3144 ->GetFrameTree() | 3226 ->GetFrameTree() |
3145 ->root(); | 3227 ->root(); |
3146 RenderProcessKilledObserver kill_observer(shell()->web_contents()); | 3228 RenderProcessKilledObserver kill_observer(shell()->web_contents()); |
3147 | 3229 |
3148 // Redirect so that we can use ReloadOriginalRequest. | 3230 // Redirect so that we can use ReloadOriginalRequest. |
| 3231 // TODO(creis): The test is failing because this replacement isn't preserving |
| 3232 // the redirect chain or original_request_url for a cross process transfer. |
| 3233 // I think it worked before because those values stuck around when we just |
| 3234 // updated the old NavEntry, but that's not a safe thing to do on a |
| 3235 // SiteInstance change. Instead, we should propagate them during the transfer |
| 3236 // so that they show up in the new commit. |
| 3237 // We appear to be trying to propagate the redirect chain, but the request in |
| 3238 // the network stack doesn't have the earlier items in the chain. Is this a |
| 3239 // bug or expected? Does it apply to all client redirects, or just this test? |
| 3240 // Does it apply to server redirects? |
3149 GURL redirect_url(embedded_test_server()->GetURL( | 3241 GURL redirect_url(embedded_test_server()->GetURL( |
3150 "foo.com", "/navigation_controller/simple_page_1.html")); | 3242 "foo.com", "/navigation_controller/simple_page_1.html")); |
3151 { | 3243 { |
3152 std::string script = "location.replace('" + redirect_url.spec() + "');"; | 3244 std::string script = "location.replace('" + redirect_url.spec() + "');"; |
3153 FrameNavigateParamsCapturer capturer(root); | 3245 FrameNavigateParamsCapturer capturer(root); |
3154 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | 3246 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); |
3155 capturer.Wait(); | 3247 capturer.Wait(); |
3156 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, | 3248 EXPECT_EQ(ui::PAGE_TRANSITION_LINK | ui::PAGE_TRANSITION_CLIENT_REDIRECT, |
3157 capturer.params().transition); | 3249 capturer.params().transition); |
3158 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 3250 EXPECT_EQ(NAVIGATION_TYPE_NEW_PAGE, capturer.details().type); |
3159 } | 3251 } |
3160 | 3252 |
3161 // Modify an entry in the session history and reload the original request. | 3253 // Modify an entry in the session history and reload the original request. |
3162 { | 3254 { |
3163 // We first send a replaceState() to the renderer, which will cause the | 3255 // We first send a replaceState() to the renderer, which will cause the |
3164 // renderer to send back a DidCommitProvisionalLoad. Immediately after, | 3256 // renderer to send back a DidCommitProvisionalLoad. Immediately after, |
3165 // we send a ReloadOriginalRequest (which in this case is a different | 3257 // we send a ReloadOriginalRequest (which in this case is a different |
3166 // origin) and will also cause the renderer to commit the frame. In the | 3258 // origin) and will also cause the renderer to commit the frame. In the |
3167 // end we verify that both navigations committed and that the URLs are | 3259 // end we verify that both navigations committed and that the URLs are |
3168 // correct. | 3260 // correct. |
3169 std::string script = "history.replaceState({}, '', 'foo');"; | 3261 std::string script = "history.replaceState({}, '', 'foo');"; |
3170 root->render_manager() | 3262 root->render_manager() |
3171 ->current_frame_host() | 3263 ->current_frame_host() |
3172 ->ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script)); | 3264 ->ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script)); |
3173 EXPECT_FALSE(shell()->web_contents()->IsLoading()); | 3265 EXPECT_FALSE(shell()->web_contents()->IsLoading()); |
3174 shell()->web_contents()->GetController().ReloadOriginalRequestURL(false); | 3266 shell()->web_contents()->GetController().ReloadOriginalRequestURL(false); |
3175 EXPECT_TRUE(shell()->web_contents()->IsLoading()); | 3267 EXPECT_TRUE(shell()->web_contents()->IsLoading()); |
3176 EXPECT_EQ(redirect_url, shell()->web_contents()->GetLastCommittedURL()); | 3268 EXPECT_EQ(redirect_url, shell()->web_contents()->GetLastCommittedURL()); |
3177 | 3269 |
3178 // Wait until there's no more navigations. | 3270 // Wait until there's no more navigations. |
3179 GURL modified_url(embedded_test_server()->GetURL( | 3271 GURL modified_url(embedded_test_server()->GetURL( |
3180 "foo.com", "/navigation_controller/foo")); | 3272 "foo.com", "/navigation_controller/foo")); |
3181 FrameNavigateParamsCapturer capturer(root); | 3273 FrameNavigateParamsCapturer capturer(root); |
3182 capturer.set_wait_for_load(false); | 3274 capturer.set_wait_for_load(false); |
3183 capturer.set_navigations_remaining(2); | 3275 capturer.set_navigations_remaining(2); |
3184 capturer.Wait(); | 3276 capturer.Wait(); |
3185 EXPECT_EQ(2U, capturer.all_details().size()); | 3277 EXPECT_EQ(2U, capturer.all_details().size()); |
| 3278 // TODO(creis): This is failing in --site-per-process. |
3186 EXPECT_EQ(modified_url, capturer.all_params()[0].url); | 3279 EXPECT_EQ(modified_url, capturer.all_params()[0].url); |
3187 EXPECT_EQ(original_url, capturer.all_params()[1].url); | 3280 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
3188 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 3281 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
3189 } | 3282 } |
3190 | 3283 |
3191 // Make sure the renderer is still alive. | 3284 // Make sure the renderer is still alive. |
3192 EXPECT_TRUE( | 3285 EXPECT_TRUE( |
3193 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 3286 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
3194 } | 3287 } |
3195 | 3288 |
3196 } // namespace content | 3289 } // namespace content |
OLD | NEW |