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