OLD | NEW |
---|---|
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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
838 const GURL kGURL(kUrl); | 839 const GURL kGURL(kUrl); |
839 NavigateToURL(shell(), kGURL); | 840 NavigateToURL(shell(), kGURL); |
840 EXPECT_EQ(base::ASCIIToUTF16(kUrl), shell()->web_contents()->GetTitle()); | 841 EXPECT_EQ(base::ASCIIToUTF16(kUrl), shell()->web_contents()->GetTitle()); |
841 EXPECT_TRUE(shell() | 842 EXPECT_TRUE(shell() |
842 ->web_contents() | 843 ->web_contents() |
843 ->GetController() | 844 ->GetController() |
844 .GetLastCommittedEntry() | 845 .GetLastCommittedEntry() |
845 ->IsViewSourceMode()); | 846 ->IsViewSourceMode()); |
846 } | 847 } |
847 | 848 |
849 namespace { | |
850 const char kDataUrlWarningPattern[] = | |
851 "Upcoming versions will block content-initiated top frame navigations*"; | |
852 | |
853 // This class listens for console messages other than the data: URL warning. It | |
854 // fails the test if it sees a data: URL warning. | |
855 class NoDataURLWarningConsoleObserverDelegate : public ConsoleObserverDelegate { | |
856 public: | |
857 using ConsoleObserverDelegate::ConsoleObserverDelegate; | |
858 // WebContentsDelegate method: | |
859 bool DidAddMessageToConsole(WebContents* source, | |
860 int32_t level, | |
861 const base::string16& message, | |
862 int32_t line_no, | |
863 const base::string16& source_id) override { | |
864 std::string ascii_message = base::UTF16ToASCII(message); | |
865 EXPECT_FALSE(base::MatchPattern(ascii_message, kDataUrlWarningPattern)); | |
866 return ConsoleObserverDelegate::DidAddMessageToConsole( | |
867 source, level, message, line_no, source_id); | |
868 } | |
869 }; | |
870 | |
871 } // namespace | |
872 | |
873 // Test that a direct navigation to a data URL doesn't show a console warning. | |
874 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DataURLDirectNavigation) { | |
875 ASSERT_TRUE(embedded_test_server()->Start()); | |
876 const GURL kUrl(embedded_test_server()->GetURL("/simple_page.html")); | |
877 | |
878 NoDataURLWarningConsoleObserverDelegate console_delegate( | |
879 shell()->web_contents(), "FINISH"); | |
880 shell()->web_contents()->SetDelegate(&console_delegate); | |
881 | |
882 NavigateToURL( | |
883 shell(), | |
884 GURL("data:text/html,<html><script>console.log('FINISH');</script>")); | |
885 console_delegate.Wait(); | |
886 EXPECT_TRUE(shell()->web_contents()->GetURL().SchemeIs(url::kDataScheme)); | |
887 EXPECT_FALSE( | |
888 base::MatchPattern(console_delegate.message(), kDataUrlWarningPattern)); | |
889 } | |
890 | |
891 // Test that window.open to a data URL shows a console warning. | |
Charlie Reis
2017/02/15 23:36:43
Just curious-- have you checked whether any of our
meacer
2017/02/16 01:58:43
Yes, there are tests that use data URLs. Some exam
Charlie Reis
2017/02/16 17:59:50
Ah, ok. So we'll have to update the ones that hav
| |
892 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
893 DataURLWindowOpen_ShouldWarn) { | |
894 ASSERT_TRUE(embedded_test_server()->Start()); | |
895 const GURL kUrl(embedded_test_server()->GetURL("/simple_page.html")); | |
896 NavigateToURL(shell(), kUrl); | |
897 | |
898 ShellAddedObserver new_shell_observer; | |
899 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | |
900 "window.open('data:text/plain,test');")); | |
901 Shell* new_shell = new_shell_observer.GetShell(); | |
902 | |
903 ConsoleObserverDelegate console_delegate( | |
904 new_shell->web_contents(), | |
905 "Upcoming versions will block content-initiated top frame navigations*"); | |
906 new_shell->web_contents()->SetDelegate(&console_delegate); | |
907 console_delegate.Wait(); | |
908 EXPECT_TRUE(new_shell->web_contents()->GetURL().SchemeIs(url::kDataScheme)); | |
909 } | |
910 | |
911 // Test that a content initiated navigation to a data URL shows a console | |
912 // warning. | |
913 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DataURLRedirect_ShouldWarn) { | |
914 ASSERT_TRUE(embedded_test_server()->Start()); | |
915 const GURL kUrl(embedded_test_server()->GetURL("/simple_page.html")); | |
916 NavigateToURL(shell(), kUrl); | |
917 | |
918 ConsoleObserverDelegate console_delegate( | |
919 shell()->web_contents(), | |
920 "Upcoming versions will block content-initiated top frame navigations*"); | |
921 shell()->web_contents()->SetDelegate(&console_delegate); | |
922 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | |
923 "window.location.href = 'data:text/plain,test';")); | |
924 console_delegate.Wait(); | |
925 EXPECT_TRUE(shell() | |
926 ->web_contents() | |
927 ->GetController() | |
928 .GetLastCommittedEntry() | |
929 ->GetURL() | |
930 .SchemeIs(url::kDataScheme)); | |
931 } | |
932 | |
848 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { | 933 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { |
849 ASSERT_TRUE(embedded_test_server()->Start()); | 934 ASSERT_TRUE(embedded_test_server()->Start()); |
850 | 935 |
851 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); | 936 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); |
852 EXPECT_TRUE(NavigateToURL(shell(), url)); | 937 EXPECT_TRUE(NavigateToURL(shell(), url)); |
853 | 938 |
854 { | 939 { |
855 ShellAddedObserver new_shell_observer; | 940 ShellAddedObserver new_shell_observer; |
856 | 941 |
857 // Open a new, named window. | 942 // Open a new, named window. |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1319 // Make sure the WebContents cleaned up the previous pending request. A new | 1404 // Make sure the WebContents cleaned up the previous pending request. A new |
1320 // request should be forwarded to the WebContentsDelegate. | 1405 // request should be forwarded to the WebContentsDelegate. |
1321 delegate.get()->request_to_lock_mouse_called_ = false; | 1406 delegate.get()->request_to_lock_mouse_called_ = false; |
1322 ASSERT_TRUE(ExecuteScript(shell(), | 1407 ASSERT_TRUE(ExecuteScript(shell(), |
1323 "window.domAutomationController.send(document.body." | 1408 "window.domAutomationController.send(document.body." |
1324 "requestPointerLock());")); | 1409 "requestPointerLock());")); |
1325 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_); | 1410 EXPECT_TRUE(delegate.get()->request_to_lock_mouse_called_); |
1326 } | 1411 } |
1327 | 1412 |
1328 } // namespace content | 1413 } // namespace content |
OLD | NEW |