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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 | 88 |
89 bool IsDeferringRedirect() { | 89 bool IsDeferringRedirect() { |
90 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; | 90 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; |
91 } | 91 } |
92 | 92 |
93 bool IsDeferringResponse() { | 93 bool IsDeferringResponse() { |
94 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE; | 94 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE; |
95 } | 95 } |
96 | 96 |
97 bool IsCanceling() { | 97 bool IsCancelingRequest() { |
98 return test_handle_->state() == NavigationHandleImpl::CANCELING; | 98 return test_handle_->state() == NavigationHandleImpl::CANCELING_REQUEST; |
| 99 } |
| 100 |
| 101 bool IsCancelingResponse() { |
| 102 return test_handle_->state() == NavigationHandleImpl::CANCELING_RESPONSE; |
99 } | 103 } |
100 | 104 |
101 // Helper function to call WillStartRequest on |handle|. If this function | 105 // Helper function to call WillStartRequest on |handle|. If this function |
102 // returns DEFER, |callback_result_| will be set to the actual result of | 106 // returns DEFER, |callback_result_| will be set to the actual result of |
103 // the throttle checks when they are finished. | 107 // the throttle checks when they are finished. |
104 void SimulateWillStartRequest() { | 108 void SimulateWillStartRequest() { |
105 was_callback_called_ = false; | 109 was_callback_called_ = false; |
106 callback_result_ = NavigationThrottle::DEFER; | 110 callback_result_ = NavigationThrottle::DEFER; |
107 | 111 |
108 // It's safe to use base::Unretained since the NavigationHandle is owned by | 112 // It's safe to use base::Unretained since the NavigationHandle is owned by |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 EXPECT_FALSE(was_callback_called()); | 329 EXPECT_FALSE(was_callback_called()); |
326 EXPECT_EQ(1, test_throttle->will_start_calls()); | 330 EXPECT_EQ(1, test_throttle->will_start_calls()); |
327 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 331 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
328 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 332 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
329 | 333 |
330 // Cancel the request. The callback should have been called. | 334 // Cancel the request. The callback should have been called. |
331 test_handle()->CancelDeferredNavigation( | 335 test_handle()->CancelDeferredNavigation( |
332 NavigationThrottle::CANCEL_AND_IGNORE); | 336 NavigationThrottle::CANCEL_AND_IGNORE); |
333 EXPECT_FALSE(IsDeferringStart()); | 337 EXPECT_FALSE(IsDeferringStart()); |
334 EXPECT_FALSE(IsDeferringRedirect()); | 338 EXPECT_FALSE(IsDeferringRedirect()); |
335 EXPECT_TRUE(IsCanceling()); | 339 EXPECT_TRUE(IsCancelingRequest()); |
336 EXPECT_TRUE(was_callback_called()); | 340 EXPECT_TRUE(was_callback_called()); |
337 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 341 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
338 EXPECT_EQ(1, test_throttle->will_start_calls()); | 342 EXPECT_EQ(1, test_throttle->will_start_calls()); |
339 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 343 EXPECT_EQ(0, 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 | 346 |
343 // Checks that a navigation deferred during WillRedirectRequest can be properly | 347 // Checks that a navigation deferred during WillRedirectRequest can be properly |
344 // cancelled. | 348 // cancelled. |
345 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { | 349 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { |
(...skipping 13 matching lines...) Expand all Loading... |
359 EXPECT_FALSE(was_callback_called()); | 363 EXPECT_FALSE(was_callback_called()); |
360 EXPECT_EQ(0, test_throttle->will_start_calls()); | 364 EXPECT_EQ(0, test_throttle->will_start_calls()); |
361 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 365 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
362 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 366 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
363 | 367 |
364 // Cancel the request. The callback should have been called. | 368 // Cancel the request. The callback should have been called. |
365 test_handle()->CancelDeferredNavigation( | 369 test_handle()->CancelDeferredNavigation( |
366 NavigationThrottle::CANCEL_AND_IGNORE); | 370 NavigationThrottle::CANCEL_AND_IGNORE); |
367 EXPECT_FALSE(IsDeferringStart()); | 371 EXPECT_FALSE(IsDeferringStart()); |
368 EXPECT_FALSE(IsDeferringRedirect()); | 372 EXPECT_FALSE(IsDeferringRedirect()); |
369 EXPECT_TRUE(IsCanceling()); | 373 EXPECT_TRUE(IsCancelingRequest()); |
370 EXPECT_TRUE(was_callback_called()); | 374 EXPECT_TRUE(was_callback_called()); |
371 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 375 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
372 EXPECT_EQ(0, test_throttle->will_start_calls()); | 376 EXPECT_EQ(0, test_throttle->will_start_calls()); |
373 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 377 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
374 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 378 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
375 } | 379 } |
376 | 380 |
377 // Checks that a navigation deferred can be canceled and not ignored. | 381 // Checks that a navigation deferred can be canceled and not ignored. |
378 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { | 382 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { |
379 TestNavigationThrottle* test_throttle = | 383 TestNavigationThrottle* test_throttle = |
(...skipping 12 matching lines...) Expand all Loading... |
392 EXPECT_FALSE(was_callback_called()); | 396 EXPECT_FALSE(was_callback_called()); |
393 EXPECT_EQ(1, test_throttle->will_start_calls()); | 397 EXPECT_EQ(1, test_throttle->will_start_calls()); |
394 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 398 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
395 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 399 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
396 | 400 |
397 // Cancel the request. The callback should have been called with CANCEL, and | 401 // Cancel the request. The callback should have been called with CANCEL, and |
398 // not CANCEL_AND_IGNORE. | 402 // not CANCEL_AND_IGNORE. |
399 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); | 403 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); |
400 EXPECT_FALSE(IsDeferringStart()); | 404 EXPECT_FALSE(IsDeferringStart()); |
401 EXPECT_FALSE(IsDeferringRedirect()); | 405 EXPECT_FALSE(IsDeferringRedirect()); |
402 EXPECT_TRUE(IsCanceling()); | 406 EXPECT_TRUE(IsCancelingRequest()); |
403 EXPECT_TRUE(was_callback_called()); | 407 EXPECT_TRUE(was_callback_called()); |
404 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); | 408 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); |
405 EXPECT_EQ(1, test_throttle->will_start_calls()); | 409 EXPECT_EQ(1, test_throttle->will_start_calls()); |
406 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 410 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
407 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 411 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
408 } | 412 } |
409 | 413 |
410 // Checks that a NavigationThrottle asking to defer followed by a | 414 // Checks that a NavigationThrottle asking to defer followed by a |
411 // NavigationThrottle asking to proceed behave correctly. | 415 // NavigationThrottle asking to proceed behave correctly. |
412 TEST_F(NavigationHandleImplTest, DeferThenProceed) { | 416 TEST_F(NavigationHandleImplTest, DeferThenProceed) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 506 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
503 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 507 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
504 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 508 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
505 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 509 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
506 | 510 |
507 // Resume the request. The callback should have been called. The second | 511 // Resume the request. The callback should have been called. The second |
508 // throttle should have been notified. | 512 // throttle should have been notified. |
509 test_handle()->Resume(); | 513 test_handle()->Resume(); |
510 EXPECT_FALSE(IsDeferringStart()); | 514 EXPECT_FALSE(IsDeferringStart()); |
511 EXPECT_FALSE(IsDeferringRedirect()); | 515 EXPECT_FALSE(IsDeferringRedirect()); |
512 EXPECT_TRUE(IsCanceling()); | 516 EXPECT_TRUE(IsCancelingRequest()); |
513 EXPECT_TRUE(was_callback_called()); | 517 EXPECT_TRUE(was_callback_called()); |
514 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 518 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
515 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 519 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
516 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 520 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
517 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 521 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
518 EXPECT_EQ(1, cancel_throttle->will_start_calls()); | 522 EXPECT_EQ(1, cancel_throttle->will_start_calls()); |
519 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 523 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
520 } | 524 } |
521 | 525 |
522 // Checks that a NavigationThrottle asking to defer followed by a | 526 // Checks that a NavigationThrottle asking to defer followed by a |
(...skipping 22 matching lines...) Expand all Loading... |
545 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 549 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
546 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 550 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
547 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 551 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
548 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 552 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
549 | 553 |
550 // Resume the request. The callback should have been called. The second | 554 // Resume the request. The callback should have been called. The second |
551 // throttle should have been notified. | 555 // throttle should have been notified. |
552 test_handle()->Resume(); | 556 test_handle()->Resume(); |
553 EXPECT_FALSE(IsDeferringStart()); | 557 EXPECT_FALSE(IsDeferringStart()); |
554 EXPECT_FALSE(IsDeferringRedirect()); | 558 EXPECT_FALSE(IsDeferringRedirect()); |
555 EXPECT_TRUE(IsCanceling()); | 559 EXPECT_TRUE(IsCancelingRequest()); |
556 EXPECT_TRUE(was_callback_called()); | 560 EXPECT_TRUE(was_callback_called()); |
557 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 561 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
558 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 562 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
559 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 563 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
560 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 564 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
561 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 565 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
562 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); | 566 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); |
563 } | 567 } |
564 | 568 |
565 // Checks that a NavigationThrottle asking to cancel followed by a | 569 // Checks that a NavigationThrottle asking to cancel followed by a |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); | 645 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
642 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 646 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
643 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 647 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
644 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 648 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
645 | 649 |
646 // Simulate WillRedirectRequest. The request should not be deferred. The | 650 // Simulate WillRedirectRequest. The request should not be deferred. The |
647 // callback should have been called. | 651 // callback should have been called. |
648 SimulateWillProcessResponse(); | 652 SimulateWillProcessResponse(); |
649 EXPECT_FALSE(IsDeferringStart()); | 653 EXPECT_FALSE(IsDeferringStart()); |
650 EXPECT_FALSE(IsDeferringRedirect()); | 654 EXPECT_FALSE(IsDeferringRedirect()); |
| 655 EXPECT_TRUE(IsCancelingRequest()); |
651 EXPECT_TRUE(was_callback_called()); | 656 EXPECT_TRUE(was_callback_called()); |
652 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 657 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
653 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 658 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
654 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 659 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
655 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 660 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
656 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 661 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
657 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 662 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
658 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); | 663 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); |
659 } | 664 } |
660 | 665 |
(...skipping 24 matching lines...) Expand all Loading... |
685 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 690 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
686 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 691 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
687 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 692 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
688 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 693 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
689 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 694 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
690 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 695 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
691 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 696 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
692 } | 697 } |
693 | 698 |
694 } // namespace content | 699 } // namespace content |
OLD | NEW |