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

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

Issue 872473003: PlzNavigate: Remove the RequestNavigation IPC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits + fix compilation error 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"
11 #include "content/browser/frame_host/navigation_request_info.h" 11 #include "content/browser/frame_host/navigation_request_info.h"
12 #include "content/browser/frame_host/navigator.h" 12 #include "content/browser/frame_host/navigator.h"
13 #include "content/browser/frame_host/navigator_impl.h" 13 #include "content/browser/frame_host/navigator_impl.h"
14 #include "content/browser/frame_host/render_frame_host_manager.h" 14 #include "content/browser/frame_host/render_frame_host_manager.h"
15 #include "content/browser/site_instance_impl.h" 15 #include "content/browser/site_instance_impl.h"
16 #include "content/browser/streams/stream.h" 16 #include "content/browser/streams/stream.h"
17 #include "content/common/frame_messages.h"
17 #include "content/common/navigation_params.h" 18 #include "content/common/navigation_params.h"
18 #include "content/public/browser/stream_handle.h" 19 #include "content/public/browser/stream_handle.h"
19 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
20 #include "content/public/common/url_constants.h" 21 #include "content/public/common/url_constants.h"
21 #include "content/public/common/url_utils.h" 22 #include "content/public/common/url_utils.h"
22 #include "content/public/test/mock_render_process_host.h" 23 #include "content/public/test/mock_render_process_host.h"
23 #include "content/test/browser_side_navigation_test_utils.h" 24 #include "content/test/browser_side_navigation_test_utils.h"
24 #include "content/test/test_navigation_url_loader.h" 25 #include "content/test/test_navigation_url_loader.h"
25 #include "content/test/test_render_frame_host.h" 26 #include "content/test/test_render_frame_host.h"
26 #include "content/test/test_web_contents.h" 27 #include "content/test/test_web_contents.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); 142 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node();
142 SendRequestNavigation(subframe_node, kUrl2); 143 SendRequestNavigation(subframe_node, kUrl2);
143 // There is no previous renderer in the subframe, so BeginNavigation is 144 // There is no previous renderer in the subframe, so BeginNavigation is
144 // handled already. 145 // handled already.
145 NavigationRequest* subframe_request = 146 NavigationRequest* subframe_request =
146 GetNavigationRequestForFrameTreeNode(subframe_node); 147 GetNavigationRequestForFrameTreeNode(subframe_node);
147 TestNavigationURLLoader* subframe_loader = 148 TestNavigationURLLoader* subframe_loader =
148 GetLoaderForNavigationRequest(subframe_request); 149 GetLoaderForNavigationRequest(subframe_request);
149 ASSERT_TRUE(subframe_request); 150 ASSERT_TRUE(subframe_request);
150 EXPECT_EQ(kUrl2, subframe_request->common_params().url); 151 EXPECT_EQ(kUrl2, subframe_request->common_params().url);
151 EXPECT_EQ(kUrl2, subframe_loader->common_params().url); 152 EXPECT_EQ(kUrl2, subframe_loader->request_info()->common_params.url);
152 // First party for cookies url should be that of the main frame. 153 // First party for cookies url should be that of the main frame.
153 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); 154 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies);
154 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); 155 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame);
155 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); 156 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame);
156 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node)); 157 EXPECT_FALSE(GetSpeculativeRenderFrameHost(root_node));
157 158
158 // Subframe navigations should never create a speculative RenderFrameHost, 159 // Subframe navigations should never create a speculative RenderFrameHost,
159 // unless site-per-process is enabled. In that case, as the subframe 160 // unless site-per-process is enabled. In that case, as the subframe
160 // navigation is to a different site and is still ongoing, it should have one. 161 // navigation is to a different site and is still ongoing, it should have one.
161 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 162 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
162 switches::kSitePerProcess)) { 163 switches::kSitePerProcess)) {
163 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node)); 164 EXPECT_TRUE(GetSpeculativeRenderFrameHost(subframe_node));
164 } else { 165 } else {
165 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node)); 166 EXPECT_FALSE(GetSpeculativeRenderFrameHost(subframe_node));
166 } 167 }
167 168
168 SendRequestNavigation(root_node, kUrl3); 169 SendRequestNavigation(root_node, kUrl3);
169 // Simulate a BeginNavigation IPC on the main frame. 170 // Simulate a BeginNavigation IPC on the main frame.
170 main_test_rfh()->SendBeginNavigationWithURL(kUrl3); 171 main_test_rfh()->SendBeginNavigationWithURL(kUrl3);
171 NavigationRequest* main_request = 172 NavigationRequest* main_request =
172 GetNavigationRequestForFrameTreeNode(root_node); 173 GetNavigationRequestForFrameTreeNode(root_node);
173 TestNavigationURLLoader* main_loader = 174 TestNavigationURLLoader* main_loader =
174 GetLoaderForNavigationRequest(main_request); 175 GetLoaderForNavigationRequest(main_request);
175 ASSERT_TRUE(main_request); 176 ASSERT_TRUE(main_request);
176 EXPECT_EQ(kUrl3, main_request->common_params().url); 177 EXPECT_EQ(kUrl3, main_request->common_params().url);
177 EXPECT_EQ(kUrl3, main_loader->common_params().url); 178 EXPECT_EQ(kUrl3, main_loader->request_info()->common_params.url);
178 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); 179 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
179 EXPECT_TRUE(main_loader->request_info()->is_main_frame); 180 EXPECT_TRUE(main_loader->request_info()->is_main_frame);
180 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); 181 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
181 182
182 // Main frame navigation to a different site should use a speculative 183 // Main frame navigation to a different site should use a speculative
183 // RenderFrameHost. 184 // RenderFrameHost.
184 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node)); 185 EXPECT_TRUE(GetSpeculativeRenderFrameHost(root_node));
185 186
186 // As the main frame hasn't yet committed the subframe still exists. Thus, the 187 // As the main frame hasn't yet committed the subframe still exists. Thus, the
187 // above situation regarding subframe navigations is valid here. 188 // above situation regarding subframe navigations is valid here.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // RenderFrame when the navigation can commit. A speculative RenderFrameHost 447 // RenderFrame when the navigation can commit. A speculative RenderFrameHost
447 // should not be created at any step. 448 // should not be created at any step.
448 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) { 449 TEST_F(NavigatorTestWithBrowserSideNavigation, Reload) {
449 const GURL kUrl("http://www.google.com/"); 450 const GURL kUrl("http://www.google.com/");
450 contents()->NavigateAndCommit(kUrl); 451 contents()->NavigateAndCommit(kUrl);
451 452
452 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 453 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
453 SendRequestNavigationWithParameters( 454 SendRequestNavigationWithParameters(
454 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 455 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK,
455 NavigationController::RELOAD); 456 NavigationController::RELOAD);
456 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
457 // A NavigationRequest should have been generated. 457 // A NavigationRequest should have been generated.
458 NavigationRequest* main_request = 458 NavigationRequest* main_request =
459 GetNavigationRequestForFrameTreeNode(node); 459 GetNavigationRequestForFrameTreeNode(node);
460 ASSERT_TRUE(main_request != NULL); 460 ASSERT_TRUE(main_request != NULL);
461 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD, 461 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD,
462 main_request->common_params().navigation_type); 462 main_request->common_params().navigation_type);
463 main_test_rfh()->PrepareForCommit(kUrl);
463 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 464 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
464 465
465 main_test_rfh()->SendNavigate(0, kUrl); 466 main_test_rfh()->SendNavigate(0, kUrl);
466 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 467 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
467 468
468 // Now do a shift+reload. 469 // Now do a shift+reload.
469 SendRequestNavigationWithParameters( 470 SendRequestNavigationWithParameters(
470 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK, 471 node, kUrl, Referrer(), ui::PAGE_TRANSITION_LINK,
471 NavigationController::RELOAD_IGNORING_CACHE); 472 NavigationController::RELOAD_IGNORING_CACHE);
472 main_test_rfh()->SendBeginNavigationWithURL(kUrl);
473 // A NavigationRequest should have been generated. 473 // A NavigationRequest should have been generated.
474 main_request = GetNavigationRequestForFrameTreeNode(node); 474 main_request = GetNavigationRequestForFrameTreeNode(node);
475 ASSERT_TRUE(main_request != NULL); 475 ASSERT_TRUE(main_request != NULL);
476 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, 476 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
477 main_request->common_params().navigation_type); 477 main_request->common_params().navigation_type);
478 main_test_rfh()->PrepareForCommit(kUrl);
478 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node)); 479 EXPECT_FALSE(GetSpeculativeRenderFrameHost(node));
479 } 480 }
480 481
481 // PlzNavigate: Confirm that a speculative RenderFrameHost is used when 482 // PlzNavigate: Confirm that a speculative RenderFrameHost is used when
482 // navigating from one site to another. 483 // navigating from one site to another.
483 TEST_F(NavigatorTestWithBrowserSideNavigation, 484 TEST_F(NavigatorTestWithBrowserSideNavigation,
484 SpeculativeRendererWorksBaseCase) { 485 SpeculativeRendererWorksBaseCase) {
485 // Navigate to an initial site. 486 // Navigate to an initial site.
486 const GURL kUrlInit("http://wikipedia.org/"); 487 const GURL kUrlInit("http://wikipedia.org/");
487 contents()->NavigateAndCommit(kUrlInit); 488 contents()->NavigateAndCommit(kUrlInit);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1)); 637 EXPECT_TRUE(DidRenderFrameHostRequestCommit(rfh1));
637 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh())); 638 EXPECT_FALSE(DidRenderFrameHostRequestCommit(main_test_rfh()));
638 639
639 rfh1->SendNavigate(1, kUrl1); 640 rfh1->SendNavigate(1, kUrl1);
640 EXPECT_EQ(rfh1, main_test_rfh()); 641 EXPECT_EQ(rfh1, main_test_rfh());
641 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state()); 642 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh1->rfh_state());
642 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1)); 643 EXPECT_FALSE(rfhm->IsOnSwappedOutList(rfh1));
643 } 644 }
644 645
645 } // namespace content 646 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigator_impl.cc ('k') | content/browser/frame_host/render_frame_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698