OLD | NEW |
---|---|
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 load_params.frame_tree_node_id = node->frame_tree_node_id(); | 64 load_params.frame_tree_node_id = node->frame_tree_node_id(); |
65 load_params.referrer = referrer; | 65 load_params.referrer = referrer; |
66 load_params.transition_type = transition_type; | 66 load_params.transition_type = transition_type; |
67 | 67 |
68 controller().LoadURLWithParams(load_params); | 68 controller().LoadURLWithParams(load_params); |
69 } | 69 } |
70 | 70 |
71 NavigationRequest* GetNavigationRequestForFrameTreeNode( | 71 NavigationRequest* GetNavigationRequestForFrameTreeNode( |
72 FrameTreeNode* frame_tree_node) { | 72 FrameTreeNode* frame_tree_node) { |
73 return static_cast<NavigatorImpl*>(frame_tree_node->navigator()) | 73 return static_cast<NavigatorImpl*>(frame_tree_node->navigator()) |
74 ->GetNavigationRequestForNodeForTesting(frame_tree_node); | 74 ->GetNavigationRequestForNodeForTesting( |
75 frame_tree_node->frame_tree_node_id()); | |
75 } | 76 } |
76 | 77 |
77 TestRenderFrameHost* GetSpeculativeRenderFrameHost(FrameTreeNode* node) { | 78 TestRenderFrameHost* GetSpeculativeRenderFrameHost(FrameTreeNode* node) { |
78 return static_cast<TestRenderFrameHost*>( | 79 return static_cast<TestRenderFrameHost*>( |
79 node->render_manager()->speculative_render_frame_host_.get()); | 80 node->render_manager()->speculative_render_frame_host_.get()); |
80 } | 81 } |
81 | 82 |
82 // Checks if this RenderFrameHost sent a single FrameMsg_CommitNavigation | 83 // Checks if this RenderFrameHost sent a single FrameMsg_CommitNavigation |
83 // since the last clearing of the sink. | 84 // since the last clearing of the sink. |
84 // Note: caller must invoke ClearMessages on the sink at some point before | 85 // Note: caller must invoke ClearMessages on the sink at some point before |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 } | 268 } |
268 | 269 |
269 // PlzNavigate: Test that a proper NavigationRequest is created by | 270 // PlzNavigate: Test that a proper NavigationRequest is created by |
270 // RequestNavigation. | 271 // RequestNavigation. |
271 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { | 272 TEST_F(NavigatorTestWithBrowserSideNavigation, BeginNavigation) { |
272 const GURL kUrl1("http://www.google.com/"); | 273 const GURL kUrl1("http://www.google.com/"); |
273 const GURL kUrl2("http://www.chromium.org/"); | 274 const GURL kUrl2("http://www.chromium.org/"); |
274 const GURL kUrl3("http://www.gmail.com/"); | 275 const GURL kUrl3("http://www.gmail.com/"); |
275 | 276 |
276 contents()->NavigateAndCommit(kUrl1); | 277 contents()->NavigateAndCommit(kUrl1); |
278 process()->sink().ClearMessages(); | |
clamy
2015/04/14 15:32:03
Why this line?
carlosk
2015/04/23 16:10:12
As there's more than one commit happening and we c
| |
277 | 279 |
278 // Add a subframe. | 280 // Add a subframe. |
279 FrameTreeNode* root_node = contents()->GetFrameTree()->root(); | 281 FrameTreeNode* root_node = contents()->GetFrameTree()->root(); |
282 NavigatorImpl* navigator = | |
283 static_cast<NavigatorImpl*>(root_node->navigator()); | |
280 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); | 284 TestRenderFrameHost* subframe_rfh = main_test_rfh()->AppendChild("Child"); |
281 ASSERT_TRUE(subframe_rfh); | 285 ASSERT_TRUE(subframe_rfh); |
282 | 286 |
283 // Start a navigation at the subframe. | 287 // Start a navigation at the subframe. |
284 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); | 288 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); |
285 RequestNavigation(subframe_node, kUrl2); | 289 RequestNavigation(subframe_node, kUrl2); |
286 NavigationRequest* subframe_request = | 290 NavigationRequest* subframe_request = |
287 GetNavigationRequestForFrameTreeNode(subframe_node); | 291 navigator->GetNavigationRequestForNodeForTesting( |
292 subframe_node->frame_tree_node_id()); | |
288 TestNavigationURLLoader* subframe_loader = | 293 TestNavigationURLLoader* subframe_loader = |
289 GetLoaderForNavigationRequest(subframe_request); | 294 GetLoaderForNavigationRequest(subframe_request); |
290 | 295 |
291 // Subframe navigations should start right away as they don't have to request | 296 // Subframe navigations should start right away as they don't have to request |
292 // beforeUnload to run at the renderer. | 297 // beforeUnload to run at the renderer. |
293 ASSERT_TRUE(subframe_request); | 298 ASSERT_TRUE(subframe_request); |
294 ASSERT_TRUE(subframe_loader); | 299 ASSERT_TRUE(subframe_loader); |
295 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state()); | 300 EXPECT_EQ(NavigationRequest::STARTED, subframe_request->state()); |
296 EXPECT_EQ(kUrl2, subframe_request->common_params().url); | 301 EXPECT_EQ(kUrl2, subframe_request->common_params().url); |
297 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url); | 302 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url); |
(...skipping 10 matching lines...) Expand all Loading... | |
308 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 313 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
309 switches::kSitePerProcess)) { | 314 switches::kSitePerProcess)) { |
310 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); | 315 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); |
311 } else { | 316 } else { |
312 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); | 317 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); |
313 } | 318 } |
314 | 319 |
315 // Now start a navigation at the root node. | 320 // Now start a navigation at the root node. |
316 RequestNavigation(root_node, kUrl3); | 321 RequestNavigation(root_node, kUrl3); |
317 NavigationRequest* main_request = | 322 NavigationRequest* main_request = |
318 GetNavigationRequestForFrameTreeNode(root_node); | 323 navigator->GetNavigationRequestForNodeForTesting( |
324 root_node->frame_tree_node_id()); | |
319 ASSERT_TRUE(main_request); | 325 ASSERT_TRUE(main_request); |
320 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, | 326 EXPECT_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, |
321 main_request->state()); | 327 main_request->state()); |
322 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); | 328 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); |
323 | 329 |
324 // Simulate a BeforeUnloadACK IPC on the main frame. | 330 // Simulate a BeforeUnloadACK IPC on the main frame. |
325 main_test_rfh()->SendBeforeUnloadACK(true); | 331 main_test_rfh()->SendBeforeUnloadACK(true); |
326 TestNavigationURLLoader* main_loader = | 332 TestNavigationURLLoader* main_loader = |
327 GetLoaderForNavigationRequest(main_request); | 333 GetLoaderForNavigationRequest(main_request); |
328 EXPECT_EQ(kUrl3, main_request->common_params().url); | 334 EXPECT_EQ(kUrl3, main_request->common_params().url); |
329 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); | 335 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url); |
330 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); | 336 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); |
331 EXPECT_TRUE(main_loader->request_info()->is_main_frame); | 337 EXPECT_TRUE(main_loader->request_info()->is_main_frame); |
332 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); | 338 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); |
333 EXPECT_TRUE(main_request->browser_initiated()); | 339 EXPECT_TRUE(main_request->browser_initiated()); |
334 // BeforeUnloadACK was received from the renderer so the navigation should | 340 // BeforeUnloadACK was received from the renderer so the navigation should |
335 // have started. | 341 // have started. |
336 EXPECT_EQ(NavigationRequest::STARTED, main_request->state()); | 342 EXPECT_EQ(NavigationRequest::STARTED, main_request->state()); |
337 | 343 |
338 // Main frame navigation to a different site should use a speculative | 344 // Main frame navigation to a different site should use a speculative |
339 // RenderFrameHost. | 345 // RenderFrameHost. |
340 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); | 346 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); |
341 | 347 |
342 // As the main frame hasn't yet committed the subframe still exists. Thus, the | 348 // As the main frame hasn't yet committed the subframe still exists. Thus, the |
343 // above situation regarding subframe navigations is valid here. | 349 // above situation regarding subframe navigations is valid here. |
350 ASSERT_TRUE(navigator->GetNavigationRequestForNodeForTesting( | |
351 subframe_node->frame_tree_node_id())); | |
344 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 352 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
345 switches::kSitePerProcess)) { | 353 switches::kSitePerProcess)) { |
346 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); | 354 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); |
347 } else { | 355 } else { |
348 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); | 356 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); |
349 } | 357 } |
358 | |
359 // Have the root node's speculative RenderFrameHost commit the navigation. | |
360 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
361 main_loader->CallOnResponseStarted(response, MakeEmptyStream()); | |
362 TestRenderFrameHost* speculative_root_rfh = | |
363 GetSpeculativeRenderFrameHost(root_node); | |
364 ASSERT_TRUE(speculative_root_rfh); | |
365 EXPECT_TRUE(DidRenderFrameHostRequestCommit(speculative_root_rfh)); | |
366 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); | |
367 | |
368 // The subframe request is still there as the subframe still exists. | |
nasko
2015/04/14 16:06:29
This doesn't match reality and I'm not sure it is
carlosk
2015/04/23 16:10:13
The request still exists because at this stage we'
| |
369 ASSERT_TRUE(navigator->GetNavigationRequestForNodeForTesting( | |
370 subframe_node->frame_tree_node_id())); | |
371 | |
372 // Commit the navigation. | |
clamy
2015/04/14 15:32:03
Add that the subframe will be destroyed as a resul
carlosk
2015/04/23 16:10:13
This code was removed.
| |
373 int64 subframe_node_id = subframe_node->frame_tree_node_id(); | |
374 speculative_root_rfh->SendNavigate(1, kUrl3); | |
375 subframe_node = nullptr; // Was just destroyed. | |
clamy
2015/04/14 15:32:03
I don't think this line is needed.
carlosk
2015/04/23 16:10:12
I was copying a pattern I saw in RenderFrameHostMa
| |
376 | |
377 // The subframe request should have been cleaned up with the subframe. | |
378 ASSERT_FALSE(navigator->GetNavigationRequestForNodeForTesting( | |
379 subframe_node_id)); | |
350 } | 380 } |
351 | 381 |
352 // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels | 382 // PlzNavigate: Test that committing an HTTP 204 or HTTP 205 response cancels |
353 // the navigation. | 383 // the navigation. |
354 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { | 384 TEST_F(NavigatorTestWithBrowserSideNavigation, NoContent) { |
355 const GURL kUrl1("http://www.chromium.org/"); | 385 const GURL kUrl1("http://www.chromium.org/"); |
356 const GURL kUrl2("http://www.google.com/"); | 386 const GURL kUrl2("http://www.google.com/"); |
357 | 387 |
358 // Load a URL. | 388 // Load a URL. |
359 contents()->NavigateAndCommit(kUrl1); | 389 contents()->NavigateAndCommit(kUrl1); |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1130 | 1160 |
1131 SiteInstance* converted_instance_2 = | 1161 SiteInstance* converted_instance_2 = |
1132 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get()); | 1162 ConvertToSiteInstance(rfhm, descriptor, unrelated_instance.get()); |
1133 // Should return |unrelated_instance| because its site matches and it is | 1163 // Should return |unrelated_instance| because its site matches and it is |
1134 // unrelated to the current SiteInstance. | 1164 // unrelated to the current SiteInstance. |
1135 EXPECT_EQ(unrelated_instance.get(), converted_instance_2); | 1165 EXPECT_EQ(unrelated_instance.get(), converted_instance_2); |
1136 } | 1166 } |
1137 } | 1167 } |
1138 | 1168 |
1139 } // namespace content | 1169 } // namespace content |
OLD | NEW |