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

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

Issue 519533002: Initial PlzNavigate RDH-side logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 6 years, 2 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/test/histogram_tester.h" 6 #include "base/test/histogram_tester.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/frame_host/navigation_before_commit_info.h"
9 #include "content/browser/frame_host/navigation_controller_impl.h" 8 #include "content/browser/frame_host/navigation_controller_impl.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
11 #include "content/browser/frame_host/navigation_request.h" 10 #include "content/browser/frame_host/navigation_request.h"
12 #include "content/browser/frame_host/navigation_request_info.h" 11 #include "content/browser/frame_host/navigation_request_info.h"
13 #include "content/browser/frame_host/navigator.h" 12 #include "content/browser/frame_host/navigator.h"
14 #include "content/browser/frame_host/navigator_impl.h" 13 #include "content/browser/frame_host/navigator_impl.h"
15 #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/loader/navigation_url_loader.h"
16 #include "content/browser/loader/navigation_url_loader_factory.h"
16 #include "content/browser/site_instance_impl.h" 17 #include "content/browser/site_instance_impl.h"
17 #include "content/common/navigation_params.h" 18 #include "content/common/navigation_params.h"
19 #include "content/public/browser/stream_handle.h"
18 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
19 #include "content/public/common/url_constants.h" 21 #include "content/public/common/url_constants.h"
20 #include "content/public/common/url_utils.h" 22 #include "content/public/common/url_utils.h"
21 #include "content/test/test_render_frame_host.h" 23 #include "content/test/test_render_frame_host.h"
22 #include "content/test/test_web_contents.h" 24 #include "content/test/test_web_contents.h"
23 #include "net/base/load_flags.h" 25 #include "net/base/load_flags.h"
26 #include "net/url_request/redirect_info.h"
24 #include "ui/base/page_transition_types.h" 27 #include "ui/base/page_transition_types.h"
25 28
26 namespace content { 29 namespace content {
27 30
31 namespace {
32
33 class TestNavigationURLLoader : public NavigationURLLoader {
34 public:
35 TestNavigationURLLoader(const CommonNavigationParams& common_params,
36 scoped_ptr<NavigationRequestInfo> request_info,
37 NavigationURLLoader::Delegate* delegate)
38 : common_params_(common_params),
39 request_info_(request_info.Pass()),
40 delegate_(delegate) {
41 }
42
43 virtual ~TestNavigationURLLoader() {
44 // Record the number of times a loader was canceled before ResponseStarted
45 // or RequestFailed was returned.
46 if (delegate_)
47 cancel_count_++;
48 }
49
50 // NavigationURLLoader implementation.
51 virtual void FollowRedirect() OVERRIDE {
52 redirect_count_++;
53 }
54
55 const CommonNavigationParams& common_params() const { return common_params_; }
56 NavigationRequestInfo* request_info() const { return request_info_.get(); }
57
58 void CallOnRequestRedirected(const net::RedirectInfo& redirect_info,
59 ResourceResponse* response) {
60 delegate_->OnRequestRedirected(redirect_info, response);
61 }
62
63 void CallOnResponseStarted(ResourceResponse* response,
64 scoped_ptr<StreamHandle> body) {
65 delegate_->OnResponseStarted(response, body.Pass());
66 delegate_ = NULL;
67 }
68
69 static int redirect_count() { return redirect_count_; }
70 static int cancel_count() { return cancel_count_; }
71
72 private:
73 static int redirect_count_;
74 static int cancel_count_;
75
76 CommonNavigationParams common_params_;
77 scoped_ptr<NavigationRequestInfo> request_info_;
78 NavigationURLLoader::Delegate* delegate_;
79 };
80
81 int TestNavigationURLLoader::redirect_count_ = 0;
82 int TestNavigationURLLoader::cancel_count_ = 0;
83
84 class TestNavigationURLLoaderFactory : public NavigationURLLoaderFactory {
85 public:
86 // NavigationURLLoaderFactory implementation.
87 virtual scoped_ptr<NavigationURLLoader> CreateLoader(
88 BrowserContext* browser_context,
89 int64 frame_tree_node_id,
90 const CommonNavigationParams& common_params,
91 scoped_ptr<NavigationRequestInfo> request_info,
92 ResourceRequestBody* request_body,
93 NavigationURLLoader::Delegate* delegate) OVERRIDE {
94 return scoped_ptr<NavigationURLLoader>(new TestNavigationURLLoader(
95 common_params, request_info.Pass(), delegate));
96 }
97 };
98
99 // Mocked out stream handle to call OnResponseStarted with.
100 class TestStreamHandle : public StreamHandle {
101 public:
102 TestStreamHandle() : url_("test:stream") {}
103
104 virtual const GURL& GetURL() OVERRIDE {
105 return url_;
106 }
107
108 virtual void AddCloseListener(const base::Closure& callback) OVERRIDE {
109 NOTREACHED();
110 }
111 private:
112 GURL url_;
113
114 DISALLOW_COPY_AND_ASSIGN(TestStreamHandle);
115 };
116
117 }
118
28 class NavigatorTest 119 class NavigatorTest
29 : public RenderViewHostImplTestHarness { 120 : public RenderViewHostImplTestHarness {
30 public: 121 public:
122 virtual void SetUp() OVERRIDE {
123 RenderViewHostImplTestHarness::SetUp();
124 loader_factory_.reset(new TestNavigationURLLoaderFactory);
125 NavigationURLLoader::SetFactoryForTesting(loader_factory_.get());
126 }
127
128 virtual void TearDown() OVERRIDE {
129 NavigationURLLoader::SetFactoryForTesting(NULL);
130 loader_factory_.reset();
131 RenderViewHostImplTestHarness::TearDown();
132 }
133
31 NavigationRequest* GetNavigationRequestForFrameTreeNode( 134 NavigationRequest* GetNavigationRequestForFrameTreeNode(
32 FrameTreeNode* frame_tree_node) const { 135 FrameTreeNode* frame_tree_node) const {
33 NavigatorImpl* navigator = 136 NavigatorImpl* navigator =
34 static_cast<NavigatorImpl*>(frame_tree_node->navigator()); 137 static_cast<NavigatorImpl*>(frame_tree_node->navigator());
35 return navigator->navigation_request_map_.get( 138 return navigator->navigation_request_map_.get(
36 frame_tree_node->frame_tree_node_id()); 139 frame_tree_node->frame_tree_node_id());
37 } 140 }
38 141
142 TestNavigationURLLoader* GetLoaderForNavigationRequest(
143 NavigationRequest* request) const {
144 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing());
145 }
146
39 void EnableBrowserSideNavigation() { 147 void EnableBrowserSideNavigation() {
40 CommandLine::ForCurrentProcess()->AppendSwitch( 148 CommandLine::ForCurrentProcess()->AppendSwitch(
41 switches::kEnableBrowserSideNavigation); 149 switches::kEnableBrowserSideNavigation);
42 } 150 }
43 151
44 void SendRequestNavigation(FrameTreeNode* node, 152 void SendRequestNavigation(FrameTreeNode* node,
45 const GURL& url) { 153 const GURL& url) {
46 SendRequestNavigationWithParameters( 154 SendRequestNavigationWithParameters(
47 node, url, Referrer(), ui::PAGE_TRANSITION_LINK, 155 node, url, Referrer(), ui::PAGE_TRANSITION_LINK,
48 NavigationController::NO_RELOAD); 156 NavigationController::NO_RELOAD);
(...skipping 10 matching lines...) Expand all
59 NavigationController::CreateNavigationEntry( 167 NavigationController::CreateNavigationEntry(
60 url, 168 url,
61 referrer, 169 referrer,
62 transition_type, 170 transition_type,
63 false, 171 false,
64 std::string(), 172 std::string(),
65 controller().GetBrowserContext()))); 173 controller().GetBrowserContext())));
66 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( 174 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation(
67 node, *entry, reload_type, base::TimeTicks::Now()); 175 node, *entry, reload_type, base::TimeTicks::Now());
68 } 176 }
177
178 private:
179 scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_;
69 }; 180 };
70 181
71 // PlzNavigate: Test that a proper NavigationRequest is created by 182 // PlzNavigate: Test that a proper NavigationRequest is created by
72 // BeginNavigation. 183 // BeginNavigation.
73 // Note that all PlzNavigate methods on the browser side require the use of the 184 // Note that all PlzNavigate methods on the browser side require the use of the
74 // flag kEnableBrowserSideNavigation. 185 // flag kEnableBrowserSideNavigation.
75 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) { 186 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) {
76 const GURL kUrl1("http://www.google.com/"); 187 const GURL kUrl1("http://www.google.com/");
77 const GURL kUrl2("http://www.chromium.org/"); 188 const GURL kUrl2("http://www.chromium.org/");
78 const GURL kUrl3("http://www.gmail.com/"); 189 const GURL kUrl3("http://www.gmail.com/");
79 const int64 kFirstNavRequestID = 1;
80 190
81 EnableBrowserSideNavigation(); 191 EnableBrowserSideNavigation();
82 contents()->NavigateAndCommit(kUrl1); 192 contents()->NavigateAndCommit(kUrl1);
83 193
84 // Add a subframe. 194 // Add a subframe.
85 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( 195 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>(
86 contents()->GetFrameTree()->AddFrame( 196 contents()->GetFrameTree()->AddFrame(
87 contents()->GetFrameTree()->root(), 14, "Child")); 197 contents()->GetFrameTree()->root(), 14, "Child"));
88 198
89 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); 199 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node();
90 SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2); 200 SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2);
91 // Simulate a BeginNavigation IPC on the subframe. 201 // There is no previous renderer, so BeginNavigation is handled already.
92 subframe_rfh->SendBeginNavigationWithURL(kUrl2);
93 NavigationRequest* subframe_request = 202 NavigationRequest* subframe_request =
94 GetNavigationRequestForFrameTreeNode(subframe_node); 203 GetNavigationRequestForFrameTreeNode(subframe_node);
204 TestNavigationURLLoader* subframe_loader =
205 GetLoaderForNavigationRequest(subframe_request);
95 ASSERT_TRUE(subframe_request); 206 ASSERT_TRUE(subframe_request);
96 EXPECT_EQ(kUrl2, subframe_request->common_params().url); 207 EXPECT_EQ(kUrl2, subframe_request->common_params().url);
208 EXPECT_EQ(kUrl2, subframe_loader->common_params().url);
97 // First party for cookies url should be that of the main frame. 209 // First party for cookies url should be that of the main frame.
98 EXPECT_EQ(kUrl1, subframe_request->info_for_test()->first_party_for_cookies); 210 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies);
99 EXPECT_FALSE(subframe_request->info_for_test()->is_main_frame); 211 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame);
100 EXPECT_TRUE(subframe_request->info_for_test()->parent_is_main_frame); 212 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame);
101 EXPECT_EQ(kFirstNavRequestID + 1, subframe_request->navigation_request_id());
102 213
103 FrameTreeNode* main_frame_node = 214 FrameTreeNode* main_frame_node =
104 contents()->GetMainFrame()->frame_tree_node(); 215 contents()->GetMainFrame()->frame_tree_node();
105 SendRequestNavigation(main_frame_node, kUrl3); 216 SendRequestNavigation(main_frame_node, kUrl3);
106 // Simulate a BeginNavigation IPC on the main frame. 217 // There is no previous renderer, so BeginNavigation is handled already.
107 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3);
108 NavigationRequest* main_request = 218 NavigationRequest* main_request =
109 GetNavigationRequestForFrameTreeNode(main_frame_node); 219 GetNavigationRequestForFrameTreeNode(main_frame_node);
220 TestNavigationURLLoader* main_loader =
221 GetLoaderForNavigationRequest(main_request);
110 ASSERT_TRUE(main_request); 222 ASSERT_TRUE(main_request);
111 EXPECT_EQ(kUrl3, main_request->common_params().url); 223 EXPECT_EQ(kUrl3, main_request->common_params().url);
112 EXPECT_EQ(kUrl3, main_request->info_for_test()->first_party_for_cookies); 224 EXPECT_EQ(kUrl3, main_loader->common_params().url);
113 EXPECT_TRUE(main_request->info_for_test()->is_main_frame); 225 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies);
114 EXPECT_FALSE(main_request->info_for_test()->parent_is_main_frame); 226 EXPECT_TRUE(main_loader->request_info()->is_main_frame);
115 EXPECT_EQ(kFirstNavRequestID + 2, main_request->navigation_request_id()); 227 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame);
116 } 228 }
117 229
118 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that 230 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
119 // RenderFrameHost is not modified when the navigation commits. 231 // RenderFrameHost is not modified when the navigation commits.
120 TEST_F(NavigatorTest, 232 TEST_F(NavigatorTest, BrowserSideNavigationRequestNavigationNoLiveRenderer) {
121 BrowserSideNavigationRequestNavigationNoLiveRenderer) {
122 const GURL kUrl("http://www.google.com/"); 233 const GURL kUrl("http://www.google.com/");
123 234
124 EnableBrowserSideNavigation(); 235 EnableBrowserSideNavigation();
125 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 236 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
126 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 237 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
127 SendRequestNavigation(node, kUrl); 238 SendRequestNavigation(node, kUrl);
128 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 239 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
129 // A NavigationRequest should have been generated. 240 // A NavigationRequest should have been generated.
130 EXPECT_TRUE(main_request != NULL); 241 EXPECT_TRUE(main_request != NULL);
131 RenderFrameHostImpl* rfh = main_test_rfh(); 242 RenderFrameHostImpl* rfh = main_test_rfh();
132 243
133 // Now commit the same url. 244 // Now return the response without any redirects. This will cause the
134 NavigationBeforeCommitInfo commit_info; 245 // navigation to commit at the same URL.
135 commit_info.navigation_url = kUrl; 246 scoped_refptr<ResourceResponse> response(new ResourceResponse);
136 commit_info.navigation_request_id = main_request->navigation_request_id(); 247 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
137 node->navigator()->CommitNavigation(node, commit_info); 248 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
138 main_request = GetNavigationRequestForFrameTreeNode(node); 249 main_request = GetNavigationRequestForFrameTreeNode(node);
139 250
140 // The main RFH should not have been changed, and the renderer should have 251 // The main RFH should not have been changed, and the renderer should have
141 // been initialized. 252 // been initialized.
142 EXPECT_EQ(rfh, main_test_rfh()); 253 EXPECT_EQ(rfh, main_test_rfh());
143 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); 254 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive());
144 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 255 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
145 } 256 }
146 257
147 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross 258 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross
148 // site navigation. 259 // site navigation.
149 TEST_F(NavigatorTest, 260 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) {
150 BrowserSideNavigationCrossSiteNavigation) {
151 const GURL kUrl1("http://www.chromium.org/"); 261 const GURL kUrl1("http://www.chromium.org/");
152 const GURL kUrl2("http://www.google.com/"); 262 const GURL kUrl2("http://www.google.com/");
153 263
154 EnableBrowserSideNavigation();
155 contents()->NavigateAndCommit(kUrl1); 264 contents()->NavigateAndCommit(kUrl1);
156 RenderFrameHostImpl* rfh = main_test_rfh(); 265 RenderFrameHostImpl* rfh = main_test_rfh();
157 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); 266 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
158 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 267 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
159 268
269 EnableBrowserSideNavigation();
270
160 // Navigate to a different site. 271 // Navigate to a different site.
161 SendRequestNavigation(node, kUrl2); 272 SendRequestNavigation(node, kUrl2);
162 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 273 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
163 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 274 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
164 ASSERT_TRUE(main_request); 275 ASSERT_TRUE(main_request);
165 276
166 NavigationBeforeCommitInfo commit_info; 277 scoped_refptr<ResourceResponse> response(new ResourceResponse);
167 commit_info.navigation_url = kUrl2; 278 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
168 commit_info.navigation_request_id = main_request->navigation_request_id(); 279 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
169 node->navigator()->CommitNavigation(node, commit_info); 280 RenderFrameHostImpl* pending_rfh =
170 EXPECT_NE(main_test_rfh(), rfh); 281 node->render_manager()->pending_frame_host();
171 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); 282 ASSERT_TRUE(pending_rfh);
172 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 283 EXPECT_NE(pending_rfh, rfh);
284 EXPECT_TRUE(pending_rfh->IsRenderFrameLive());
285 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive());
173 } 286 }
174 287
175 // PlzNavigate: Test that a navigation commit is ignored if another request has 288 // PlzNavigate: Test that redirects are followed.
176 // been issued in the meantime. 289 TEST_F(NavigatorTest, BrowserSideNavigationRedirectCrossSite) {
177 // TODO(carlosk): add checks to assert that the cancel call was sent to 290 const GURL kUrl1("http://www.chromium.org/");
178 // ResourceDispatcherHost in the IO thread by extending 291 const GURL kUrl2("http://www.google.com/");
179 // ResourceDispatcherHostDelegate (like in cross_site_transfer_browsertest.cc 292
180 // and plugin_browsertest.cc). 293 contents()->NavigateAndCommit(kUrl1);
181 TEST_F(NavigatorTest, 294 RenderFrameHostImpl* rfh = main_test_rfh();
182 BrowserSideNavigationIgnoreStaleNavigationCommit) { 295 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
296 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
297
298 EnableBrowserSideNavigation();
299
300 // Navigate to a URL on the same site.
301 SendRequestNavigation(node, kUrl1);
302 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
303 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
304 ASSERT_TRUE(main_request);
305
306 // It then redirects to another site.
307 net::RedirectInfo redirect_info;
308 redirect_info.status_code = 302;
309 redirect_info.new_method = "GET";
310 redirect_info.new_url = kUrl2;
311 redirect_info.new_first_party_for_cookies = kUrl2;
312 scoped_refptr<ResourceResponse> response(new ResourceResponse);
313 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected(
314 redirect_info, response.get());
315
316 // The redirect should have been followed.
317 EXPECT_EQ(1, TestNavigationURLLoader::redirect_count());
318
319 // Then it commits.
320 response = new ResourceResponse;
321 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted(
322 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
323 RenderFrameHostImpl* pending_rfh =
324 node->render_manager()->pending_frame_host();
325 ASSERT_TRUE(pending_rfh);
326 EXPECT_NE(pending_rfh, rfh);
327 EXPECT_TRUE(pending_rfh->IsRenderFrameLive());
328 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive());
329 }
330
331 // PlzNavigate: Test that a navigation is cancelled if another request has been
332 // issued in the meantime.
333 TEST_F(NavigatorTest, BrowserSideNavigationReplacePendingNavigation) {
183 const GURL kUrl0("http://www.wikipedia.org/"); 334 const GURL kUrl0("http://www.wikipedia.org/");
184 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); 335 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0);
185 const GURL kUrl1("http://www.chromium.org/"); 336 const GURL kUrl1("http://www.chromium.org/");
186 const GURL kUrl2("http://www.google.com/"); 337 const GURL kUrl2("http://www.google.com/");
187 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); 338 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2);
188 339
189 // Initialization. 340 // Initialization.
190 contents()->NavigateAndCommit(kUrl0); 341 contents()->NavigateAndCommit(kUrl0);
191 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 342 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
192 EnableBrowserSideNavigation(); 343 EnableBrowserSideNavigation();
193 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); 344 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
194 345
195 // Request navigation to the 1st URL and gather data. 346 // Request navigation to the 1st URL and gather data.
196 SendRequestNavigation(node, kUrl1); 347 SendRequestNavigation(node, kUrl1);
197 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); 348 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
198 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node); 349 NavigationRequest* request1 = GetNavigationRequestForFrameTreeNode(node);
199 ASSERT_TRUE(request1); 350 ASSERT_TRUE(request1);
200 int64 request_id1 = request1->navigation_request_id(); 351 int cancel_count = TestNavigationURLLoader::cancel_count();
201 352
202 // Request navigation to the 2nd URL and gather more data. 353 // Request navigation to the 2nd URL and gather more data.
203 SendRequestNavigation(node, kUrl2); 354 SendRequestNavigation(main_test_rfh()->frame_tree_node(), kUrl2);
204 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 355 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
205 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); 356 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
206 ASSERT_TRUE(request2); 357 ASSERT_TRUE(request2);
207 int64 request_id2 = request2->navigation_request_id();
208 EXPECT_NE(request_id1, request_id2);
209 358
210 // Confirms that a stale commit is ignored by the Navigator. 359 // Confirm that the first request got canceled.
211 NavigationBeforeCommitInfo nbc_info; 360 EXPECT_EQ(cancel_count + 1, TestNavigationURLLoader::cancel_count());
212 nbc_info.navigation_url = kUrl1;
213 nbc_info.navigation_request_id = request_id1;
214 node->navigator()->CommitNavigation(node, nbc_info);
215 EXPECT_FALSE(node->render_manager()->pending_frame_host());
216 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL());
217 361
218 // Confirms that a valid, request-matching commit is correctly processed. 362 // Confirms that a valid, request-matching commit is correctly processed.
219 nbc_info.navigation_url = kUrl2; 363 scoped_refptr<ResourceResponse> response(new ResourceResponse);
220 nbc_info.navigation_request_id = request_id2; 364 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted(
221 node->navigator()->CommitNavigation(node, nbc_info); 365 response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
222 RenderFrameHostImpl* pending_rfh = 366 RenderFrameHostImpl* pending_rfh =
223 node->render_manager()->pending_frame_host(); 367 node->render_manager()->pending_frame_host();
224 ASSERT_TRUE(pending_rfh); 368 ASSERT_TRUE(pending_rfh);
225 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); 369 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL());
370
371 // The loader should not have been canceled.
372 EXPECT_EQ(cancel_count + 1, TestNavigationURLLoader::cancel_count());
226 } 373 }
227 374
228 // PlzNavigate: Tests that the navigation histograms are correctly tracked both 375 // PlzNavigate: Tests that the navigation histograms are correctly tracked both
229 // when PlzNavigate is enabled and disabled, and also ignores in-tab renderer 376 // when PlzNavigate is enabled and disabled, and also ignores in-tab renderer
230 // initiated navigation for the non-enabled case. 377 // initiated navigation for the non-enabled case.
231 // Note: the related histogram, Navigation.TimeToURLJobStart, cannot be tracked 378 // Note: the related histogram, Navigation.TimeToURLJobStart, cannot be tracked
232 // by this test as the IO thread is not running. 379 // by this test as the IO thread is not running.
233 TEST_F(NavigatorTest, BrowserSideNavigationHistogramTest) { 380 TEST_F(NavigatorTest, BrowserSideNavigationHistogramTest) {
234 const GURL kUrl0("http://www.google.com/"); 381 const GURL kUrl0("http://www.google.com/");
235 const GURL kUrl1("http://www.chromium.org/"); 382 const GURL kUrl1("http://www.chromium.org/");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 NavigationController::RELOAD_IGNORING_CACHE); 426 NavigationController::RELOAD_IGNORING_CACHE);
280 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); 427 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl);
281 // A NavigationRequest should have been generated. 428 // A NavigationRequest should have been generated.
282 main_request = GetNavigationRequestForFrameTreeNode(node); 429 main_request = GetNavigationRequestForFrameTreeNode(node);
283 ASSERT_TRUE(main_request != NULL); 430 ASSERT_TRUE(main_request != NULL);
284 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, 431 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
285 main_request->common_params().navigation_type); 432 main_request->common_params().navigation_type);
286 } 433 }
287 434
288 } // namespace content 435 } // 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