| 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 scoped_refptr<SiteInstance> new_site_instance2( | 837 scoped_refptr<SiteInstance> new_site_instance2( |
| 838 shell()->web_contents()->GetSiteInstance()); | 838 shell()->web_contents()->GetSiteInstance()); |
| 839 EXPECT_EQ(new_site_instance, new_site_instance2); | 839 EXPECT_EQ(new_site_instance, new_site_instance2); |
| 840 } | 840 } |
| 841 | 841 |
| 842 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 | 842 // Test for crbug.com/76666. A cross-site navigation that fails with a 204 |
| 843 // error should not make us ignore future renderer-initiated navigations. | 843 // error should not make us ignore future renderer-initiated navigations. |
| 844 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ClickLinkAfter204Error) { | 844 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ClickLinkAfter204Error) { |
| 845 StartServer(); | 845 StartServer(); |
| 846 | 846 |
| 847 // Load a page with links that open in a new window. | |
| 848 // The links will point to foo.com. | |
| 849 std::string replacement_path; | |
| 850 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 851 "files/click-noreferrer-links.html", | |
| 852 foo_host_port_, | |
| 853 &replacement_path)); | |
| 854 NavigateToURL(shell(), test_server()->GetURL(replacement_path)); | |
| 855 | |
| 856 // Get the original SiteInstance for later comparison. | 847 // Get the original SiteInstance for later comparison. |
| 857 scoped_refptr<SiteInstance> orig_site_instance( | 848 scoped_refptr<SiteInstance> orig_site_instance( |
| 858 shell()->web_contents()->GetSiteInstance()); | 849 shell()->web_contents()->GetSiteInstance()); |
| 859 EXPECT_TRUE(orig_site_instance.get() != NULL); | 850 EXPECT_TRUE(orig_site_instance.get() != NULL); |
| 860 | 851 |
| 861 // Load a cross-site page that fails with a 204 error. | 852 // Load a cross-site page that fails with a 204 error. |
| 862 NavigateToURL(shell(),GetCrossSiteURL("nocontent")); | 853 NavigateToURL(shell(), GetCrossSiteURL("nocontent")); |
| 863 | 854 |
| 864 // We should still be looking at the normal page. The typed URL will | 855 // We should still be looking at the normal page. Because we started from a |
| 865 // still be visible until the user clears it manually, but the last | 856 // blank new tab, the typed URL will still be visible until the user clears it |
| 866 // committed URL will be the previous page. | 857 // manually. The last committed URL will be the previous page. |
| 867 scoped_refptr<SiteInstance> post_nav_site_instance( | 858 scoped_refptr<SiteInstance> post_nav_site_instance( |
| 868 shell()->web_contents()->GetSiteInstance()); | 859 shell()->web_contents()->GetSiteInstance()); |
| 869 EXPECT_EQ(orig_site_instance, post_nav_site_instance); | 860 EXPECT_EQ(orig_site_instance, post_nav_site_instance); |
| 870 EXPECT_EQ("/nocontent", | 861 EXPECT_EQ("/nocontent", |
| 871 shell()->web_contents()->GetVisibleURL().path()); | 862 shell()->web_contents()->GetVisibleURL().path()); |
| 872 EXPECT_EQ("/files/click-noreferrer-links.html", | 863 EXPECT_FALSE( |
| 873 shell()->web_contents()->GetController(). | 864 shell()->web_contents()->GetController().GetLastCommittedEntry()); |
| 874 GetLastCommittedEntry()->GetVirtualURL().path()); | |
| 875 | 865 |
| 876 // Renderer-initiated navigations should work. | 866 // Renderer-initiated navigations should work. |
| 877 bool success = false; | 867 base::string16 expected_title = ASCIIToUTF16("Title Of Awesomeness"); |
| 878 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 868 TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 869 GURL url = test_server()->GetURL("files/title2.html"); |
| 870 EXPECT_TRUE(ExecuteScript( |
| 879 shell()->web_contents(), | 871 shell()->web_contents(), |
| 880 "window.domAutomationController.send(clickNoRefLink());", | 872 base::StringPrintf("location.href = '%s'", url.spec().c_str()))); |
| 881 &success)); | 873 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 882 EXPECT_TRUE(success); | |
| 883 | |
| 884 // Wait for the cross-site transition in the current tab to finish. | |
| 885 WaitForLoadStop(shell()->web_contents()); | |
| 886 | 874 |
| 887 // Opens in same tab. | 875 // Opens in same tab. |
| 888 EXPECT_EQ(1u, Shell::windows().size()); | 876 EXPECT_EQ(1u, Shell::windows().size()); |
| 889 EXPECT_EQ("/files/title2.html", | 877 EXPECT_EQ("/files/title2.html", |
| 890 shell()->web_contents()->GetLastCommittedURL().path()); | 878 shell()->web_contents()->GetLastCommittedURL().path()); |
| 891 | 879 |
| 892 // Should have the same SiteInstance. | 880 // Should have the same SiteInstance. |
| 893 scoped_refptr<SiteInstance> noref_site_instance( | 881 scoped_refptr<SiteInstance> new_site_instance( |
| 894 shell()->web_contents()->GetSiteInstance()); | 882 shell()->web_contents()->GetSiteInstance()); |
| 895 EXPECT_EQ(orig_site_instance, noref_site_instance); | 883 EXPECT_EQ(orig_site_instance, new_site_instance); |
| 896 } | 884 } |
| 897 | 885 |
| 898 // Test for crbug.com/9682. We should show the URL for a pending renderer- | 886 // Test for crbug.com/9682. We should show the URL for a pending renderer- |
| 899 // initiated navigation in a new tab, until the content of the initial | 887 // initiated navigation in a new tab, until the content of the initial |
| 900 // about:blank page is modified by another window. At that point, we should | 888 // about:blank page is modified by another window. At that point, we should |
| 901 // revert to showing about:blank to prevent a URL spoof. | 889 // revert to showing about:blank to prevent a URL spoof. |
| 902 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ShowLoadingURLUntilSpoof) { | 890 IN_PROC_BROWSER_TEST_F(RenderFrameHostManagerTest, ShowLoadingURLUntilSpoof) { |
| 903 ASSERT_TRUE(test_server()->Start()); | 891 ASSERT_TRUE(test_server()->Start()); |
| 904 | 892 |
| 905 // Load a page that can open a URL that won't commit in a new window. | 893 // Load a page that can open a URL that won't commit in a new window. |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 // Go back and ensure we have no WebUI bindings. | 1387 // Go back and ensure we have no WebUI bindings. |
| 1400 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); | 1388 TestNavigationObserver back_nav_load_observer(shell()->web_contents()); |
| 1401 shell()->web_contents()->GetController().GoBack(); | 1389 shell()->web_contents()->GetController().GoBack(); |
| 1402 back_nav_load_observer.Wait(); | 1390 back_nav_load_observer.Wait(); |
| 1403 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 1391 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
| 1404 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1392 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 1405 shell()->web_contents()->GetRenderProcessHost()->GetID())); | 1393 shell()->web_contents()->GetRenderProcessHost()->GetID())); |
| 1406 } | 1394 } |
| 1407 | 1395 |
| 1408 } // namespace content | 1396 } // namespace content |
| OLD | NEW |