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

Side by Side Diff: content/browser/renderer_host/render_view_host_manager_browsertest.cc

Issue 14283005: Allow showing pending URL for new tab navigations, but only if safe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h" 10 #include "content/browser/renderer_host/render_view_host_impl.h"
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 // Opens in same tab. 851 // Opens in same tab.
852 EXPECT_EQ(1u, Shell::windows().size()); 852 EXPECT_EQ(1u, Shell::windows().size());
853 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path()); 853 EXPECT_EQ("/files/title2.html", shell()->web_contents()->GetURL().path());
854 854
855 // Should have the same SiteInstance. 855 // Should have the same SiteInstance.
856 scoped_refptr<SiteInstance> noref_site_instance( 856 scoped_refptr<SiteInstance> noref_site_instance(
857 shell()->web_contents()->GetSiteInstance()); 857 shell()->web_contents()->GetSiteInstance());
858 EXPECT_EQ(orig_site_instance, noref_site_instance); 858 EXPECT_EQ(orig_site_instance, noref_site_instance);
859 } 859 }
860 860
861 // Test for crbug.com/9682. We should show the URL for a pending renderer-
862 // initiated navigation in a new tab, until the content of the initial
863 // about:blank page is modified by another window. At that point, we should
864 // revert to showing about:blank to prevent a URL spoof.
865 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, ShowLoadingURLUntilSpoof) {
866 ASSERT_TRUE(test_server()->Start());
867
868 // Load a page that can open a URL that won't commit in a new window.
869 NavigateToURL(
870 shell(), test_server()->GetURL("files/click-nocontent-link.html"));
871 WebContents* orig_contents = shell()->web_contents();
872
873 // Click a /nocontent link that opens in a new window but never commits.
874 ShellAddedObserver new_shell_observer;
875 bool success = false;
876 EXPECT_TRUE(ExecuteScriptAndExtractBool(
877 orig_contents,
878 "window.domAutomationController.send(clickNoContentTargetedLink());",
879 &success));
880 EXPECT_TRUE(success);
881
882 // Wait for the window to open.
883 Shell* new_shell = new_shell_observer.GetShell();
884
885 // Ensure the destination URL is visible, because it is considered the
886 // initial navigation.
887 WebContents* contents = new_shell->web_contents();
888 EXPECT_TRUE(contents->GetController().IsInitialNavigation());
889 EXPECT_EQ("/nocontent",
890 contents->GetController().GetVisibleEntry()->GetURL().path());
891
892 // Now modify the contents of the new window from the opener. This will also
893 // modify the title of the document to give us something to listen for.
894 WindowedNotificationObserver title_observer(
895 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
896 Source<WebContents>(contents));
897 success = false;
898 EXPECT_TRUE(ExecuteScriptAndExtractBool(
899 orig_contents,
900 "window.domAutomationController.send(modifyNewWindow());",
901 &success));
902 EXPECT_TRUE(success);
903 title_observer.Wait();
904 EXPECT_EQ(ASCIIToUTF16("Modified Title"), contents->GetTitle());
905
906 // At this point, we should no longer be showing the destination URL.
907 // The visible entry should be null, resulting in about:blank in the address
908 // bar.
909 EXPECT_FALSE(contents->GetController().GetVisibleEntry());
910 }
911
912 // Test for crbug.com/9682. We should not show the URL for a pending renderer-
913 // initiated navigation in a new tab if it is not the initial navigation. In
914 // this case, the renderer will not notify us of a modification, so we cannot
915 // show the pending URL without allowing a spoof.
916 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest,
917 DontShowLoadingURLIfNotInitialNav) {
918 ASSERT_TRUE(test_server()->Start());
919
920 // Load a page that can open a URL that won't commit in a new window.
921 NavigateToURL(
922 shell(), test_server()->GetURL("files/click-nocontent-link.html"));
923 WebContents* orig_contents = shell()->web_contents();
924
925 // Click a /nocontent link that opens in a new window but never commits.
926 // By using an onclick handler that first creates the window, the slow
927 // navigation is not considered an initial navigation.
928 ShellAddedObserver new_shell_observer;
929 bool success = false;
930 EXPECT_TRUE(ExecuteScriptAndExtractBool(
931 orig_contents,
932 "window.domAutomationController.send("
933 "clickNoContentScriptedTargetedLink());",
934 &success));
935 EXPECT_TRUE(success);
936
937 // Wait for the window to open.
938 Shell* new_shell = new_shell_observer.GetShell();
939
940 // Ensure the destination URL is not visible, because it is not the initial
941 // navigation.
942 WebContents* contents = new_shell->web_contents();
943 EXPECT_FALSE(contents->GetController().IsInitialNavigation());
944 EXPECT_FALSE(contents->GetController().GetVisibleEntry());
945 }
946
861 // Test for http://crbug.com/93427. Ensure that cross-site navigations 947 // Test for http://crbug.com/93427. Ensure that cross-site navigations
862 // do not cause back/forward navigations to be considered stale by the 948 // do not cause back/forward navigations to be considered stale by the
863 // renderer. 949 // renderer.
864 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) { 950 IN_PROC_BROWSER_TEST_F(RenderViewHostManagerTest, BackForwardNotStale) {
865 NavigateToURL(shell(), GURL(kAboutBlankURL)); 951 NavigateToURL(shell(), GURL(kAboutBlankURL));
866 952
867 // Start two servers with different sites. 953 // Start two servers with different sites.
868 ASSERT_TRUE(test_server()->Start()); 954 ASSERT_TRUE(test_server()->Start());
869 net::SpawnedTestServer https_server( 955 net::SpawnedTestServer https_server(
870 net::SpawnedTestServer::TYPE_HTTPS, 956 net::SpawnedTestServer::TYPE_HTTPS,
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 NavigateToURL(shell(), https_server.GetURL("files/title1.html")); 1308 NavigateToURL(shell(), https_server.GetURL("files/title1.html"));
1223 1309
1224 // Make sure it ends up at the right page. 1310 // Make sure it ends up at the right page.
1225 WaitForLoadStop(shell()->web_contents()); 1311 WaitForLoadStop(shell()->web_contents());
1226 EXPECT_EQ(https_server.GetURL("files/title1.html"), 1312 EXPECT_EQ(https_server.GetURL("files/title1.html"),
1227 shell()->web_contents()->GetURL()); 1313 shell()->web_contents()->GetURL());
1228 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance()); 1314 EXPECT_EQ(new_site_instance, shell()->web_contents()->GetSiteInstance());
1229 } 1315 }
1230 1316
1231 } // namespace content 1317 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | content/browser/web_contents/navigation_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698