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/public/browser/ssl_status.h" | 8 #include "content/public/browser/ssl_status.h" |
9 #include "content/public/common/request_context_type.h" | 9 #include "content/public/common/request_context_type.h" |
10 #include "content/test/test_render_frame_host.h" | 10 #include "content/test/test_render_frame_host.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 bool IsDeferringRedirect() { | 87 bool IsDeferringRedirect() { |
88 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; | 88 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; |
89 } | 89 } |
90 | 90 |
91 bool IsDeferringResponse() { | 91 bool IsDeferringResponse() { |
92 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE; | 92 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE; |
93 } | 93 } |
94 | 94 |
95 bool IsCanceling() { | 95 bool IsCancelingRequest() { |
96 return test_handle_->state() == NavigationHandleImpl::CANCELING; | 96 return test_handle_->state() == NavigationHandleImpl::CANCELING_REQUEST; |
| 97 } |
| 98 |
| 99 bool IsCancelingResponse() { |
| 100 return test_handle_->state() == NavigationHandleImpl::CANCELING_RESPONSE; |
97 } | 101 } |
98 | 102 |
99 // Helper function to call WillStartRequest on |handle|. If this function | 103 // Helper function to call WillStartRequest on |handle|. If this function |
100 // returns DEFER, |callback_result_| will be set to the actual result of | 104 // returns DEFER, |callback_result_| will be set to the actual result of |
101 // the throttle checks when they are finished. | 105 // the throttle checks when they are finished. |
102 void SimulateWillStartRequest() { | 106 void SimulateWillStartRequest() { |
103 was_callback_called_ = false; | 107 was_callback_called_ = false; |
104 callback_result_ = NavigationThrottle::DEFER; | 108 callback_result_ = NavigationThrottle::DEFER; |
105 | 109 |
106 // It's safe to use base::Unretained since the NavigationHandle is owned by | 110 // It's safe to use base::Unretained since the NavigationHandle is owned by |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 EXPECT_FALSE(was_callback_called()); | 307 EXPECT_FALSE(was_callback_called()); |
304 EXPECT_EQ(1, test_throttle->will_start_calls()); | 308 EXPECT_EQ(1, test_throttle->will_start_calls()); |
305 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 309 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
306 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 310 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
307 | 311 |
308 // Cancel the request. The callback should have been called. | 312 // Cancel the request. The callback should have been called. |
309 test_handle()->CancelDeferredNavigation( | 313 test_handle()->CancelDeferredNavigation( |
310 NavigationThrottle::CANCEL_AND_IGNORE); | 314 NavigationThrottle::CANCEL_AND_IGNORE); |
311 EXPECT_FALSE(IsDeferringStart()); | 315 EXPECT_FALSE(IsDeferringStart()); |
312 EXPECT_FALSE(IsDeferringRedirect()); | 316 EXPECT_FALSE(IsDeferringRedirect()); |
313 EXPECT_TRUE(IsCanceling()); | 317 EXPECT_TRUE(IsCancelingRequest()); |
314 EXPECT_TRUE(was_callback_called()); | 318 EXPECT_TRUE(was_callback_called()); |
315 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 319 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
316 EXPECT_EQ(1, test_throttle->will_start_calls()); | 320 EXPECT_EQ(1, test_throttle->will_start_calls()); |
317 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 321 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
318 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 322 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
319 } | 323 } |
320 | 324 |
321 // Checks that a navigation deferred during WillRedirectRequest can be properly | 325 // Checks that a navigation deferred during WillRedirectRequest can be properly |
322 // cancelled. | 326 // cancelled. |
323 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { | 327 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { |
(...skipping 13 matching lines...) Expand all Loading... |
337 EXPECT_FALSE(was_callback_called()); | 341 EXPECT_FALSE(was_callback_called()); |
338 EXPECT_EQ(0, test_throttle->will_start_calls()); | 342 EXPECT_EQ(0, test_throttle->will_start_calls()); |
339 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 343 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
340 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 344 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
341 | 345 |
342 // Cancel the request. The callback should have been called. | 346 // Cancel the request. The callback should have been called. |
343 test_handle()->CancelDeferredNavigation( | 347 test_handle()->CancelDeferredNavigation( |
344 NavigationThrottle::CANCEL_AND_IGNORE); | 348 NavigationThrottle::CANCEL_AND_IGNORE); |
345 EXPECT_FALSE(IsDeferringStart()); | 349 EXPECT_FALSE(IsDeferringStart()); |
346 EXPECT_FALSE(IsDeferringRedirect()); | 350 EXPECT_FALSE(IsDeferringRedirect()); |
347 EXPECT_TRUE(IsCanceling()); | 351 EXPECT_TRUE(IsCancelingRequest()); |
348 EXPECT_TRUE(was_callback_called()); | 352 EXPECT_TRUE(was_callback_called()); |
349 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 353 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
350 EXPECT_EQ(0, test_throttle->will_start_calls()); | 354 EXPECT_EQ(0, test_throttle->will_start_calls()); |
351 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 355 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
352 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 356 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
353 } | 357 } |
354 | 358 |
355 // Checks that a navigation deferred can be canceled and not ignored. | 359 // Checks that a navigation deferred can be canceled and not ignored. |
356 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { | 360 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { |
357 TestNavigationThrottle* test_throttle = | 361 TestNavigationThrottle* test_throttle = |
(...skipping 12 matching lines...) Expand all Loading... |
370 EXPECT_FALSE(was_callback_called()); | 374 EXPECT_FALSE(was_callback_called()); |
371 EXPECT_EQ(1, test_throttle->will_start_calls()); | 375 EXPECT_EQ(1, test_throttle->will_start_calls()); |
372 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 376 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
373 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 377 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
374 | 378 |
375 // Cancel the request. The callback should have been called with CANCEL, and | 379 // Cancel the request. The callback should have been called with CANCEL, and |
376 // not CANCEL_AND_IGNORE. | 380 // not CANCEL_AND_IGNORE. |
377 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); | 381 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); |
378 EXPECT_FALSE(IsDeferringStart()); | 382 EXPECT_FALSE(IsDeferringStart()); |
379 EXPECT_FALSE(IsDeferringRedirect()); | 383 EXPECT_FALSE(IsDeferringRedirect()); |
380 EXPECT_TRUE(IsCanceling()); | 384 EXPECT_TRUE(IsCancelingRequest()); |
381 EXPECT_TRUE(was_callback_called()); | 385 EXPECT_TRUE(was_callback_called()); |
382 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); | 386 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); |
383 EXPECT_EQ(1, test_throttle->will_start_calls()); | 387 EXPECT_EQ(1, test_throttle->will_start_calls()); |
384 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 388 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
385 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 389 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
386 } | 390 } |
387 | 391 |
388 // Checks that a NavigationThrottle asking to defer followed by a | 392 // Checks that a NavigationThrottle asking to defer followed by a |
389 // NavigationThrottle asking to proceed behave correctly. | 393 // NavigationThrottle asking to proceed behave correctly. |
390 TEST_F(NavigationHandleImplTest, DeferThenProceed) { | 394 TEST_F(NavigationHandleImplTest, DeferThenProceed) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 484 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
481 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 485 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
482 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 486 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
483 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 487 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
484 | 488 |
485 // Resume the request. The callback should have been called. The second | 489 // Resume the request. The callback should have been called. The second |
486 // throttle should have been notified. | 490 // throttle should have been notified. |
487 test_handle()->Resume(); | 491 test_handle()->Resume(); |
488 EXPECT_FALSE(IsDeferringStart()); | 492 EXPECT_FALSE(IsDeferringStart()); |
489 EXPECT_FALSE(IsDeferringRedirect()); | 493 EXPECT_FALSE(IsDeferringRedirect()); |
490 EXPECT_TRUE(IsCanceling()); | 494 EXPECT_TRUE(IsCancelingRequest()); |
491 EXPECT_TRUE(was_callback_called()); | 495 EXPECT_TRUE(was_callback_called()); |
492 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 496 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
493 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 497 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
494 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 498 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
495 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 499 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
496 EXPECT_EQ(1, cancel_throttle->will_start_calls()); | 500 EXPECT_EQ(1, cancel_throttle->will_start_calls()); |
497 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 501 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
498 } | 502 } |
499 | 503 |
500 // Checks that a NavigationThrottle asking to defer followed by a | 504 // Checks that a NavigationThrottle asking to defer followed by a |
(...skipping 22 matching lines...) Expand all Loading... |
523 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 527 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
524 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 528 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
525 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 529 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
526 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 530 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
527 | 531 |
528 // Resume the request. The callback should have been called. The second | 532 // Resume the request. The callback should have been called. The second |
529 // throttle should have been notified. | 533 // throttle should have been notified. |
530 test_handle()->Resume(); | 534 test_handle()->Resume(); |
531 EXPECT_FALSE(IsDeferringStart()); | 535 EXPECT_FALSE(IsDeferringStart()); |
532 EXPECT_FALSE(IsDeferringRedirect()); | 536 EXPECT_FALSE(IsDeferringRedirect()); |
533 EXPECT_TRUE(IsCanceling()); | 537 EXPECT_TRUE(IsCancelingRequest()); |
534 EXPECT_TRUE(was_callback_called()); | 538 EXPECT_TRUE(was_callback_called()); |
535 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 539 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
536 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 540 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
537 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 541 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
538 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 542 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
539 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 543 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
540 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); | 544 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); |
541 } | 545 } |
542 | 546 |
543 // Checks that a NavigationThrottle asking to cancel followed by a | 547 // Checks that a NavigationThrottle asking to cancel followed by a |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); | 623 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
620 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 624 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
621 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 625 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
622 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 626 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
623 | 627 |
624 // Simulate WillRedirectRequest. The request should not be deferred. The | 628 // Simulate WillRedirectRequest. The request should not be deferred. The |
625 // callback should have been called. | 629 // callback should have been called. |
626 SimulateWillProcessResponse(); | 630 SimulateWillProcessResponse(); |
627 EXPECT_FALSE(IsDeferringStart()); | 631 EXPECT_FALSE(IsDeferringStart()); |
628 EXPECT_FALSE(IsDeferringRedirect()); | 632 EXPECT_FALSE(IsDeferringRedirect()); |
| 633 EXPECT_TRUE(IsCancelingResponse()); |
629 EXPECT_TRUE(was_callback_called()); | 634 EXPECT_TRUE(was_callback_called()); |
630 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 635 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
631 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 636 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
632 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 637 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
633 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 638 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
634 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 639 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
635 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 640 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
636 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); | 641 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); |
637 } | 642 } |
638 | 643 |
(...skipping 24 matching lines...) Expand all Loading... |
663 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 668 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
664 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 669 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
665 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 670 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
666 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 671 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
667 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 672 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
668 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 673 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
669 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 674 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
670 } | 675 } |
671 | 676 |
672 } // namespace content | 677 } // namespace content |
OLD | NEW |