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

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: Feedback. Created 4 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 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) {
clamy 2016/01/26 14:08:55 Is this change still used in the unit tests ?
Mike West 2016/01/27 07:44:33 Nope. Removed, thanks!
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();
56 test_handle_ = NavigationHandleImpl::Create( 71 test_handle_ = NavigationHandleImpl::Create(
57 GURL(), main_test_rfh()->frame_tree_node(), base::TimeTicks::Now()); 72 GURL(), main_test_rfh()->frame_tree_node(), base::TimeTicks::Now());
58 } 73 }
59 74
60 void TearDown() override { 75 void TearDown() override {
61 // Release the |test_handle_| before destroying the WebContents, to match 76 // Release the |test_handle_| before destroying the WebContents, to match
62 // the WebContentsObserverSanityChecker expectations. 77 // the WebContentsObserverSanityChecker expectations.
63 test_handle_.reset(); 78 test_handle_.reset();
64 RenderViewHostImplTestHarness::TearDown(); 79 RenderViewHostImplTestHarness::TearDown();
65 } 80 }
66 81
67 bool IsDeferringStart() { 82 bool IsDeferringStart() {
68 return test_handle_->state() == NavigationHandleImpl::DEFERRING_START; 83 return test_handle_->state() == NavigationHandleImpl::DEFERRING_START;
69 } 84 }
70 85
71 bool IsDeferringRedirect() { 86 bool IsDeferringRedirect() {
72 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; 87 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT;
73 } 88 }
74 89
90 bool IsDeferringResponse() {
91 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE;
92 }
93
75 bool IsCanceling() { 94 bool IsCanceling() {
76 return test_handle_->state() == NavigationHandleImpl::CANCELING; 95 return test_handle_->state() == NavigationHandleImpl::CANCELING;
77 } 96 }
78 97
79 // Helper function to call WillStartRequest on |handle|. If this function 98 // Helper function to call WillStartRequest on |handle|. If this function
80 // returns DEFER, |callback_result_| will be set to the actual result of 99 // returns DEFER, |callback_result_| will be set to the actual result of
81 // the throttle checks when they are finished. 100 // the throttle checks when they are finished.
82 void SimulateWillStartRequest() { 101 void SimulateWillStartRequest() {
83 was_callback_called_ = false; 102 was_callback_called_ = false;
84 callback_result_ = NavigationThrottle::DEFER; 103 callback_result_ = NavigationThrottle::DEFER;
(...skipping 16 matching lines...) Expand all
101 callback_result_ = NavigationThrottle::DEFER; 120 callback_result_ = NavigationThrottle::DEFER;
102 121
103 // It's safe to use base::Unretained since the NavigationHandle is owned by 122 // It's safe to use base::Unretained since the NavigationHandle is owned by
104 // the NavigationHandleImplTest. 123 // the NavigationHandleImplTest.
105 test_handle_->WillRedirectRequest( 124 test_handle_->WillRedirectRequest(
106 GURL(), false, GURL(), false, scoped_refptr<net::HttpResponseHeaders>(), 125 GURL(), false, GURL(), false, scoped_refptr<net::HttpResponseHeaders>(),
107 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, 126 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult,
108 base::Unretained(this))); 127 base::Unretained(this)));
109 } 128 }
110 129
130 // Helper function to call WillProcessResponse on |handle|. If this function
131 // returns DEFER, |callback_result_| will be set to the actual result of the
132 // throttle checks when they are finished.
133 // TODO(clamy): this should also simulate that WillStartRequest was called if
134 // it has not been called before.
135 void SimulateWillProcessResponse() {
136 was_callback_called_ = false;
137 callback_result_ = NavigationThrottle::DEFER;
138
139 // It's safe to use base::Unretained since the NavigationHandle is owned by
140 // the NavigationHandleImplTest.
141 test_handle_->WillProcessResponse(
142 scoped_refptr<net::HttpResponseHeaders>(),
143 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult,
144 base::Unretained(this)));
145 }
146
111 // Returns the handle used in tests. 147 // Returns the handle used in tests.
112 NavigationHandleImpl* test_handle() const { return test_handle_.get(); } 148 NavigationHandleImpl* test_handle() const { return test_handle_.get(); }
113 149
114 // Whether the callback was called. 150 // Whether the callback was called.
115 bool was_callback_called() const { return was_callback_called_; } 151 bool was_callback_called() const { return was_callback_called_; }
116 152
117 // Returns the callback_result. 153 // Returns the callback_result.
118 NavigationThrottle::ThrottleCheckResult callback_result() const { 154 NavigationThrottle::ThrottleCheckResult callback_result() const {
119 return callback_result_; 155 return callback_result_;
120 } 156 }
(...skipping 22 matching lines...) Expand all
143 bool was_callback_called_; 179 bool was_callback_called_;
144 NavigationThrottle::ThrottleCheckResult callback_result_; 180 NavigationThrottle::ThrottleCheckResult callback_result_;
145 }; 181 };
146 182
147 // Checks that a deferred navigation can be properly resumed. 183 // Checks that a deferred navigation can be properly resumed.
148 TEST_F(NavigationHandleImplTest, ResumeDeferred) { 184 TEST_F(NavigationHandleImplTest, ResumeDeferred) {
149 TestNavigationThrottle* test_throttle = 185 TestNavigationThrottle* test_throttle =
150 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 186 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
151 EXPECT_FALSE(IsDeferringStart()); 187 EXPECT_FALSE(IsDeferringStart());
152 EXPECT_FALSE(IsDeferringRedirect()); 188 EXPECT_FALSE(IsDeferringRedirect());
189 EXPECT_FALSE(IsDeferringResponse());
153 EXPECT_EQ(0, test_throttle->will_start_calls()); 190 EXPECT_EQ(0, test_throttle->will_start_calls());
154 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 191 EXPECT_EQ(0, test_throttle->will_redirect_calls());
192 EXPECT_EQ(0, test_throttle->will_process_response_calls());
155 193
156 // Simulate WillStartRequest. The request should be deferred. The callback 194 // Simulate WillStartRequest. The request should be deferred. The callback
157 // should not have been called. 195 // should not have been called.
158 SimulateWillStartRequest(); 196 SimulateWillStartRequest();
159 EXPECT_TRUE(IsDeferringStart()); 197 EXPECT_TRUE(IsDeferringStart());
160 EXPECT_FALSE(IsDeferringRedirect()); 198 EXPECT_FALSE(IsDeferringRedirect());
199 EXPECT_FALSE(IsDeferringResponse());
161 EXPECT_FALSE(was_callback_called()); 200 EXPECT_FALSE(was_callback_called());
162 EXPECT_EQ(1, test_throttle->will_start_calls()); 201 EXPECT_EQ(1, test_throttle->will_start_calls());
163 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 202 EXPECT_EQ(0, test_throttle->will_redirect_calls());
203 EXPECT_EQ(0, test_throttle->will_process_response_calls());
164 204
165 // Resume the request. It should no longer be deferred and the callback 205 // Resume the request. It should no longer be deferred and the callback
166 // should have been called. 206 // should have been called.
167 test_handle()->Resume(); 207 test_handle()->Resume();
168 EXPECT_FALSE(IsDeferringStart()); 208 EXPECT_FALSE(IsDeferringStart());
169 EXPECT_FALSE(IsDeferringRedirect()); 209 EXPECT_FALSE(IsDeferringRedirect());
210 EXPECT_FALSE(IsDeferringResponse());
170 EXPECT_TRUE(was_callback_called()); 211 EXPECT_TRUE(was_callback_called());
171 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); 212 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
172 EXPECT_EQ(1, test_throttle->will_start_calls()); 213 EXPECT_EQ(1, test_throttle->will_start_calls());
173 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 214 EXPECT_EQ(0, test_throttle->will_redirect_calls());
215 EXPECT_EQ(0, test_throttle->will_process_response_calls());
174 216
175 // Simulate WillRedirectRequest. The request should be deferred. The callback 217 // Simulate WillRedirectRequest. The request should be deferred. The callback
176 // should not have been called. 218 // should not have been called.
177 SimulateWillRedirectRequest(); 219 SimulateWillRedirectRequest();
178 EXPECT_FALSE(IsDeferringStart()); 220 EXPECT_FALSE(IsDeferringStart());
179 EXPECT_TRUE(IsDeferringRedirect()); 221 EXPECT_TRUE(IsDeferringRedirect());
222 EXPECT_FALSE(IsDeferringResponse());
180 EXPECT_FALSE(was_callback_called()); 223 EXPECT_FALSE(was_callback_called());
181 EXPECT_EQ(1, test_throttle->will_start_calls()); 224 EXPECT_EQ(1, test_throttle->will_start_calls());
182 EXPECT_EQ(1, test_throttle->will_redirect_calls()); 225 EXPECT_EQ(1, test_throttle->will_redirect_calls());
226 EXPECT_EQ(0, test_throttle->will_process_response_calls());
183 227
184 // Resume the request. It should no longer be deferred and the callback 228 // Resume the request. It should no longer be deferred and the callback
185 // should have been called. 229 // should have been called.
186 test_handle()->Resume(); 230 test_handle()->Resume();
187 EXPECT_FALSE(IsDeferringStart()); 231 EXPECT_FALSE(IsDeferringStart());
188 EXPECT_FALSE(IsDeferringRedirect()); 232 EXPECT_FALSE(IsDeferringRedirect());
233 EXPECT_FALSE(IsDeferringResponse());
189 EXPECT_TRUE(was_callback_called()); 234 EXPECT_TRUE(was_callback_called());
190 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); 235 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
191 EXPECT_EQ(1, test_throttle->will_start_calls()); 236 EXPECT_EQ(1, test_throttle->will_start_calls());
192 EXPECT_EQ(1, test_throttle->will_redirect_calls()); 237 EXPECT_EQ(1, test_throttle->will_redirect_calls());
238 EXPECT_EQ(0, test_throttle->will_process_response_calls());
239
240 // Simulate WillProcessResponse. It will be deferred. The callback should not
241 // have been called.
242 SimulateWillProcessResponse();
243 EXPECT_FALSE(IsDeferringStart());
244 EXPECT_FALSE(IsDeferringRedirect());
245 EXPECT_TRUE(IsDeferringResponse());
246 EXPECT_FALSE(was_callback_called());
247 EXPECT_EQ(1, test_throttle->will_start_calls());
248 EXPECT_EQ(1, test_throttle->will_redirect_calls());
249 EXPECT_EQ(1, test_throttle->will_process_response_calls());
250
251 // Resume the request. It should no longer be deferred and the callback should
252 // have been called.
253 test_handle()->Resume();
254 EXPECT_FALSE(IsDeferringStart());
255 EXPECT_FALSE(IsDeferringRedirect());
256 EXPECT_FALSE(IsDeferringResponse());
257 EXPECT_TRUE(was_callback_called());
258 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
259 EXPECT_EQ(1, test_throttle->will_start_calls());
260 EXPECT_EQ(1, test_throttle->will_redirect_calls());
261 EXPECT_EQ(1, test_throttle->will_process_response_calls());
193 } 262 }
194 263
195 // Checks that a navigation deferred during WillStartRequest can be properly 264 // Checks that a navigation deferred during WillStartRequest can be properly
196 // cancelled. 265 // cancelled.
197 TEST_F(NavigationHandleImplTest, CancelDeferredWillStart) { 266 TEST_F(NavigationHandleImplTest, CancelDeferredWillStart) {
198 TestNavigationThrottle* test_throttle = 267 TestNavigationThrottle* test_throttle =
199 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 268 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
200 EXPECT_FALSE(IsDeferringStart()); 269 EXPECT_FALSE(IsDeferringStart());
201 EXPECT_FALSE(IsDeferringRedirect()); 270 EXPECT_FALSE(IsDeferringRedirect());
202 EXPECT_EQ(0, test_throttle->will_start_calls()); 271 EXPECT_EQ(0, test_throttle->will_start_calls());
203 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 272 EXPECT_EQ(0, test_throttle->will_redirect_calls());
273 EXPECT_EQ(0, test_throttle->will_process_response_calls());
204 274
205 // Simulate WillStartRequest. The request should be deferred. The callback 275 // Simulate WillStartRequest. The request should be deferred. The callback
206 // should not have been called. 276 // should not have been called.
207 SimulateWillStartRequest(); 277 SimulateWillStartRequest();
208 EXPECT_TRUE(IsDeferringStart()); 278 EXPECT_TRUE(IsDeferringStart());
209 EXPECT_FALSE(IsDeferringRedirect()); 279 EXPECT_FALSE(IsDeferringRedirect());
210 EXPECT_FALSE(was_callback_called()); 280 EXPECT_FALSE(was_callback_called());
211 EXPECT_EQ(1, test_throttle->will_start_calls()); 281 EXPECT_EQ(1, test_throttle->will_start_calls());
212 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 282 EXPECT_EQ(0, test_throttle->will_redirect_calls());
283 EXPECT_EQ(0, test_throttle->will_process_response_calls());
213 284
214 // Cancel the request. The callback should have been called. 285 // Cancel the request. The callback should have been called.
215 test_handle()->CancelDeferredNavigation( 286 test_handle()->CancelDeferredNavigation(
216 NavigationThrottle::CANCEL_AND_IGNORE); 287 NavigationThrottle::CANCEL_AND_IGNORE);
217 EXPECT_FALSE(IsDeferringStart()); 288 EXPECT_FALSE(IsDeferringStart());
218 EXPECT_FALSE(IsDeferringRedirect()); 289 EXPECT_FALSE(IsDeferringRedirect());
219 EXPECT_TRUE(IsCanceling()); 290 EXPECT_TRUE(IsCanceling());
220 EXPECT_TRUE(was_callback_called()); 291 EXPECT_TRUE(was_callback_called());
221 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 292 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
222 EXPECT_EQ(1, test_throttle->will_start_calls()); 293 EXPECT_EQ(1, test_throttle->will_start_calls());
223 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 294 EXPECT_EQ(0, test_throttle->will_redirect_calls());
295 EXPECT_EQ(0, test_throttle->will_process_response_calls());
224 } 296 }
225 297
226 // Checks that a navigation deferred during WillRedirectRequest can be properly 298 // Checks that a navigation deferred during WillRedirectRequest can be properly
227 // cancelled. 299 // cancelled.
228 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { 300 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) {
229 TestNavigationThrottle* test_throttle = 301 TestNavigationThrottle* test_throttle =
230 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 302 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
231 EXPECT_FALSE(IsDeferringStart()); 303 EXPECT_FALSE(IsDeferringStart());
232 EXPECT_FALSE(IsDeferringRedirect()); 304 EXPECT_FALSE(IsDeferringRedirect());
233 EXPECT_EQ(0, test_throttle->will_start_calls()); 305 EXPECT_EQ(0, test_throttle->will_start_calls());
234 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 306 EXPECT_EQ(0, test_throttle->will_redirect_calls());
307 EXPECT_EQ(0, test_throttle->will_process_response_calls());
235 308
236 // Simulate WillRedirectRequest. The request should be deferred. The callback 309 // Simulate WillRedirectRequest. The request should be deferred. The callback
237 // should not have been called. 310 // should not have been called.
238 SimulateWillRedirectRequest(); 311 SimulateWillRedirectRequest();
239 EXPECT_FALSE(IsDeferringStart()); 312 EXPECT_FALSE(IsDeferringStart());
240 EXPECT_TRUE(IsDeferringRedirect()); 313 EXPECT_TRUE(IsDeferringRedirect());
241 EXPECT_FALSE(was_callback_called()); 314 EXPECT_FALSE(was_callback_called());
242 EXPECT_EQ(0, test_throttle->will_start_calls()); 315 EXPECT_EQ(0, test_throttle->will_start_calls());
243 EXPECT_EQ(1, test_throttle->will_redirect_calls()); 316 EXPECT_EQ(1, test_throttle->will_redirect_calls());
317 EXPECT_EQ(0, test_throttle->will_process_response_calls());
244 318
245 // Cancel the request. The callback should have been called. 319 // Cancel the request. The callback should have been called.
246 test_handle()->CancelDeferredNavigation( 320 test_handle()->CancelDeferredNavigation(
247 NavigationThrottle::CANCEL_AND_IGNORE); 321 NavigationThrottle::CANCEL_AND_IGNORE);
248 EXPECT_FALSE(IsDeferringStart()); 322 EXPECT_FALSE(IsDeferringStart());
249 EXPECT_FALSE(IsDeferringRedirect()); 323 EXPECT_FALSE(IsDeferringRedirect());
250 EXPECT_TRUE(IsCanceling()); 324 EXPECT_TRUE(IsCanceling());
251 EXPECT_TRUE(was_callback_called()); 325 EXPECT_TRUE(was_callback_called());
252 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 326 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
253 EXPECT_EQ(0, test_throttle->will_start_calls()); 327 EXPECT_EQ(0, test_throttle->will_start_calls());
254 EXPECT_EQ(1, test_throttle->will_redirect_calls()); 328 EXPECT_EQ(1, test_throttle->will_redirect_calls());
329 EXPECT_EQ(0, test_throttle->will_process_response_calls());
255 } 330 }
256 331
257 // Checks that a navigation deferred can be canceled and not ignored. 332 // Checks that a navigation deferred can be canceled and not ignored.
258 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { 333 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) {
259 TestNavigationThrottle* test_throttle = 334 TestNavigationThrottle* test_throttle =
260 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 335 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
261 EXPECT_FALSE(IsDeferringStart()); 336 EXPECT_FALSE(IsDeferringStart());
262 EXPECT_FALSE(IsDeferringRedirect()); 337 EXPECT_FALSE(IsDeferringRedirect());
263 EXPECT_EQ(0, test_throttle->will_start_calls()); 338 EXPECT_EQ(0, test_throttle->will_start_calls());
264 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 339 EXPECT_EQ(0, test_throttle->will_redirect_calls());
340 EXPECT_EQ(0, test_throttle->will_process_response_calls());
265 341
266 // Simulate WillRedirectRequest. The request should be deferred. The callback 342 // Simulate WillRedirectRequest. The request should be deferred. The callback
267 // should not have been called. 343 // should not have been called.
268 SimulateWillStartRequest(); 344 SimulateWillStartRequest();
269 EXPECT_TRUE(IsDeferringStart()); 345 EXPECT_TRUE(IsDeferringStart());
270 EXPECT_FALSE(IsDeferringRedirect()); 346 EXPECT_FALSE(IsDeferringRedirect());
271 EXPECT_FALSE(was_callback_called()); 347 EXPECT_FALSE(was_callback_called());
272 EXPECT_EQ(1, test_throttle->will_start_calls()); 348 EXPECT_EQ(1, test_throttle->will_start_calls());
273 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 349 EXPECT_EQ(0, test_throttle->will_redirect_calls());
350 EXPECT_EQ(0, test_throttle->will_process_response_calls());
274 351
275 // Cancel the request. The callback should have been called with CANCEL, and 352 // Cancel the request. The callback should have been called with CANCEL, and
276 // not CANCEL_AND_IGNORE. 353 // not CANCEL_AND_IGNORE.
277 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); 354 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL);
278 EXPECT_FALSE(IsDeferringStart()); 355 EXPECT_FALSE(IsDeferringStart());
279 EXPECT_FALSE(IsDeferringRedirect()); 356 EXPECT_FALSE(IsDeferringRedirect());
280 EXPECT_TRUE(IsCanceling()); 357 EXPECT_TRUE(IsCanceling());
281 EXPECT_TRUE(was_callback_called()); 358 EXPECT_TRUE(was_callback_called());
282 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); 359 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result());
283 EXPECT_EQ(1, test_throttle->will_start_calls()); 360 EXPECT_EQ(1, test_throttle->will_start_calls());
284 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 361 EXPECT_EQ(0, test_throttle->will_redirect_calls());
362 EXPECT_EQ(0, test_throttle->will_process_response_calls());
285 } 363 }
286 364
287 // Checks that a NavigationThrottle asking to defer followed by a 365 // Checks that a NavigationThrottle asking to defer followed by a
288 // NavigationThrottle asking to proceed behave correctly. 366 // NavigationThrottle asking to proceed behave correctly.
289 TEST_F(NavigationHandleImplTest, DeferThenProceed) { 367 TEST_F(NavigationHandleImplTest, DeferThenProceed) {
290 TestNavigationThrottle* defer_throttle = 368 TestNavigationThrottle* defer_throttle =
291 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 369 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
292 TestNavigationThrottle* proceed_throttle = 370 TestNavigationThrottle* proceed_throttle =
293 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); 371 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
294 EXPECT_FALSE(IsDeferringStart()); 372 EXPECT_FALSE(IsDeferringStart());
295 EXPECT_FALSE(IsDeferringRedirect()); 373 EXPECT_FALSE(IsDeferringRedirect());
296 EXPECT_EQ(0, defer_throttle->will_start_calls()); 374 EXPECT_EQ(0, defer_throttle->will_start_calls());
297 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 375 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
376 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
298 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 377 EXPECT_EQ(0, proceed_throttle->will_start_calls());
299 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 378 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
379 EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
300 380
301 // Simulate WillStartRequest. The request should be deferred. The callback 381 // Simulate WillStartRequest. The request should be deferred. The callback
302 // should not have been called. The second throttle should not have been 382 // should not have been called. The second throttle should not have been
303 // notified. 383 // notified.
304 SimulateWillStartRequest(); 384 SimulateWillStartRequest();
305 EXPECT_TRUE(IsDeferringStart()); 385 EXPECT_TRUE(IsDeferringStart());
306 EXPECT_FALSE(IsDeferringRedirect()); 386 EXPECT_FALSE(IsDeferringRedirect());
307 EXPECT_FALSE(was_callback_called()); 387 EXPECT_FALSE(was_callback_called());
308 EXPECT_EQ(1, defer_throttle->will_start_calls()); 388 EXPECT_EQ(1, defer_throttle->will_start_calls());
309 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 389 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
390 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
310 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 391 EXPECT_EQ(0, proceed_throttle->will_start_calls());
311 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 392 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
312 393
313 // Resume the request. It should no longer be deferred and the callback 394 // Resume the request. It should no longer be deferred and the callback
314 // should have been called. The second throttle should have been notified. 395 // should have been called. The second throttle should have been notified.
315 test_handle()->Resume(); 396 test_handle()->Resume();
316 EXPECT_FALSE(IsDeferringStart()); 397 EXPECT_FALSE(IsDeferringStart());
317 EXPECT_FALSE(IsDeferringRedirect()); 398 EXPECT_FALSE(IsDeferringRedirect());
318 EXPECT_TRUE(was_callback_called()); 399 EXPECT_TRUE(was_callback_called());
319 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); 400 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
320 EXPECT_EQ(1, defer_throttle->will_start_calls()); 401 EXPECT_EQ(1, defer_throttle->will_start_calls());
321 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 402 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
403 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
322 EXPECT_EQ(1, proceed_throttle->will_start_calls()); 404 EXPECT_EQ(1, proceed_throttle->will_start_calls());
323 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 405 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
324 406
325 // Simulate WillRedirectRequest. The request should be deferred. The callback 407 // Simulate WillRedirectRequest. The request should be deferred. The callback
326 // should not have been called. The second throttle should not have been 408 // should not have been called. The second throttle should not have been
327 // notified. 409 // notified.
328 SimulateWillRedirectRequest(); 410 SimulateWillRedirectRequest();
329 EXPECT_FALSE(IsDeferringStart()); 411 EXPECT_FALSE(IsDeferringStart());
330 EXPECT_TRUE(IsDeferringRedirect()); 412 EXPECT_TRUE(IsDeferringRedirect());
331 EXPECT_FALSE(was_callback_called()); 413 EXPECT_FALSE(was_callback_called());
332 EXPECT_EQ(1, defer_throttle->will_start_calls()); 414 EXPECT_EQ(1, defer_throttle->will_start_calls());
333 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); 415 EXPECT_EQ(1, defer_throttle->will_redirect_calls());
416 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
334 EXPECT_EQ(1, proceed_throttle->will_start_calls()); 417 EXPECT_EQ(1, proceed_throttle->will_start_calls());
335 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 418 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
336 419
337 // Resume the request. It should no longer be deferred and the callback 420 // Resume the request. It should no longer be deferred and the callback
338 // should have been called. The second throttle should have been notified. 421 // should have been called. The second throttle should have been notified.
339 test_handle()->Resume(); 422 test_handle()->Resume();
340 EXPECT_FALSE(IsDeferringStart()); 423 EXPECT_FALSE(IsDeferringStart());
341 EXPECT_FALSE(IsDeferringRedirect()); 424 EXPECT_FALSE(IsDeferringRedirect());
342 EXPECT_TRUE(was_callback_called()); 425 EXPECT_TRUE(was_callback_called());
343 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); 426 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result());
344 EXPECT_EQ(1, defer_throttle->will_start_calls()); 427 EXPECT_EQ(1, defer_throttle->will_start_calls());
345 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); 428 EXPECT_EQ(1, defer_throttle->will_redirect_calls());
429 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
346 EXPECT_EQ(1, proceed_throttle->will_start_calls()); 430 EXPECT_EQ(1, proceed_throttle->will_start_calls());
347 EXPECT_EQ(1, proceed_throttle->will_redirect_calls()); 431 EXPECT_EQ(1, proceed_throttle->will_redirect_calls());
348 } 432 }
349 433
350 // Checks that a NavigationThrottle asking to defer followed by a 434 // Checks that a NavigationThrottle asking to defer followed by a
351 // NavigationThrottle asking to cancel behave correctly in WillStartRequest. 435 // NavigationThrottle asking to cancel behave correctly in WillStartRequest.
352 TEST_F(NavigationHandleImplTest, DeferThenCancelWillStartRequest) { 436 TEST_F(NavigationHandleImplTest, DeferThenCancelWillStartRequest) {
353 TestNavigationThrottle* defer_throttle = 437 TestNavigationThrottle* defer_throttle =
354 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 438 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
355 TestNavigationThrottle* cancel_throttle = 439 TestNavigationThrottle* cancel_throttle =
356 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); 440 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
357 EXPECT_FALSE(IsDeferringStart()); 441 EXPECT_FALSE(IsDeferringStart());
358 EXPECT_FALSE(IsDeferringRedirect()); 442 EXPECT_FALSE(IsDeferringRedirect());
359 EXPECT_EQ(0, defer_throttle->will_start_calls()); 443 EXPECT_EQ(0, defer_throttle->will_start_calls());
360 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 444 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
445 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
361 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 446 EXPECT_EQ(0, cancel_throttle->will_start_calls());
362 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 447 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
363 448
364 // Simulate WillStartRequest. The request should be deferred. The callback 449 // Simulate WillStartRequest. The request should be deferred. The callback
365 // should not have been called. The second throttle should not have been 450 // should not have been called. The second throttle should not have been
366 // notified. 451 // notified.
367 SimulateWillStartRequest(); 452 SimulateWillStartRequest();
368 EXPECT_TRUE(IsDeferringStart()); 453 EXPECT_TRUE(IsDeferringStart());
369 EXPECT_FALSE(IsDeferringRedirect()); 454 EXPECT_FALSE(IsDeferringRedirect());
370 EXPECT_FALSE(was_callback_called()); 455 EXPECT_FALSE(was_callback_called());
371 EXPECT_EQ(1, defer_throttle->will_start_calls()); 456 EXPECT_EQ(1, defer_throttle->will_start_calls());
372 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 457 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
458 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
373 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 459 EXPECT_EQ(0, cancel_throttle->will_start_calls());
374 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 460 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
375 461
376 // Resume the request. The callback should have been called. The second 462 // Resume the request. The callback should have been called. The second
377 // throttle should have been notified. 463 // throttle should have been notified.
378 test_handle()->Resume(); 464 test_handle()->Resume();
379 EXPECT_FALSE(IsDeferringStart()); 465 EXPECT_FALSE(IsDeferringStart());
380 EXPECT_FALSE(IsDeferringRedirect()); 466 EXPECT_FALSE(IsDeferringRedirect());
381 EXPECT_TRUE(IsCanceling()); 467 EXPECT_TRUE(IsCanceling());
382 EXPECT_TRUE(was_callback_called()); 468 EXPECT_TRUE(was_callback_called());
383 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 469 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
384 EXPECT_EQ(1, defer_throttle->will_start_calls()); 470 EXPECT_EQ(1, defer_throttle->will_start_calls());
385 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 471 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
472 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
386 EXPECT_EQ(1, cancel_throttle->will_start_calls()); 473 EXPECT_EQ(1, cancel_throttle->will_start_calls());
387 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 474 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
388 } 475 }
389 476
390 // Checks that a NavigationThrottle asking to defer followed by a 477 // Checks that a NavigationThrottle asking to defer followed by a
391 // NavigationThrottle asking to cancel behave correctly in WillRedirectRequest. 478 // NavigationThrottle asking to cancel behave correctly in WillRedirectRequest.
392 TEST_F(NavigationHandleImplTest, DeferThenCancelWillRedirectRequest) { 479 TEST_F(NavigationHandleImplTest, DeferThenCancelWillRedirectRequest) {
393 TestNavigationThrottle* defer_throttle = 480 TestNavigationThrottle* defer_throttle =
394 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 481 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
395 TestNavigationThrottle* cancel_throttle = 482 TestNavigationThrottle* cancel_throttle =
396 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); 483 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
397 EXPECT_FALSE(IsDeferringStart()); 484 EXPECT_FALSE(IsDeferringStart());
398 EXPECT_FALSE(IsDeferringRedirect()); 485 EXPECT_FALSE(IsDeferringRedirect());
399 EXPECT_EQ(0, defer_throttle->will_start_calls()); 486 EXPECT_EQ(0, defer_throttle->will_start_calls());
400 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); 487 EXPECT_EQ(0, defer_throttle->will_redirect_calls());
488 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
401 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 489 EXPECT_EQ(0, cancel_throttle->will_start_calls());
402 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 490 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
403 491
404 // Simulate WillRedirectRequest. The request should be deferred. The callback 492 // Simulate WillRedirectRequest. The request should be deferred. The callback
405 // should not have been called. The second throttle should not have been 493 // should not have been called. The second throttle should not have been
406 // notified. 494 // notified.
407 SimulateWillRedirectRequest(); 495 SimulateWillRedirectRequest();
408 EXPECT_FALSE(IsDeferringStart()); 496 EXPECT_FALSE(IsDeferringStart());
409 EXPECT_TRUE(IsDeferringRedirect()); 497 EXPECT_TRUE(IsDeferringRedirect());
410 EXPECT_FALSE(was_callback_called()); 498 EXPECT_FALSE(was_callback_called());
411 EXPECT_EQ(0, defer_throttle->will_start_calls()); 499 EXPECT_EQ(0, defer_throttle->will_start_calls());
412 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); 500 EXPECT_EQ(1, defer_throttle->will_redirect_calls());
501 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
413 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 502 EXPECT_EQ(0, cancel_throttle->will_start_calls());
414 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 503 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
415 504
416 // Resume the request. The callback should have been called. The second 505 // Resume the request. The callback should have been called. The second
417 // throttle should have been notified. 506 // throttle should have been notified.
418 test_handle()->Resume(); 507 test_handle()->Resume();
419 EXPECT_FALSE(IsDeferringStart()); 508 EXPECT_FALSE(IsDeferringStart());
420 EXPECT_FALSE(IsDeferringRedirect()); 509 EXPECT_FALSE(IsDeferringRedirect());
421 EXPECT_TRUE(IsCanceling()); 510 EXPECT_TRUE(IsCanceling());
422 EXPECT_TRUE(was_callback_called()); 511 EXPECT_TRUE(was_callback_called());
423 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 512 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
424 EXPECT_EQ(0, defer_throttle->will_start_calls()); 513 EXPECT_EQ(0, defer_throttle->will_start_calls());
425 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); 514 EXPECT_EQ(1, defer_throttle->will_redirect_calls());
515 EXPECT_EQ(0, defer_throttle->will_process_response_calls());
426 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 516 EXPECT_EQ(0, cancel_throttle->will_start_calls());
427 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); 517 EXPECT_EQ(1, cancel_throttle->will_redirect_calls());
428 } 518 }
429 519
430 // Checks that a NavigationThrottle asking to cancel followed by a 520 // Checks that a NavigationThrottle asking to cancel followed by a
431 // NavigationThrottle asking to proceed behave correctly in WillStartRequest. 521 // NavigationThrottle asking to proceed behave correctly in WillStartRequest.
432 // The navigation will be canceled directly, and the second throttle will not 522 // The navigation will be canceled directly, and the second throttle will not
433 // be called. 523 // be called.
434 TEST_F(NavigationHandleImplTest, CancelThenProceedWillStartRequest) { 524 TEST_F(NavigationHandleImplTest, CancelThenProceedWillStartRequest) {
435 TestNavigationThrottle* cancel_throttle = 525 TestNavigationThrottle* cancel_throttle =
436 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); 526 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
437 TestNavigationThrottle* proceed_throttle = 527 TestNavigationThrottle* proceed_throttle =
438 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); 528 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
439 EXPECT_FALSE(IsDeferringStart()); 529 EXPECT_FALSE(IsDeferringStart());
440 EXPECT_FALSE(IsDeferringRedirect()); 530 EXPECT_FALSE(IsDeferringRedirect());
441 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 531 EXPECT_EQ(0, cancel_throttle->will_start_calls());
442 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 532 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
533 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
443 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 534 EXPECT_EQ(0, proceed_throttle->will_start_calls());
444 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 535 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
445 536
446 // Simulate WillStartRequest. The request should not be deferred. The 537 // Simulate WillStartRequest. The request should not be deferred. The
447 // callback should not have been called. The second throttle should not have 538 // callback should not have been called. The second throttle should not have
448 // been notified. 539 // been notified.
449 SimulateWillStartRequest(); 540 SimulateWillStartRequest();
450 EXPECT_FALSE(IsDeferringStart()); 541 EXPECT_FALSE(IsDeferringStart());
451 EXPECT_FALSE(IsDeferringRedirect()); 542 EXPECT_FALSE(IsDeferringRedirect());
452 EXPECT_TRUE(was_callback_called()); 543 EXPECT_TRUE(was_callback_called());
453 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 544 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
454 EXPECT_EQ(1, cancel_throttle->will_start_calls()); 545 EXPECT_EQ(1, cancel_throttle->will_start_calls());
455 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 546 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
547 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
456 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 548 EXPECT_EQ(0, proceed_throttle->will_start_calls());
457 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 549 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
458 } 550 }
459 551
460 // Checks that a NavigationThrottle asking to cancel followed by a 552 // Checks that a NavigationThrottle asking to cancel followed by a
461 // NavigationThrottle asking to proceed behave correctly in WillRedirectRequest. 553 // NavigationThrottle asking to proceed behave correctly in WillRedirectRequest.
462 // The navigation will be canceled directly, and the second throttle will not 554 // The navigation will be canceled directly, and the second throttle will not
463 // be called. 555 // be called.
464 TEST_F(NavigationHandleImplTest, CancelThenProceedWillRedirectRequest) { 556 TEST_F(NavigationHandleImplTest, CancelThenProceedWillRedirectRequest) {
465 TestNavigationThrottle* cancel_throttle = 557 TestNavigationThrottle* cancel_throttle =
466 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); 558 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
467 TestNavigationThrottle* proceed_throttle = 559 TestNavigationThrottle* proceed_throttle =
468 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); 560 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
469 EXPECT_FALSE(IsDeferringStart()); 561 EXPECT_FALSE(IsDeferringStart());
470 EXPECT_FALSE(IsDeferringRedirect()); 562 EXPECT_FALSE(IsDeferringRedirect());
471 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 563 EXPECT_EQ(0, cancel_throttle->will_start_calls());
472 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 564 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
565 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
473 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 566 EXPECT_EQ(0, proceed_throttle->will_start_calls());
474 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 567 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
475 568
476 // Simulate WillRedirectRequest. The request should not be deferred. The 569 // Simulate WillRedirectRequest. The request should not be deferred. The
477 // callback should not have been called. The second throttle should not have 570 // callback should not have been called. The second throttle should not have
478 // been notified. 571 // been notified.
479 SimulateWillRedirectRequest(); 572 SimulateWillRedirectRequest();
480 EXPECT_FALSE(IsDeferringStart()); 573 EXPECT_FALSE(IsDeferringStart());
481 EXPECT_FALSE(IsDeferringRedirect()); 574 EXPECT_FALSE(IsDeferringRedirect());
482 EXPECT_TRUE(was_callback_called()); 575 EXPECT_TRUE(was_callback_called());
483 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 576 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
484 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 577 EXPECT_EQ(0, cancel_throttle->will_start_calls());
485 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); 578 EXPECT_EQ(1, cancel_throttle->will_redirect_calls());
579 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
486 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 580 EXPECT_EQ(0, proceed_throttle->will_start_calls());
487 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 581 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
488 } 582 }
489 583
584 // Checks that a NavigationThrottle asking to proceed followed by a
585 // NavigationThrottle asking to cancel behave correctly in WillProcessResponse.
586 // Both throttles will be called, and the request will be cancelled.
587 TEST_F(NavigationHandleImplTest, ProceedThenCancelWillProcessResponse) {
588 TestNavigationThrottle* proceed_throttle =
589 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
590 TestNavigationThrottle* cancel_throttle =
591 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
592 EXPECT_FALSE(IsDeferringStart());
593 EXPECT_FALSE(IsDeferringRedirect());
594 EXPECT_EQ(0, cancel_throttle->will_start_calls());
595 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
596 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
597 EXPECT_EQ(0, proceed_throttle->will_start_calls());
598 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
599 EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
600
601 // Simulate WillRedirectRequest. The request should not be deferred. The
602 // callback should have been called.
603 SimulateWillProcessResponse();
604 EXPECT_FALSE(IsDeferringStart());
605 EXPECT_FALSE(IsDeferringRedirect());
606 EXPECT_TRUE(was_callback_called());
607 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
608 EXPECT_EQ(0, cancel_throttle->will_start_calls());
609 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
610 EXPECT_EQ(1, 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 EXPECT_EQ(1, proceed_throttle->will_process_response_calls());
614 }
615
616 // Checks that a NavigationThrottle asking to cancel followed by a
617 // NavigationThrottle asking to proceed behave correctly in WillProcessResponse.
618 // The navigation will be canceled directly, and the second throttle will not
619 // be called.
620 TEST_F(NavigationHandleImplTest, CancelThenProceedWillProcessResponse) {
621 TestNavigationThrottle* cancel_throttle =
622 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE);
623 TestNavigationThrottle* proceed_throttle =
624 CreateTestNavigationThrottle(NavigationThrottle::PROCEED);
625 EXPECT_FALSE(IsDeferringStart());
626 EXPECT_FALSE(IsDeferringRedirect());
627 EXPECT_EQ(0, cancel_throttle->will_start_calls());
628 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
629 EXPECT_EQ(0, cancel_throttle->will_process_response_calls());
630 EXPECT_EQ(0, proceed_throttle->will_start_calls());
631 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
632
633 // Simulate WillRedirectRequest. The request should not be deferred. The
634 // callback should have been called. The second throttle should not have
635 // been notified.
636 SimulateWillProcessResponse();
637 EXPECT_FALSE(IsDeferringStart());
638 EXPECT_FALSE(IsDeferringRedirect());
639 EXPECT_TRUE(was_callback_called());
640 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
641 EXPECT_EQ(0, cancel_throttle->will_start_calls());
642 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
643 EXPECT_EQ(1, cancel_throttle->will_process_response_calls());
644 EXPECT_EQ(0, proceed_throttle->will_start_calls());
645 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
646 EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
647 }
648
490 } // namespace content 649 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698