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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 } | 91 } |
92 | 92 |
93 bool IsDeferringRedirect() { | 93 bool IsDeferringRedirect() { |
94 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; | 94 return test_handle_->state() == NavigationHandleImpl::DEFERRING_REDIRECT; |
95 } | 95 } |
96 | 96 |
97 bool IsDeferringResponse() { | 97 bool IsDeferringResponse() { |
98 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE; | 98 return test_handle_->state() == NavigationHandleImpl::DEFERRING_RESPONSE; |
99 } | 99 } |
100 | 100 |
101 bool IsCanceling() { | 101 bool IsCancelingRequest() { |
102 return test_handle_->state() == NavigationHandleImpl::CANCELING; | 102 return test_handle_->state() == NavigationHandleImpl::CANCELING_REQUEST; |
103 } | |
104 | |
105 bool IsCancelingResponse() { | |
clamy
2016/12/06 17:09:44
I don't see this function being used in the tests.
arthursonzogni
2016/12/07 16:25:02
Good idea.
Instead, I merged the two state, this f
| |
106 return test_handle_->state() == NavigationHandleImpl::CANCELING_RESPONSE; | |
103 } | 107 } |
104 | 108 |
105 // Helper function to call WillStartRequest on |handle|. If this function | 109 // Helper function to call WillStartRequest on |handle|. If this function |
106 // returns DEFER, |callback_result_| will be set to the actual result of | 110 // returns DEFER, |callback_result_| will be set to the actual result of |
107 // the throttle checks when they are finished. | 111 // the throttle checks when they are finished. |
108 void SimulateWillStartRequest() { | 112 void SimulateWillStartRequest() { |
109 was_callback_called_ = false; | 113 was_callback_called_ = false; |
110 callback_result_ = NavigationThrottle::DEFER; | 114 callback_result_ = NavigationThrottle::DEFER; |
111 | 115 |
112 // It's safe to use base::Unretained since the NavigationHandle is owned by | 116 // 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... | |
329 EXPECT_FALSE(was_callback_called()); | 333 EXPECT_FALSE(was_callback_called()); |
330 EXPECT_EQ(1, test_throttle->will_start_calls()); | 334 EXPECT_EQ(1, test_throttle->will_start_calls()); |
331 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 335 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
332 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 336 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
333 | 337 |
334 // Cancel the request. The callback should have been called. | 338 // Cancel the request. The callback should have been called. |
335 test_handle()->CancelDeferredNavigation( | 339 test_handle()->CancelDeferredNavigation( |
336 NavigationThrottle::CANCEL_AND_IGNORE); | 340 NavigationThrottle::CANCEL_AND_IGNORE); |
337 EXPECT_FALSE(IsDeferringStart()); | 341 EXPECT_FALSE(IsDeferringStart()); |
338 EXPECT_FALSE(IsDeferringRedirect()); | 342 EXPECT_FALSE(IsDeferringRedirect()); |
339 EXPECT_TRUE(IsCanceling()); | 343 EXPECT_TRUE(IsCancelingRequest()); |
340 EXPECT_TRUE(was_callback_called()); | 344 EXPECT_TRUE(was_callback_called()); |
341 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 345 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
342 EXPECT_EQ(1, test_throttle->will_start_calls()); | 346 EXPECT_EQ(1, test_throttle->will_start_calls()); |
343 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 347 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
344 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 348 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
345 } | 349 } |
346 | 350 |
347 // Checks that a navigation deferred during WillRedirectRequest can be properly | 351 // Checks that a navigation deferred during WillRedirectRequest can be properly |
348 // cancelled. | 352 // cancelled. |
349 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { | 353 TEST_F(NavigationHandleImplTest, CancelDeferredWillRedirect) { |
(...skipping 13 matching lines...) Expand all Loading... | |
363 EXPECT_FALSE(was_callback_called()); | 367 EXPECT_FALSE(was_callback_called()); |
364 EXPECT_EQ(0, test_throttle->will_start_calls()); | 368 EXPECT_EQ(0, test_throttle->will_start_calls()); |
365 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 369 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
366 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 370 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
367 | 371 |
368 // Cancel the request. The callback should have been called. | 372 // Cancel the request. The callback should have been called. |
369 test_handle()->CancelDeferredNavigation( | 373 test_handle()->CancelDeferredNavigation( |
370 NavigationThrottle::CANCEL_AND_IGNORE); | 374 NavigationThrottle::CANCEL_AND_IGNORE); |
371 EXPECT_FALSE(IsDeferringStart()); | 375 EXPECT_FALSE(IsDeferringStart()); |
372 EXPECT_FALSE(IsDeferringRedirect()); | 376 EXPECT_FALSE(IsDeferringRedirect()); |
373 EXPECT_TRUE(IsCanceling()); | 377 EXPECT_TRUE(IsCancelingRequest()); |
374 EXPECT_TRUE(was_callback_called()); | 378 EXPECT_TRUE(was_callback_called()); |
375 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 379 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
376 EXPECT_EQ(0, test_throttle->will_start_calls()); | 380 EXPECT_EQ(0, test_throttle->will_start_calls()); |
377 EXPECT_EQ(1, test_throttle->will_redirect_calls()); | 381 EXPECT_EQ(1, test_throttle->will_redirect_calls()); |
378 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 382 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
379 } | 383 } |
380 | 384 |
381 // Checks that a navigation deferred can be canceled and not ignored. | 385 // Checks that a navigation deferred can be canceled and not ignored. |
382 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { | 386 TEST_F(NavigationHandleImplTest, CancelDeferredNoIgnore) { |
383 TestNavigationThrottle* test_throttle = | 387 TestNavigationThrottle* test_throttle = |
(...skipping 12 matching lines...) Expand all Loading... | |
396 EXPECT_FALSE(was_callback_called()); | 400 EXPECT_FALSE(was_callback_called()); |
397 EXPECT_EQ(1, test_throttle->will_start_calls()); | 401 EXPECT_EQ(1, test_throttle->will_start_calls()); |
398 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 402 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
399 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 403 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
400 | 404 |
401 // Cancel the request. The callback should have been called with CANCEL, and | 405 // Cancel the request. The callback should have been called with CANCEL, and |
402 // not CANCEL_AND_IGNORE. | 406 // not CANCEL_AND_IGNORE. |
403 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); | 407 test_handle()->CancelDeferredNavigation(NavigationThrottle::CANCEL); |
404 EXPECT_FALSE(IsDeferringStart()); | 408 EXPECT_FALSE(IsDeferringStart()); |
405 EXPECT_FALSE(IsDeferringRedirect()); | 409 EXPECT_FALSE(IsDeferringRedirect()); |
406 EXPECT_TRUE(IsCanceling()); | 410 EXPECT_TRUE(IsCancelingRequest()); |
407 EXPECT_TRUE(was_callback_called()); | 411 EXPECT_TRUE(was_callback_called()); |
408 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); | 412 EXPECT_EQ(NavigationThrottle::CANCEL, callback_result()); |
409 EXPECT_EQ(1, test_throttle->will_start_calls()); | 413 EXPECT_EQ(1, test_throttle->will_start_calls()); |
410 EXPECT_EQ(0, test_throttle->will_redirect_calls()); | 414 EXPECT_EQ(0, test_throttle->will_redirect_calls()); |
411 EXPECT_EQ(0, test_throttle->will_process_response_calls()); | 415 EXPECT_EQ(0, test_throttle->will_process_response_calls()); |
412 } | 416 } |
413 | 417 |
414 // Checks that a NavigationThrottle asking to defer followed by a | 418 // Checks that a NavigationThrottle asking to defer followed by a |
415 // NavigationThrottle asking to proceed behave correctly. | 419 // NavigationThrottle asking to proceed behave correctly. |
416 TEST_F(NavigationHandleImplTest, DeferThenProceed) { | 420 TEST_F(NavigationHandleImplTest, DeferThenProceed) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 510 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
507 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 511 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
508 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 512 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
509 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 513 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
510 | 514 |
511 // Resume the request. The callback should have been called. The second | 515 // Resume the request. The callback should have been called. The second |
512 // throttle should have been notified. | 516 // throttle should have been notified. |
513 test_handle()->Resume(); | 517 test_handle()->Resume(); |
514 EXPECT_FALSE(IsDeferringStart()); | 518 EXPECT_FALSE(IsDeferringStart()); |
515 EXPECT_FALSE(IsDeferringRedirect()); | 519 EXPECT_FALSE(IsDeferringRedirect()); |
516 EXPECT_TRUE(IsCanceling()); | 520 EXPECT_TRUE(IsCancelingRequest()); |
517 EXPECT_TRUE(was_callback_called()); | 521 EXPECT_TRUE(was_callback_called()); |
518 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 522 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
519 EXPECT_EQ(1, defer_throttle->will_start_calls()); | 523 EXPECT_EQ(1, defer_throttle->will_start_calls()); |
520 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); | 524 EXPECT_EQ(0, defer_throttle->will_redirect_calls()); |
521 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 525 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
522 EXPECT_EQ(1, cancel_throttle->will_start_calls()); | 526 EXPECT_EQ(1, cancel_throttle->will_start_calls()); |
523 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 527 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
524 } | 528 } |
525 | 529 |
526 // Checks that a NavigationThrottle asking to defer followed by a | 530 // Checks that a NavigationThrottle asking to defer followed by a |
(...skipping 22 matching lines...) Expand all Loading... | |
549 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 553 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
550 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 554 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
551 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 555 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
552 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 556 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
553 | 557 |
554 // Resume the request. The callback should have been called. The second | 558 // Resume the request. The callback should have been called. The second |
555 // throttle should have been notified. | 559 // throttle should have been notified. |
556 test_handle()->Resume(); | 560 test_handle()->Resume(); |
557 EXPECT_FALSE(IsDeferringStart()); | 561 EXPECT_FALSE(IsDeferringStart()); |
558 EXPECT_FALSE(IsDeferringRedirect()); | 562 EXPECT_FALSE(IsDeferringRedirect()); |
559 EXPECT_TRUE(IsCanceling()); | 563 EXPECT_TRUE(IsCancelingRequest()); |
560 EXPECT_TRUE(was_callback_called()); | 564 EXPECT_TRUE(was_callback_called()); |
561 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 565 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
562 EXPECT_EQ(0, defer_throttle->will_start_calls()); | 566 EXPECT_EQ(0, defer_throttle->will_start_calls()); |
563 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); | 567 EXPECT_EQ(1, defer_throttle->will_redirect_calls()); |
564 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); | 568 EXPECT_EQ(0, defer_throttle->will_process_response_calls()); |
565 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 569 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
566 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); | 570 EXPECT_EQ(1, cancel_throttle->will_redirect_calls()); |
567 } | 571 } |
568 | 572 |
569 // Checks that a NavigationThrottle asking to cancel followed by a | 573 // Checks that a NavigationThrottle asking to cancel followed by a |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); | 649 EXPECT_EQ(0, cancel_throttle->will_process_response_calls()); |
646 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 650 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
647 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 651 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
648 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 652 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
649 | 653 |
650 // Simulate WillRedirectRequest. The request should not be deferred. The | 654 // Simulate WillRedirectRequest. The request should not be deferred. The |
651 // callback should have been called. | 655 // callback should have been called. |
652 SimulateWillProcessResponse(); | 656 SimulateWillProcessResponse(); |
653 EXPECT_FALSE(IsDeferringStart()); | 657 EXPECT_FALSE(IsDeferringStart()); |
654 EXPECT_FALSE(IsDeferringRedirect()); | 658 EXPECT_FALSE(IsDeferringRedirect()); |
659 EXPECT_TRUE(IsCancelingRequest()); | |
655 EXPECT_TRUE(was_callback_called()); | 660 EXPECT_TRUE(was_callback_called()); |
656 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 661 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
657 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 662 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
658 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 663 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
659 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 664 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
660 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 665 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
661 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 666 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
662 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); | 667 EXPECT_EQ(1, proceed_throttle->will_process_response_calls()); |
663 } | 668 } |
664 | 669 |
(...skipping 24 matching lines...) Expand all Loading... | |
689 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); | 694 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); |
690 EXPECT_EQ(0, cancel_throttle->will_start_calls()); | 695 EXPECT_EQ(0, cancel_throttle->will_start_calls()); |
691 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); | 696 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); |
692 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); | 697 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); |
693 EXPECT_EQ(0, proceed_throttle->will_start_calls()); | 698 EXPECT_EQ(0, proceed_throttle->will_start_calls()); |
694 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); | 699 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); |
695 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); | 700 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); |
696 } | 701 } |
697 | 702 |
698 } // namespace content | 703 } // namespace content |
OLD | NEW |