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

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

Issue 1616943003: Teach navigation throttles how to cancel requests in WillProcessResponse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fiddling. Created 4 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/macros.h" 5 #include "base/macros.h"
6 #include "content/browser/frame_host/navigation_handle_impl.h" 6 #include "content/browser/frame_host/navigation_handle_impl.h"
7 #include "content/public/browser/navigation_throttle.h" 7 #include "content/public/browser/navigation_throttle.h"
8 #include "content/test/test_render_frame_host.h" 8 #include "content/test/test_render_frame_host.h"
9 9
10 namespace content { 10 namespace content {
11 11
12 // Test version of a NavigationThrottle. It will always return the same 12 // Test version of a NavigationThrottle. It will always return the current
13 // NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the 13 // NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the
14 // number of times WillStartRequest and WillRedirectRequest were called. 14 // number of times WillStartRequest, WillRedirectRequest, and
15 // WillProcessResponse were called.
15 class TestNavigationThrottle : public NavigationThrottle { 16 class TestNavigationThrottle : public NavigationThrottle {
16 public: 17 public:
17 TestNavigationThrottle(NavigationHandle* handle, 18 TestNavigationThrottle(NavigationHandle* handle,
18 NavigationThrottle::ThrottleCheckResult result) 19 NavigationThrottle::ThrottleCheckResult result)
19 : NavigationThrottle(handle), 20 : NavigationThrottle(handle),
20 result_(result), 21 result_(result),
21 will_start_calls_(0), 22 will_start_calls_(0),
22 will_redirect_calls_(0) {} 23 will_redirect_calls_(0),
24 will_process_response_calls_(0) {}
23 25
24 ~TestNavigationThrottle() override {} 26 ~TestNavigationThrottle() override {}
25 27
28 void SetResult(NavigationThrottle::ThrottleCheckResult result) {
29 result_ = result;
30 }
31
26 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { 32 NavigationThrottle::ThrottleCheckResult WillStartRequest() override {
27 ++will_start_calls_; 33 ++will_start_calls_;
28 return result_; 34 return result_;
29 } 35 }
30 36
31 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override { 37 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override {
32 ++will_redirect_calls_; 38 ++will_redirect_calls_;
33 return result_; 39 return result_;
34 } 40 }
35 41
42 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override {
43 ++will_process_response_calls_;
44 return result_;
45 }
46
36 int will_start_calls() const { return will_start_calls_; } 47 int will_start_calls() const { return will_start_calls_; }
37 int will_redirect_calls() const { return will_redirect_calls_; } 48 int will_redirect_calls() const { return will_redirect_calls_; }
49 int will_process_response_calls() const {
50 return will_process_response_calls_;
51 }
38 52
39 private: 53 private:
40 // The result returned by the TestNavigationThrottle. 54 // The result returned by the TestNavigationThrottle.
41 NavigationThrottle::ThrottleCheckResult result_; 55 NavigationThrottle::ThrottleCheckResult result_;
42 56
43 // The number of times WillStartRequest and WillRedirectRequest were called. 57 // The number of times each handler was called.
44 int will_start_calls_; 58 int will_start_calls_;
45 int will_redirect_calls_; 59 int will_redirect_calls_;
60 int will_process_response_calls_;
46 }; 61 };
47 62
48 class NavigationHandleImplTest : public RenderViewHostImplTestHarness { 63 class NavigationHandleImplTest : public RenderViewHostImplTestHarness {
49 public: 64 public:
50 NavigationHandleImplTest() 65 NavigationHandleImplTest()
51 : was_callback_called_(false), 66 : was_callback_called_(false),
52 callback_result_(NavigationThrottle::DEFER) {} 67 callback_result_(NavigationThrottle::DEFER) {}
53 68
54 void SetUp() override { 69 void SetUp() override {
55 RenderViewHostImplTestHarness::SetUp(); 70 RenderViewHostImplTestHarness::SetUp();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 callback_result_ = NavigationThrottle::DEFER; 116 callback_result_ = NavigationThrottle::DEFER;
102 117
103 // It's safe to use base::Unretained since the NavigationHandle is owned by 118 // It's safe to use base::Unretained since the NavigationHandle is owned by
104 // the NavigationHandleImplTest. 119 // the NavigationHandleImplTest.
105 test_handle_->WillRedirectRequest( 120 test_handle_->WillRedirectRequest(
106 GURL(), false, GURL(), false, scoped_refptr<net::HttpResponseHeaders>(), 121 GURL(), false, GURL(), false, scoped_refptr<net::HttpResponseHeaders>(),
107 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, 122 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult,
108 base::Unretained(this))); 123 base::Unretained(this)));
109 } 124 }
110 125
126 // Helper function to call WillProcessResponse on |handle|. |callback_result_|
127 // will be set to the actual result of the throttle checks when they are
128 // finished.
129 //
130 // TODO(clamy): this should also simulate that WillStartRequest was called if
131 // it has not been called before.
132 void SimulateWillProcessResponse() {
133 was_callback_called_ = false;
134 callback_result_ = NavigationThrottle::DEFER;
135
136 // It's safe to use base::Unretained since the NavigationHandle is owned by
137 // the NavigationHandleImplTest.
138 test_handle_->WillProcessResponse(
139 scoped_refptr<net::HttpResponseHeaders>(),
140 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult,
141 base::Unretained(this)));
142 }
143
111 // Returns the handle used in tests. 144 // Returns the handle used in tests.
112 NavigationHandleImpl* test_handle() const { return test_handle_.get(); } 145 NavigationHandleImpl* test_handle() const { return test_handle_.get(); }
113 146
114 // Whether the callback was called. 147 // Whether the callback was called.
115 bool was_callback_called() const { return was_callback_called_; } 148 bool was_callback_called() const { return was_callback_called_; }
116 149
117 // Returns the callback_result. 150 // Returns the callback_result.
118 NavigationThrottle::ThrottleCheckResult callback_result() const { 151 NavigationThrottle::ThrottleCheckResult callback_result() const {
119 return callback_result_; 152 return callback_result_;
120 } 153 }
(...skipping 24 matching lines...) Expand all
145 }; 178 };
146 179
147 // Checks that a deferred navigation can be properly resumed. 180 // Checks that a deferred navigation can be properly resumed.
148 TEST_F(NavigationHandleImplTest, ResumeDeferred) { 181 TEST_F(NavigationHandleImplTest, ResumeDeferred) {
149 TestNavigationThrottle* test_throttle = 182 TestNavigationThrottle* test_throttle =
150 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 183 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
151 EXPECT_FALSE(IsDeferringStart()); 184 EXPECT_FALSE(IsDeferringStart());
152 EXPECT_FALSE(IsDeferringRedirect()); 185 EXPECT_FALSE(IsDeferringRedirect());
153 EXPECT_EQ(0, test_throttle->will_start_calls()); 186 EXPECT_EQ(0, test_throttle->will_start_calls());
154 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 187 EXPECT_EQ(0, test_throttle->will_redirect_calls());
188 EXPECT_EQ(0, test_throttle->will_process_response_calls());
155 189
156 // Simulate WillStartRequest. The request should be deferred. The callback 190 // Simulate WillStartRequest. The request should be deferred. The callback
157 // should not have been called. 191 // should not have been called.
158 SimulateWillStartRequest(); 192 SimulateWillStartRequest();
159 EXPECT_TRUE(IsDeferringStart()); 193 EXPECT_TRUE(IsDeferringStart());
160 EXPECT_FALSE(IsDeferringRedirect()); 194 EXPECT_FALSE(IsDeferringRedirect());
161 EXPECT_FALSE(was_callback_called()); 195 EXPECT_FALSE(was_callback_called());
162 EXPECT_EQ(1, test_throttle->will_start_calls()); 196 EXPECT_EQ(1, test_throttle->will_start_calls());
163 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 197 EXPECT_EQ(0, test_throttle->will_redirect_calls());
198 EXPECT_EQ(0, test_throttle->will_process_response_calls());
164 199
165 // Resume the request. It should no longer be deferred and the callback 200 // Resume the request. It should no longer be deferred and the callback
166 // should have been called. 201 // should have been called.
167 test_handle()->Resume(); 202 test_handle()->Resume();
168 EXPECT_FALSE(IsDeferringStart()); 203 EXPECT_FALSE(IsDeferringStart());
169 EXPECT_FALSE(IsDeferringRedirect()); 204 EXPECT_FALSE(IsDeferringRedirect());
170 EXPECT_TRUE(was_callback_called()); 205 EXPECT_TRUE(was_callback_called());
171 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); 206 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
172 EXPECT_EQ(1, test_throttle->will_start_calls()); 207 EXPECT_EQ(1, test_throttle->will_start_calls());
173 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 208 EXPECT_EQ(0, test_throttle->will_redirect_calls());
209 EXPECT_EQ(0, test_throttle->will_process_response_calls());
174 210
175 // Simulate WillRedirectRequest. The request should be deferred. The callback 211 // Simulate WillRedirectRequest. The request should be deferred. The callback
176 // should not have been called. 212 // should not have been called.
177 SimulateWillRedirectRequest(); 213 SimulateWillRedirectRequest();
178 EXPECT_FALSE(IsDeferringStart()); 214 EXPECT_FALSE(IsDeferringStart());
179 EXPECT_TRUE(IsDeferringRedirect()); 215 EXPECT_TRUE(IsDeferringRedirect());
180 EXPECT_FALSE(was_callback_called()); 216 EXPECT_FALSE(was_callback_called());
181 EXPECT_EQ(1, test_throttle->will_start_calls()); 217 EXPECT_EQ(1, test_throttle->will_start_calls());
182 EXPECT_EQ(1, test_throttle->will_redirect_calls()); 218 EXPECT_EQ(1, test_throttle->will_redirect_calls());
219 EXPECT_EQ(0, test_throttle->will_process_response_calls());
183 220
184 // Resume the request. It should no longer be deferred and the callback 221 // Resume the request. It should no longer be deferred and the callback
185 // should have been called. 222 // should have been called.
186 test_handle()->Resume(); 223 test_handle()->Resume();
187 EXPECT_FALSE(IsDeferringStart()); 224 EXPECT_FALSE(IsDeferringStart());
188 EXPECT_FALSE(IsDeferringRedirect()); 225 EXPECT_FALSE(IsDeferringRedirect());
189 EXPECT_TRUE(was_callback_called()); 226 EXPECT_TRUE(was_callback_called());
190 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); 227 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
191 EXPECT_EQ(1, test_throttle->will_start_calls()); 228 EXPECT_EQ(1, test_throttle->will_start_calls());
192 EXPECT_EQ(1, test_throttle->will_redirect_calls()); 229 EXPECT_EQ(1, test_throttle->will_redirect_calls());
230 EXPECT_EQ(0, test_throttle->will_process_response_calls());
231
232 // Simulate WillProcessResponse. We'll change the result to PROCEED here, as
233 // WillProcessResponse cannot be deferred. The callback will be called.
clamy 2016/01/25 16:36:21 As mentioned in other comments, I'd like if WillPr
234 test_throttle->SetResult(NavigationThrottle::PROCEED);
235 SimulateWillProcessResponse();
236 EXPECT_FALSE(IsDeferringStart());
237 EXPECT_FALSE(IsDeferringRedirect());
238 EXPECT_TRUE(was_callback_called());
239 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
240 EXPECT_EQ(1, test_throttle->will_start_calls());
241 EXPECT_EQ(1, test_throttle->will_redirect_calls());
242 EXPECT_EQ(1, test_throttle->will_process_response_calls());
193 } 243 }
194 244
195 // Checks that a navigation deferred during WillStartRequest can be properly 245 // Checks that a navigation deferred during WillStartRequest can be properly
196 // cancelled. 246 // cancelled.
197 TEST_F(NavigationHandleImplTest, CancelDeferredWillStart) { 247 TEST_F(NavigationHandleImplTest, CancelDeferredWillStart) {
198 TestNavigationThrottle* test_throttle = 248 TestNavigationThrottle* test_throttle =
199 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 249 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
200 EXPECT_FALSE(IsDeferringStart()); 250 EXPECT_FALSE(IsDeferringStart());
201 EXPECT_FALSE(IsDeferringRedirect()); 251 EXPECT_FALSE(IsDeferringRedirect());
202 EXPECT_EQ(0, test_throttle->will_start_calls()); 252 EXPECT_EQ(0, test_throttle->will_start_calls());
203 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 253 EXPECT_EQ(0, test_throttle->will_redirect_calls());
254 EXPECT_EQ(0, test_throttle->will_process_response_calls());
204 255
205 // Simulate WillStartRequest. The request should be deferred. The callback 256 // Simulate WillStartRequest. The request should be deferred. The callback
206 // should not have been called. 257 // should not have been called.
207 SimulateWillStartRequest(); 258 SimulateWillStartRequest();
208 EXPECT_TRUE(IsDeferringStart()); 259 EXPECT_TRUE(IsDeferringStart());
209 EXPECT_FALSE(IsDeferringRedirect()); 260 EXPECT_FALSE(IsDeferringRedirect());
210 EXPECT_FALSE(was_callback_called()); 261 EXPECT_FALSE(was_callback_called());
211 EXPECT_EQ(1, test_throttle->will_start_calls()); 262 EXPECT_EQ(1, test_throttle->will_start_calls());
212 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 263 EXPECT_EQ(0, test_throttle->will_redirect_calls());
264 EXPECT_EQ(0, test_throttle->will_process_response_calls());
213 265
214 // Cancel the request. The callback should have been called. 266 // Cancel the request. The callback should have been called.
215 test_handle()->CancelDeferredNavigation( 267 test_handle()->CancelDeferredNavigation(
216 NavigationThrottle::CANCEL_AND_IGNORE); 268 NavigationThrottle::CANCEL_AND_IGNORE);
217 EXPECT_FALSE(IsDeferringStart()); 269 EXPECT_FALSE(IsDeferringStart());
218 EXPECT_FALSE(IsDeferringRedirect()); 270 EXPECT_FALSE(IsDeferringRedirect());
219 EXPECT_TRUE(IsCanceling()); 271 EXPECT_TRUE(IsCanceling());
220 EXPECT_TRUE(was_callback_called()); 272 EXPECT_TRUE(was_callback_called());
221 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 273 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
222 EXPECT_EQ(1, test_throttle->will_start_calls()); 274 EXPECT_EQ(1, test_throttle->will_start_calls());
223 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 275 EXPECT_EQ(0, test_throttle->will_redirect_calls());
276 EXPECT_EQ(0, test_throttle->will_process_response_calls());
224 } 277 }
225 278
226 // Checks that a navigation deferred during WillRedirectRequest can be properly 279 // Checks that a navigation deferred during WillRedirectRequest can be properly
227 // cancelled. 280 // cancelled.
228 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { 281 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) {
229 TestNavigationThrottle* test_throttle = 282 TestNavigationThrottle* test_throttle =
230 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 283 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
231 EXPECT_FALSE(IsDeferringStart()); 284 EXPECT_FALSE(IsDeferringStart());
232 EXPECT_FALSE(IsDeferringRedirect()); 285 EXPECT_FALSE(IsDeferringRedirect());
233 EXPECT_EQ(0, test_throttle->will_start_calls()); 286 EXPECT_EQ(0, test_throttle->will_start_calls());
234 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 287 EXPECT_EQ(0, test_throttle->will_redirect_calls());
288 EXPECT_EQ(0, test_throttle->will_process_response_calls());
235 289
236 // Simulate WillRedirectRequest. The request should be deferred. The callback 290 // Simulate WillRedirectRequest. The request should be deferred. The callback
237 // should not have been called. 291 // should not have been called.
238 SimulateWillRedirectRequest(); 292 SimulateWillRedirectRequest();
239 EXPECT_FALSE(IsDeferringStart()); 293 EXPECT_FALSE(IsDeferringStart());
240 EXPECT_TRUE(IsDeferringRedirect()); 294 EXPECT_TRUE(IsDeferringRedirect());
241 EXPECT_FALSE(was_callback_called()); 295 EXPECT_FALSE(was_callback_called());
242 EXPECT_EQ(0, test_throttle->will_start_calls()); 296 EXPECT_EQ(0, test_throttle->will_start_calls());
243 EXPECT_EQ(1, test_throttle->will_redirect_calls()); 297 EXPECT_EQ(1, test_throttle->will_redirect_calls());
298 EXPECT_EQ(0, test_throttle->will_process_response_calls());
244 299
245 // Cancel the request. The callback should have been called. 300 // Cancel the request. The callback should have been called.
246 test_handle()->CancelDeferredNavigation( 301 test_handle()->CancelDeferredNavigation(
247 NavigationThrottle::CANCEL_AND_IGNORE); 302 NavigationThrottle::CANCEL_AND_IGNORE);
248 EXPECT_FALSE(IsDeferringStart()); 303 EXPECT_FALSE(IsDeferringStart());
249 EXPECT_FALSE(IsDeferringRedirect()); 304 EXPECT_FALSE(IsDeferringRedirect());
250 EXPECT_TRUE(IsCanceling()); 305 EXPECT_TRUE(IsCanceling());
251 EXPECT_TRUE(was_callback_called()); 306 EXPECT_TRUE(was_callback_called());
252 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 307 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
253 EXPECT_EQ(0, test_throttle->will_start_calls()); 308 EXPECT_EQ(0, test_throttle->will_start_calls());
254 EXPECT_EQ(1, test_throttle->will_redirect_calls()); 309 EXPECT_EQ(1, test_throttle->will_redirect_calls());
310 EXPECT_EQ(0, test_throttle->will_process_response_calls());
255 } 311 }
256 312
257 // Checks that a navigation deferred can be canceled and not ignored. 313 // Checks that a navigation deferred can be canceled and not ignored.
258 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { 314 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) {
259 TestNavigationThrottle* test_throttle = 315 TestNavigationThrottle* test_throttle =
260 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 316 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
261 EXPECT_FALSE(IsDeferringStart()); 317 EXPECT_FALSE(IsDeferringStart());
262 EXPECT_FALSE(IsDeferringRedirect()); 318 EXPECT_FALSE(IsDeferringRedirect());
263 EXPECT_EQ(0, test_throttle->will_start_calls()); 319 EXPECT_EQ(0, test_throttle->will_start_calls());
264 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 320 EXPECT_EQ(0, test_throttle->will_redirect_calls());
321 EXPECT_EQ(0, test_throttle->will_process_response_calls());
265 322
266 // Simulate WillRedirectRequest. The request should be deferred. The callback 323 // Simulate WillRedirectRequest. The request should be deferred. The callback
267 // should not have been called. 324 // should not have been called.
268 SimulateWillStartRequest(); 325 SimulateWillStartRequest();
269 EXPECT_TRUE(IsDeferringStart()); 326 EXPECT_TRUE(IsDeferringStart());
270 EXPECT_FALSE(IsDeferringRedirect()); 327 EXPECT_FALSE(IsDeferringRedirect());
271 EXPECT_FALSE(was_callback_called()); 328 EXPECT_FALSE(was_callback_called());
272 EXPECT_EQ(1, test_throttle->will_start_calls()); 329 EXPECT_EQ(1, test_throttle->will_start_calls());
273 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 330 EXPECT_EQ(0, test_throttle->will_redirect_calls());
331 EXPECT_EQ(0, test_throttle->will_process_response_calls());
274 332
275 // Cancel the request. The callback should have been called with CANCEL, and 333 // Cancel the request. The callback should have been called with CANCEL, and
276 // not CANCEL_AND_IGNORE. 334 // not CANCEL_AND_IGNORE.
277 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); 335 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL);
278 EXPECT_FALSE(IsDeferringStart()); 336 EXPECT_FALSE(IsDeferringStart());
279 EXPECT_FALSE(IsDeferringRedirect()); 337 EXPECT_FALSE(IsDeferringRedirect());
280 EXPECT_TRUE(IsCanceling()); 338 EXPECT_TRUE(IsCanceling());
281 EXPECT_TRUE(was_callback_called()); 339 EXPECT_TRUE(was_callback_called());
282 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); 340 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result());
283 EXPECT_EQ(1, test_throttle->will_start_calls()); 341 EXPECT_EQ(1, test_throttle->will_start_calls());
284 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 342 EXPECT_EQ(0, test_throttle->will_redirect_calls());
343 EXPECT_EQ(0, test_throttle->will_process_response_calls());
285 } 344 }
286 345
287 // Checks that a NavigationThrottle asking to defer followed by a 346 // Checks that a NavigationThrottle asking to defer followed by a
288 // NavigationThrottle asking to proceed behave correctly. 347 // NavigationThrottle asking to proceed behave correctly.
289 TEST_F(NavigationHandleImplTest, DeferThenProceed) { 348 TEST_F(NavigationHandleImplTest, DeferThenProceed) {
290 TestNavigationThrottle* defer_throttle = 349 TestNavigationThrottle* defer_throttle =
291 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 350 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
292 TestNavigationThrottle* proceed_throttle = 351 TestNavigationThrottle* proceed_throttle =
293 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); 352 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
294 EXPECT_FALSE(IsDeferringStart()); 353 EXPECT_FALSE(IsDeferringStart());
295 EXPECT_FALSE(IsDeferringRedirect()); 354 EXPECT_FALSE(IsDeferringRedirect());
296 EXPECT_EQ(0, defer_throttle->will_start_calls()); 355 EXPECT_EQ(0, defer_throttle->will_start_calls());
297 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 356 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
357 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
298 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 358 EXPECT_EQ(0, proceed_throttle->will_start_calls());
299 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 359 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
360 EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
300 361
301 // Simulate WillStartRequest. The request should be deferred. The callback 362 // Simulate WillStartRequest. The request should be deferred. The callback
302 // should not have been called. The second throttle should not have been 363 // should not have been called. The second throttle should not have been
303 // notified. 364 // notified.
304 SimulateWillStartRequest(); 365 SimulateWillStartRequest();
305 EXPECT_TRUE(IsDeferringStart()); 366 EXPECT_TRUE(IsDeferringStart());
306 EXPECT_FALSE(IsDeferringRedirect()); 367 EXPECT_FALSE(IsDeferringRedirect());
307 EXPECT_FALSE(was_callback_called()); 368 EXPECT_FALSE(was_callback_called());
308 EXPECT_EQ(1, defer_throttle->will_start_calls()); 369 EXPECT_EQ(1, defer_throttle->will_start_calls());
309 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 370 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
371 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
310 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 372 EXPECT_EQ(0, proceed_throttle->will_start_calls());
311 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 373 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
312 374
313 // Resume the request. It should no longer be deferred and the callback 375 // Resume the request. It should no longer be deferred and the callback
314 // should have been called. The second throttle should have been notified. 376 // should have been called. The second throttle should have been notified.
315 test_handle()->Resume(); 377 test_handle()->Resume();
316 EXPECT_FALSE(IsDeferringStart()); 378 EXPECT_FALSE(IsDeferringStart());
317 EXPECT_FALSE(IsDeferringRedirect()); 379 EXPECT_FALSE(IsDeferringRedirect());
318 EXPECT_TRUE(was_callback_called()); 380 EXPECT_TRUE(was_callback_called());
319 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); 381 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
320 EXPECT_EQ(1, defer_throttle->will_start_calls()); 382 EXPECT_EQ(1, defer_throttle->will_start_calls());
321 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 383 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
384 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
322 EXPECT_EQ(1, proceed_throttle->will_start_calls()); 385 EXPECT_EQ(1, proceed_throttle->will_start_calls());
323 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 386 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
324 387
325 // Simulate WillRedirectRequest. The request should be deferred. The callback 388 // Simulate WillRedirectRequest. The request should be deferred. The callback
326 // should not have been called. The second throttle should not have been 389 // should not have been called. The second throttle should not have been
327 // notified. 390 // notified.
328 SimulateWillRedirectRequest(); 391 SimulateWillRedirectRequest();
329 EXPECT_FALSE(IsDeferringStart()); 392 EXPECT_FALSE(IsDeferringStart());
330 EXPECT_TRUE(IsDeferringRedirect()); 393 EXPECT_TRUE(IsDeferringRedirect());
331 EXPECT_FALSE(was_callback_called()); 394 EXPECT_FALSE(was_callback_called());
332 EXPECT_EQ(1, defer_throttle->will_start_calls()); 395 EXPECT_EQ(1, defer_throttle->will_start_calls());
333 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); 396 EXPECT_EQ(1, defer_throttle->will_redirect_calls());
397 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
334 EXPECT_EQ(1, proceed_throttle->will_start_calls()); 398 EXPECT_EQ(1, proceed_throttle->will_start_calls());
335 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 399 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
336 400
337 // Resume the request. It should no longer be deferred and the callback 401 // Resume the request. It should no longer be deferred and the callback
338 // should have been called. The second throttle should have been notified. 402 // should have been called. The second throttle should have been notified.
339 test_handle()->Resume(); 403 test_handle()->Resume();
340 EXPECT_FALSE(IsDeferringStart()); 404 EXPECT_FALSE(IsDeferringStart());
341 EXPECT_FALSE(IsDeferringRedirect()); 405 EXPECT_FALSE(IsDeferringRedirect());
342 EXPECT_TRUE(was_callback_called()); 406 EXPECT_TRUE(was_callback_called());
343 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); 407 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
344 EXPECT_EQ(1, defer_throttle->will_start_calls()); 408 EXPECT_EQ(1, defer_throttle->will_start_calls());
345 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); 409 EXPECT_EQ(1, defer_throttle->will_redirect_calls());
410 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
346 EXPECT_EQ(1, proceed_throttle->will_start_calls()); 411 EXPECT_EQ(1, proceed_throttle->will_start_calls());
347 EXPECT_EQ(1, proceed_throttle->will_redirect_calls()); 412 EXPECT_EQ(1, proceed_throttle->will_redirect_calls());
348 } 413 }
349 414
350 // Checks that a NavigationThrottle asking to defer followed by a 415 // Checks that a NavigationThrottle asking to defer followed by a
351 // NavigationThrottle asking to cancel behave correctly in WillStartRequest. 416 // NavigationThrottle asking to cancel behave correctly in WillStartRequest.
352 TEST_F(NavigationHandleImplTest, DeferThenCancelWillStartRequest) { 417 TEST_F(NavigationHandleImplTest, DeferThenCancelWillStartRequest) {
353 TestNavigationThrottle* defer_throttle = 418 TestNavigationThrottle* defer_throttle =
354 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 419 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
355 TestNavigationThrottle* cancel_throttle = 420 TestNavigationThrottle* cancel_throttle =
356 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); 421 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
357 EXPECT_FALSE(IsDeferringStart()); 422 EXPECT_FALSE(IsDeferringStart());
358 EXPECT_FALSE(IsDeferringRedirect()); 423 EXPECT_FALSE(IsDeferringRedirect());
359 EXPECT_EQ(0, defer_throttle->will_start_calls()); 424 EXPECT_EQ(0, defer_throttle->will_start_calls());
360 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 425 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
426 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
361 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 427 EXPECT_EQ(0, cancel_throttle->will_start_calls());
362 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 428 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
363 429
364 // Simulate WillStartRequest. The request should be deferred. The callback 430 // Simulate WillStartRequest. The request should be deferred. The callback
365 // should not have been called. The second throttle should not have been 431 // should not have been called. The second throttle should not have been
366 // notified. 432 // notified.
367 SimulateWillStartRequest(); 433 SimulateWillStartRequest();
368 EXPECT_TRUE(IsDeferringStart()); 434 EXPECT_TRUE(IsDeferringStart());
369 EXPECT_FALSE(IsDeferringRedirect()); 435 EXPECT_FALSE(IsDeferringRedirect());
370 EXPECT_FALSE(was_callback_called()); 436 EXPECT_FALSE(was_callback_called());
371 EXPECT_EQ(1, defer_throttle->will_start_calls()); 437 EXPECT_EQ(1, defer_throttle->will_start_calls());
372 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 438 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
439 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
373 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 440 EXPECT_EQ(0, cancel_throttle->will_start_calls());
374 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 441 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
375 442
376 // Resume the request. The callback should have been called. The second 443 // Resume the request. The callback should have been called. The second
377 // throttle should have been notified. 444 // throttle should have been notified.
378 test_handle()->Resume(); 445 test_handle()->Resume();
379 EXPECT_FALSE(IsDeferringStart()); 446 EXPECT_FALSE(IsDeferringStart());
380 EXPECT_FALSE(IsDeferringRedirect()); 447 EXPECT_FALSE(IsDeferringRedirect());
381 EXPECT_TRUE(IsCanceling()); 448 EXPECT_TRUE(IsCanceling());
382 EXPECT_TRUE(was_callback_called()); 449 EXPECT_TRUE(was_callback_called());
383 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 450 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
384 EXPECT_EQ(1, defer_throttle->will_start_calls()); 451 EXPECT_EQ(1, defer_throttle->will_start_calls());
385 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 452 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
453 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
386 EXPECT_EQ(1, cancel_throttle->will_start_calls()); 454 EXPECT_EQ(1, cancel_throttle->will_start_calls());
387 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 455 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
388 } 456 }
389 457
390 // Checks that a NavigationThrottle asking to defer followed by a 458 // Checks that a NavigationThrottle asking to defer followed by a
391 // NavigationThrottle asking to cancel behave correctly in WillRedirectRequest. 459 // NavigationThrottle asking to cancel behave correctly in WillRedirectRequest.
392 TEST_F(NavigationHandleImplTest, DeferThenCancelWillRedirectRequest) { 460 TEST_F(NavigationHandleImplTest, DeferThenCancelWillRedirectRequest) {
393 TestNavigationThrottle* defer_throttle = 461 TestNavigationThrottle* defer_throttle =
394 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 462 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
395 TestNavigationThrottle* cancel_throttle = 463 TestNavigationThrottle* cancel_throttle =
396 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); 464 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
397 EXPECT_FALSE(IsDeferringStart()); 465 EXPECT_FALSE(IsDeferringStart());
398 EXPECT_FALSE(IsDeferringRedirect()); 466 EXPECT_FALSE(IsDeferringRedirect());
399 EXPECT_EQ(0, defer_throttle->will_start_calls()); 467 EXPECT_EQ(0, defer_throttle->will_start_calls());
400 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 468 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
469 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
401 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 470 EXPECT_EQ(0, cancel_throttle->will_start_calls());
402 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 471 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
403 472
404 // Simulate WillRedirectRequest. The request should be deferred. The callback 473 // Simulate WillRedirectRequest. The request should be deferred. The callback
405 // should not have been called. The second throttle should not have been 474 // should not have been called. The second throttle should not have been
406 // notified. 475 // notified.
407 SimulateWillRedirectRequest(); 476 SimulateWillRedirectRequest();
408 EXPECT_FALSE(IsDeferringStart()); 477 EXPECT_FALSE(IsDeferringStart());
409 EXPECT_TRUE(IsDeferringRedirect()); 478 EXPECT_TRUE(IsDeferringRedirect());
410 EXPECT_FALSE(was_callback_called()); 479 EXPECT_FALSE(was_callback_called());
411 EXPECT_EQ(0, defer_throttle->will_start_calls()); 480 EXPECT_EQ(0, defer_throttle->will_start_calls());
412 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); 481 EXPECT_EQ(1, defer_throttle->will_redirect_calls());
482 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
413 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 483 EXPECT_EQ(0, cancel_throttle->will_start_calls());
414 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 484 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
415 485
416 // Resume the request. The callback should have been called. The second 486 // Resume the request. The callback should have been called. The second
417 // throttle should have been notified. 487 // throttle should have been notified.
418 test_handle()->Resume(); 488 test_handle()->Resume();
419 EXPECT_FALSE(IsDeferringStart()); 489 EXPECT_FALSE(IsDeferringStart());
420 EXPECT_FALSE(IsDeferringRedirect()); 490 EXPECT_FALSE(IsDeferringRedirect());
421 EXPECT_TRUE(IsCanceling()); 491 EXPECT_TRUE(IsCanceling());
422 EXPECT_TRUE(was_callback_called()); 492 EXPECT_TRUE(was_callback_called());
423 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 493 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
424 EXPECT_EQ(0, defer_throttle->will_start_calls()); 494 EXPECT_EQ(0, defer_throttle->will_start_calls());
425 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); 495 EXPECT_EQ(1, defer_throttle->will_redirect_calls());
496 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
426 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 497 EXPECT_EQ(0, cancel_throttle->will_start_calls());
427 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); 498 EXPECT_EQ(1, cancel_throttle->will_redirect_calls());
428 } 499 }
429 500
430 // Checks that a NavigationThrottle asking to cancel followed by a 501 // Checks that a NavigationThrottle asking to cancel followed by a
431 // NavigationThrottle asking to proceed behave correctly in WillStartRequest. 502 // NavigationThrottle asking to proceed behave correctly in WillStartRequest.
432 // The navigation will be canceled directly, and the second throttle will not 503 // The navigation will be canceled directly, and the second throttle will not
433 // be called. 504 // be called.
434 TEST_F(NavigationHandleImplTest, CancelThenProceedWillStartRequest) { 505 TEST_F(NavigationHandleImplTest, CancelThenProceedWillStartRequest) {
435 TestNavigationThrottle* cancel_throttle = 506 TestNavigationThrottle* cancel_throttle =
436 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); 507 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
437 TestNavigationThrottle* proceed_throttle = 508 TestNavigationThrottle* proceed_throttle =
438 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); 509 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
439 EXPECT_FALSE(IsDeferringStart()); 510 EXPECT_FALSE(IsDeferringStart());
440 EXPECT_FALSE(IsDeferringRedirect()); 511 EXPECT_FALSE(IsDeferringRedirect());
441 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 512 EXPECT_EQ(0, cancel_throttle->will_start_calls());
442 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 513 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
514 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
443 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 515 EXPECT_EQ(0, proceed_throttle->will_start_calls());
444 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 516 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
445 517
446 // Simulate WillStartRequest. The request should not be deferred. The 518 // Simulate WillStartRequest. The request should not be deferred. The
447 // callback should not have been called. The second throttle should not have 519 // callback should not have been called. The second throttle should not have
448 // been notified. 520 // been notified.
449 SimulateWillStartRequest(); 521 SimulateWillStartRequest();
450 EXPECT_FALSE(IsDeferringStart()); 522 EXPECT_FALSE(IsDeferringStart());
451 EXPECT_FALSE(IsDeferringRedirect()); 523 EXPECT_FALSE(IsDeferringRedirect());
452 EXPECT_TRUE(was_callback_called()); 524 EXPECT_TRUE(was_callback_called());
453 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 525 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
454 EXPECT_EQ(1, cancel_throttle->will_start_calls()); 526 EXPECT_EQ(1, cancel_throttle->will_start_calls());
455 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 527 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
528 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
456 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 529 EXPECT_EQ(0, proceed_throttle->will_start_calls());
457 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 530 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
458 } 531 }
459 532
460 // Checks that a NavigationThrottle asking to cancel followed by a 533 // Checks that a NavigationThrottle asking to cancel followed by a
461 // NavigationThrottle asking to proceed behave correctly in WillRedirectRequest. 534 // NavigationThrottle asking to proceed behave correctly in WillRedirectRequest.
462 // The navigation will be canceled directly, and the second throttle will not 535 // The navigation will be canceled directly, and the second throttle will not
463 // be called. 536 // be called.
464 TEST_F(NavigationHandleImplTest, CancelThenProceedWillRedirectRequest) { 537 TEST_F(NavigationHandleImplTest, CancelThenProceedWillRedirectRequest) {
465 TestNavigationThrottle* cancel_throttle = 538 TestNavigationThrottle* cancel_throttle =
466 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); 539 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
467 TestNavigationThrottle* proceed_throttle = 540 TestNavigationThrottle* proceed_throttle =
468 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); 541 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
469 EXPECT_FALSE(IsDeferringStart()); 542 EXPECT_FALSE(IsDeferringStart());
470 EXPECT_FALSE(IsDeferringRedirect()); 543 EXPECT_FALSE(IsDeferringRedirect());
471 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 544 EXPECT_EQ(0, cancel_throttle->will_start_calls());
472 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 545 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
546 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
473 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 547 EXPECT_EQ(0, proceed_throttle->will_start_calls());
474 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 548 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
475 549
476 // Simulate WillRedirectRequest. The request should not be deferred. The 550 // Simulate WillRedirectRequest. The request should not be deferred. The
477 // callback should not have been called. The second throttle should not have 551 // callback should not have been called. The second throttle should not have
478 // been notified. 552 // been notified.
479 SimulateWillRedirectRequest(); 553 SimulateWillRedirectRequest();
480 EXPECT_FALSE(IsDeferringStart()); 554 EXPECT_FALSE(IsDeferringStart());
481 EXPECT_FALSE(IsDeferringRedirect()); 555 EXPECT_FALSE(IsDeferringRedirect());
482 EXPECT_TRUE(was_callback_called()); 556 EXPECT_TRUE(was_callback_called());
483 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 557 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
484 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 558 EXPECT_EQ(0, cancel_throttle->will_start_calls());
485 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); 559 EXPECT_EQ(1, cancel_throttle->will_redirect_calls());
560 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
486 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 561 EXPECT_EQ(0, proceed_throttle->will_start_calls());
487 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 562 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
488 } 563 }
489 564
565 // Checks that a NavigationThrottle asking to proceed followed by a
566 // NavigationThrottle asking to cancel behave correctly in WillProcessResponse.
567 // Both throttles will be called, and the request will be cancelled.
568 TEST_F(NavigationHandleImplTest, ProceedThenCancelWillProcessResponse) {
569 TestNavigationThrottle* proceed_throttle =
570 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
571 TestNavigationThrottle* cancel_throttle =
572 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
573 EXPECT_FALSE(IsDeferringStart());
574 EXPECT_FALSE(IsDeferringRedirect());
575 EXPECT_EQ(0, cancel_throttle->will_start_calls());
576 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
577 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
578 EXPECT_EQ(0, proceed_throttle->will_start_calls());
579 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
580 EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
581
582 // Simulate WillRedirectRequest. The request should not be deferred. The
583 // callback should have been called.
584 SimulateWillProcessResponse();
585 EXPECT_FALSE(IsDeferringStart());
586 EXPECT_FALSE(IsDeferringRedirect());
587 EXPECT_TRUE(was_callback_called());
588 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
589 EXPECT_EQ(0, cancel_throttle->will_start_calls());
590 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
591 EXPECT_EQ(1, cancel_throttle->will_process_response_calls());
592 EXPECT_EQ(0, proceed_throttle->will_start_calls());
593 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
594 EXPECT_EQ(1, proceed_throttle->will_process_response_calls());
595 }
596
597 // Checks that a NavigationThrottle asking to cancel followed by a
598 // NavigationThrottle asking to proceed behave correctly in WillProcessResponse.
599 // The navigation will be canceled directly, and the second throttle will not
600 // be called.
601 TEST_F(NavigationHandleImplTest, CancelThenProceedWillProcessResponse) {
602 TestNavigationThrottle* cancel_throttle =
603 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
604 TestNavigationThrottle* proceed_throttle =
605 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
606 EXPECT_FALSE(IsDeferringStart());
607 EXPECT_FALSE(IsDeferringRedirect());
608 EXPECT_EQ(0, cancel_throttle->will_start_calls());
609 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
610 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
611 EXPECT_EQ(0, proceed_throttle->will_start_calls());
612 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
613
614 // Simulate WillRedirectRequest. The request should not be deferred. The
615 // callback should have been called. The second throttle should not have
616 // been notified.
617 SimulateWillProcessResponse();
618 EXPECT_FALSE(IsDeferringStart());
619 EXPECT_FALSE(IsDeferringRedirect());
620 EXPECT_TRUE(was_callback_called());
621 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
622 EXPECT_EQ(0, cancel_throttle->will_start_calls());
623 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
624 EXPECT_EQ(1, cancel_throttle->will_process_response_calls());
625 EXPECT_EQ(0, proceed_throttle->will_start_calls());
626 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
627 EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
628 }
629
490 } // namespace content 630 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698