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

Side by Side Diff: content/browser/browser_side_navigation_browsertest.cc

Issue 715203004: PlzNavigate: Add a browser test for basic navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Folded the TestNavigationWebContentsObserver in TestNavigationObserver Created 6 years 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
« no previous file with comments | « no previous file | content/browser/site_per_process_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/public/test/test_navigation_observer.h"
13 #include "content/shell/browser/shell.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 {
41 TestNavigationObserver observer(shell()->web_contents());
42 GURL main_url(embedded_test_server()->GetURL("/title1.html"));
carlosk 2014/11/26 15:02:53 nit: main_url now seems like a bad name choice as
clamy 2014/11/27 17:16:54 Done.
43 NavigateToURL(shell(), main_url);
44 EXPECT_EQ(main_url, observer.last_navigation_url());
45 EXPECT_TRUE(observer.last_navigation_succeeded());
46 }
47
48 RenderFrameHost* initial_rfh =
49 static_cast<WebContentsImpl*>(shell()->web_contents())
50 ->GetFrameTree()->root()->current_frame_host();
51
52 // Perform a same site navigation.
53 {
54 TestNavigationObserver observer(shell()->web_contents());
55 GURL main_url(embedded_test_server()->GetURL("/title2.html"));
56 NavigateToURL(shell(), main_url);
57 EXPECT_EQ(main_url, observer.last_navigation_url());
58 EXPECT_TRUE(observer.last_navigation_succeeded());
59 }
60
61 // The RenderFrameHost should not have changed.
62 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents())
63 ->GetFrameTree()->root()->current_frame_host());
64
65 // Perform a cross-site navigation.
66 {
67 TestNavigationObserver observer(shell()->web_contents());
68 GURL main_url = embedded_test_server()->GetURL("foo.com", "/title3.html");
69 NavigateToURL(shell(), main_url);
70 EXPECT_EQ(main_url, observer.last_navigation_url());
71 EXPECT_TRUE(observer.last_navigation_succeeded());
72 }
73
74 // The RenderFrameHost should have changed.
75 EXPECT_NE(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents())
76 ->GetFrameTree()->root()->current_frame_host());
77 }
78
79 // Ensure that renderer initiated basic navigations work with browser side
80 // navigation.
81 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest,
82 RendererInitiatedNavigations) {
83 // Perform a navigation with no live renderer.
84 {
85 TestNavigationObserver observer(shell()->web_contents());
86 GURL main_url(embedded_test_server()->GetURL("/simple_links.html"));
87 NavigateToURL(shell(), main_url);
88 EXPECT_EQ(main_url, observer.last_navigation_url());
89 EXPECT_TRUE(observer.last_navigation_succeeded());
90 }
91
92 RenderFrameHost* initial_rfh =
93 static_cast<WebContentsImpl*>(shell()->web_contents())
94 ->GetFrameTree()->root()->current_frame_host();
95
96 // Simulate clicking on a same-site link.
97 {
98 TestNavigationObserver observer(shell()->web_contents());
99 GURL main_url(embedded_test_server()->GetURL("/title2.html"));
100 bool success = false;
101 EXPECT_TRUE(ExecuteScriptAndExtractBool(
102 shell()->web_contents(),
103 "window.domAutomationController.send(clickSameSiteLink());", &success));
104 EXPECT_TRUE(success);
105 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
106 EXPECT_EQ(main_url, observer.last_navigation_url());
107 EXPECT_TRUE(observer.last_navigation_succeeded());
108 }
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 // Go to the main link page again.
carlosk 2014/11/26 15:02:53 This next step is resetting the test to its initia
clamy 2014/11/27 17:16:54 Done.
115 {
116 TestNavigationObserver observer(shell()->web_contents());
117 GURL main_url(embedded_test_server()->GetURL("/simple_links.html"));
118 NavigateToURL(shell(), main_url);
119 EXPECT_EQ(main_url, observer.last_navigation_url());
120 EXPECT_TRUE(observer.last_navigation_succeeded());
121 }
122
123 // The RenderFrameHost should not have changed.
124 EXPECT_EQ(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents())
125 ->GetFrameTree()->root()->current_frame_host());
126
127 // Simulate clicking on a cross-site link.
128 {
129 TestNavigationObserver observer(shell()->web_contents());
130 GURL main_url = GURL("http://foo.com/title2.html");
131 bool success = false;
132 EXPECT_TRUE(ExecuteScriptAndExtractBool(
133 shell()->web_contents(),
134 "window.domAutomationController.send(clickCrossSiteLink());",
135 &success));
136 EXPECT_TRUE(success);
137 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
138 EXPECT_EQ(main_url, observer.last_navigation_url());
139 EXPECT_TRUE(observer.last_navigation_succeeded());
140 }
141
142 // The RenderFrameHost should have changed.
143 EXPECT_NE(initial_rfh, static_cast<WebContentsImpl*>(shell()->web_contents())
144 ->GetFrameTree()->root()->current_frame_host());
145 }
146
147 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/site_per_process_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698