OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/json/json_reader.h" | 6 #include "base/json/json_reader.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 // Opens in same tab. | 886 // Opens in same tab. |
887 EXPECT_EQ(1u, Shell::windows().size()); | 887 EXPECT_EQ(1u, Shell::windows().size()); |
888 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); | 888 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); |
889 | 889 |
890 // Should have the same SiteInstance. | 890 // Should have the same SiteInstance. |
891 scoped_refptr<SiteInstance> noref_site_instance( | 891 scoped_refptr<SiteInstance> noref_site_instance( |
892 shell()->web_contents()->GetSiteInstance()); | 892 shell()->web_contents()->GetSiteInstance()); |
893 EXPECT_EQ(orig_site_instance, noref_site_instance); | 893 EXPECT_EQ(orig_site_instance, noref_site_instance); |
894 } | 894 } |
895 | 895 |
| 896 // Test for crbug.com/9682. We should show the URL for a pending renderer- |
| 897 // initiated navigation in a new tab, until the content of the initial |
| 898 // about:blank page is modified by another window. At that point, we should |
| 899 // revert to showing about:blank to prevent a URL spoof. |
| 900 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ShowLoadingURLUntilSpoof) { |
| 901 ASSERT_TRUE(test_server()->Start()); |
| 902 |
| 903 // Load a page that can open a URL that won't commit in a new window. |
| 904 NavigateToURL( |
| 905 shell(), test_server()->GetURL("files/click-nocontent-link.html")); |
| 906 WebContents* orig_contents = shell()->web_contents(); |
| 907 |
| 908 // Click a /nocontent link that opens in a new window but never commits. |
| 909 ShellAddedObserver new_shell_observer; |
| 910 bool success = false; |
| 911 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 912 orig_contents, |
| 913 "window.domAutomationController.send(clickNoContentTargetedLink());", |
| 914 &success)); |
| 915 EXPECT_TRUE(success); |
| 916 |
| 917 // Wait for the window to open. |
| 918 Shell* new_shell = new_shell_observer.GetShell(); |
| 919 |
| 920 // Ensure the destination URL is visible, because it is considered the |
| 921 // initial navigation. |
| 922 WebContents* contents = new_shell->web_contents(); |
| 923 EXPECT_TRUE(contents->GetController().IsInitialNavigation()); |
| 924 EXPECT_EQ("/nocontent", |
| 925 contents->GetController().GetVisibleEntry()->GetURL().path()); |
| 926 |
| 927 // Now modify the contents of the new window from the opener. This will also |
| 928 // modify the title of the document to give us something to listen for. |
| 929 WindowedNotificationObserver title_observer( |
| 930 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 931 Source<WebContents>(contents)); |
| 932 success = false; |
| 933 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 934 orig_contents, |
| 935 "window.domAutomationController.send(modifyNewWindow());", |
| 936 &success)); |
| 937 EXPECT_TRUE(success); |
| 938 title_observer.Wait(); |
| 939 EXPECT_EQ(ASCIIToUTF16("Modified Title"), contents->GetTitle()); |
| 940 |
| 941 // At this point, we should no longer be showing the destination URL. |
| 942 // The visible entry should be null, resulting in about:blank in the address |
| 943 // bar. |
| 944 EXPECT_FALSE(contents->GetController().GetVisibleEntry()); |
| 945 } |
| 946 |
| 947 // Test for crbug.com/9682. We should not show the URL for a pending renderer- |
| 948 // initiated navigation in a new tab if it is not the initial navigation. In |
| 949 // this case, the renderer will not notify us of a modification, so we cannot |
| 950 // show the pending URL without allowing a spoof. |
| 951 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
| 952 DontShowLoadingURLIfNotInitialNav) { |
| 953 ASSERT_TRUE(test_server()->Start()); |
| 954 |
| 955 // Load a page that can open a URL that won't commit in a new window. |
| 956 NavigateToURL( |
| 957 shell(), test_server()->GetURL("files/click-nocontent-link.html")); |
| 958 WebContents* orig_contents = shell()->web_contents(); |
| 959 |
| 960 // Click a /nocontent link that opens in a new window but never commits. |
| 961 // By using an onclick handler that first creates the window, the slow |
| 962 // navigation is not considered an initial navigation. |
| 963 ShellAddedObserver new_shell_observer; |
| 964 bool success = false; |
| 965 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 966 orig_contents, |
| 967 "window.domAutomationController.send(" |
| 968 "clickNoContentScriptedTargetedLink());", |
| 969 &success)); |
| 970 EXPECT_TRUE(success); |
| 971 |
| 972 // Wait for the window to open. |
| 973 Shell* new_shell = new_shell_observer.GetShell(); |
| 974 |
| 975 // Ensure the destination URL is not visible, because it is not the initial |
| 976 // navigation. |
| 977 WebContents* contents = new_shell->web_contents(); |
| 978 EXPECT_FALSE(contents->GetController().IsInitialNavigation()); |
| 979 EXPECT_FALSE(contents->GetController().GetVisibleEntry()); |
| 980 } |
| 981 |
896 // Test for http://crbug.com/93427. Ensure that cross-site navigations | 982 // Test for http://crbug.com/93427. Ensure that cross-site navigations |
897 // do not cause back/forward navigations to be considered stale by the | 983 // do not cause back/forward navigations to be considered stale by the |
898 // renderer. | 984 // renderer. |
899 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { | 985 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { |
900 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); | 986 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); |
901 | 987 |
902 // Start two servers with different sites. | 988 // Start two servers with different sites. |
903 ASSERT_TRUE(test_server()->Start()); | 989 ASSERT_TRUE(test_server()->Start()); |
904 net::TestServer https_server( | 990 net::TestServer https_server( |
905 net::TestServer::TYPE_HTTPS, | 991 net::TestServer::TYPE_HTTPS, |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); | 1510 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); |
1425 | 1511 |
1426 // Make sure it ends up at the right page. | 1512 // Make sure it ends up at the right page. |
1427 WaitForLoadStop(shell()->web_contents()); | 1513 WaitForLoadStop(shell()->web_contents()); |
1428 EXPECT_EQ(https_server.GetURL("files/title1.html"), | 1514 EXPECT_EQ(https_server.GetURL("files/title1.html"), |
1429 shell()->web_contents()->GetURL()); | 1515 shell()->web_contents()->GetURL()); |
1430 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); | 1516 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); |
1431 } | 1517 } |
1432 | 1518 |
1433 } // namespace content | 1519 } // namespace content |
OLD | NEW |