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