| 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(), |
| 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()); |
| 259 EXPECT_TRUE(test_handle()->GetRenderFrameHost()); |
| 193 } | 260 } |
| 194 | 261 |
| 195 // Checks that a navigation deferred during WillStartRequest can be properly | 262 // Checks that a navigation deferred during WillStartRequest can be properly |
| 196 // cancelled. | 263 // cancelled. |
| 197 TEST_F(NavigationHandleImplTest, CancelDeferredWillStart) { | 264 TEST_F(NavigationHandleImplTest, CancelDeferredWillStart) { |
| 198 TestNavigationThrottle* test_throttle = | 265 TestNavigationThrottle* test_throttle = |
| 199 CreateTestNavigationThrottle(NavigationThrottle::DEFER); | 266 CreateTestNavigationThrottle(NavigationThrottle::DEFER); |
| 200 EXPECT_FALSE(IsDeferringStart()); | 267 EXPECT_FALSE(IsDeferringStart()); |
| 201 EXPECT_FALSE(IsDeferringRedirect()); | 268 EXPECT_FALSE(IsDeferringRedirect()); |
| 202 EXPECT_EQ(0, test_throttle->will_start_calls()); | 269 EXPECT_EQ(0, test_throttle->will_start_calls()); |
| 203 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 270 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
| 271 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 204 | 272 |
| 205 // Simulate WillStartRequest. The request should be deferred. The callback | 273 // Simulate WillStartRequest. The request should be deferred. The callback |
| 206 // should not have been called. | 274 // should not have been called. |
| 207 SimulateWillStartRequest(); | 275 SimulateWillStartRequest(); |
| 208 EXPECT_TRUE(IsDeferringStart()); | 276 EXPECT_TRUE(IsDeferringStart()); |
| 209 EXPECT_FALSE(IsDeferringRedirect()); | 277 EXPECT_FALSE(IsDeferringRedirect()); |
| 210 EXPECT_FALSE(was_callback_called()); | 278 EXPECT_FALSE(was_callback_called()); |
| 211 EXPECT_EQ(1, test_throttle->will_start_calls()); | 279 EXPECT_EQ(1, test_throttle->will_start_calls()); |
| 212 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 280 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
| 281 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 213 | 282 |
| 214 // Cancel the request. The callback should have been called. | 283 // Cancel the request. The callback should have been called. |
| 215 test_handle()->CancelDeferredNavigation( | 284 test_handle()->CancelDeferredNavigation( |
| 216 NavigationThrottle::CANCEL_AND_IGNORE); | 285 NavigationThrottle::CANCEL_AND_IGNORE); |
| 217 EXPECT_FALSE(IsDeferringStart()); | 286 EXPECT_FALSE(IsDeferringStart()); |
| 218 EXPECT_FALSE(IsDeferringRedirect()); | 287 EXPECT_FALSE(IsDeferringRedirect()); |
| 219 EXPECT_TRUE(IsCanceling()); | 288 EXPECT_TRUE(IsCanceling()); |
| 220 EXPECT_TRUE(was_callback_called()); | 289 EXPECT_TRUE(was_callback_called()); |
| 221 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 290 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 222 EXPECT_EQ(1, test_throttle->will_start_calls()); | 291 EXPECT_EQ(1, test_throttle->will_start_calls()); |
| 223 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 292 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
| 293 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 224 } | 294 } |
| 225 | 295 |
| 226 // Checks that a navigation deferred during WillRedirectRequest can be properly | 296 // Checks that a navigation deferred during WillRedirectRequest can be properly |
| 227 // cancelled. | 297 // cancelled. |
| 228 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { | 298 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { |
| 229 TestNavigationThrottle* test_throttle = | 299 TestNavigationThrottle* test_throttle = |
| 230 CreateTestNavigationThrottle(NavigationThrottle::DEFER); | 300 CreateTestNavigationThrottle(NavigationThrottle::DEFER); |
| 231 EXPECT_FALSE(IsDeferringStart()); | 301 EXPECT_FALSE(IsDeferringStart()); |
| 232 EXPECT_FALSE(IsDeferringRedirect()); | 302 EXPECT_FALSE(IsDeferringRedirect()); |
| 233 EXPECT_EQ(0, test_throttle->will_start_calls()); | 303 EXPECT_EQ(0, test_throttle->will_start_calls()); |
| 234 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 304 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
| 305 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 235 | 306 |
| 236 // Simulate WillRedirectRequest. The request should be deferred. The callback | 307 // Simulate WillRedirectRequest. The request should be deferred. The callback |
| 237 // should not have been called. | 308 // should not have been called. |
| 238 SimulateWillRedirectRequest(); | 309 SimulateWillRedirectRequest(); |
| 239 EXPECT_FALSE(IsDeferringStart()); | 310 EXPECT_FALSE(IsDeferringStart()); |
| 240 EXPECT_TRUE(IsDeferringRedirect()); | 311 EXPECT_TRUE(IsDeferringRedirect()); |
| 241 EXPECT_FALSE(was_callback_called()); | 312 EXPECT_FALSE(was_callback_called()); |
| 242 EXPECT_EQ(0, test_throttle->will_start_calls()); | 313 EXPECT_EQ(0, test_throttle->will_start_calls()); |
| 243 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 314 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
| 315 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 244 | 316 |
| 245 // Cancel the request. The callback should have been called. | 317 // Cancel the request. The callback should have been called. |
| 246 test_handle()->CancelDeferredNavigation( | 318 test_handle()->CancelDeferredNavigation( |
| 247 NavigationThrottle::CANCEL_AND_IGNORE); | 319 NavigationThrottle::CANCEL_AND_IGNORE); |
| 248 EXPECT_FALSE(IsDeferringStart()); | 320 EXPECT_FALSE(IsDeferringStart()); |
| 249 EXPECT_FALSE(IsDeferringRedirect()); | 321 EXPECT_FALSE(IsDeferringRedirect()); |
| 250 EXPECT_TRUE(IsCanceling()); | 322 EXPECT_TRUE(IsCanceling()); |
| 251 EXPECT_TRUE(was_callback_called()); | 323 EXPECT_TRUE(was_callback_called()); |
| 252 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 324 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 253 EXPECT_EQ(0, test_throttle->will_start_calls()); | 325 EXPECT_EQ(0, test_throttle->will_start_calls()); |
| 254 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 326 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
| 327 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 255 } | 328 } |
| 256 | 329 |
| 257 // Checks that a navigation deferred can be canceled and not ignored. | 330 // Checks that a navigation deferred can be canceled and not ignored. |
| 258 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { | 331 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { |
| 259 TestNavigationThrottle* test_throttle = | 332 TestNavigationThrottle* test_throttle = |
| 260 CreateTestNavigationThrottle(NavigationThrottle::DEFER); | 333 CreateTestNavigationThrottle(NavigationThrottle::DEFER); |
| 261 EXPECT_FALSE(IsDeferringStart()); | 334 EXPECT_FALSE(IsDeferringStart()); |
| 262 EXPECT_FALSE(IsDeferringRedirect()); | 335 EXPECT_FALSE(IsDeferringRedirect()); |
| 263 EXPECT_EQ(0, test_throttle->will_start_calls()); | 336 EXPECT_EQ(0, test_throttle->will_start_calls()); |
| 264 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 337 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
| 338 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 265 | 339 |
| 266 // Simulate WillRedirectRequest. The request should be deferred. The callback | 340 // Simulate WillRedirectRequest. The request should be deferred. The callback |
| 267 // should not have been called. | 341 // should not have been called. |
| 268 SimulateWillStartRequest(); | 342 SimulateWillStartRequest(); |
| 269 EXPECT_TRUE(IsDeferringStart()); | 343 EXPECT_TRUE(IsDeferringStart()); |
| 270 EXPECT_FALSE(IsDeferringRedirect()); | 344 EXPECT_FALSE(IsDeferringRedirect()); |
| 271 EXPECT_FALSE(was_callback_called()); | 345 EXPECT_FALSE(was_callback_called()); |
| 272 EXPECT_EQ(1, test_throttle->will_start_calls()); | 346 EXPECT_EQ(1, test_throttle->will_start_calls()); |
| 273 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 347 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
| 348 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 274 | 349 |
| 275 // Cancel the request. The callback should have been called with CANCEL, and | 350 // Cancel the request. The callback should have been called with CANCEL, and |
| 276 // not CANCEL_AND_IGNORE. | 351 // not CANCEL_AND_IGNORE. |
| 277 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); | 352 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); |
| 278 EXPECT_FALSE(IsDeferringStart()); | 353 EXPECT_FALSE(IsDeferringStart()); |
| 279 EXPECT_FALSE(IsDeferringRedirect()); | 354 EXPECT_FALSE(IsDeferringRedirect()); |
| 280 EXPECT_TRUE(IsCanceling()); | 355 EXPECT_TRUE(IsCanceling()); |
| 281 EXPECT_TRUE(was_callback_called()); | 356 EXPECT_TRUE(was_callback_called()); |
| 282 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); | 357 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); |
| 283 EXPECT_EQ(1, test_throttle->will_start_calls()); | 358 EXPECT_EQ(1, test_throttle->will_start_calls()); |
| 284 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 359 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
| 360 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
| 285 } | 361 } |
| 286 | 362 |
| 287 // Checks that a NavigationThrottle asking to defer followed by a | 363 // Checks that a NavigationThrottle asking to defer followed by a |
| 288 // NavigationThrottle asking to proceed behave correctly. | 364 // NavigationThrottle asking to proceed behave correctly. |
| 289 TEST_F(NavigationHandleImplTest, DeferThenProceed) { | 365 TEST_F(NavigationHandleImplTest, DeferThenProceed) { |
| 290 TestNavigationThrottle* defer_throttle = | 366 TestNavigationThrottle* defer_throttle = |
| 291 CreateTestNavigationThrottle(NavigationThrottle::DEFER); | 367 CreateTestNavigationThrottle(NavigationThrottle::DEFER); |
| 292 TestNavigationThrottle* proceed_throttle = | 368 TestNavigationThrottle* proceed_throttle = |
| 293 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); | 369 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); |
| 294 EXPECT_FALSE(IsDeferringStart()); | 370 EXPECT_FALSE(IsDeferringStart()); |
| 295 EXPECT_FALSE(IsDeferringRedirect()); | 371 EXPECT_FALSE(IsDeferringRedirect()); |
| 296 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 372 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
| 297 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 373 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
| 374 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 298 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 375 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 299 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 376 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 377 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
| 300 | 378 |
| 301 // Simulate WillStartRequest. The request should be deferred. The callback | 379 // Simulate WillStartRequest. The request should be deferred. The callback |
| 302 // should not have been called. The second throttle should not have been | 380 // should not have been called. The second throttle should not have been |
| 303 // notified. | 381 // notified. |
| 304 SimulateWillStartRequest(); | 382 SimulateWillStartRequest(); |
| 305 EXPECT_TRUE(IsDeferringStart()); | 383 EXPECT_TRUE(IsDeferringStart()); |
| 306 EXPECT_FALSE(IsDeferringRedirect()); | 384 EXPECT_FALSE(IsDeferringRedirect()); |
| 307 EXPECT_FALSE(was_callback_called()); | 385 EXPECT_FALSE(was_callback_called()); |
| 308 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 386 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
| 309 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 387 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
| 388 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 310 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 389 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 311 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 390 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 312 | 391 |
| 313 // Resume the request. It should no longer be deferred and the callback | 392 // Resume the request. It should no longer be deferred and the callback |
| 314 // should have been called. The second throttle should have been notified. | 393 // should have been called. The second throttle should have been notified. |
| 315 test_handle()->Resume(); | 394 test_handle()->Resume(); |
| 316 EXPECT_FALSE(IsDeferringStart()); | 395 EXPECT_FALSE(IsDeferringStart()); |
| 317 EXPECT_FALSE(IsDeferringRedirect()); | 396 EXPECT_FALSE(IsDeferringRedirect()); |
| 318 EXPECT_TRUE(was_callback_called()); | 397 EXPECT_TRUE(was_callback_called()); |
| 319 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); | 398 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); |
| 320 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 399 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
| 321 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 400 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
| 401 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 322 EXPECT_EQ(1, proceed_throttle->will_start_calls()); | 402 EXPECT_EQ(1, proceed_throttle->will_start_calls()); |
| 323 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 403 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 324 | 404 |
| 325 // Simulate WillRedirectRequest. The request should be deferred. The callback | 405 // Simulate WillRedirectRequest. The request should be deferred. The callback |
| 326 // should not have been called. The second throttle should not have been | 406 // should not have been called. The second throttle should not have been |
| 327 // notified. | 407 // notified. |
| 328 SimulateWillRedirectRequest(); | 408 SimulateWillRedirectRequest(); |
| 329 EXPECT_FALSE(IsDeferringStart()); | 409 EXPECT_FALSE(IsDeferringStart()); |
| 330 EXPECT_TRUE(IsDeferringRedirect()); | 410 EXPECT_TRUE(IsDeferringRedirect()); |
| 331 EXPECT_FALSE(was_callback_called()); | 411 EXPECT_FALSE(was_callback_called()); |
| 332 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 412 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
| 333 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 413 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
| 414 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 334 EXPECT_EQ(1, proceed_throttle->will_start_calls()); | 415 EXPECT_EQ(1, proceed_throttle->will_start_calls()); |
| 335 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 416 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 336 | 417 |
| 337 // Resume the request. It should no longer be deferred and the callback | 418 // Resume the request. It should no longer be deferred and the callback |
| 338 // should have been called. The second throttle should have been notified. | 419 // should have been called. The second throttle should have been notified. |
| 339 test_handle()->Resume(); | 420 test_handle()->Resume(); |
| 340 EXPECT_FALSE(IsDeferringStart()); | 421 EXPECT_FALSE(IsDeferringStart()); |
| 341 EXPECT_FALSE(IsDeferringRedirect()); | 422 EXPECT_FALSE(IsDeferringRedirect()); |
| 342 EXPECT_TRUE(was_callback_called()); | 423 EXPECT_TRUE(was_callback_called()); |
| 343 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); | 424 EXPECT_EQ(NavigationThrottle::PROCEED, callback_result()); |
| 344 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 425 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
| 345 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 426 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
| 427 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 346 EXPECT_EQ(1, proceed_throttle->will_start_calls()); | 428 EXPECT_EQ(1, proceed_throttle->will_start_calls()); |
| 347 EXPECT_EQ(1, proceed_throttle->will_redirect_calls()); | 429 EXPECT_EQ(1, proceed_throttle->will_redirect_calls()); |
| 348 } | 430 } |
| 349 | 431 |
| 350 // Checks that a NavigationThrottle asking to defer followed by a | 432 // Checks that a NavigationThrottle asking to defer followed by a |
| 351 // NavigationThrottle asking to cancel behave correctly in WillStartRequest. | 433 // NavigationThrottle asking to cancel behave correctly in WillStartRequest. |
| 352 TEST_F(NavigationHandleImplTest, DeferThenCancelWillStartRequest) { | 434 TEST_F(NavigationHandleImplTest, DeferThenCancelWillStartRequest) { |
| 353 TestNavigationThrottle* defer_throttle = | 435 TestNavigationThrottle* defer_throttle = |
| 354 CreateTestNavigationThrottle(NavigationThrottle::DEFER); | 436 CreateTestNavigationThrottle(NavigationThrottle::DEFER); |
| 355 TestNavigationThrottle* cancel_throttle = | 437 TestNavigationThrottle* cancel_throttle = |
| 356 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); | 438 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); |
| 357 EXPECT_FALSE(IsDeferringStart()); | 439 EXPECT_FALSE(IsDeferringStart()); |
| 358 EXPECT_FALSE(IsDeferringRedirect()); | 440 EXPECT_FALSE(IsDeferringRedirect()); |
| 359 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 441 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
| 360 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 442 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
| 443 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 361 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 444 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 362 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 445 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 363 | 446 |
| 364 // Simulate WillStartRequest. The request should be deferred. The callback | 447 // Simulate WillStartRequest. The request should be deferred. The callback |
| 365 // should not have been called. The second throttle should not have been | 448 // should not have been called. The second throttle should not have been |
| 366 // notified. | 449 // notified. |
| 367 SimulateWillStartRequest(); | 450 SimulateWillStartRequest(); |
| 368 EXPECT_TRUE(IsDeferringStart()); | 451 EXPECT_TRUE(IsDeferringStart()); |
| 369 EXPECT_FALSE(IsDeferringRedirect()); | 452 EXPECT_FALSE(IsDeferringRedirect()); |
| 370 EXPECT_FALSE(was_callback_called()); | 453 EXPECT_FALSE(was_callback_called()); |
| 371 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 454 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
| 372 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 455 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
| 456 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 373 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 457 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 374 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 458 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 375 | 459 |
| 376 // Resume the request. The callback should have been called. The second | 460 // Resume the request. The callback should have been called. The second |
| 377 // throttle should have been notified. | 461 // throttle should have been notified. |
| 378 test_handle()->Resume(); | 462 test_handle()->Resume(); |
| 379 EXPECT_FALSE(IsDeferringStart()); | 463 EXPECT_FALSE(IsDeferringStart()); |
| 380 EXPECT_FALSE(IsDeferringRedirect()); | 464 EXPECT_FALSE(IsDeferringRedirect()); |
| 381 EXPECT_TRUE(IsCanceling()); | 465 EXPECT_TRUE(IsCanceling()); |
| 382 EXPECT_TRUE(was_callback_called()); | 466 EXPECT_TRUE(was_callback_called()); |
| 383 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 467 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 384 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 468 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
| 385 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 469 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
| 470 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 386 EXPECT_EQ(1, cancel_throttle->will_start_calls()); | 471 EXPECT_EQ(1, cancel_throttle->will_start_calls()); |
| 387 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 472 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 388 } | 473 } |
| 389 | 474 |
| 390 // Checks that a NavigationThrottle asking to defer followed by a | 475 // Checks that a NavigationThrottle asking to defer followed by a |
| 391 // NavigationThrottle asking to cancel behave correctly in WillRedirectRequest. | 476 // NavigationThrottle asking to cancel behave correctly in WillRedirectRequest. |
| 392 TEST_F(NavigationHandleImplTest, DeferThenCancelWillRedirectRequest) { | 477 TEST_F(NavigationHandleImplTest, DeferThenCancelWillRedirectRequest) { |
| 393 TestNavigationThrottle* defer_throttle = | 478 TestNavigationThrottle* defer_throttle = |
| 394 CreateTestNavigationThrottle(NavigationThrottle::DEFER); | 479 CreateTestNavigationThrottle(NavigationThrottle::DEFER); |
| 395 TestNavigationThrottle* cancel_throttle = | 480 TestNavigationThrottle* cancel_throttle = |
| 396 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); | 481 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); |
| 397 EXPECT_FALSE(IsDeferringStart()); | 482 EXPECT_FALSE(IsDeferringStart()); |
| 398 EXPECT_FALSE(IsDeferringRedirect()); | 483 EXPECT_FALSE(IsDeferringRedirect()); |
| 399 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 484 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
| 400 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 485 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
| 486 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 401 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 487 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 402 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 488 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 403 | 489 |
| 404 // Simulate WillRedirectRequest. The request should be deferred. The callback | 490 // Simulate WillRedirectRequest. The request should be deferred. The callback |
| 405 // should not have been called. The second throttle should not have been | 491 // should not have been called. The second throttle should not have been |
| 406 // notified. | 492 // notified. |
| 407 SimulateWillRedirectRequest(); | 493 SimulateWillRedirectRequest(); |
| 408 EXPECT_FALSE(IsDeferringStart()); | 494 EXPECT_FALSE(IsDeferringStart()); |
| 409 EXPECT_TRUE(IsDeferringRedirect()); | 495 EXPECT_TRUE(IsDeferringRedirect()); |
| 410 EXPECT_FALSE(was_callback_called()); | 496 EXPECT_FALSE(was_callback_called()); |
| 411 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 497 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
| 412 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 498 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
| 499 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 413 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 500 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 414 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 501 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 415 | 502 |
| 416 // Resume the request. The callback should have been called. The second | 503 // Resume the request. The callback should have been called. The second |
| 417 // throttle should have been notified. | 504 // throttle should have been notified. |
| 418 test_handle()->Resume(); | 505 test_handle()->Resume(); |
| 419 EXPECT_FALSE(IsDeferringStart()); | 506 EXPECT_FALSE(IsDeferringStart()); |
| 420 EXPECT_FALSE(IsDeferringRedirect()); | 507 EXPECT_FALSE(IsDeferringRedirect()); |
| 421 EXPECT_TRUE(IsCanceling()); | 508 EXPECT_TRUE(IsCanceling()); |
| 422 EXPECT_TRUE(was_callback_called()); | 509 EXPECT_TRUE(was_callback_called()); |
| 423 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 510 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 424 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 511 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
| 425 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 512 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
| 513 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
| 426 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 514 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 427 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); | 515 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); |
| 428 } | 516 } |
| 429 | 517 |
| 430 // Checks that a NavigationThrottle asking to cancel followed by a | 518 // Checks that a NavigationThrottle asking to cancel followed by a |
| 431 // NavigationThrottle asking to proceed behave correctly in WillStartRequest. | 519 // NavigationThrottle asking to proceed behave correctly in WillStartRequest. |
| 432 // The navigation will be canceled directly, and the second throttle will not | 520 // The navigation will be canceled directly, and the second throttle will not |
| 433 // be called. | 521 // be called. |
| 434 TEST_F(NavigationHandleImplTest, CancelThenProceedWillStartRequest) { | 522 TEST_F(NavigationHandleImplTest, CancelThenProceedWillStartRequest) { |
| 435 TestNavigationThrottle* cancel_throttle = | 523 TestNavigationThrottle* cancel_throttle = |
| 436 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); | 524 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); |
| 437 TestNavigationThrottle* proceed_throttle = | 525 TestNavigationThrottle* proceed_throttle = |
| 438 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); | 526 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); |
| 439 EXPECT_FALSE(IsDeferringStart()); | 527 EXPECT_FALSE(IsDeferringStart()); |
| 440 EXPECT_FALSE(IsDeferringRedirect()); | 528 EXPECT_FALSE(IsDeferringRedirect()); |
| 441 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 529 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 442 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 530 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 531 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
| 443 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 532 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 444 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 533 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 445 | 534 |
| 446 // Simulate WillStartRequest. The request should not be deferred. The | 535 // Simulate WillStartRequest. The request should not be deferred. The |
| 447 // callback should not have been called. The second throttle should not have | 536 // callback should not have been called. The second throttle should not have |
| 448 // been notified. | 537 // been notified. |
| 449 SimulateWillStartRequest(); | 538 SimulateWillStartRequest(); |
| 450 EXPECT_FALSE(IsDeferringStart()); | 539 EXPECT_FALSE(IsDeferringStart()); |
| 451 EXPECT_FALSE(IsDeferringRedirect()); | 540 EXPECT_FALSE(IsDeferringRedirect()); |
| 452 EXPECT_TRUE(was_callback_called()); | 541 EXPECT_TRUE(was_callback_called()); |
| 453 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 542 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 454 EXPECT_EQ(1, cancel_throttle->will_start_calls()); | 543 EXPECT_EQ(1, cancel_throttle->will_start_calls()); |
| 455 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 544 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 545 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
| 456 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 546 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 457 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 547 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 458 } | 548 } |
| 459 | 549 |
| 460 // Checks that a NavigationThrottle asking to cancel followed by a | 550 // Checks that a NavigationThrottle asking to cancel followed by a |
| 461 // NavigationThrottle asking to proceed behave correctly in WillRedirectRequest. | 551 // NavigationThrottle asking to proceed behave correctly in WillRedirectRequest. |
| 462 // The navigation will be canceled directly, and the second throttle will not | 552 // The navigation will be canceled directly, and the second throttle will not |
| 463 // be called. | 553 // be called. |
| 464 TEST_F(NavigationHandleImplTest, CancelThenProceedWillRedirectRequest) { | 554 TEST_F(NavigationHandleImplTest, CancelThenProceedWillRedirectRequest) { |
| 465 TestNavigationThrottle* cancel_throttle = | 555 TestNavigationThrottle* cancel_throttle = |
| 466 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); | 556 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); |
| 467 TestNavigationThrottle* proceed_throttle = | 557 TestNavigationThrottle* proceed_throttle = |
| 468 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); | 558 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); |
| 469 EXPECT_FALSE(IsDeferringStart()); | 559 EXPECT_FALSE(IsDeferringStart()); |
| 470 EXPECT_FALSE(IsDeferringRedirect()); | 560 EXPECT_FALSE(IsDeferringRedirect()); |
| 471 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 561 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 472 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 562 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 563 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
| 473 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 564 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 474 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 565 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 475 | 566 |
| 476 // Simulate WillRedirectRequest. The request should not be deferred. The | 567 // Simulate WillRedirectRequest. The request should not be deferred. The |
| 477 // callback should not have been called. The second throttle should not have | 568 // callback should not have been called. The second throttle should not have |
| 478 // been notified. | 569 // been notified. |
| 479 SimulateWillRedirectRequest(); | 570 SimulateWillRedirectRequest(); |
| 480 EXPECT_FALSE(IsDeferringStart()); | 571 EXPECT_FALSE(IsDeferringStart()); |
| 481 EXPECT_FALSE(IsDeferringRedirect()); | 572 EXPECT_FALSE(IsDeferringRedirect()); |
| 482 EXPECT_TRUE(was_callback_called()); | 573 EXPECT_TRUE(was_callback_called()); |
| 483 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 574 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 484 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 575 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 485 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); | 576 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); |
| 577 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
| 486 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 578 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 487 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 579 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 488 } | 580 } |
| 489 | 581 |
| 582 // Checks that a NavigationThrottle asking to proceed followed by a |
| 583 // NavigationThrottle asking to cancel behave correctly in WillProcessResponse. |
| 584 // Both throttles will be called, and the request will be cancelled. |
| 585 TEST_F(NavigationHandleImplTest, ProceedThenCancelWillProcessResponse) { |
| 586 TestNavigationThrottle* proceed_throttle = |
| 587 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); |
| 588 TestNavigationThrottle* cancel_throttle = |
| 589 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); |
| 590 EXPECT_FALSE(IsDeferringStart()); |
| 591 EXPECT_FALSE(IsDeferringRedirect()); |
| 592 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 593 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 594 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
| 595 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 596 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 597 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
| 598 |
| 599 // Simulate WillRedirectRequest. The request should not be deferred. The |
| 600 // callback should have been called. |
| 601 SimulateWillProcessResponse(); |
| 602 EXPECT_FALSE(IsDeferringStart()); |
| 603 EXPECT_FALSE(IsDeferringRedirect()); |
| 604 EXPECT_TRUE(was_callback_called()); |
| 605 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 606 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 607 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 608 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
| 609 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 610 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 611 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); |
| 612 } |
| 613 |
| 614 // Checks that a NavigationThrottle asking to cancel followed by a |
| 615 // NavigationThrottle asking to proceed behave correctly in WillProcessResponse. |
| 616 // The navigation will be canceled directly, and the second throttle will not |
| 617 // be called. |
| 618 TEST_F(NavigationHandleImplTest, CancelThenProceedWillProcessResponse) { |
| 619 TestNavigationThrottle* cancel_throttle = |
| 620 CreateTestNavigationThrottle(NavigationThrottle::CANCEL_AND_IGNORE); |
| 621 TestNavigationThrottle* proceed_throttle = |
| 622 CreateTestNavigationThrottle(NavigationThrottle::PROCEED); |
| 623 EXPECT_FALSE(IsDeferringStart()); |
| 624 EXPECT_FALSE(IsDeferringRedirect()); |
| 625 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 626 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 627 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
| 628 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 629 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 630 |
| 631 // Simulate WillRedirectRequest. The request should not be deferred. The |
| 632 // callback should have been called. The second throttle should not have |
| 633 // been notified. |
| 634 SimulateWillProcessResponse(); |
| 635 EXPECT_FALSE(IsDeferringStart()); |
| 636 EXPECT_FALSE(IsDeferringRedirect()); |
| 637 EXPECT_TRUE(was_callback_called()); |
| 638 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
| 639 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
| 640 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
| 641 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
| 642 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
| 643 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
| 644 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
| 645 } |
| 646 |
| 490 } // namespace content | 647 } // namespace content |
| OLD | NEW |