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

Side by Side Diff: content/browser/frame_host/navigator_impl_unittest.cc

Issue 914223002: PlzNavigate: Updated navigation cancel policy for renderer-initiated requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some fixes and a new test added. Created 5 years, 10 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/frame_host/navigation_request.h" 10 #include "content/browser/frame_host/navigation_request.h"
(...skipping 28 matching lines...) Expand all
39 void SetUp() override { 39 void SetUp() override {
40 EnableBrowserSideNavigation(); 40 EnableBrowserSideNavigation();
41 RenderViewHostImplTestHarness::SetUp(); 41 RenderViewHostImplTestHarness::SetUp();
42 } 42 }
43 43
44 TestNavigationURLLoader* GetLoaderForNavigationRequest( 44 TestNavigationURLLoader* GetLoaderForNavigationRequest(
45 NavigationRequest* request) const { 45 NavigationRequest* request) const {
46 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); 46 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
47 } 47 }
48 48
49 void SendRequestNavigation(FrameTreeNode* node, 49 void RequestNavigation(FrameTreeNode* node, const GURL& url) {
50 const GURL& url) { 50 RequestNavigationWithParameters(node, url, Referrer(),
51 SendRequestNavigationWithParameters( 51 ui::PAGE_TRANSITION_LINK,
52 node, url, Referrer(), ui::PAGE_TRANSITION_LINK, 52 NavigationController::NO_RELOAD);
53 NavigationController::NO_RELOAD);
54 } 53 }
55 54
56 void SendRequestNavigationWithParameters( 55 void RequestNavigationWithParameters(
57 FrameTreeNode* node, 56 FrameTreeNode* node,
58 const GURL& url, 57 const GURL& url,
59 const Referrer& referrer, 58 const Referrer& referrer,
60 ui::PageTransition transition_type, 59 ui::PageTransition transition_type,
61 NavigationController::ReloadType reload_type) { 60 NavigationController::ReloadType reload_type) {
62 scoped_ptr<NavigationEntryImpl> entry( 61 scoped_ptr<NavigationEntryImpl> entry(
63 NavigationEntryImpl::FromNavigationEntry( 62 NavigationEntryImpl::FromNavigationEntry(
64 NavigationController::CreateNavigationEntry( 63 NavigationController::CreateNavigationEntry(
65 url, 64 url,
66 referrer, 65 referrer,
(...skipping 26 matching lines...) Expand all
93 static_cast<MockRenderProcessHost*>(rfh->GetProcess()); 92 static_cast<MockRenderProcessHost*>(rfh->GetProcess());
94 const FrameMsg_CommitNavigation* commit_message = 93 const FrameMsg_CommitNavigation* commit_message =
95 static_cast<const FrameMsg_CommitNavigation*>( 94 static_cast<const FrameMsg_CommitNavigation*>(
96 rph->sink().GetUniqueMessageMatching( 95 rph->sink().GetUniqueMessageMatching(
97 FrameMsg_CommitNavigation::ID)); 96 FrameMsg_CommitNavigation::ID));
98 return commit_message && 97 return commit_message &&
99 rfh->GetRoutingID() == commit_message->routing_id(); 98 rfh->GetRoutingID() == commit_message->routing_id();
100 } 99 }
101 }; 100 };
102 101
103 // PlzNavigate: Test final state after a complete navigation (to avoid repeating 102 // PlzNavigate: Test a complete browser-initiated navigation starting with a
104 // these checks in other tests). 103 // non-live renderer.
105 TEST_F(NavigatorTestWithBrowserSideNavigation, NavigationFinishedState) { 104 TEST_F(NavigatorTestWithBrowserSideNavigation,
105 SimpleBrowserInitiatedNavigationFromNonLiveRenderer) {
106 const GURL kUrl("http://chromium.org/"); 106 const GURL kUrl("http://chromium.org/");
107 contents()->NavigateAndCommit(kUrl); 107
108 ASSERT_TRUE(main_test_rfh()); 108 EXPECT_FALSE(main_test_rfh()->IsRenderFrameLive());
109
110 // Start a browser-initiated navigation.
111 int32 site_instance_id = main_test_rfh()->GetSiteInstance()->GetId();
112 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
113 RequestNavigation(node, kUrl);
114 NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node);
115 ASSERT_TRUE(request);
116 EXPECT_EQ(kUrl, request->common_params().url);
117 EXPECT_TRUE(request->browser_initiated());
118
119 // As there's no live renderer the navigation should not wait for a
120 // beforeUnload ACK from the renderer and start right away.
121 EXPECT_EQ(NavigationRequest::STARTED, request->state());
122 ASSERT_TRUE(GetLoaderForNavigationRequest(request));
123 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
124 EXPECT_FALSE(node->render_manager()->pending_frame_host());
125
126 // Have the current RenderFrameHost commit the navigation.
127 scoped_refptr<ResourceResponse> response(new ResourceResponse);
128 GetLoaderForNavigationRequest(request)
129 ->CallOnResponseStarted(response, MakeEmptyStream());
130 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh()));
131 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state());
132
133 // Commit the navigation.
134 main_test_rfh()->SendNavigate(0, kUrl);
109 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); 135 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
110 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl), 136 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
111 main_test_rfh()->GetSiteInstance()->GetSiteURL()); 137 main_test_rfh()->GetSiteInstance()->GetSiteURL());
112 EXPECT_EQ(kUrl, contents()->GetLastCommittedURL()); 138 EXPECT_EQ(kUrl, contents()->GetLastCommittedURL());
139 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
140 EXPECT_FALSE(node->render_manager()->pending_frame_host());
141
142 // The main RFH should not have been changed, and the renderer should have
143 // been initialized.
144 EXPECT_EQ(site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
145 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive());
113 146
114 // After a navigation is finished no speculative RenderFrameHost should 147 // After a navigation is finished no speculative RenderFrameHost should
115 // exist. 148 // exist.
116 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
117 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 149 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
118 150
119 // With PlzNavigate enabled a pending RenderFrameHost should never exist. 151 // With PlzNavigate enabled a pending RenderFrameHost should never exist.
120 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 152 EXPECT_FALSE(node->render_manager()->pending_frame_host());
121 } 153 }
122 154
155 // PlzNavigate: Test a complete renderer-initiated same-site navigation.
156 TEST_F(NavigatorTestWithBrowserSideNavigation,
157 SimpleRendererInitiatedNavigation) {
158 const GURL kUrl1("http://www.chromium.org/");
159 const GURL kUrl2("http://www.chromium.org/Home");
160
161 contents()->NavigateAndCommit(kUrl1);
162 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive());
163
164 // Start a renderer-initiated non-user-initiated navigation.
165 process()->sink().ClearMessages();
166 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false);
167 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
168 NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node);
169 ASSERT_TRUE(request);
170
171 // The navigation is immediately started as there's no need to wait for
172 // beforeUnload to be executed.
173 EXPECT_EQ(NavigationRequest::STARTED, request->state());
174 EXPECT_FALSE(request->begin_params().has_user_gesture);
175 EXPECT_EQ(kUrl2, request->common_params().url);
176 EXPECT_FALSE(request->browser_initiated());
177 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
178
179 // Have the current RenderFrameHost commit the navigation.
180 scoped_refptr<ResourceResponse> response(new ResourceResponse);
181 GetLoaderForNavigationRequest(request)
182 ->CallOnResponseStarted(response, MakeEmptyStream());
183 EXPECT_TRUE(DidRenderFrameHostRequestCommit(main_test_rfh()));
184 EXPECT_EQ(NavigationRequest::RESPONSE_STARTED, request->state());
185
186 // Commit the navigation.
187 main_test_rfh()->SendNavigate(0, kUrl2);
188 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
189 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl2),
190 main_test_rfh()->GetSiteInstance()->GetSiteURL());
191 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL());
192 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
193 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
194 EXPECT_FALSE(node->render_manager()->pending_frame_host());
195 }
196
197 // PlzNavigate: Test that a beforeUnload denial cancels the navigation.
198 TEST_F(NavigatorTestWithBrowserSideNavigation,
199 BeforeUnloadDenialCancelNavigation) {
200 const GURL kUrl1("http://www.google.com/");
201 const GURL kUrl2("http://www.chromium.org/");
202
203 contents()->NavigateAndCommit(kUrl1);
204
205 // Start a new navigation.
206 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
207 RequestNavigation(node, kUrl2);
208 NavigationRequest* request = GetNavigationRequestForFrameTreeNode(node);
209 ASSERT_TRUE(request);
210 EXPECT_TRUE(request->browser_initiated());
211 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, request->state());
212 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
213
214 // Simulate a beforeUnload denial.
215 main_test_rfh()->SendBeforeUnloadACK(false);
216 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
217 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
218 }
219
123 // PlzNavigate: Test that a proper NavigationRequest is created by 220 // PlzNavigate: Test that a proper NavigationRequest is created by
124 // BeginNavigation. 221 // RequestNavigation.
125 // Note that all PlzNavigate methods on the browser side require the use of the
126 // flag kEnableBrowserSideNavigation.
127 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { 222 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) {
128 const GURL kUrl1("http://www.google.com/"); 223 const GURL kUrl1("http://www.google.com/");
129 const GURL kUrl2("http://www.chromium.org/"); 224 const GURL kUrl2("http://www.chromium.org/");
130 const GURL kUrl3("http://www.gmail.com/"); 225 const GURL kUrl3("http://www.gmail.com/");
131 226
132 contents()->NavigateAndCommit(kUrl1); 227 contents()->NavigateAndCommit(kUrl1);
133 228
134 // Add a subframe. 229 // Add a subframe.
135 FrameTreeNode* root_node = contents()->GetFrameTree()->root(); 230 FrameTreeNode* root_node = contents()->GetFrameTree()->root();
136 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); 231 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child");
137 ASSERT_TRUE(subframe_rfh); 232 ASSERT_TRUE(subframe_rfh);
138 233
234 // Start a navigation at the subframe.
139 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); 235 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node();
140 SendRequestNavigation(subframe_node, kUrl2); 236 RequestNavigation(subframe_node, kUrl2);
141 // There is no previous renderer in the subframe, so BeginNavigation is
142 // handled already.
143 NavigationRequest* subframe_request = 237 NavigationRequest* subframe_request =
144 GetNavigationRequestForFrameTreeNode(subframe_node); 238 GetNavigationRequestForFrameTreeNode(subframe_node);
145 TestNavigationURLLoader* subframe_loader = 239 TestNavigationURLLoader* subframe_loader =
146 GetLoaderForNavigationRequest(subframe_request); 240 GetLoaderForNavigationRequest(subframe_request);
241
242 // Subframe navigations should start right away as they don't have to request
243 // beforeUnload to run at the renderer.
147 ASSERT_TRUE(subframe_request); 244 ASSERT_TRUE(subframe_request);
245 ASSERT_TRUE(subframe_loader);
246 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state());
148 EXPECT_EQ(kUrl2, subframe_request->common_params().url); 247 EXPECT_EQ(kUrl2, subframe_request->common_params().url);
149 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url); 248 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url);
150 // First party for cookies url should be that of the main frame. 249 // First party for cookies url should be that of the main frame.
151 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); 250 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies);
152 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); 251 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame);
153 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); 252 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame);
253 EXPECT_TRUE(subframe_request->browser_initiated());
154 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); 254 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
155 255
156 // Subframe navigations should never create a speculative RenderFrameHost, 256 // Subframe navigations should never create a speculative RenderFrameHost,
157 // unless site-per-process is enabled. In that case, as the subframe 257 // unless site-per-process is enabled. In that case, as the subframe
158 // navigation is to a different site and is still ongoing, it should have one. 258 // navigation is to a different site and is still ongoing, it should have one.
159 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 259 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
160 switches::kSitePerProcess)) { 260 switches::kSitePerProcess)) {
161 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); 261 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
162 } else { 262 } else {
163 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); 263 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
164 } 264 }
165 265
166 SendRequestNavigation(root_node, kUrl3); 266 // Now start a navigation at the root node.
167 // Simulate a BeginNavigation IPC on the main frame. 267 RequestNavigation(root_node, kUrl3);
168 main_test_rfh()->SendBeginNavigationWithURL(kUrl3);
169 NavigationRequest* main_request = 268 NavigationRequest* main_request =
170 GetNavigationRequestForFrameTreeNode(root_node); 269 GetNavigationRequestForFrameTreeNode(root_node);
270 ASSERT_TRUE(main_request);
271 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE,
272 main_request->state());
273 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
274
275 // Simulate a BeforeUnloadACK IPC on the main frame.
276 main_test_rfh()->SendBeforeUnloadACK(true);
171 TestNavigationURLLoader* main_loader = 277 TestNavigationURLLoader* main_loader =
172 GetLoaderForNavigationRequest(main_request); 278 GetLoaderForNavigationRequest(main_request);
173 ASSERT_TRUE(main_request);
174 EXPECT_EQ(kUrl3, main_request->common_params().url); 279 EXPECT_EQ(kUrl3, main_request->common_params().url);
175 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); 280 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url);
176 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); 281 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
177 EXPECT_TRUE(main_loader->request_info()->is_main_frame); 282 EXPECT_TRUE(main_loader->request_info()->is_main_frame);
178 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); 283 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
284 EXPECT_TRUE(main_request->browser_initiated());
285 // BeforeUnloadACK was received from the renderer so the navigation should
286 // have started.
287 EXPECT_EQ(NavigationRequest::STARTED, main_request->state());
179 288
180 // Main frame navigation to a different site should use a speculative 289 // Main frame navigation to a different site should use a speculative
181 // RenderFrameHost. 290 // RenderFrameHost.
182 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); 291 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node));
183 292
184 // As the main frame hasn't yet committed the subframe still exists. Thus, the 293 // As the main frame hasn't yet committed the subframe still exists. Thus, the
185 // above situation regarding subframe navigations is valid here. 294 // above situation regarding subframe navigations is valid here.
186 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 295 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
187 switches::kSitePerProcess)) { 296 switches::kSitePerProcess)) {
188 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); 297 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
189 } else { 298 } else {
190 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); 299 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
191 } 300 }
192 } 301 }
193 302
194 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
195 // RenderFrameHost is not modified when the navigation commits.
196 TEST_F(NavigatorTestWithBrowserSideNavigation, NoLiveRenderer) {
197 const GURL kUrl("http://www.google.com/");
198
199 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
200 RenderFrameHostImpl* rfh = main_test_rfh();
201 FrameTreeNode* node = rfh->frame_tree_node();
202 SendRequestNavigation(node, kUrl);
203
204 // A NavigationRequest should have been generated.
205 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
206 EXPECT_TRUE(main_request != NULL);
207
208 // Since we're re-using the current RenderFrameHost, no speculative one should
209 // be created.
210 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
211
212 // Now return the response without any redirects. This will cause the
213 // navigation to commit at the same URL.
214 scoped_refptr<ResourceResponse> response(new ResourceResponse);
215 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
216 response, MakeEmptyStream());
217 main_request = GetNavigationRequestForFrameTreeNode(node);
218
219 // The main RFH should not have been changed, and the renderer should have
220 // been initialized.
221 EXPECT_EQ(rfh, main_test_rfh());
222 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive());
223 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
224 }
225
226 // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels 303 // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels
227 // the navigation. 304 // the navigation.
228 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { 305 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) {
229 const GURL kUrl1("http://www.chromium.org/"); 306 const GURL kUrl1("http://www.chromium.org/");
230 const GURL kUrl2("http://www.google.com/"); 307 const GURL kUrl2("http://www.google.com/");
231 308
232 // Load a URL. 309 // Load a URL.
233 contents()->NavigateAndCommit(kUrl1); 310 contents()->NavigateAndCommit(kUrl1);
234 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 311 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
235 312
236 // Navigate to a different site. 313 // Navigate to a different site.
237 process()->sink().ClearMessages(); 314 process()->sink().ClearMessages();
238 SendRequestNavigation(node, kUrl2); 315 RequestNavigation(node, kUrl2);
239 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 316 main_test_rfh()->SendBeforeUnloadACK(true);
240 317
241 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 318 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
242 ASSERT_TRUE(main_request); 319 ASSERT_TRUE(main_request);
243 320
244 // Navigations to a different site do create a speculative RenderFrameHost. 321 // Navigations to a different site do create a speculative RenderFrameHost.
245 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node)); 322 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
246 323
247 // Commit an HTTP 204 response. 324 // Commit an HTTP 204 response.
248 scoped_refptr<ResourceResponse> response(new ResourceResponse); 325 scoped_refptr<ResourceResponse> response(new ResourceResponse);
249 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0"; 326 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0";
250 response->head.headers = new net::HttpResponseHeaders( 327 response->head.headers = new net::HttpResponseHeaders(
251 std::string(kNoContentHeaders, arraysize(kNoContentHeaders))); 328 std::string(kNoContentHeaders, arraysize(kNoContentHeaders)));
252 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 329 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
253 response, MakeEmptyStream()); 330 response, MakeEmptyStream());
254 331
255 // There should be no pending nor speculative RenderFrameHost; the navigation 332 // There should be no pending nor speculative RenderFrameHost; the navigation
256 // was aborted. 333 // was aborted.
257 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); 334 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
258 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); 335 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
259 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 336 EXPECT_FALSE(node->render_manager()->pending_frame_host());
260 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 337 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
261 338
262 // Now, repeat the test with 205 Reset Content. 339 // Now, repeat the test with 205 Reset Content.
263 340
264 // Navigate to a different site again. 341 // Navigate to a different site again.
265 process()->sink().ClearMessages(); 342 process()->sink().ClearMessages();
266 SendRequestNavigation(node, kUrl2); 343 RequestNavigation(node, kUrl2);
267 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 344 main_test_rfh()->SendBeforeUnloadACK(true);
268 345
269 main_request = GetNavigationRequestForFrameTreeNode(node); 346 main_request = GetNavigationRequestForFrameTreeNode(node);
270 ASSERT_TRUE(main_request); 347 ASSERT_TRUE(main_request);
271 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node)); 348 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
272 349
273 // Commit an HTTP 205 response. 350 // Commit an HTTP 205 response.
274 response = new ResourceResponse; 351 response = new ResourceResponse;
275 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0"; 352 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0";
276 response->head.headers = new net::HttpResponseHeaders( 353 response->head.headers = new net::HttpResponseHeaders(
277 std::string(kResetContentHeaders, arraysize(kResetContentHeaders))); 354 std::string(kResetContentHeaders, arraysize(kResetContentHeaders)));
(...skipping 13 matching lines...) Expand all
291 TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) { 368 TEST_F(NavigatorTestWithBrowserSideNavigation, CrossSiteNavigation) {
292 const GURL kUrl1("http://www.chromium.org/"); 369 const GURL kUrl1("http://www.chromium.org/");
293 const GURL kUrl2("http://www.google.com/"); 370 const GURL kUrl2("http://www.google.com/");
294 371
295 contents()->NavigateAndCommit(kUrl1); 372 contents()->NavigateAndCommit(kUrl1);
296 RenderFrameHostImpl* initial_rfh = main_test_rfh(); 373 RenderFrameHostImpl* initial_rfh = main_test_rfh();
297 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 374 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
298 375
299 // Navigate to a different site. 376 // Navigate to a different site.
300 process()->sink().ClearMessages(); 377 process()->sink().ClearMessages();
301 SendRequestNavigation(node, kUrl2); 378 RequestNavigation(node, kUrl2);
302 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 379 main_test_rfh()->SendBeforeUnloadACK(true);
303 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 380 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
304 ASSERT_TRUE(main_request); 381 ASSERT_TRUE(main_request);
305 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node)); 382 EXPECT_TRUE(GetSpeculativeRenderFrameHost(node));
306 383
307 scoped_refptr<ResourceResponse> response(new ResourceResponse); 384 scoped_refptr<ResourceResponse> response(new ResourceResponse);
308 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 385 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
309 response, MakeEmptyStream()); 386 response, MakeEmptyStream());
310 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); 387 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
311 ASSERT_TRUE(speculative_rfh); 388 ASSERT_TRUE(speculative_rfh);
312 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh)); 389 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh));
(...skipping 14 matching lines...) Expand all
327 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) { 404 TEST_F(NavigatorTestWithBrowserSideNavigation, RedirectCrossSite) {
328 const GURL kUrl1("http://www.chromium.org/"); 405 const GURL kUrl1("http://www.chromium.org/");
329 const GURL kUrl2("http://www.google.com/"); 406 const GURL kUrl2("http://www.google.com/");
330 407
331 contents()->NavigateAndCommit(kUrl1); 408 contents()->NavigateAndCommit(kUrl1);
332 RenderFrameHostImpl* rfh = main_test_rfh(); 409 RenderFrameHostImpl* rfh = main_test_rfh();
333 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 410 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
334 411
335 // Navigate to a URL on the same site. 412 // Navigate to a URL on the same site.
336 process()->sink().ClearMessages(); 413 process()->sink().ClearMessages();
337 SendRequestNavigation(node, kUrl1); 414 RequestNavigation(node, kUrl1);
338 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 415 main_test_rfh()->SendBeforeUnloadACK(true);
339 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 416 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
340 ASSERT_TRUE(main_request); 417 ASSERT_TRUE(main_request);
341 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 418 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
342 419
343 // It then redirects to another site. 420 // It then redirects to another site.
344 net::RedirectInfo redirect_info; 421 net::RedirectInfo redirect_info;
345 redirect_info.status_code = 302; 422 redirect_info.status_code = 302;
346 redirect_info.new_method = "GET"; 423 redirect_info.new_method = "GET";
347 redirect_info.new_url = kUrl2; 424 redirect_info.new_url = kUrl2;
348 redirect_info.new_first_party_for_cookies = kUrl2; 425 redirect_info.new_first_party_for_cookies = kUrl2;
349 scoped_refptr<ResourceResponse> response(new ResourceResponse); 426 scoped_refptr<ResourceResponse> response(new ResourceResponse);
350 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected( 427 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected(
351 redirect_info, response); 428 redirect_info, response);
352 429
353 // The redirect should have been followed. 430 // The redirect should have been followed.
354 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count()); 431 EXPECT_EQ(1, GetLoaderForNavigationRequest(main_request)->redirect_count());
355 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 432 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
356 433
357 // Request the RenderFrameHost to commit. 434 // Request the RenderFrameHost to commit.
358 response = new ResourceResponse; 435 response = new ResourceResponse;
359 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( 436 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
360 response, MakeEmptyStream()); 437 response, MakeEmptyStream());
361 TestRenderFrameHost* final_speculative_rfh = 438 TestRenderFrameHost* final_speculative_rfh =
362 GetSpeculativeRenderFrameHost(node); 439 GetSpeculativeRenderFrameHost(node);
363 EXPECT_TRUE(final_speculative_rfh); 440 EXPECT_TRUE(final_speculative_rfh);
364 EXPECT_TRUE(DidRenderFrameHostRequestCommit(final_speculative_rfh)); 441 EXPECT_TRUE(DidRenderFrameHostRequestCommit(final_speculative_rfh));
365 442
366 // And commit provisional load. 443 // Commit the navigation.
367 final_speculative_rfh->SendNavigate(0, kUrl2); 444 final_speculative_rfh->SendNavigate(0, kUrl2);
368 RenderFrameHostImpl* final_rfh = main_test_rfh(); 445 RenderFrameHostImpl* final_rfh = main_test_rfh();
369 ASSERT_TRUE(final_rfh); 446 ASSERT_TRUE(final_rfh);
370 EXPECT_NE(rfh, final_rfh); 447 EXPECT_NE(rfh, final_rfh);
371 EXPECT_EQ(final_speculative_rfh, final_rfh); 448 EXPECT_EQ(final_speculative_rfh, final_rfh);
372 EXPECT_TRUE(final_rfh->IsRenderFrameLive()); 449 EXPECT_TRUE(final_rfh->IsRenderFrameLive());
373 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive()); 450 EXPECT_TRUE(final_rfh->render_view_host()->IsRenderViewLive());
374 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 451 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
375 } 452 }
376 453
377 // PlzNavigate: Test that a navigation is canceled if another request has been 454 // PlzNavigate: Test that a navigation is canceled if another browser-initiated
378 // issued in the meantime. Also confirms that the speculative RenderFrameHost is 455 // request has been issued in the meantime. Also confirms that the speculative
379 // correctly updated in the process. 456 // RenderFrameHost is correctly updated in the process.
380 TEST_F(NavigatorTestWithBrowserSideNavigation, ReplacePendingNavigation) { 457 TEST_F(NavigatorTestWithBrowserSideNavigation,
458 BrowserInitiatedNavigationCancel) {
381 const GURL kUrl0("http://www.wikipedia.org/"); 459 const GURL kUrl0("http://www.wikipedia.org/");
382 const GURL kUrl1("http://www.chromium.org/"); 460 const GURL kUrl1("http://www.chromium.org/");
383 const GURL kUrl1_site = SiteInstance::GetSiteForURL(browser_context(), kUrl1); 461 const GURL kUrl1_site = SiteInstance::GetSiteForURL(browser_context(), kUrl1);
384 const GURL kUrl2("http://www.google.com/"); 462 const GURL kUrl2("http://www.google.com/");
385 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); 463 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2);
386 464
387 // Initialization. 465 // Initialization.
388 contents()->NavigateAndCommit(kUrl0); 466 contents()->NavigateAndCommit(kUrl0);
389 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 467 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
390 468
391 // Request navigation to the 1st URL. 469 // Request navigation to the 1st URL.
392 process()->sink().ClearMessages(); 470 process()->sink().ClearMessages();
393 SendRequestNavigation(node, kUrl1); 471 RequestNavigation(node, kUrl1);
394 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 472 main_test_rfh()->SendBeforeUnloadACK(true);
395 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); 473 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
396 ASSERT_TRUE(request1); 474 ASSERT_TRUE(request1);
397 EXPECT_EQ(kUrl1, request1->common_params().url); 475 EXPECT_EQ(kUrl1, request1->common_params().url);
476 EXPECT_TRUE(request1->browser_initiated());
398 base::WeakPtr<TestNavigationURLLoader> loader1 = 477 base::WeakPtr<TestNavigationURLLoader> loader1 =
399 GetLoaderForNavigationRequest(request1)->AsWeakPtr(); 478 GetLoaderForNavigationRequest(request1)->AsWeakPtr();
479 EXPECT_TRUE(loader1);
400 480
401 // Confirm a speculative RFH was created. 481 // Confirm a speculative RFH was created.
402 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); 482 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
403 ASSERT_TRUE(speculative_rfh); 483 ASSERT_TRUE(speculative_rfh);
404 int32 site_instance_id_1 = speculative_rfh->GetSiteInstance()->GetId(); 484 int32 site_instance_id_1 = speculative_rfh->GetSiteInstance()->GetId();
405 EXPECT_EQ(kUrl1_site, speculative_rfh->GetSiteInstance()->GetSiteURL()); 485 EXPECT_EQ(kUrl1_site, speculative_rfh->GetSiteInstance()->GetSiteURL());
406 486
407 // Request navigation to the 2nd URL; the NavigationRequest must have been 487 // Request navigation to the 2nd URL; the NavigationRequest must have been
408 // replaced by a new one with a different URL. 488 // replaced by a new one with a different URL.
409 SendRequestNavigation(node, kUrl2); 489 RequestNavigation(node, kUrl2);
410 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 490 main_test_rfh()->SendBeforeUnloadACK(true);
411 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); 491 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
412 ASSERT_TRUE(request2); 492 ASSERT_TRUE(request2);
413 EXPECT_EQ(kUrl2, request2->common_params().url); 493 EXPECT_EQ(kUrl2, request2->common_params().url);
494 EXPECT_TRUE(request2->browser_initiated());
414 495
415 // Confirm that the first loader got destroyed. 496 // Confirm that the first loader got destroyed.
416 EXPECT_FALSE(loader1); 497 EXPECT_FALSE(loader1);
417 498
418 // Confirm that a new speculative RFH was created. 499 // Confirm that a new speculative RFH was created.
419 speculative_rfh = GetSpeculativeRenderFrameHost(node); 500 speculative_rfh = GetSpeculativeRenderFrameHost(node);
420 ASSERT_TRUE(speculative_rfh); 501 ASSERT_TRUE(speculative_rfh);
421 int32 site_instance_id_2 = speculative_rfh->GetSiteInstance()->GetId(); 502 int32 site_instance_id_2 = speculative_rfh->GetSiteInstance()->GetId();
422 EXPECT_NE(site_instance_id_1, site_instance_id_2); 503 EXPECT_NE(site_instance_id_1, site_instance_id_2);
423 504
424 // Request the RenderFrameHost to commit. 505 // Request the RenderFrameHost to commit.
425 scoped_refptr<ResourceResponse> response(new ResourceResponse); 506 scoped_refptr<ResourceResponse> response(new ResourceResponse);
426 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( 507 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted(
427 response, MakeEmptyStream()); 508 response, MakeEmptyStream());
428 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh)); 509 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_rfh));
429 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); 510 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
430 511
431 // And commit provisional load. 512 // Commit the navigation.
432 speculative_rfh->SendNavigate(0, kUrl2); 513 speculative_rfh->SendNavigate(0, kUrl2);
433 514
434 // Confirm that the commit corresponds to the new request. 515 // Confirm that the commit corresponds to the new request.
435 ASSERT_TRUE(main_test_rfh()); 516 ASSERT_TRUE(main_test_rfh());
436 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); 517 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
437 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL()); 518 EXPECT_EQ(kUrl2, contents()->GetLastCommittedURL());
438 519
439 // Confirm that the committed RFH is the latest speculative one. 520 // Confirm that the committed RFH is the latest speculative one.
440 EXPECT_EQ(site_instance_id_2, main_test_rfh()->GetSiteInstance()->GetId()); 521 EXPECT_EQ(site_instance_id_2, main_test_rfh()->GetSiteInstance()->GetId());
441 } 522 }
442 523
524 // PlzNavigate: Test that a navigation is canceled if another renderer-initiated
525 // user-initiated request has been issued in the meantime.
526 TEST_F(NavigatorTestWithBrowserSideNavigation,
527 RendererUserInitiatedNavigationCancel) {
clamy 2015/02/12 18:08:07 I am thinking that we may want to have these tests
carlosk 2015/02/13 13:44:29 Done. This made me find a few more test improvemen
528 const GURL kUrl0("http://www.wikipedia.org/");
529 const GURL kUrl1("http://www.chromium.org/");
530 const GURL kUrl2("http://www.google.com/");
531
532 // Initialization.
533 contents()->NavigateAndCommit(kUrl0);
534 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
535
536 // Start a browser-initiated navigation to the 1st URL and receive its
537 // beforeUnload ACK.
538 RequestNavigation(node, kUrl1);
539 main_test_rfh()->SendBeforeUnloadACK(true);
540 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
541 ASSERT_TRUE(request1);
542 EXPECT_EQ(kUrl1, request1->common_params().url);
543 EXPECT_TRUE(request1->browser_initiated());
544 base::WeakPtr<TestNavigationURLLoader> loader1 =
545 GetLoaderForNavigationRequest(request1)->AsWeakPtr();
546 EXPECT_TRUE(loader1);
547
548 // Confirm a speculative RFH was created.
549 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
550 ASSERT_TRUE(speculative_rfh);
551 int32 site_instance_id_1 = speculative_rfh->GetSiteInstance()->GetId();
552
553 // Now receive a renderer-initiated user-initiated request. It should replace
554 // the current NavigationRequest.
555 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, true);
556 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
557 ASSERT_TRUE(request2);
558 EXPECT_EQ(kUrl2, request2->common_params().url);
559 EXPECT_FALSE(request2->browser_initiated());
560 EXPECT_TRUE(request2->begin_params().has_user_gesture);
561
562 // Confirm that the first loader got destroyed.
563 EXPECT_FALSE(loader1);
564
565 // Confirm that a new speculative RFH was created.
566 speculative_rfh = GetSpeculativeRenderFrameHost(node);
567 ASSERT_TRUE(speculative_rfh);
568 int32 site_instance_id_2 = speculative_rfh->GetSiteInstance()->GetId();
569 EXPECT_NE(site_instance_id_1, site_instance_id_2);
570 }
571
572 // PlzNavigate: Test that a renderer-initiated user-initiated navigation is NOT
573 // canceled if a renderer-initiated non-user-initiated request is issued in the
574 // meantime.
575 TEST_F(NavigatorTestWithBrowserSideNavigation,
576 RendererNonUserInitiatedNavigationDoesntCancelRendererUserInitiated) {
577 const GURL kUrl0("http://www.wikipedia.org/");
578 const GURL kUrl1("http://www.chromium.org/");
579 const GURL kUrl2("http://www.google.com/");
580
581 // Initialization.
582 contents()->NavigateAndCommit(kUrl0);
583 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
584
585 // Start a renderer-initiated user-initiated navigation to the 1st URL.
586 main_test_rfh()->SendBeginNavigationWithURL(kUrl1, true);
587 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
588 ASSERT_TRUE(request1);
589 EXPECT_EQ(kUrl1, request1->common_params().url);
590 EXPECT_FALSE(request1->browser_initiated());
591 EXPECT_TRUE(request1->begin_params().has_user_gesture);
592
593 // Now receive a renderer-initiated non-user-initiated request. Nothing should
594 // change.
595 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false);
596 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
597 ASSERT_TRUE(request2);
598 EXPECT_EQ(request1, request2);
599 EXPECT_EQ(kUrl1, request2->common_params().url);
600 EXPECT_FALSE(request2->browser_initiated());
601 EXPECT_TRUE(request2->begin_params().has_user_gesture);
602 }
603
604 // PlzNavigate: Test that a browser-initiated navigation is NOT canceled if a
605 // renderer-initiated non-user-initiated request is issued in the meantime.
606 TEST_F(NavigatorTestWithBrowserSideNavigation,
607 RendererNonUserInitiatedNavigationDoesntCancelBrowserInitiated) {
608 const GURL kUrl0("http://www.wikipedia.org/");
609 const GURL kUrl1("http://www.chromium.org/");
610 const GURL kUrl2("http://www.google.com/");
611
612 // Initialization.
613 contents()->NavigateAndCommit(kUrl0);
614 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
615
616 // Start a browser-initiated navigation to the 1st URL.
617 RequestNavigation(node, kUrl1);
618 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
619 ASSERT_TRUE(request1);
620 EXPECT_EQ(kUrl1, request1->common_params().url);
621 EXPECT_TRUE(request1->browser_initiated());
622
623 // Now receive a renderer-initiated non-user-initiated request. Nothing should
624 // change.
625 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false);
626 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
627 ASSERT_TRUE(request2);
628 EXPECT_EQ(request1, request2);
629 EXPECT_EQ(kUrl1, request2->common_params().url);
630 EXPECT_TRUE(request2->browser_initiated());
631 }
632
633 // PlzNavigate: Test that a renderer-initiated non-user-initiated navigation is
634 // canceled if a another similar request is issued in the meantime.
635 TEST_F(NavigatorTestWithBrowserSideNavigation,
636 RendererNonUserInitiatedNavigationCancelSimilarNavigation) {
637 const GURL kUrl0("http://www.wikipedia.org/");
638 const GURL kUrl1("http://www.chromium.org/");
639 const GURL kUrl2("http://www.google.com/");
640
641 // Initialization.
642 contents()->NavigateAndCommit(kUrl0);
643 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
644
645 // Start a renderer-initiated non-user-initiated navigation to the 1st URL.
646 main_test_rfh()->SendBeginNavigationWithURL(kUrl1, false);
647 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
648 ASSERT_TRUE(request1);
649 EXPECT_EQ(kUrl1, request1->common_params().url);
650 EXPECT_FALSE(request1->browser_initiated());
651 EXPECT_FALSE(request1->begin_params().has_user_gesture);
652
653 // Now receive a 2nd similar request that should replace the current one.
654 main_test_rfh()->SendBeginNavigationWithURL(kUrl2, false);
655 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
656 EXPECT_EQ(kUrl2, request2->common_params().url);
657 EXPECT_FALSE(request2->browser_initiated());
658 EXPECT_FALSE(request2->begin_params().has_user_gesture);
659 }
660
443 // PlzNavigate: Test that a reload navigation is properly signaled to the 661 // PlzNavigate: Test that a reload navigation is properly signaled to the
444 // RenderFrame when the navigation can commit. A speculative RenderFrameHost 662 // RenderFrame when the navigation can commit. A speculative RenderFrameHost
445 // should not be created at any step. 663 // should not be created at any step.
446 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { 664 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
447 const GURL kUrl("http://www.google.com/"); 665 const GURL kUrl("http://www.google.com/");
448 contents()->NavigateAndCommit(kUrl); 666 contents()->NavigateAndCommit(kUrl);
449 667
450 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 668 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
451 SendRequestNavigationWithParameters( 669 RequestNavigationWithParameters(node, kUrl, Referrer(),
452 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 670 ui::PAGE_TRANSITION_LINK,
453 NavigationController::RELOAD); 671 NavigationController::RELOAD);
454 // A NavigationRequest should have been generated. 672 // A NavigationRequest should have been generated.
455 NavigationRequest* main_request = 673 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
456 GetNavigationRequestForFrameTreeNode(node);
457 ASSERT_TRUE(main_request != NULL); 674 ASSERT_TRUE(main_request != NULL);
458 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, 675 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD,
459 main_request->common_params().navigation_type); 676 main_request->common_params().navigation_type);
460 main_test_rfh()->PrepareForCommit(kUrl); 677 main_test_rfh()->PrepareForCommit(kUrl);
461 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 678 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
462 679
463 main_test_rfh()->SendNavigate(0, kUrl); 680 main_test_rfh()->SendNavigate(0, kUrl);
464 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 681 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
465 682
466 // Now do a shift+reload. 683 // Now do a shift+reload.
467 SendRequestNavigationWithParameters( 684 RequestNavigationWithParameters(node, kUrl, Referrer(),
468 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 685 ui::PAGE_TRANSITION_LINK,
469 NavigationController::RELOAD_IGNORING_CACHE); 686 NavigationController::RELOAD_IGNORING_CACHE);
470 // A NavigationRequest should have been generated. 687 // A NavigationRequest should have been generated.
471 main_request = GetNavigationRequestForFrameTreeNode(node); 688 main_request = GetNavigationRequestForFrameTreeNode(node);
472 ASSERT_TRUE(main_request != NULL); 689 ASSERT_TRUE(main_request != NULL);
473 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, 690 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
474 main_request->common_params().navigation_type); 691 main_request->common_params().navigation_type);
475 main_test_rfh()->PrepareForCommit(kUrl); 692 main_test_rfh()->PrepareForCommit(kUrl);
476 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 693 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
477 } 694 }
478 695
479 // PlzNavigate: Confirm that a speculative RenderFrameHost is used when 696 // PlzNavigate: Confirm that a speculative RenderFrameHost is used when
480 // navigating from one site to another. 697 // navigating from one site to another.
481 TEST_F(NavigatorTestWithBrowserSideNavigation, 698 TEST_F(NavigatorTestWithBrowserSideNavigation,
482 SpeculativeRendererWorksBaseCase) { 699 SpeculativeRendererWorksBaseCase) {
483 // Navigate to an initial site. 700 // Navigate to an initial site.
484 const GURL kUrlInit("http://wikipedia.org/"); 701 const GURL kUrlInit("http://wikipedia.org/");
485 contents()->NavigateAndCommit(kUrlInit); 702 contents()->NavigateAndCommit(kUrlInit);
486 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 703 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
487 704
488 // Begin navigating to another site. 705 // Begin navigating to another site.
489 const GURL kUrl("http://google.com/"); 706 const GURL kUrl("http://google.com/");
490 process()->sink().ClearMessages(); 707 process()->sink().ClearMessages();
491 SendRequestNavigation(node, kUrl); 708 RequestNavigation(node, kUrl);
492 main_test_rfh()->SendBeginNavigationWithURL(kUrl); 709 main_test_rfh()->SendBeforeUnloadACK(true);
493 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); 710 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
494 ASSERT_TRUE(speculative_rfh); 711 ASSERT_TRUE(speculative_rfh);
495 EXPECT_NE(speculative_rfh, main_test_rfh()); 712 EXPECT_NE(speculative_rfh, main_test_rfh());
496 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl), 713 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
497 speculative_rfh->GetSiteInstance()->GetSiteURL()); 714 speculative_rfh->GetSiteInstance()->GetSiteURL());
498 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 715 EXPECT_FALSE(node->render_manager()->pending_frame_host());
499 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId(); 716 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
500 717
501 // Ask Navigator to commit the navigation by simulating a call to 718 // Ask Navigator to commit the navigation by simulating a call to
502 // OnResponseStarted. 719 // OnResponseStarted.
(...skipping 19 matching lines...) Expand all
522 SpeculativeRendererDiscardedAfterRedirectToAnotherSite) { 739 SpeculativeRendererDiscardedAfterRedirectToAnotherSite) {
523 // Navigate to an initial site. 740 // Navigate to an initial site.
524 const GURL kUrlInit("http://wikipedia.org/"); 741 const GURL kUrlInit("http://wikipedia.org/");
525 contents()->NavigateAndCommit(kUrlInit); 742 contents()->NavigateAndCommit(kUrlInit);
526 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 743 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
527 int32 init_site_instance_id = main_test_rfh()->GetSiteInstance()->GetId(); 744 int32 init_site_instance_id = main_test_rfh()->GetSiteInstance()->GetId();
528 745
529 // Begin navigating to another site. 746 // Begin navigating to another site.
530 const GURL kUrl("http://google.com/"); 747 const GURL kUrl("http://google.com/");
531 process()->sink().ClearMessages(); 748 process()->sink().ClearMessages();
532 SendRequestNavigation(node, kUrl); 749 RequestNavigation(node, kUrl);
533 main_test_rfh()->SendBeginNavigationWithURL(kUrl); 750 main_test_rfh()->SendBeforeUnloadACK(true);
534 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node); 751 TestRenderFrameHost* speculative_rfh = GetSpeculativeRenderFrameHost(node);
535 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId(); 752 int32 site_instance_id = speculative_rfh->GetSiteInstance()->GetId();
536 EXPECT_NE(init_site_instance_id, site_instance_id); 753 EXPECT_NE(init_site_instance_id, site_instance_id);
537 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId()); 754 EXPECT_EQ(init_site_instance_id, main_test_rfh()->GetSiteInstance()->GetId());
538 ASSERT_TRUE(speculative_rfh); 755 ASSERT_TRUE(speculative_rfh);
539 EXPECT_NE(speculative_rfh, main_test_rfh()); 756 EXPECT_NE(speculative_rfh, main_test_rfh());
540 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl), 757 EXPECT_EQ(SiteInstanceImpl::GetSiteForURL(browser_context(), kUrl),
541 speculative_rfh->GetSiteInstance()->GetSiteURL()); 758 speculative_rfh->GetSiteInstance()->GetSiteURL());
542 759
543 // It then redirects to yet another site. 760 // It then redirects to yet another site.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 829 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
613 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state()); 830 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, main_test_rfh()->rfh_state());
614 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1)); 831 EXPECT_TRUE(rfhm->IsOnSwappedOutList(rfh1));
615 832
616 // Now go back to the initial site so that the swapped out RenderFrameHost 833 // Now go back to the initial site so that the swapped out RenderFrameHost
617 // should be reused. 834 // should be reused.
618 process()->sink().ClearMessages(); 835 process()->sink().ClearMessages();
619 static_cast<MockRenderProcessHost*>(rfh1->GetProcess()) 836 static_cast<MockRenderProcessHost*>(rfh1->GetProcess())
620 ->sink() 837 ->sink()
621 .ClearMessages(); 838 .ClearMessages();
622 SendRequestNavigation(node, kUrl1); 839 RequestNavigation(node, kUrl1);
623 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 840 main_test_rfh()->SendBeforeUnloadACK(true);
624 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); 841 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
625 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT, 842 EXPECT_NE(RenderFrameHostImpl::STATE_DEFAULT,
626 GetSpeculativeRenderFrameHost(node)->rfh_state()); 843 GetSpeculativeRenderFrameHost(node)->rfh_state());
627 844
628 scoped_refptr<ResourceResponse> response(new ResourceResponse); 845 scoped_refptr<ResourceResponse> response(new ResourceResponse);
629 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node)) 846 GetLoaderForNavigationRequest(GetNavigationRequestForFrameTreeNode(node))
630 ->CallOnResponseStarted(response, MakeEmptyStream()); 847 ->CallOnResponseStarted(response, MakeEmptyStream());
631 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node)); 848 EXPECT_EQ(rfh1, GetSpeculativeRenderFrameHost(node));
632 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, 849 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT,
633 GetSpeculativeRenderFrameHost(node)->rfh_state()); 850 GetSpeculativeRenderFrameHost(node)->rfh_state());
634 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1)); 851 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1));
635 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); 852 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
636 853
637 rfh1->SendNavigate(1, kUrl1); 854 rfh1->SendNavigate(1, kUrl1);
638 EXPECT_EQ(rfh1, main_test_rfh()); 855 EXPECT_EQ(rfh1, main_test_rfh());
639 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 856 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
640 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1)); 857 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1));
641 } 858 }
642 859
643 } // namespace content 860 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698