OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/pattern.h" | 10 #include "base/strings/pattern.h" |
| 11 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "base/test/scoped_feature_list.h" | 13 #include "base/test/scoped_feature_list.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "build/buildflag.h" | 15 #include "build/buildflag.h" |
15 #include "content/browser/site_per_process_browsertest.h" | 16 #include "content/browser/site_per_process_browsertest.h" |
16 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
19 #include "content/public/common/browser_side_navigation_policy.h" | 20 #include "content/public/common/browser_side_navigation_policy.h" |
20 #include "content/public/common/content_features.h" | 21 #include "content/public/common/content_features.h" |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 EXPECT_TRUE( | 953 EXPECT_TRUE( |
953 ExecuteScript(shell()->web_contents(), | 954 ExecuteScript(shell()->web_contents(), |
954 "document.getElementById('window-open-redirect').click()")); | 955 "document.getElementById('window-open-redirect').click()")); |
955 Shell* new_shell = new_shell_observer.GetShell(); | 956 Shell* new_shell = new_shell_observer.GetShell(); |
956 NavigationController* controller = | 957 NavigationController* controller = |
957 &new_shell->web_contents()->GetController(); | 958 &new_shell->web_contents()->GetController(); |
958 WaitForLoadStop(new_shell->web_contents()); | 959 WaitForLoadStop(new_shell->web_contents()); |
959 | 960 |
960 // The window.open() should have resulted in an error page. The blocked | 961 // The window.open() should have resulted in an error page. The blocked |
961 // URL should be in the virtual URL, not the actual URL. | 962 // URL should be in the virtual URL, not the actual URL. |
| 963 // |
| 964 // TODO(nasko): Now that the error commits on the previous URL, the blocked |
| 965 // navigation logic is no longer needed. |
962 { | 966 { |
963 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); | 967 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); |
964 NavigationEntry* entry = controller->GetLastCommittedEntry(); | 968 NavigationEntry* entry = controller->GetLastCommittedEntry(); |
965 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); | 969 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
966 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); | 970 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); |
967 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme)); | 971 EXPECT_TRUE(base::StartsWith( |
| 972 entry->GetVirtualURL().spec(), |
| 973 embedded_test_server()->GetURL("/server-redirect?").spec(), |
| 974 base::CompareCase::SENSITIVE)); |
968 } | 975 } |
969 | 976 |
970 // Navigate forward and then go back to ensure the navigation to data: URL | 977 // Navigate forward and then go back to ensure the navigation to data: URL |
971 // is blocked. Use a browser-initiated back navigation, equivalent to user | 978 // is blocked. Use a browser-initiated back navigation, equivalent to user |
972 // pressing the back button. | 979 // pressing the back button. |
973 EXPECT_TRUE( | 980 EXPECT_TRUE( |
974 NavigateToURL(new_shell, embedded_test_server()->GetURL("/title1.html"))); | 981 NavigateToURL(new_shell, embedded_test_server()->GetURL("/title1.html"))); |
975 EXPECT_EQ(1, controller->GetLastCommittedEntryIndex()); | 982 EXPECT_EQ(1, controller->GetLastCommittedEntryIndex()); |
976 { | 983 { |
977 TestNavigationObserver observer(new_shell->web_contents()); | 984 TestNavigationObserver observer(new_shell->web_contents()); |
978 controller->GoBack(); | 985 controller->GoBack(); |
979 observer.Wait(); | 986 observer.Wait(); |
980 | 987 |
981 NavigationEntry* entry = controller->GetLastCommittedEntry(); | 988 NavigationEntry* entry = controller->GetLastCommittedEntry(); |
982 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); | 989 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); |
983 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); | 990 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); |
984 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme)); | 991 EXPECT_TRUE(base::StartsWith( |
| 992 entry->GetVirtualURL().spec(), |
| 993 embedded_test_server()->GetURL("/server-redirect?").spec(), |
| 994 base::CompareCase::SENSITIVE)); |
985 EXPECT_EQ(url::kAboutBlankURL, entry->GetURL().spec()); | 995 EXPECT_EQ(url::kAboutBlankURL, entry->GetURL().spec()); |
986 } | 996 } |
987 | 997 |
988 // Do another new navigation, but then use JavaScript to navigate back, | 998 // Do another new navigation, but then use JavaScript to navigate back, |
989 // equivalent to document executing JS. | 999 // equivalent to document executing JS. |
990 EXPECT_TRUE( | 1000 EXPECT_TRUE( |
991 NavigateToURL(new_shell, embedded_test_server()->GetURL("/title1.html"))); | 1001 NavigateToURL(new_shell, embedded_test_server()->GetURL("/title1.html"))); |
992 EXPECT_EQ(1, controller->GetLastCommittedEntryIndex()); | 1002 EXPECT_EQ(1, controller->GetLastCommittedEntryIndex()); |
993 { | 1003 { |
994 TestNavigationObserver observer(new_shell->web_contents()); | 1004 TestNavigationObserver observer(new_shell->web_contents()); |
995 EXPECT_TRUE(ExecuteScript(new_shell, "history.go(-1)")); | 1005 EXPECT_TRUE(ExecuteScript(new_shell, "history.go(-1)")); |
996 observer.Wait(); | 1006 observer.Wait(); |
997 | 1007 |
998 NavigationEntry* entry = controller->GetLastCommittedEntry(); | 1008 NavigationEntry* entry = controller->GetLastCommittedEntry(); |
999 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); | 1009 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); |
1000 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); | 1010 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); |
1001 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme)); | 1011 EXPECT_TRUE(base::StartsWith( |
| 1012 entry->GetVirtualURL().spec(), |
| 1013 embedded_test_server()->GetURL("/server-redirect?").spec(), |
| 1014 base::CompareCase::SENSITIVE)); |
1002 EXPECT_EQ(url::kAboutBlankURL, entry->GetURL().spec()); | 1015 EXPECT_EQ(url::kAboutBlankURL, entry->GetURL().spec()); |
1003 } | 1016 } |
1004 } | 1017 } |
1005 | 1018 |
1006 } // content | 1019 } // content |
OLD | NEW |