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

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

Issue 625993002: Split up streams logic to prepare for PlzNavigate RDH changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove TestStreamHandle in favor of just making an empty one. 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/guid.h"
6 #include "base/macros.h" 7 #include "base/macros.h"
7 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
8 #include "base/time/time.h" 9 #include "base/time/time.h"
9 #include "content/browser/frame_host/navigation_controller_impl.h" 10 #include "content/browser/frame_host/navigation_controller_impl.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 11 #include "content/browser/frame_host/navigation_entry_impl.h"
11 #include "content/browser/frame_host/navigation_request.h" 12 #include "content/browser/frame_host/navigation_request.h"
12 #include "content/browser/frame_host/navigation_request_info.h" 13 #include "content/browser/frame_host/navigation_request_info.h"
13 #include "content/browser/frame_host/navigator.h" 14 #include "content/browser/frame_host/navigator.h"
14 #include "content/browser/frame_host/navigator_impl.h" 15 #include "content/browser/frame_host/navigator_impl.h"
15 #include "content/browser/frame_host/render_frame_host_manager.h" 16 #include "content/browser/frame_host/render_frame_host_manager.h"
16 #include "content/browser/site_instance_impl.h" 17 #include "content/browser/site_instance_impl.h"
18 #include "content/browser/streams/stream.h"
19 #include "content/browser/streams/stream_registry.h"
17 #include "content/common/navigation_params.h" 20 #include "content/common/navigation_params.h"
18 #include "content/public/browser/stream_handle.h" 21 #include "content/public/browser/stream_handle.h"
19 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
20 #include "content/public/common/url_constants.h" 23 #include "content/public/common/url_constants.h"
21 #include "content/public/common/url_utils.h" 24 #include "content/public/common/url_utils.h"
22 #include "content/test/test_render_frame_host.h" 25 #include "content/test/test_render_frame_host.h"
23 #include "content/test/test_web_contents.h" 26 #include "content/test/test_web_contents.h"
24 #include "net/base/load_flags.h" 27 #include "net/base/load_flags.h"
25 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
26 #include "ui/base/page_transition_types.h" 29 #include "ui/base/page_transition_types.h"
30 #include "url/url_constants.h"
27 31
28 namespace content { 32 namespace content {
29 33
30 namespace { 34 class NavigatorTest : public RenderViewHostImplTestHarness {
35 public:
36 NavigatorTest() : stream_registry_(new StreamRegistry) {}
31 37
32 // Mocked out stream handle to commit the navigation with.
33 class TestStreamHandle : public StreamHandle {
34 public:
35 TestStreamHandle() : url_("test:stream") {}
36
37 virtual const GURL& GetURL() override {
38 return url_;
39 }
40
41 virtual const GURL& GetOriginalURL() override {
42 NOTREACHED();
43 return original_url_;
44 }
45
46 virtual const std::string& GetMimeType() override {
47 NOTREACHED();
48 return mime_type_;
49 }
50
51 virtual scoped_refptr<net::HttpResponseHeaders>
52 GetResponseHeaders() override {
53 NOTREACHED();
54 return NULL;
55 }
56
57 virtual void AddCloseListener(const base::Closure& callback) override {
58 NOTREACHED();
59 }
60
61 private:
62 GURL url_;
63 GURL original_url_;
64 std::string mime_type_;
65
66 DISALLOW_COPY_AND_ASSIGN(TestStreamHandle);
67 };
68
69 }
70
71 class NavigatorTest
72 : public RenderViewHostImplTestHarness {
73 public:
74 NavigationRequest* GetNavigationRequestForFrameTreeNode( 38 NavigationRequest* GetNavigationRequestForFrameTreeNode(
75 FrameTreeNode* frame_tree_node) const { 39 FrameTreeNode* frame_tree_node) const {
76 NavigatorImpl* navigator = 40 NavigatorImpl* navigator =
77 static_cast<NavigatorImpl*>(frame_tree_node->navigator()); 41 static_cast<NavigatorImpl*>(frame_tree_node->navigator());
78 return navigator->navigation_request_map_.get( 42 return navigator->navigation_request_map_.get(
79 frame_tree_node->frame_tree_node_id()); 43 frame_tree_node->frame_tree_node_id());
80 } 44 }
81 45
82 void EnableBrowserSideNavigation() { 46 void EnableBrowserSideNavigation() {
83 CommandLine::ForCurrentProcess()->AppendSwitch( 47 CommandLine::ForCurrentProcess()->AppendSwitch(
(...skipping 18 matching lines...) Expand all
102 NavigationController::CreateNavigationEntry( 66 NavigationController::CreateNavigationEntry(
103 url, 67 url,
104 referrer, 68 referrer,
105 transition_type, 69 transition_type,
106 false, 70 false,
107 std::string(), 71 std::string(),
108 controller().GetBrowserContext()))); 72 controller().GetBrowserContext())));
109 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation( 73 static_cast<NavigatorImpl*>(node->navigator())->RequestNavigation(
110 node, *entry, reload_type, base::TimeTicks::Now()); 74 node, *entry, reload_type, base::TimeTicks::Now());
111 } 75 }
76
77 scoped_ptr<StreamHandle> MakeEmptyStream() {
78 GURL url(std::string(url::kBlobScheme) + "://" + base::GenerateGUID());
79 scoped_refptr<Stream> stream(new Stream(stream_registry_.get(), NULL, url));
80 stream->Finalize();
81 return stream->CreateHandle();
82 }
83
84 private:
85 scoped_ptr<StreamRegistry> stream_registry_;
112 }; 86 };
113 87
114 // PlzNavigate: Test that a proper NavigationRequest is created by 88 // PlzNavigate: Test that a proper NavigationRequest is created by
115 // BeginNavigation. 89 // BeginNavigation.
116 // Note that all PlzNavigate methods on the browser side require the use of the 90 // Note that all PlzNavigate methods on the browser side require the use of the
117 // flag kEnableBrowserSideNavigation. 91 // flag kEnableBrowserSideNavigation.
118 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) { 92 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) {
119 const GURL kUrl1("http://www.google.com/"); 93 const GURL kUrl1("http://www.google.com/");
120 const GURL kUrl2("http://www.chromium.org/"); 94 const GURL kUrl2("http://www.chromium.org/");
121 const GURL kUrl3("http://www.gmail.com/"); 95 const GURL kUrl3("http://www.gmail.com/");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 139 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
166 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 140 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
167 SendRequestNavigation(node, kUrl); 141 SendRequestNavigation(node, kUrl);
168 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 142 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
169 // A NavigationRequest should have been generated. 143 // A NavigationRequest should have been generated.
170 EXPECT_TRUE(main_request != NULL); 144 EXPECT_TRUE(main_request != NULL);
171 RenderFrameHostImpl* rfh = main_test_rfh(); 145 RenderFrameHostImpl* rfh = main_test_rfh();
172 146
173 // Now commit the same url. 147 // Now commit the same url.
174 scoped_refptr<ResourceResponse> response(new ResourceResponse); 148 scoped_refptr<ResourceResponse> response(new ResourceResponse);
175 node->navigator()->CommitNavigation( 149 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream());
176 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
177 main_request = GetNavigationRequestForFrameTreeNode(node); 150 main_request = GetNavigationRequestForFrameTreeNode(node);
178 151
179 // The main RFH should not have been changed, and the renderer should have 152 // The main RFH should not have been changed, and the renderer should have
180 // been initialized. 153 // been initialized.
181 EXPECT_EQ(rfh, main_test_rfh()); 154 EXPECT_EQ(rfh, main_test_rfh());
182 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); 155 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive());
183 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 156 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive());
184 } 157 }
185 158
186 // PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the 159 // PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the
(...skipping 14 matching lines...) Expand all
201 SendRequestNavigation(node, kUrl2); 174 SendRequestNavigation(node, kUrl2);
202 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 175 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
203 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 176 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
204 ASSERT_TRUE(main_request); 177 ASSERT_TRUE(main_request);
205 178
206 // Commit an HTTP 204 response. 179 // Commit an HTTP 204 response.
207 scoped_refptr<ResourceResponse> response(new ResourceResponse); 180 scoped_refptr<ResourceResponse> response(new ResourceResponse);
208 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0"; 181 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0";
209 response->head.headers = new net::HttpResponseHeaders( 182 response->head.headers = new net::HttpResponseHeaders(
210 std::string(kNoContentHeaders, arraysize(kNoContentHeaders))); 183 std::string(kNoContentHeaders, arraysize(kNoContentHeaders)));
211 node->navigator()->CommitNavigation( 184 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream());
212 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
213 185
214 // There should be no pending RenderFrameHost; the navigation was aborted. 186 // There should be no pending RenderFrameHost; the navigation was aborted.
215 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); 187 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
216 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 188 EXPECT_FALSE(node->render_manager()->pending_frame_host());
217 189
218 // Now, repeat the test with 205 Reset Content. 190 // Now, repeat the test with 205 Reset Content.
219 191
220 // Navigate to a different site again. 192 // Navigate to a different site again.
221 SendRequestNavigation(node, kUrl2); 193 SendRequestNavigation(node, kUrl2);
222 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 194 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
223 main_request = GetNavigationRequestForFrameTreeNode(node); 195 main_request = GetNavigationRequestForFrameTreeNode(node);
224 ASSERT_TRUE(main_request); 196 ASSERT_TRUE(main_request);
225 197
226 // Commit an HTTP 205 response. 198 // Commit an HTTP 205 response.
227 response = new ResourceResponse; 199 response = new ResourceResponse;
228 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0"; 200 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0";
229 response->head.headers = new net::HttpResponseHeaders( 201 response->head.headers = new net::HttpResponseHeaders(
230 std::string(kResetContentHeaders, arraysize(kResetContentHeaders))); 202 std::string(kResetContentHeaders, arraysize(kResetContentHeaders)));
231 node->navigator()->CommitNavigation( 203 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream());
232 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
233 204
234 // There should be no pending RenderFrameHost; the navigation was aborted. 205 // There should be no pending RenderFrameHost; the navigation was aborted.
235 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); 206 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node));
236 EXPECT_FALSE(node->render_manager()->pending_frame_host()); 207 EXPECT_FALSE(node->render_manager()->pending_frame_host());
237 } 208 }
238 209
239 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross 210 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross
240 // site navigation. 211 // site navigation.
241 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) { 212 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) {
242 const GURL kUrl1("http://www.chromium.org/"); 213 const GURL kUrl1("http://www.chromium.org/");
243 const GURL kUrl2("http://www.google.com/"); 214 const GURL kUrl2("http://www.google.com/");
244 215
245 contents()->NavigateAndCommit(kUrl1); 216 contents()->NavigateAndCommit(kUrl1);
246 RenderFrameHostImpl* rfh = main_test_rfh(); 217 RenderFrameHostImpl* rfh = main_test_rfh();
247 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); 218 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state());
248 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); 219 FrameTreeNode* node = main_test_rfh()->frame_tree_node();
249 220
250 EnableBrowserSideNavigation(); 221 EnableBrowserSideNavigation();
251 222
252 // Navigate to a different site. 223 // Navigate to a different site.
253 SendRequestNavigation(node, kUrl2); 224 SendRequestNavigation(node, kUrl2);
254 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 225 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
255 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); 226 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node);
256 ASSERT_TRUE(main_request); 227 ASSERT_TRUE(main_request);
257 228
258 scoped_refptr<ResourceResponse> response(new ResourceResponse); 229 scoped_refptr<ResourceResponse> response(new ResourceResponse);
259 node->navigator()->CommitNavigation( 230 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream());
260 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
261 RenderFrameHostImpl* pending_rfh = 231 RenderFrameHostImpl* pending_rfh =
262 node->render_manager()->pending_frame_host(); 232 node->render_manager()->pending_frame_host();
263 ASSERT_TRUE(pending_rfh); 233 ASSERT_TRUE(pending_rfh);
264 EXPECT_NE(pending_rfh, rfh); 234 EXPECT_NE(pending_rfh, rfh);
265 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); 235 EXPECT_TRUE(pending_rfh->IsRenderFrameLive());
266 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); 236 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive());
267 } 237 }
268 238
269 // PlzNavigate: Test that a navigation is cancelled if another request has been 239 // PlzNavigate: Test that a navigation is cancelled if another request has been
270 // issued in the meantime. 240 // issued in the meantime.
(...skipping 20 matching lines...) Expand all
291 // Request navigation to the 2nd URL; the NavigationRequest must have been 261 // Request navigation to the 2nd URL; the NavigationRequest must have been
292 // replaced by a new one with a different URL. 262 // replaced by a new one with a different URL.
293 SendRequestNavigation(node, kUrl2); 263 SendRequestNavigation(node, kUrl2);
294 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 264 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
295 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); 265 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node);
296 ASSERT_TRUE(request2); 266 ASSERT_TRUE(request2);
297 EXPECT_EQ(kUrl2, request2->common_params().url); 267 EXPECT_EQ(kUrl2, request2->common_params().url);
298 268
299 // Confirm that the commit corresonds to the new request. 269 // Confirm that the commit corresonds to the new request.
300 scoped_refptr<ResourceResponse> response(new ResourceResponse); 270 scoped_refptr<ResourceResponse> response(new ResourceResponse);
301 node->navigator()->CommitNavigation( 271 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream());
302 node, response.get(), scoped_ptr<StreamHandle>(new TestStreamHandle));
303 RenderFrameHostImpl* pending_rfh = 272 RenderFrameHostImpl* pending_rfh =
304 node->render_manager()->pending_frame_host(); 273 node->render_manager()->pending_frame_host();
305 ASSERT_TRUE(pending_rfh); 274 ASSERT_TRUE(pending_rfh);
306 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); 275 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL());
307 } 276 }
308 277
309 // PlzNavigate: Tests that the navigation histograms are correctly tracked both 278 // PlzNavigate: Tests that the navigation histograms are correctly tracked both
310 // when PlzNavigate is enabled and disabled, and also ignores in-tab renderer 279 // when PlzNavigate is enabled and disabled, and also ignores in-tab renderer
311 // initiated navigation for the non-enabled case. 280 // initiated navigation for the non-enabled case.
312 // Note: the related histogram, Navigation.TimeToURLJobStart, cannot be tracked 281 // Note: the related histogram, Navigation.TimeToURLJobStart, cannot be tracked
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 NavigationController::RELOAD_IGNORING_CACHE); 329 NavigationController::RELOAD_IGNORING_CACHE);
361 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); 330 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl);
362 // A NavigationRequest should have been generated. 331 // A NavigationRequest should have been generated.
363 main_request = GetNavigationRequestForFrameTreeNode(node); 332 main_request = GetNavigationRequestForFrameTreeNode(node);
364 ASSERT_TRUE(main_request != NULL); 333 ASSERT_TRUE(main_request != NULL);
365 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, 334 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE,
366 main_request->common_params().navigation_type); 335 main_request->common_params().navigation_type);
367 } 336 }
368 337
369 } // namespace content 338 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698