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" |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 ChildFrameAt(shell()->web_contents()->GetMainFrame(), 0); | 932 ChildFrameAt(shell()->web_contents()->GetMainFrame(), 0); |
933 ASSERT_TRUE(child); | 933 ASSERT_TRUE(child); |
934 if (AreAllSitesIsolatedForTesting()) { | 934 if (AreAllSitesIsolatedForTesting()) { |
935 ASSERT_TRUE(child->IsCrossProcessSubframe()); | 935 ASSERT_TRUE(child->IsCrossProcessSubframe()); |
936 } | 936 } |
937 ExecuteScriptAndCheckNavigationDownload( | 937 ExecuteScriptAndCheckNavigationDownload( |
938 child, "document.getElementById('window-open-pdf').click()"); | 938 child, "document.getElementById('window-open-pdf').click()"); |
939 #endif | 939 #endif |
940 } | 940 } |
941 | 941 |
| 942 // Test case to verify that redirects to data: URLs are properly disallowed, |
| 943 // even when invoked through history navigations. |
| 944 // See https://crbug.com/723796. |
| 945 IN_PROC_BROWSER_TEST_F(DataUrlNavigationBrowserTest, |
| 946 WindowOpenRedirectAndBack) { |
| 947 NavigateToURL(shell(), |
| 948 embedded_test_server()->GetURL("/data_url_navigations.html")); |
| 949 |
| 950 // This test will need to navigate the newly opened window. |
| 951 ShellAddedObserver new_shell_observer; |
| 952 EXPECT_TRUE( |
| 953 ExecuteScript(shell()->web_contents(), |
| 954 "document.getElementById('window-open-redirect').click()")); |
| 955 Shell* new_shell = new_shell_observer.GetShell(); |
| 956 NavigationController* controller = |
| 957 &new_shell->web_contents()->GetController(); |
| 958 WaitForLoadStop(new_shell->web_contents()); |
| 959 |
| 960 // 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 { |
| 963 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); |
| 964 NavigationEntry* entry = controller->GetLastCommittedEntry(); |
| 965 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType()); |
| 966 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); |
| 967 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme)); |
| 968 } |
| 969 |
| 970 // 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 |
| 972 // pressing the back button. |
| 973 EXPECT_TRUE( |
| 974 NavigateToURL(new_shell, embedded_test_server()->GetURL("/title1.html"))); |
| 975 EXPECT_EQ(1, controller->GetLastCommittedEntryIndex()); |
| 976 { |
| 977 TestNavigationObserver observer(new_shell->web_contents()); |
| 978 controller->GoBack(); |
| 979 observer.Wait(); |
| 980 |
| 981 NavigationEntry* entry = controller->GetLastCommittedEntry(); |
| 982 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); |
| 983 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); |
| 984 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme)); |
| 985 EXPECT_EQ(url::kAboutBlankURL, entry->GetURL().spec()); |
| 986 } |
| 987 |
| 988 // Do another new navigation, but then use JavaScript to navigate back, |
| 989 // equivalent to document executing JS. |
| 990 EXPECT_TRUE( |
| 991 NavigateToURL(new_shell, embedded_test_server()->GetURL("/title1.html"))); |
| 992 EXPECT_EQ(1, controller->GetLastCommittedEntryIndex()); |
| 993 { |
| 994 TestNavigationObserver observer(new_shell->web_contents()); |
| 995 EXPECT_TRUE(ExecuteScript(new_shell, "history.go(-1)")); |
| 996 observer.Wait(); |
| 997 |
| 998 NavigationEntry* entry = controller->GetLastCommittedEntry(); |
| 999 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex()); |
| 1000 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme)); |
| 1001 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme)); |
| 1002 EXPECT_EQ(url::kAboutBlankURL, entry->GetURL().spec()); |
| 1003 } |
| 1004 } |
| 1005 |
942 } // content | 1006 } // content |
OLD | NEW |