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/guid.h" | 6 #include "base/guid.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
11 #include "content/browser/frame_host/navigation_entry_impl.h" | 11 #include "content/browser/frame_host/navigation_entry_impl.h" |
12 #include "content/browser/frame_host/navigation_request.h" | 12 #include "content/browser/frame_host/navigation_request.h" |
13 #include "content/browser/frame_host/navigation_request_info.h" | 13 #include "content/browser/frame_host/navigation_request_info.h" |
14 #include "content/browser/frame_host/navigator.h" | 14 #include "content/browser/frame_host/navigator.h" |
15 #include "content/browser/frame_host/navigator_impl.h" | 15 #include "content/browser/frame_host/navigator_impl.h" |
16 #include "content/browser/frame_host/render_frame_host_manager.h" | 16 #include "content/browser/frame_host/render_frame_host_manager.h" |
17 #include "content/browser/loader/navigation_url_loader.h" | |
18 #include "content/browser/loader/navigation_url_loader_factory.h" | |
17 #include "content/browser/site_instance_impl.h" | 19 #include "content/browser/site_instance_impl.h" |
18 #include "content/browser/streams/stream.h" | 20 #include "content/browser/streams/stream.h" |
19 #include "content/browser/streams/stream_registry.h" | 21 #include "content/browser/streams/stream_registry.h" |
20 #include "content/common/navigation_params.h" | 22 #include "content/common/navigation_params.h" |
21 #include "content/public/browser/stream_handle.h" | 23 #include "content/public/browser/stream_handle.h" |
22 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
23 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
24 #include "content/public/common/url_utils.h" | 26 #include "content/public/common/url_utils.h" |
25 #include "content/test/test_render_frame_host.h" | 27 #include "content/test/test_render_frame_host.h" |
26 #include "content/test/test_web_contents.h" | 28 #include "content/test/test_web_contents.h" |
27 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
28 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
31 #include "net/url_request/redirect_info.h" | |
29 #include "ui/base/page_transition_types.h" | 32 #include "ui/base/page_transition_types.h" |
30 #include "url/url_constants.h" | 33 #include "url/url_constants.h" |
31 | 34 |
32 namespace content { | 35 namespace content { |
33 | 36 |
37 namespace { | |
38 | |
39 class TestNavigationURLLoader : public NavigationURLLoader { | |
40 public: | |
41 TestNavigationURLLoader(const CommonNavigationParams& common_params, | |
42 scoped_ptr<NavigationRequestInfo> request_info, | |
43 NavigationURLLoader::Delegate* delegate) | |
44 : common_params_(common_params), | |
45 request_info_(request_info.Pass()), | |
46 delegate_(delegate) { | |
47 } | |
48 | |
49 virtual ~TestNavigationURLLoader() { | |
50 // Record the number of times a loader was canceled before ResponseStarted | |
51 // or RequestFailed was returned. | |
52 if (delegate_) | |
nasko
2014/10/20 13:52:17
What would set delegate_ to nullptr?
davidben
2014/10/22 01:32:37
Oh hrm. I think CallOnResponseStarted used to null
| |
53 cancel_count_++; | |
54 } | |
55 | |
56 // NavigationURLLoader implementation. | |
57 virtual void FollowRedirect() override { | |
58 redirect_count_++; | |
59 } | |
60 | |
61 const CommonNavigationParams& common_params() const { return common_params_; } | |
62 NavigationRequestInfo* request_info() const { return request_info_.get(); } | |
63 | |
64 void CallOnRequestRedirected(const net::RedirectInfo& redirect_info, | |
65 ResourceResponse* response) { | |
66 delegate_->OnRequestRedirected(redirect_info, response); | |
67 } | |
68 | |
69 void CallOnResponseStarted(ResourceResponse* response, | |
70 scoped_ptr<StreamHandle> body) { | |
71 delegate_->OnResponseStarted(response, body.Pass()); | |
72 } | |
73 | |
74 static int redirect_count() { return redirect_count_; } | |
75 static int cancel_count() { return cancel_count_; } | |
76 | |
77 private: | |
78 static int redirect_count_; | |
79 static int cancel_count_; | |
80 | |
81 CommonNavigationParams common_params_; | |
82 scoped_ptr<NavigationRequestInfo> request_info_; | |
83 NavigationURLLoader::Delegate* delegate_; | |
84 }; | |
85 | |
86 int TestNavigationURLLoader::redirect_count_ = 0; | |
87 int TestNavigationURLLoader::cancel_count_ = 0; | |
88 | |
89 class TestNavigationURLLoaderFactory : public NavigationURLLoaderFactory { | |
90 public: | |
91 // NavigationURLLoaderFactory implementation. | |
92 virtual scoped_ptr<NavigationURLLoader> CreateLoader( | |
93 BrowserContext* browser_context, | |
94 int64 frame_tree_node_id, | |
95 const CommonNavigationParams& common_params, | |
96 scoped_ptr<NavigationRequestInfo> request_info, | |
97 ResourceRequestBody* request_body, | |
98 NavigationURLLoader::Delegate* delegate) override { | |
99 return scoped_ptr<NavigationURLLoader>(new TestNavigationURLLoader( | |
100 common_params, request_info.Pass(), delegate)); | |
101 } | |
102 }; | |
103 | |
104 } // namespace | |
105 | |
34 class NavigatorTest : public RenderViewHostImplTestHarness { | 106 class NavigatorTest : public RenderViewHostImplTestHarness { |
35 public: | 107 public: |
36 NavigatorTest() : stream_registry_(new StreamRegistry) {} | 108 NavigatorTest() : stream_registry_(new StreamRegistry) {} |
37 | 109 |
110 virtual void SetUp() override { | |
111 RenderViewHostImplTestHarness::SetUp(); | |
112 loader_factory_.reset(new TestNavigationURLLoaderFactory); | |
113 NavigationURLLoader::SetFactoryForTesting(loader_factory_.get()); | |
114 } | |
115 | |
116 virtual void TearDown() override { | |
117 NavigationURLLoader::SetFactoryForTesting(nullptr); | |
118 loader_factory_.reset(); | |
119 RenderViewHostImplTestHarness::TearDown(); | |
120 } | |
121 | |
38 NavigationRequest* GetNavigationRequestForFrameTreeNode( | 122 NavigationRequest* GetNavigationRequestForFrameTreeNode( |
39 FrameTreeNode* frame_tree_node) const { | 123 FrameTreeNode* frame_tree_node) const { |
40 NavigatorImpl* navigator = | 124 NavigatorImpl* navigator = |
41 static_cast<NavigatorImpl*>(frame_tree_node->navigator()); | 125 static_cast<NavigatorImpl*>(frame_tree_node->navigator()); |
42 return navigator->navigation_request_map_.get( | 126 return navigator->navigation_request_map_.get( |
43 frame_tree_node->frame_tree_node_id()); | 127 frame_tree_node->frame_tree_node_id()); |
44 } | 128 } |
45 | 129 |
130 TestNavigationURLLoader* GetLoaderForNavigationRequest( | |
131 NavigationRequest* request) const { | |
132 return static_cast<TestNavigationURLLoader*>(request->loader_for_testing()); | |
133 } | |
134 | |
46 void EnableBrowserSideNavigation() { | 135 void EnableBrowserSideNavigation() { |
47 CommandLine::ForCurrentProcess()->AppendSwitch( | 136 CommandLine::ForCurrentProcess()->AppendSwitch( |
48 switches::kEnableBrowserSideNavigation); | 137 switches::kEnableBrowserSideNavigation); |
49 } | 138 } |
50 | 139 |
51 void SendRequestNavigation(FrameTreeNode* node, | 140 void SendRequestNavigation(FrameTreeNode* node, |
52 const GURL& url) { | 141 const GURL& url) { |
53 SendRequestNavigationWithParameters( | 142 SendRequestNavigationWithParameters( |
54 node, url, Referrer(), ui::PAGE_TRANSITION_LINK, | 143 node, url, Referrer(), ui::PAGE_TRANSITION_LINK, |
55 NavigationController::NO_RELOAD); | 144 NavigationController::NO_RELOAD); |
(...skipping 20 matching lines...) Expand all Loading... | |
76 | 165 |
77 scoped_ptr<StreamHandle> MakeEmptyStream() { | 166 scoped_ptr<StreamHandle> MakeEmptyStream() { |
78 GURL url(std::string(url::kBlobScheme) + "://" + base::GenerateGUID()); | 167 GURL url(std::string(url::kBlobScheme) + "://" + base::GenerateGUID()); |
79 scoped_refptr<Stream> stream(new Stream(stream_registry_.get(), NULL, url)); | 168 scoped_refptr<Stream> stream(new Stream(stream_registry_.get(), NULL, url)); |
80 stream->Finalize(); | 169 stream->Finalize(); |
81 return stream->CreateHandle(); | 170 return stream->CreateHandle(); |
82 } | 171 } |
83 | 172 |
84 private: | 173 private: |
85 scoped_ptr<StreamRegistry> stream_registry_; | 174 scoped_ptr<StreamRegistry> stream_registry_; |
175 scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_; | |
86 }; | 176 }; |
87 | 177 |
88 // PlzNavigate: Test that a proper NavigationRequest is created by | 178 // PlzNavigate: Test that a proper NavigationRequest is created by |
89 // BeginNavigation. | 179 // BeginNavigation. |
90 // Note that all PlzNavigate methods on the browser side require the use of the | 180 // Note that all PlzNavigate methods on the browser side require the use of the |
91 // flag kEnableBrowserSideNavigation. | 181 // flag kEnableBrowserSideNavigation. |
92 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) { | 182 TEST_F(NavigatorTest, BrowserSideNavigationBeginNavigation) { |
93 const GURL kUrl1("http://www.google.com/"); | 183 const GURL kUrl1("http://www.google.com/"); |
94 const GURL kUrl2("http://www.chromium.org/"); | 184 const GURL kUrl2("http://www.chromium.org/"); |
95 const GURL kUrl3("http://www.gmail.com/"); | 185 const GURL kUrl3("http://www.gmail.com/"); |
96 | 186 |
97 contents()->NavigateAndCommit(kUrl1); | 187 contents()->NavigateAndCommit(kUrl1); |
98 | 188 |
99 EnableBrowserSideNavigation(); | 189 EnableBrowserSideNavigation(); |
100 | 190 |
101 // Add a subframe. | 191 // Add a subframe. |
102 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( | 192 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( |
103 contents()->GetFrameTree()->AddFrame( | 193 contents()->GetFrameTree()->AddFrame( |
104 contents()->GetFrameTree()->root(), 14, "Child")); | 194 contents()->GetFrameTree()->root(), 14, "Child")); |
105 | 195 |
106 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); | 196 FrameTreeNode* subframe_node = subframe_rfh->frame_tree_node(); |
107 SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2); | 197 SendRequestNavigation(subframe_rfh->frame_tree_node(), kUrl2); |
108 // There is no previous renderer in the subframe, so BeginNavigation is | 198 // There is no previous renderer in the subframe, so BeginNavigation is |
109 // handled already. | 199 // handled already. |
110 NavigationRequest* subframe_request = | 200 NavigationRequest* subframe_request = |
111 GetNavigationRequestForFrameTreeNode(subframe_node); | 201 GetNavigationRequestForFrameTreeNode(subframe_node); |
202 TestNavigationURLLoader* subframe_loader = | |
203 GetLoaderForNavigationRequest(subframe_request); | |
112 ASSERT_TRUE(subframe_request); | 204 ASSERT_TRUE(subframe_request); |
113 EXPECT_EQ(kUrl2, subframe_request->common_params().url); | 205 EXPECT_EQ(kUrl2, subframe_request->common_params().url); |
206 EXPECT_EQ(kUrl2, subframe_loader->common_params().url); | |
114 // First party for cookies url should be that of the main frame. | 207 // First party for cookies url should be that of the main frame. |
115 EXPECT_EQ(kUrl1, subframe_request->info_for_test()->first_party_for_cookies); | 208 EXPECT_EQ(kUrl1, subframe_loader->request_info()->first_party_for_cookies); |
116 EXPECT_FALSE(subframe_request->info_for_test()->is_main_frame); | 209 EXPECT_FALSE(subframe_loader->request_info()->is_main_frame); |
117 EXPECT_TRUE(subframe_request->info_for_test()->parent_is_main_frame); | 210 EXPECT_TRUE(subframe_loader->request_info()->parent_is_main_frame); |
118 | 211 |
119 FrameTreeNode* main_frame_node = | 212 FrameTreeNode* main_frame_node = |
120 contents()->GetMainFrame()->frame_tree_node(); | 213 contents()->GetMainFrame()->frame_tree_node(); |
121 SendRequestNavigation(main_frame_node, kUrl3); | 214 SendRequestNavigation(main_frame_node, kUrl3); |
122 // Simulate a BeginNavigation IPC on the main frame. | 215 // Simulate a BeginNavigation IPC on the main frame. |
123 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); | 216 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); |
124 NavigationRequest* main_request = | 217 NavigationRequest* main_request = |
125 GetNavigationRequestForFrameTreeNode(main_frame_node); | 218 GetNavigationRequestForFrameTreeNode(main_frame_node); |
219 TestNavigationURLLoader* main_loader = | |
220 GetLoaderForNavigationRequest(main_request); | |
126 ASSERT_TRUE(main_request); | 221 ASSERT_TRUE(main_request); |
127 EXPECT_EQ(kUrl3, main_request->common_params().url); | 222 EXPECT_EQ(kUrl3, main_request->common_params().url); |
128 EXPECT_EQ(kUrl3, main_request->info_for_test()->first_party_for_cookies); | 223 EXPECT_EQ(kUrl3, main_loader->common_params().url); |
129 EXPECT_TRUE(main_request->info_for_test()->is_main_frame); | 224 EXPECT_EQ(kUrl3, main_loader->request_info()->first_party_for_cookies); |
130 EXPECT_FALSE(main_request->info_for_test()->parent_is_main_frame); | 225 EXPECT_TRUE(main_loader->request_info()->is_main_frame); |
226 EXPECT_FALSE(main_loader->request_info()->parent_is_main_frame); | |
131 } | 227 } |
132 | 228 |
133 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that | 229 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that |
134 // RenderFrameHost is not modified when the navigation commits. | 230 // RenderFrameHost is not modified when the navigation commits. |
135 TEST_F(NavigatorTest, BrowserSideNavigationRequestNavigationNoLiveRenderer) { | 231 TEST_F(NavigatorTest, BrowserSideNavigationRequestNavigationNoLiveRenderer) { |
136 const GURL kUrl("http://www.google.com/"); | 232 const GURL kUrl("http://www.google.com/"); |
137 | 233 |
138 EnableBrowserSideNavigation(); | 234 EnableBrowserSideNavigation(); |
139 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 235 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
140 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 236 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
141 SendRequestNavigation(node, kUrl); | 237 SendRequestNavigation(node, kUrl); |
142 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 238 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
143 // A NavigationRequest should have been generated. | 239 // A NavigationRequest should have been generated. |
144 EXPECT_TRUE(main_request != NULL); | 240 EXPECT_TRUE(main_request != NULL); |
145 RenderFrameHostImpl* rfh = main_test_rfh(); | 241 RenderFrameHostImpl* rfh = main_test_rfh(); |
146 | 242 |
147 // Now commit the same url. | 243 // Now return the response without any redirects. This will cause the |
244 // navigation to commit at the same URL. | |
148 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 245 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
149 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream()); | 246 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
247 response.get(), MakeEmptyStream()); | |
150 main_request = GetNavigationRequestForFrameTreeNode(node); | 248 main_request = GetNavigationRequestForFrameTreeNode(node); |
151 | 249 |
152 // The main RFH should not have been changed, and the renderer should have | 250 // The main RFH should not have been changed, and the renderer should have |
153 // been initialized. | 251 // been initialized. |
154 EXPECT_EQ(rfh, main_test_rfh()); | 252 EXPECT_EQ(rfh, main_test_rfh()); |
155 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); | 253 EXPECT_TRUE(main_test_rfh()->IsRenderFrameLive()); |
156 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 254 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
157 } | 255 } |
158 | 256 |
159 // PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the | 257 // PlzNavigate: Test that commiting an HTTP 204 or HTTP 205 response cancels the |
(...skipping 14 matching lines...) Expand all Loading... | |
174 SendRequestNavigation(node, kUrl2); | 272 SendRequestNavigation(node, kUrl2); |
175 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 273 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
176 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 274 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
177 ASSERT_TRUE(main_request); | 275 ASSERT_TRUE(main_request); |
178 | 276 |
179 // Commit an HTTP 204 response. | 277 // Commit an HTTP 204 response. |
180 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 278 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
181 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0"; | 279 const char kNoContentHeaders[] = "HTTP/1.1 204 No Content\0\0"; |
182 response->head.headers = new net::HttpResponseHeaders( | 280 response->head.headers = new net::HttpResponseHeaders( |
183 std::string(kNoContentHeaders, arraysize(kNoContentHeaders))); | 281 std::string(kNoContentHeaders, arraysize(kNoContentHeaders))); |
184 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream()); | 282 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
283 response.get(), MakeEmptyStream()); | |
185 | 284 |
186 // There should be no pending RenderFrameHost; the navigation was aborted. | 285 // There should be no pending RenderFrameHost; the navigation was aborted. |
187 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); | 286 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
188 EXPECT_FALSE(node->render_manager()->pending_frame_host()); | 287 EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
189 | 288 |
190 // Now, repeat the test with 205 Reset Content. | 289 // Now, repeat the test with 205 Reset Content. |
191 | 290 |
192 // Navigate to a different site again. | 291 // Navigate to a different site again. |
193 SendRequestNavigation(node, kUrl2); | 292 SendRequestNavigation(node, kUrl2); |
194 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 293 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
195 main_request = GetNavigationRequestForFrameTreeNode(node); | 294 main_request = GetNavigationRequestForFrameTreeNode(node); |
196 ASSERT_TRUE(main_request); | 295 ASSERT_TRUE(main_request); |
197 | 296 |
198 // Commit an HTTP 205 response. | 297 // Commit an HTTP 205 response. |
199 response = new ResourceResponse; | 298 response = new ResourceResponse; |
200 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0"; | 299 const char kResetContentHeaders[] = "HTTP/1.1 205 Reset Content\0\0"; |
201 response->head.headers = new net::HttpResponseHeaders( | 300 response->head.headers = new net::HttpResponseHeaders( |
202 std::string(kResetContentHeaders, arraysize(kResetContentHeaders))); | 301 std::string(kResetContentHeaders, arraysize(kResetContentHeaders))); |
203 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream()); | 302 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
303 response.get(), MakeEmptyStream()); | |
204 | 304 |
205 // There should be no pending RenderFrameHost; the navigation was aborted. | 305 // There should be no pending RenderFrameHost; the navigation was aborted. |
206 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); | 306 EXPECT_FALSE(GetNavigationRequestForFrameTreeNode(node)); |
207 EXPECT_FALSE(node->render_manager()->pending_frame_host()); | 307 EXPECT_FALSE(node->render_manager()->pending_frame_host()); |
208 } | 308 } |
209 | 309 |
210 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross | 310 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross |
211 // site navigation. | 311 // site navigation. |
212 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) { | 312 TEST_F(NavigatorTest, BrowserSideNavigationCrossSiteNavigation) { |
213 const GURL kUrl1("http://www.chromium.org/"); | 313 const GURL kUrl1("http://www.chromium.org/"); |
214 const GURL kUrl2("http://www.google.com/"); | 314 const GURL kUrl2("http://www.google.com/"); |
215 | 315 |
216 contents()->NavigateAndCommit(kUrl1); | 316 contents()->NavigateAndCommit(kUrl1); |
217 RenderFrameHostImpl* rfh = main_test_rfh(); | 317 RenderFrameHostImpl* rfh = main_test_rfh(); |
218 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); | 318 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); |
219 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | 319 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); |
220 | 320 |
221 EnableBrowserSideNavigation(); | 321 EnableBrowserSideNavigation(); |
222 | 322 |
223 // Navigate to a different site. | 323 // Navigate to a different site. |
224 SendRequestNavigation(node, kUrl2); | 324 SendRequestNavigation(node, kUrl2); |
225 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 325 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
226 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | 326 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); |
227 ASSERT_TRUE(main_request); | 327 ASSERT_TRUE(main_request); |
228 | 328 |
229 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 329 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
230 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream()); | 330 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( |
331 response.get(), MakeEmptyStream()); | |
231 RenderFrameHostImpl* pending_rfh = | 332 RenderFrameHostImpl* pending_rfh = |
232 node->render_manager()->pending_frame_host(); | 333 node->render_manager()->pending_frame_host(); |
233 ASSERT_TRUE(pending_rfh); | 334 ASSERT_TRUE(pending_rfh); |
335 EXPECT_NE(pending_rfh, rfh); | |
336 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); | |
337 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); | |
338 } | |
339 | |
340 // PlzNavigate: Test that redirects are followed. | |
341 TEST_F(NavigatorTest, BrowserSideNavigationRedirectCrossSite) { | |
342 const GURL kUrl1("http://www.chromium.org/"); | |
343 const GURL kUrl2("http://www.google.com/"); | |
344 | |
345 contents()->NavigateAndCommit(kUrl1); | |
346 RenderFrameHostImpl* rfh = main_test_rfh(); | |
347 EXPECT_EQ(RenderFrameHostImpl::STATE_DEFAULT, rfh->rfh_state()); | |
348 FrameTreeNode* node = main_test_rfh()->frame_tree_node(); | |
349 | |
350 EnableBrowserSideNavigation(); | |
351 | |
352 // Navigate to a URL on the same site. | |
353 SendRequestNavigation(node, kUrl1); | |
354 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); | |
355 NavigationRequest* main_request = GetNavigationRequestForFrameTreeNode(node); | |
356 ASSERT_TRUE(main_request); | |
357 | |
358 // It then redirects to another site. | |
359 net::RedirectInfo redirect_info; | |
360 redirect_info.status_code = 302; | |
361 redirect_info.new_method = "GET"; | |
362 redirect_info.new_url = kUrl2; | |
363 redirect_info.new_first_party_for_cookies = kUrl2; | |
364 scoped_refptr<ResourceResponse> response(new ResourceResponse); | |
365 GetLoaderForNavigationRequest(main_request)->CallOnRequestRedirected( | |
366 redirect_info, response.get()); | |
367 | |
368 // The redirect should have been followed. | |
369 EXPECT_EQ(1, TestNavigationURLLoader::redirect_count()); | |
370 | |
371 // Then it commits. | |
372 response = new ResourceResponse; | |
373 GetLoaderForNavigationRequest(main_request)->CallOnResponseStarted( | |
374 response.get(), MakeEmptyStream()); | |
375 RenderFrameHostImpl* pending_rfh = | |
376 node->render_manager()->pending_frame_host(); | |
377 ASSERT_TRUE(pending_rfh); | |
234 EXPECT_NE(pending_rfh, rfh); | 378 EXPECT_NE(pending_rfh, rfh); |
235 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); | 379 EXPECT_TRUE(pending_rfh->IsRenderFrameLive()); |
236 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); | 380 EXPECT_TRUE(pending_rfh->render_view_host()->IsRenderViewLive()); |
237 } | 381 } |
238 | 382 |
239 // PlzNavigate: Test that a navigation is cancelled if another request has been | 383 // PlzNavigate: Test that a navigation is cancelled if another request has been |
240 // issued in the meantime. | 384 // issued in the meantime. |
241 TEST_F(NavigatorTest, BrowserSideNavigationReplacePendingNavigation) { | 385 TEST_F(NavigatorTest, BrowserSideNavigationReplacePendingNavigation) { |
242 const GURL kUrl0("http://www.wikipedia.org/"); | 386 const GURL kUrl0("http://www.wikipedia.org/"); |
243 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); | 387 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); |
(...skipping 17 matching lines...) Expand all Loading... | |
261 // Request navigation to the 2nd URL; the NavigationRequest must have been | 405 // Request navigation to the 2nd URL; the NavigationRequest must have been |
262 // replaced by a new one with a different URL. | 406 // replaced by a new one with a different URL. |
263 SendRequestNavigation(node, kUrl2); | 407 SendRequestNavigation(node, kUrl2); |
264 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 408 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
265 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); | 409 NavigationRequest* request2 = GetNavigationRequestForFrameTreeNode(node); |
266 ASSERT_TRUE(request2); | 410 ASSERT_TRUE(request2); |
267 EXPECT_EQ(kUrl2, request2->common_params().url); | 411 EXPECT_EQ(kUrl2, request2->common_params().url); |
268 | 412 |
269 // Confirm that the commit corresonds to the new request. | 413 // Confirm that the commit corresonds to the new request. |
270 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 414 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
271 node->navigator()->CommitNavigation(node, response.get(), MakeEmptyStream()); | 415 GetLoaderForNavigationRequest(request2)->CallOnResponseStarted( |
416 response.get(), MakeEmptyStream()); | |
272 RenderFrameHostImpl* pending_rfh = | 417 RenderFrameHostImpl* pending_rfh = |
273 node->render_manager()->pending_frame_host(); | 418 node->render_manager()->pending_frame_host(); |
274 ASSERT_TRUE(pending_rfh); | 419 ASSERT_TRUE(pending_rfh); |
275 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); | 420 EXPECT_EQ(kUrl2_site, pending_rfh->GetSiteInstance()->GetSiteURL()); |
276 } | 421 } |
277 | 422 |
278 // PlzNavigate: Tests that the navigation histograms are correctly tracked both | 423 // PlzNavigate: Tests that the navigation histograms are correctly tracked both |
279 // when PlzNavigate is enabled and disabled, and also ignores in-tab renderer | 424 // when PlzNavigate is enabled and disabled, and also ignores in-tab renderer |
280 // initiated navigation for the non-enabled case. | 425 // initiated navigation for the non-enabled case. |
281 // Note: the related histogram, Navigation.TimeToURLJobStart, cannot be tracked | 426 // Note: the related histogram, Navigation.TimeToURLJobStart, cannot be tracked |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 NavigationController::RELOAD_IGNORING_CACHE); | 474 NavigationController::RELOAD_IGNORING_CACHE); |
330 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); | 475 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl); |
331 // A NavigationRequest should have been generated. | 476 // A NavigationRequest should have been generated. |
332 main_request = GetNavigationRequestForFrameTreeNode(node); | 477 main_request = GetNavigationRequestForFrameTreeNode(node); |
333 ASSERT_TRUE(main_request != NULL); | 478 ASSERT_TRUE(main_request != NULL); |
334 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, | 479 EXPECT_EQ(FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE, |
335 main_request->common_params().navigation_type); | 480 main_request->common_params().navigation_type); |
336 } | 481 } |
337 | 482 |
338 } // namespace content | 483 } // namespace content |
OLD | NEW |