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 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 // Opens in same tab. | 872 // Opens in same tab. |
873 EXPECT_EQ(1u, Shell::windows().size()); | 873 EXPECT_EQ(1u, Shell::windows().size()); |
874 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); | 874 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); |
875 | 875 |
876 // Should have the same SiteInstance. | 876 // Should have the same SiteInstance. |
877 scoped_refptr<SiteInstance> noref_site_instance( | 877 scoped_refptr<SiteInstance> noref_site_instance( |
878 shell()->web_contents()->GetSiteInstance()); | 878 shell()->web_contents()->GetSiteInstance()); |
879 EXPECT_EQ(orig_site_instance, noref_site_instance); | 879 EXPECT_EQ(orig_site_instance, noref_site_instance); |
880 } | 880 } |
881 | 881 |
| 882 // Test for crbug.com/9682. We should show the URL for a pending renderer- |
| 883 // initiated navigation in a new tab, until the content of the initial |
| 884 // about:blank page is modified by another window. At that point, we should |
| 885 // revert to showing about:blank to prevent a URL spoof. |
| 886 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ShowLoadingURLUntilSpoof) { |
| 887 ASSERT_TRUE(test_server()->Start()); |
| 888 |
| 889 // Load a page that can open a URL that won't commit in a new window. |
| 890 NavigateToURL( |
| 891 shell(), test_server()->GetURL("files/click-nocontent-link.html")); |
| 892 WebContents* orig_contents = shell()->web_contents(); |
| 893 |
| 894 // Click a /nocontent link that opens in a new window but never commits. |
| 895 ShellAddedObserver new_shell_observer; |
| 896 bool success = false; |
| 897 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 898 orig_contents, |
| 899 "window.domAutomationController.send(clickNoContentTargetedLink());", |
| 900 &success)); |
| 901 EXPECT_TRUE(success); |
| 902 |
| 903 // Wait for the window to open. |
| 904 Shell* new_shell = new_shell_observer.GetShell(); |
| 905 |
| 906 // Ensure the destination URL is visible, because it is considered the |
| 907 // initial navigation. |
| 908 WebContents* contents = new_shell->web_contents(); |
| 909 EXPECT_TRUE(contents->GetController().IsInitialNavigation()); |
| 910 EXPECT_EQ("/nocontent", |
| 911 contents->GetController().GetVisibleEntry()->GetURL().path()); |
| 912 |
| 913 // Now modify the contents of the new window from the opener. This will also |
| 914 // modify the title of the document to give us something to listen for. |
| 915 WindowedNotificationObserver title_observer( |
| 916 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 917 Source<WebContents>(contents)); |
| 918 success = false; |
| 919 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 920 orig_contents, |
| 921 "window.domAutomationController.send(modifyNewWindow());", |
| 922 &success)); |
| 923 EXPECT_TRUE(success); |
| 924 title_observer.Wait(); |
| 925 EXPECT_EQ(ASCIIToUTF16("Modified Title"), contents->GetTitle()); |
| 926 |
| 927 // At this point, we should no longer be showing the destination URL. |
| 928 // The visible entry should be null, resulting in about:blank in the address |
| 929 // bar. |
| 930 EXPECT_FALSE(contents->GetController().GetVisibleEntry()); |
| 931 } |
| 932 |
| 933 // Test for crbug.com/9682. We should not show the URL for a pending renderer- |
| 934 // initiated navigation in a new tab if it is not the initial navigation. In |
| 935 // this case, the renderer will not notify us of a modification, so we cannot |
| 936 // show the pending URL without allowing a spoof. |
| 937 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, |
| 938 DontShowLoadingURLIfNotInitialNav) { |
| 939 ASSERT_TRUE(test_server()->Start()); |
| 940 |
| 941 // Load a page that can open a URL that won't commit in a new window. |
| 942 NavigateToURL( |
| 943 shell(), test_server()->GetURL("files/click-nocontent-link.html")); |
| 944 WebContents* orig_contents = shell()->web_contents(); |
| 945 |
| 946 // Click a /nocontent link that opens in a new window but never commits. |
| 947 // By using an onclick handler that first creates the window, the slow |
| 948 // navigation is not considered an initial navigation. |
| 949 ShellAddedObserver new_shell_observer; |
| 950 bool success = false; |
| 951 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| 952 orig_contents, |
| 953 "window.domAutomationController.send(" |
| 954 "clickNoContentScriptedTargetedLink());", |
| 955 &success)); |
| 956 EXPECT_TRUE(success); |
| 957 |
| 958 // Wait for the window to open. |
| 959 Shell* new_shell = new_shell_observer.GetShell(); |
| 960 |
| 961 // Ensure the destination URL is not visible, because it is not the initial |
| 962 // navigation. |
| 963 WebContents* contents = new_shell->web_contents(); |
| 964 EXPECT_FALSE(contents->GetController().IsInitialNavigation()); |
| 965 EXPECT_FALSE(contents->GetController().GetVisibleEntry()); |
| 966 } |
| 967 |
882 // Test for http://crbug.com/93427. Ensure that cross-site navigations | 968 // Test for http://crbug.com/93427. Ensure that cross-site navigations |
883 // do not cause back/forward navigations to be considered stale by the | 969 // do not cause back/forward navigations to be considered stale by the |
884 // renderer. | 970 // renderer. |
885 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { | 971 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { |
886 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); | 972 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); |
887 | 973 |
888 // Start two servers with different sites. | 974 // Start two servers with different sites. |
889 ASSERT_TRUE(test_server()->Start()); | 975 ASSERT_TRUE(test_server()->Start()); |
890 net::TestServer https_server( | 976 net::TestServer https_server( |
891 net::TestServer::TYPE_HTTPS, | 977 net::TestServer::TYPE_HTTPS, |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); | 1496 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); |
1411 | 1497 |
1412 // Make sure it ends up at the right page. | 1498 // Make sure it ends up at the right page. |
1413 WaitForLoadStop(shell()->web_contents()); | 1499 WaitForLoadStop(shell()->web_contents()); |
1414 EXPECT_EQ(https_server.GetURL("files/title1.html"), | 1500 EXPECT_EQ(https_server.GetURL("files/title1.html"), |
1415 shell()->web_contents()->GetURL()); | 1501 shell()->web_contents()->GetURL()); |
1416 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); | 1502 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); |
1417 } | 1503 } |
1418 | 1504 |
1419 } // namespace content | 1505 } // namespace content |
OLD | NEW |