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

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 2741513002: [Merge M-57] Add a warning for the deprecation of content-initiated data URL navigations (Closed)
Patch Set: Created 3 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/macros.h" 5 #include "base/macros.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/pattern.h"
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "build/build_config.h" 10 #include "build/build_config.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 11 #include "content/browser/frame_host/navigation_entry_impl.h"
11 #include "content/browser/renderer_host/render_widget_host_impl.h" 12 #include "content/browser/renderer_host/render_widget_host_impl.h"
12 #include "content/browser/web_contents/web_contents_impl.h" 13 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/browser/web_contents/web_contents_view.h" 14 #include "content/browser/web_contents/web_contents_view.h"
14 #include "content/common/frame_messages.h" 15 #include "content/common/frame_messages.h"
15 #include "content/common/site_isolation_policy.h" 16 #include "content/common/site_isolation_policy.h"
16 #include "content/public/browser/javascript_dialog_manager.h" 17 #include "content/public/browser/javascript_dialog_manager.h"
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 const GURL kGURL(kUrl); 841 const GURL kGURL(kUrl);
841 NavigateToURL(shell(), kGURL); 842 NavigateToURL(shell(), kGURL);
842 EXPECT_EQ(base::ASCIIToUTF16(kUrl), shell()->web_contents()->GetTitle()); 843 EXPECT_EQ(base::ASCIIToUTF16(kUrl), shell()->web_contents()->GetTitle());
843 EXPECT_TRUE(shell() 844 EXPECT_TRUE(shell()
844 ->web_contents() 845 ->web_contents()
845 ->GetController() 846 ->GetController()
846 .GetLastCommittedEntry() 847 .GetLastCommittedEntry()
847 ->IsViewSourceMode()); 848 ->IsViewSourceMode());
848 } 849 }
849 850
851 namespace {
852 const char kDataUrlWarningPattern[] =
853 "Upcoming versions will block content-initiated top frame navigations*";
854
855 // This class listens for console messages other than the data: URL warning. It
856 // fails the test if it sees a data: URL warning.
857 class NoDataURLWarningConsoleObserverDelegate : public ConsoleObserverDelegate {
858 public:
859 using ConsoleObserverDelegate::ConsoleObserverDelegate;
860 // WebContentsDelegate method:
861 bool DidAddMessageToConsole(WebContents* source,
862 int32_t level,
863 const base::string16& message,
864 int32_t line_no,
865 const base::string16& source_id) override {
866 std::string ascii_message = base::UTF16ToASCII(message);
867 EXPECT_FALSE(base::MatchPattern(ascii_message, kDataUrlWarningPattern));
868 return ConsoleObserverDelegate::DidAddMessageToConsole(
869 source, level, message, line_no, source_id);
870 }
871 };
872
873 } // namespace
874
875 // Test that a direct navigation to a data URL doesn't show a console warning.
876 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DataURLDirectNavigation) {
877 ASSERT_TRUE(embedded_test_server()->Start());
878 const GURL kUrl(embedded_test_server()->GetURL("/simple_page.html"));
879
880 NoDataURLWarningConsoleObserverDelegate console_delegate(
881 shell()->web_contents(), "FINISH");
882 shell()->web_contents()->SetDelegate(&console_delegate);
883
884 NavigateToURL(
885 shell(),
886 GURL("data:text/html,<html><script>console.log('FINISH');</script>"));
887 console_delegate.Wait();
888 EXPECT_TRUE(shell()->web_contents()->GetURL().SchemeIs(url::kDataScheme));
889 EXPECT_FALSE(
890 base::MatchPattern(console_delegate.message(), kDataUrlWarningPattern));
891 }
892
893 // Test that window.open to a data URL shows a console warning.
894 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
895 DataURLWindowOpen_ShouldWarn) {
896 ASSERT_TRUE(embedded_test_server()->Start());
897 const GURL kUrl(embedded_test_server()->GetURL("/simple_page.html"));
898 NavigateToURL(shell(), kUrl);
899
900 ShellAddedObserver new_shell_observer;
901 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
902 "window.open('data:text/plain,test');"));
903 Shell* new_shell = new_shell_observer.GetShell();
904
905 ConsoleObserverDelegate console_delegate(
906 new_shell->web_contents(),
907 "Upcoming versions will block content-initiated top frame navigations*");
908 new_shell->web_contents()->SetDelegate(&console_delegate);
909 console_delegate.Wait();
910 EXPECT_TRUE(new_shell->web_contents()->GetURL().SchemeIs(url::kDataScheme));
911 }
912
913 // Test that a content initiated navigation to a data URL shows a console
914 // warning.
915 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DataURLRedirect_ShouldWarn) {
916 ASSERT_TRUE(embedded_test_server()->Start());
917 const GURL kUrl(embedded_test_server()->GetURL("/simple_page.html"));
918 NavigateToURL(shell(), kUrl);
919
920 ConsoleObserverDelegate console_delegate(
921 shell()->web_contents(),
922 "Upcoming versions will block content-initiated top frame navigations*");
923 shell()->web_contents()->SetDelegate(&console_delegate);
924 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
925 "window.location.href = 'data:text/plain,test';"));
926 console_delegate.Wait();
927 EXPECT_TRUE(shell()
928 ->web_contents()
929 ->GetController()
930 .GetLastCommittedEntry()
931 ->GetURL()
932 .SchemeIs(url::kDataScheme));
933 }
934
850 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { 935 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) {
851 ASSERT_TRUE(embedded_test_server()->Start()); 936 ASSERT_TRUE(embedded_test_server()->Start());
852 937
853 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); 938 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html");
854 EXPECT_TRUE(NavigateToURL(shell(), url)); 939 EXPECT_TRUE(NavigateToURL(shell(), url));
855 940
856 { 941 {
857 ShellAddedObserver new_shell_observer; 942 ShellAddedObserver new_shell_observer;
858 943
859 // Open a new, named window. 944 // Open a new, named window.
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 // Make sure the WebContents cleaned up the previous pending request. A new 1407 // Make sure the WebContents cleaned up the previous pending request. A new
1323 // request should be forwarded to the WebContentsDelegate. 1408 // request should be forwarded to the WebContentsDelegate.
1324 delegate.get()->request_to_lock_mouse_called_ = false; 1409 delegate.get()->request_to_lock_mouse_called_ = false;
1325 ASSERT_TRUE(ExecuteScript(shell(), 1410 ASSERT_TRUE(ExecuteScript(shell(),
1326 "window.domAutomationController.send(document.body." 1411 "window.domAutomationController.send(document.body."
1327 "requestPointerLock());")); 1412 "requestPointerLock());"));
1328 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_); 1413 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_);
1329 } 1414 }
1330 1415
1331 } // namespace content 1416 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698