| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/basictypes.h" | |
| 6 #include "base/command_line.h" | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | |
| 9 #include "content/public/browser/web_contents.h" | |
| 10 #include "content/public/common/content_switches.h" | |
| 11 #include "content/public/test/browser_test_utils.h" | |
| 12 #include "content/public/test/content_browser_test.h" | |
| 13 #include "content/public/test/content_browser_test_utils.h" | |
| 14 #include "content/public/test/test_navigation_observer.h" | |
| 15 #include "content/shell/browser/shell.h" | |
| 16 #include "net/dns/mock_host_resolver.h" | |
| 17 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { | |
| 23 public: | |
| 24 BrowserSideNavigationBrowserTest() {} | |
| 25 | |
| 26 protected: | |
| 27 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 28 command_line->AppendSwitch(switches::kEnableBrowserSideNavigation); | |
| 29 } | |
| 30 | |
| 31 void SetUpOnMainThread() override { | |
| 32 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 33 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 34 } | |
| 35 }; | |
| 36 | |
| 37 // Ensure that browser initiated basic navigations work with browser side | |
| 38 // navigation. | |
| 39 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, | |
| 40 BrowserInitiatedNavigations) { | |
| 41 // Perform a navigation with no live renderer. | |
| 42 { | |
| 43 TestNavigationObserver observer(shell()->web_contents()); | |
| 44 GURL url(embedded_test_server()->GetURL("/title1.html")); | |
| 45 NavigateToURL(shell(), url); | |
| 46 EXPECT_EQ(url, observer.last_navigation_url()); | |
| 47 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 48 } | |
| 49 | |
| 50 RenderFrameHost* initial_rfh = | |
| 51 static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 52 ->GetFrameTree()->root()->current_frame_host(); | |
| 53 | |
| 54 // Perform a same site navigation. | |
| 55 { | |
| 56 TestNavigationObserver observer(shell()->web_contents()); | |
| 57 GURL url(embedded_test_server()->GetURL("/title2.html")); | |
| 58 NavigateToURL(shell(), url); | |
| 59 EXPECT_EQ(url, observer.last_navigation_url()); | |
| 60 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 61 } | |
| 62 | |
| 63 // The RenderFrameHost should not have changed. | |
| 64 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 65 ->GetFrameTree()->root()->current_frame_host()); | |
| 66 | |
| 67 // Perform a cross-site navigation. | |
| 68 { | |
| 69 TestNavigationObserver observer(shell()->web_contents()); | |
| 70 GURL url = embedded_test_server()->GetURL("foo.com", "/title3.html"); | |
| 71 NavigateToURL(shell(), url); | |
| 72 EXPECT_EQ(url, observer.last_navigation_url()); | |
| 73 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 74 } | |
| 75 | |
| 76 // The RenderFrameHost should have changed. | |
| 77 EXPECT_NE(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 78 ->GetFrameTree()->root()->current_frame_host()); | |
| 79 } | |
| 80 | |
| 81 // Ensure that renderer initiated same-site navigations work with browser side | |
| 82 // navigation. | |
| 83 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, | |
| 84 RendererInitiatedSameSiteNavigation) { | |
| 85 // Perform a navigation with no live renderer. | |
| 86 { | |
| 87 TestNavigationObserver observer(shell()->web_contents()); | |
| 88 GURL url(embedded_test_server()->GetURL("/simple_links.html")); | |
| 89 NavigateToURL(shell(), url); | |
| 90 EXPECT_EQ(url, observer.last_navigation_url()); | |
| 91 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 92 } | |
| 93 | |
| 94 RenderFrameHost* initial_rfh = | |
| 95 static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 96 ->GetFrameTree()->root()->current_frame_host(); | |
| 97 | |
| 98 // Simulate clicking on a same-site link. | |
| 99 { | |
| 100 TestNavigationObserver observer(shell()->web_contents()); | |
| 101 GURL url(embedded_test_server()->GetURL("/title2.html")); | |
| 102 bool success = false; | |
| 103 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 104 shell()->web_contents(), | |
| 105 "window.domAutomationController.send(clickSameSiteLink());", &success)); | |
| 106 EXPECT_TRUE(success); | |
| 107 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 108 EXPECT_EQ(url, observer.last_navigation_url()); | |
| 109 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 110 } | |
| 111 | |
| 112 // The RenderFrameHost should not have changed. | |
| 113 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 114 ->GetFrameTree()->root()->current_frame_host()); | |
| 115 } | |
| 116 | |
| 117 // Ensure that renderer initiated cross-site navigations work with browser side | |
| 118 // navigation. | |
| 119 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, | |
| 120 RendererInitiatedCrossSiteNavigation) { | |
| 121 // Perform a navigation with no live renderer. | |
| 122 { | |
| 123 TestNavigationObserver observer(shell()->web_contents()); | |
| 124 GURL url(embedded_test_server()->GetURL("/simple_links.html")); | |
| 125 NavigateToURL(shell(), url); | |
| 126 EXPECT_EQ(url, observer.last_navigation_url()); | |
| 127 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 128 } | |
| 129 | |
| 130 RenderFrameHost* initial_rfh = | |
| 131 static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 132 ->GetFrameTree()->root()->current_frame_host(); | |
| 133 | |
| 134 // Simulate clicking on a cross-site link. | |
| 135 { | |
| 136 TestNavigationObserver observer(shell()->web_contents()); | |
| 137 const char kReplacePortNumber[] = | |
| 138 "window.domAutomationController.send(setPortNumber(%d));"; | |
| 139 uint16 port_number = embedded_test_server()->port(); | |
| 140 GURL url = embedded_test_server()->GetURL("foo.com", "/title2.html"); | |
| 141 bool success = false; | |
| 142 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 143 shell()->web_contents(), | |
| 144 base::StringPrintf(kReplacePortNumber, port_number), | |
| 145 &success)); | |
| 146 success = false; | |
| 147 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 148 shell()->web_contents(), | |
| 149 "window.domAutomationController.send(clickCrossSiteLink());", | |
| 150 &success)); | |
| 151 EXPECT_TRUE(success); | |
| 152 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 153 EXPECT_EQ(url, observer.last_navigation_url()); | |
| 154 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 155 } | |
| 156 | |
| 157 // The RenderFrameHost should have changed. | |
| 158 EXPECT_NE(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 159 ->GetFrameTree()->root()->current_frame_host()); | |
| 160 } | |
| 161 | |
| 162 } // namespace content | |
| OLD | NEW |