Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: content/browser/frame_host/data_url_navigation_browsertest.cc

Issue 2889003002: Change NavigationEntry to use virtual URL in error pages for blocked navigations (Closed)
Patch Set: Add a test for reload. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
Charlie Reis 2017/05/18 22:41:46 nit: Add "The blocked URL should be in the virtual
nasko 2017/05/18 22:55:11 Done.
961 {
962 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex());
963 NavigationEntry* entry = controller->GetLastCommittedEntry();
964 EXPECT_EQ(PAGE_TYPE_ERROR, entry->GetPageType());
965 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme));
966 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme));
967 }
968
969 // Navigate forward and then go back to ensure the navigation to data: URL
970 // is blocked. Use a browser-initiated back navigation, equivalent to user
971 // pressing the back button.
972 EXPECT_TRUE(
973 NavigateToURL(new_shell, embedded_test_server()->GetURL("/title1.html")));
974 EXPECT_EQ(1, controller->GetLastCommittedEntryIndex());
975 {
976 TestNavigationObserver observer(new_shell->web_contents());
977 controller->GoBack();
978 observer.Wait();
979
980 NavigationEntry* entry = controller->GetLastCommittedEntry();
981 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex());
982 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme));
983 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme));
984 EXPECT_EQ(url::kAboutBlankURL, entry->GetURL().spec());
985 }
986
987 // Do another new navigation, but then use JavaScript to navigate back,
988 // equivalent to document executing JS.
989 EXPECT_TRUE(
990 NavigateToURL(new_shell, embedded_test_server()->GetURL("/title1.html")));
991 EXPECT_EQ(1, controller->GetLastCommittedEntryIndex());
992 {
993 TestNavigationObserver observer(new_shell->web_contents());
994 EXPECT_TRUE(ExecuteScript(new_shell, "history.go(-1)"));
995 observer.Wait();
996
997 NavigationEntry* entry = controller->GetLastCommittedEntry();
998 EXPECT_EQ(0, controller->GetLastCommittedEntryIndex());
999 EXPECT_FALSE(entry->GetURL().SchemeIs(url::kDataScheme));
1000 EXPECT_TRUE(entry->GetVirtualURL().SchemeIs(url::kDataScheme));
1001 EXPECT_EQ(url::kAboutBlankURL, entry->GetURL().spec());
1002 }
1003 }
1004
942 } // content 1005 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698