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

Side by Side Diff: components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc

Issue 893843003: Add RedirectInfo as a redirect parameter to ResourceThrottles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix webview 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "components/navigation_interception/intercept_navigation_resource_throt tle.h" 10 #include "components/navigation_interception/intercept_navigation_resource_throt tle.h"
11 #include "components/navigation_interception/navigation_params.h" 11 #include "components/navigation_interception/navigation_params.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
14 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/resource_context.h" 15 #include "content/public/browser/resource_context.h"
16 #include "content/public/browser/resource_controller.h" 16 #include "content/public/browser/resource_controller.h"
17 #include "content/public/browser/resource_dispatcher_host.h" 17 #include "content/public/browser/resource_dispatcher_host.h"
18 #include "content/public/browser/resource_dispatcher_host_delegate.h" 18 #include "content/public/browser/resource_dispatcher_host_delegate.h"
19 #include "content/public/browser/resource_request_info.h" 19 #include "content/public/browser/resource_request_info.h"
20 #include "content/public/browser/resource_throttle.h" 20 #include "content/public/browser/resource_throttle.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_contents_delegate.h" 22 #include "content/public/browser/web_contents_delegate.h"
23 #include "content/public/test/mock_resource_context.h" 23 #include "content/public/test/mock_resource_context.h"
24 #include "content/public/test/test_renderer_host.h" 24 #include "content/public/test/test_renderer_host.h"
25 #include "net/base/request_priority.h" 25 #include "net/base/request_priority.h"
26 #include "net/http/http_response_headers.h" 26 #include "net/http/http_response_headers.h"
27 #include "net/http/http_response_info.h" 27 #include "net/http/http_response_info.h"
28 #include "net/url_request/redirect_info.h"
28 #include "net/url_request/url_request.h" 29 #include "net/url_request/url_request.h"
29 #include "net/url_request/url_request_test_util.h" 30 #include "net/url_request/url_request_test_util.h"
30 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 33
33 using content::ResourceType; 34 using content::ResourceType;
34 using testing::_; 35 using testing::_;
35 using testing::Eq; 36 using testing::Eq;
36 using testing::Ne; 37 using testing::Ne;
37 using testing::Property; 38 using testing::Property;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 response_info.headers = new net::HttpResponseHeaders( 148 response_info.headers = new net::HttpResponseHeaders(
148 "Status: 302 Found\0\0"); 149 "Status: 302 Found\0\0");
149 } 150 }
150 } 151 }
151 152
152 void ThrottleWillStartRequest(bool* defer) { 153 void ThrottleWillStartRequest(bool* defer) {
153 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
154 throttle_->WillStartRequest(defer); 155 throttle_->WillStartRequest(defer);
155 } 156 }
156 157
157 void ThrottleWillRedirectRequest(const GURL& new_url, bool* defer) { 158 void ThrottleWillRedirectRequest(const GURL& new_url,
159 const std::string& new_method,
160 bool* defer) {
158 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 161 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
159 throttle_->WillRedirectRequest(new_url, defer); 162 net::RedirectInfo redirect_info;
163 redirect_info.new_url = new_url;
164 redirect_info.new_method = new_method;
davidben 2015/02/05 20:44:06 Nit: Maybe assemble the net::RedirectInfo in the c
mmenke 2015/02/05 21:20:53 Done.
165 throttle_->WillRedirectRequest(redirect_info, defer);
160 } 166 }
161 167
162 bool request_resumed() const { 168 bool request_resumed() const {
163 return throttle_controller_.status() == 169 return throttle_controller_.status() ==
164 MockResourceController::RESUMED; 170 MockResourceController::RESUMED;
165 } 171 }
166 172
167 bool request_cancelled() const { 173 bool request_cancelled() const {
168 return throttle_controller_.status() == 174 return throttle_controller_.status() ==
169 MockResourceController::CANCELLED; 175 MockResourceController::CANCELLED;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 int render_frame_id, 217 int render_frame_id,
212 bool* defer) { 218 bool* defer) {
213 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 219 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
214 TestIOThreadState* io_thread_state = 220 TestIOThreadState* io_thread_state =
215 new TestIOThreadState(url, render_process_id, render_frame_id, 221 new TestIOThreadState(url, render_process_id, render_frame_id,
216 request_method, redirect_mode, 222 request_method, redirect_mode,
217 mock_callback_receiver_.get()); 223 mock_callback_receiver_.get());
218 224
219 SetIOThreadState(io_thread_state); 225 SetIOThreadState(io_thread_state);
220 226
221 if (redirect_mode == REDIRECT_MODE_NO_REDIRECT) 227 if (redirect_mode == REDIRECT_MODE_NO_REDIRECT) {
222 io_thread_state->ThrottleWillStartRequest(defer); 228 io_thread_state->ThrottleWillStartRequest(defer);
223 else 229 } else {
224 io_thread_state->ThrottleWillRedirectRequest(url, defer); 230 // 302 redirects convert POSTs to gets.
231 io_thread_state->ThrottleWillRedirectRequest(url, "GET", defer);
232 }
225 } 233 }
226 234
227 protected: 235 protected:
228 enum ShouldIgnoreNavigationCallbackAction { 236 enum ShouldIgnoreNavigationCallbackAction {
229 IgnoreNavigation, 237 IgnoreNavigation,
230 DontIgnoreNavigation 238 DontIgnoreNavigation
231 }; 239 };
232 240
233 void SetUpWebContentsDelegateAndDrainRunLoop( 241 void SetUpWebContentsDelegateAndDrainRunLoop(
234 ShouldIgnoreNavigationCallbackAction callback_action, 242 ShouldIgnoreNavigationCallbackAction callback_action,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 REDIRECT_MODE_302, 474 REDIRECT_MODE_302,
467 web_contents()->GetRenderViewHost()->GetProcess()->GetID(), 475 web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
468 web_contents()->GetMainFrame()->GetRoutingID(), 476 web_contents()->GetMainFrame()->GetRoutingID(),
469 base::Unretained(&defer))); 477 base::Unretained(&defer)));
470 478
471 // Wait for the request to finish processing. 479 // Wait for the request to finish processing.
472 base::RunLoop().RunUntilIdle(); 480 base::RunLoop().RunUntilIdle();
473 } 481 }
474 482
475 } // namespace navigation_interception 483 } // namespace navigation_interception
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698