Chromium Code Reviews| 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/command_line.h" | |
| 6 #include "content/browser/web_contents/web_contents_impl.h" | |
| 7 #include "content/public/browser/web_contents.h" | |
| 8 #include "content/public/common/content_switches.h" | |
| 9 #include "content/public/test/browser_test_utils.h" | |
| 10 #include "content/public/test/content_browser_test.h" | |
| 11 #include "content/public/test/content_browser_test_utils.h" | |
| 12 #include "content/shell/browser/shell.h" | |
| 13 #include "content/test/content_browser_test_utils_internal.h" | |
| 14 #include "net/dns/mock_host_resolver.h" | |
| 15 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 16 #include "url/gurl.h" | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { | |
| 21 public: | |
| 22 BrowserSideNavigationBrowserTest() {} | |
| 23 | |
| 24 protected: | |
| 25 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 26 command_line->AppendSwitch(switches::kEnableBrowserSideNavigation); | |
| 27 } | |
| 28 | |
| 29 void SetUpOnMainThread() override { | |
| 30 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 31 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 32 } | |
| 33 }; | |
| 34 | |
| 35 // Ensure that browser initiated basic navigations work with browser side | |
| 36 // navigation. | |
| 37 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, | |
| 38 BrowserInitiatedNavigations) { | |
| 39 // Perform a navigation with no live renderer. | |
| 40 TestNavigationWebContentsObserver observer1(shell()->web_contents()); | |
| 41 GURL main_url1(embedded_test_server()->GetURL("/title1.html")); | |
| 42 NavigateToURL(shell(), main_url1); | |
| 43 EXPECT_EQ(main_url1, observer1.navigation_url()); | |
| 44 EXPECT_TRUE(observer1.navigation_succeeded()); | |
| 45 | |
| 46 RenderFrameHost* initial_rfh = | |
| 47 static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 48 ->GetFrameTree()->root()->current_frame_host(); | |
| 49 | |
| 50 // Perform a same site navigation. | |
| 51 TestNavigationWebContentsObserver observer2(shell()->web_contents()); | |
|
nasko
2014/11/24 23:15:00
It will be a bit more readable if you scope each o
clamy
2014/11/26 12:47:42
Done.
| |
| 52 GURL main_url2(embedded_test_server()->GetURL("/title2.html")); | |
| 53 NavigateToURL(shell(), main_url2); | |
| 54 EXPECT_EQ(main_url2, observer2.navigation_url()); | |
| 55 EXPECT_TRUE(observer2.navigation_succeeded()); | |
| 56 | |
| 57 // The RenderFrameHost should not have changed. | |
| 58 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 59 ->GetFrameTree()->root()->current_frame_host()); | |
| 60 | |
| 61 // Perform a cross-site navigation. | |
| 62 TestNavigationWebContentsObserver observer3(shell()->web_contents()); | |
| 63 GURL main_url3 = embedded_test_server()->GetURL("foo.com", "/title3.html"); | |
| 64 NavigateToURL(shell(), main_url3); | |
| 65 EXPECT_EQ(main_url3, observer3.navigation_url()); | |
| 66 EXPECT_TRUE(observer3.navigation_succeeded()); | |
| 67 | |
| 68 // The RenderFrameHost should have changed. | |
| 69 EXPECT_NE(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 70 ->GetFrameTree()->root()->current_frame_host()); | |
| 71 } | |
| 72 | |
| 73 // Ensure that renderer initiated basic navigations work with browser side | |
| 74 // navigation. | |
| 75 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, | |
| 76 RendererInitiatedNavigations) { | |
| 77 // Perform a navigation with no live renderer. | |
| 78 TestNavigationWebContentsObserver observer1(shell()->web_contents()); | |
| 79 GURL main_url1(embedded_test_server()->GetURL("/simple_links.html")); | |
|
nasko
2014/11/24 23:15:00
Any reason why the page that already exists doesn'
clamy
2014/11/26 12:47:42
I wanted a simpler page with simple links, both sa
nasko
2014/11/26 16:00:33
Acknowledged.
| |
| 80 NavigateToURL(shell(), main_url1); | |
| 81 EXPECT_EQ(main_url1, observer1.navigation_url()); | |
| 82 EXPECT_TRUE(observer1.navigation_succeeded()); | |
| 83 | |
| 84 RenderFrameHost* initial_rfh = | |
| 85 static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 86 ->GetFrameTree()->root()->current_frame_host(); | |
| 87 | |
| 88 // Simulate clicking on a same-site link. | |
| 89 TestNavigationWebContentsObserver observer2(shell()->web_contents()); | |
| 90 GURL main_url2(embedded_test_server()->GetURL("/title2.html")); | |
| 91 bool success = false; | |
| 92 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 93 shell()->web_contents(), | |
| 94 "window.domAutomationController.send(clickSameSiteLink());", &success)); | |
| 95 EXPECT_TRUE(success); | |
| 96 WaitForLoadStop(shell()->web_contents()); | |
|
nasko
2014/11/24 23:15:00
alexmos@ has done some recent work to add return v
clamy
2014/11/26 12:47:42
Done.
| |
| 97 EXPECT_EQ(main_url2, observer2.navigation_url()); | |
| 98 EXPECT_TRUE(observer2.navigation_succeeded()); | |
| 99 | |
| 100 // The RenderFrameHost should not have changed. | |
| 101 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 102 ->GetFrameTree()->root()->current_frame_host()); | |
| 103 | |
| 104 // Go to the main link page again. | |
| 105 TestNavigationWebContentsObserver observer3(shell()->web_contents()); | |
| 106 NavigateToURL(shell(), main_url1); | |
| 107 EXPECT_EQ(main_url1, observer3.navigation_url()); | |
| 108 EXPECT_TRUE(observer3.navigation_succeeded()); | |
| 109 | |
| 110 // The RenderFrameHost should not have changed. | |
| 111 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 112 ->GetFrameTree()->root()->current_frame_host()); | |
| 113 | |
| 114 // Simulate clicking on a cross-site link. | |
| 115 TestNavigationWebContentsObserver observer4(shell()->web_contents()); | |
| 116 GURL main_url3 = GURL("http://foo.com/title2.html"); | |
| 117 success = false; | |
| 118 EXPECT_TRUE(ExecuteScriptAndExtractBool( | |
| 119 shell()->web_contents(), | |
| 120 "window.domAutomationController.send(clickCrossSiteLink());", &success)); | |
| 121 EXPECT_TRUE(success); | |
| 122 WaitForLoadStop(shell()->web_contents()); | |
| 123 EXPECT_EQ(main_url3, observer4.navigation_url()); | |
| 124 EXPECT_TRUE(observer4.navigation_succeeded()); | |
| 125 | |
| 126 // The RenderFrameHost should have changed. | |
| 127 EXPECT_NE(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 128 ->GetFrameTree()->root()->current_frame_host()); | |
| 129 } | |
| 130 | |
| 131 } // namespace content | |
| OLD | NEW |