Chromium Code Reviews| Index: content/browser/browser_side_navigation_browsertest.cc |
| diff --git a/content/browser/browser_side_navigation_browsertest.cc b/content/browser/browser_side_navigation_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..789150bd171c37bc16a05f83c002c123000ef107 |
| --- /dev/null |
| +++ b/content/browser/browser_side_navigation_browsertest.cc |
| @@ -0,0 +1,131 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/command_line.h" |
| +#include "content/browser/web_contents/web_contents_impl.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/common/content_switches.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/content_browser_test.h" |
| +#include "content/public/test/content_browser_test_utils.h" |
| +#include "content/shell/browser/shell.h" |
| +#include "content/test/content_browser_test_utils_internal.h" |
| +#include "net/dns/mock_host_resolver.h" |
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| + |
| +class BrowserSideNavigationBrowserTest : public ContentBrowserTest { |
| + public: |
| + BrowserSideNavigationBrowserTest() {} |
| + |
| + protected: |
| + void SetUpCommandLine(base::CommandLine* command_line) override { |
| + command_line->AppendSwitch(switches::kEnableBrowserSideNavigation); |
| + } |
| + |
| + void SetUpOnMainThread() override { |
| + host_resolver()->AddRule("*", "127.0.0.1"); |
| + ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| + } |
| +}; |
| + |
| +// Ensure that browser initiated basic navigations work with browser side |
| +// navigation. |
| +IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, |
| + BrowserInitiatedNavigations) { |
| + // Perform a navigation with no live renderer. |
| + TestNavigationWebContentsObserver observer1(shell()->web_contents()); |
| + GURL main_url1(embedded_test_server()->GetURL("/title1.html")); |
| + NavigateToURL(shell(), main_url1); |
| + EXPECT_EQ(main_url1, observer1.navigation_url()); |
| + EXPECT_TRUE(observer1.navigation_succeeded()); |
| + |
| + RenderFrameHost* initial_rfh = |
| + static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree()->root()->current_frame_host(); |
| + |
| + // Perform a same site navigation. |
| + 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.
|
| + GURL main_url2(embedded_test_server()->GetURL("/title2.html")); |
| + NavigateToURL(shell(), main_url2); |
| + EXPECT_EQ(main_url2, observer2.navigation_url()); |
| + EXPECT_TRUE(observer2.navigation_succeeded()); |
| + |
| + // The RenderFrameHost should not have changed. |
| + EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree()->root()->current_frame_host()); |
| + |
| + // Perform a cross-site navigation. |
| + TestNavigationWebContentsObserver observer3(shell()->web_contents()); |
| + GURL main_url3 = embedded_test_server()->GetURL("foo.com", "/title3.html"); |
| + NavigateToURL(shell(), main_url3); |
| + EXPECT_EQ(main_url3, observer3.navigation_url()); |
| + EXPECT_TRUE(observer3.navigation_succeeded()); |
| + |
| + // The RenderFrameHost should have changed. |
| + EXPECT_NE(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree()->root()->current_frame_host()); |
| +} |
| + |
| +// Ensure that renderer initiated basic navigations work with browser side |
| +// navigation. |
| +IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest, |
| + RendererInitiatedNavigations) { |
| + // Perform a navigation with no live renderer. |
| + TestNavigationWebContentsObserver observer1(shell()->web_contents()); |
| + 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.
|
| + NavigateToURL(shell(), main_url1); |
| + EXPECT_EQ(main_url1, observer1.navigation_url()); |
| + EXPECT_TRUE(observer1.navigation_succeeded()); |
| + |
| + RenderFrameHost* initial_rfh = |
| + static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree()->root()->current_frame_host(); |
| + |
| + // Simulate clicking on a same-site link. |
| + TestNavigationWebContentsObserver observer2(shell()->web_contents()); |
| + GURL main_url2(embedded_test_server()->GetURL("/title2.html")); |
| + bool success = false; |
| + EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| + shell()->web_contents(), |
| + "window.domAutomationController.send(clickSameSiteLink());", &success)); |
| + EXPECT_TRUE(success); |
| + 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.
|
| + EXPECT_EQ(main_url2, observer2.navigation_url()); |
| + EXPECT_TRUE(observer2.navigation_succeeded()); |
| + |
| + // The RenderFrameHost should not have changed. |
| + EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree()->root()->current_frame_host()); |
| + |
| + // Go to the main link page again. |
| + TestNavigationWebContentsObserver observer3(shell()->web_contents()); |
| + NavigateToURL(shell(), main_url1); |
| + EXPECT_EQ(main_url1, observer3.navigation_url()); |
| + EXPECT_TRUE(observer3.navigation_succeeded()); |
| + |
| + // The RenderFrameHost should not have changed. |
| + EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree()->root()->current_frame_host()); |
| + |
| + // Simulate clicking on a cross-site link. |
| + TestNavigationWebContentsObserver observer4(shell()->web_contents()); |
| + GURL main_url3 = GURL("http://foo.com/title2.html"); |
| + success = false; |
| + EXPECT_TRUE(ExecuteScriptAndExtractBool( |
| + shell()->web_contents(), |
| + "window.domAutomationController.send(clickCrossSiteLink());", &success)); |
| + EXPECT_TRUE(success); |
| + WaitForLoadStop(shell()->web_contents()); |
| + EXPECT_EQ(main_url3, observer4.navigation_url()); |
| + EXPECT_TRUE(observer4.navigation_succeeded()); |
| + |
| + // The RenderFrameHost should have changed. |
| + EXPECT_NE(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree()->root()->current_frame_host()); |
| +} |
| + |
| +} // namespace content |