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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 // The queued CloseRoute(kRouteId2) call should be executed. | 764 // The queued CloseRoute(kRouteId2) call should be executed. |
765 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); | 765 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); |
766 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) | 766 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) |
767 .WillOnce(Return(false)); | 767 .WillOnce(Return(false)); |
768 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))); | 768 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))); |
769 BindMediaRouteProvider(); | 769 BindMediaRouteProvider(); |
770 RegisterMediaRouteProvider(); | 770 RegisterMediaRouteProvider(); |
771 ProcessEventLoop(); | 771 ProcessEventLoop(); |
772 } | 772 } |
773 | 773 |
774 TEST_F(MediaRouterMojoExtensionTest, AttemptedWakeupTooManyTimes) { | |
775 BindMediaRouteProvider(); | |
776 | |
777 // CloseRoute is called while extension is suspended. It should be queued. | |
778 // Schedule a component extension wakeup. | |
779 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) | |
780 .WillOnce(Return(true)); | |
781 EXPECT_CALL(*process_manager_, WakeEventPage(kExtensionId, _)) | |
782 .WillOnce(testing::DoAll(media::RunCallback<1>(true), Return(true))); | |
783 media_router_->CloseRoute(kRouteId); | |
784 EXPECT_EQ(1u, media_router_->pending_requests_.size()); | |
785 | |
786 // Media route provider fails to connect to media router before extension is | |
787 // suspended again, and |OnConnectionError| is invoked. Retry the wakeup. | |
788 for (int i = 0; i < MediaRouterMojoImpl::kMaxWakeupAttemptCount - 1; ++i) { | |
789 EXPECT_CALL(*process_manager_, WakeEventPage(kExtensionId, _)) | |
Kevin M
2015/10/27 23:25:40
Set this outside the loop with .Times(kMaxWakeupAt
imcheng
2015/10/27 23:32:01
Done.
| |
790 .WillOnce(testing::DoAll(media::RunCallback<1>(true), Return(true))); | |
791 media_router_->OnConnectionError(); | |
792 } | |
793 | |
794 // We have already tried |kMaxWakeupAttemptCount| times. If we get an error | |
795 // again, we will give up and the pending request queue will be drained. | |
796 media_router_->OnConnectionError(); | |
797 EXPECT_TRUE(media_router_->pending_requests_.empty()); | |
Kevin M
2015/10/27 23:25:40
Test that the queue builds up back again following
imcheng
2015/10/27 23:32:01
Done.
| |
798 } | |
799 | |
800 TEST_F(MediaRouterMojoExtensionTest, WakeupFailedDrainsQueue) { | |
801 BindMediaRouteProvider(); | |
802 | |
803 // CloseRoute is called while extension is suspended. It should be queued. | |
804 // Schedule a component extension wakeup. | |
805 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) | |
806 .WillOnce(Return(true)); | |
807 base::Callback<void(bool)> extension_wakeup_callback; | |
808 EXPECT_CALL(*process_manager_, WakeEventPage(kExtensionId, _)) | |
809 .WillOnce( | |
810 testing::DoAll(SaveArg<1>(&extension_wakeup_callback), Return(true))); | |
811 media_router_->CloseRoute(kRouteId); | |
812 EXPECT_EQ(1u, media_router_->pending_requests_.size()); | |
813 | |
814 // Extension wakeup callback returning false is an non-retryable error. | |
815 // Queue should be drained. | |
816 extension_wakeup_callback.Run(false); | |
817 EXPECT_TRUE(media_router_->pending_requests_.empty()); | |
818 } | |
819 | |
820 TEST_F(MediaRouterMojoExtensionTest, DropOldestPendingRequest) { | |
821 const size_t kMaxPendingRequests = MediaRouterMojoImpl::kMaxPendingRequests; | |
822 | |
823 // Request is queued. | |
824 media_router_->CloseRoute(kRouteId); | |
825 EXPECT_EQ(1u, media_router_->pending_requests_.size()); | |
826 | |
827 for (size_t i = 0; i < kMaxPendingRequests; ++i) | |
828 media_router_->CloseRoute(kRouteId2); | |
829 | |
830 // The request queue size should not exceed |kMaxPendingRequests|. | |
831 EXPECT_EQ(kMaxPendingRequests, media_router_->pending_requests_.size()); | |
832 | |
833 // The oldest request should have been dropped, so we don't expect to see | |
834 // CloseRoute(kRouteId) here. | |
835 BindMediaRouteProvider(); | |
836 EXPECT_CALL(provide_handler_, Invoke(testing::Not(""))); | |
837 EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId)) | |
838 .WillOnce(Return(false)); | |
839 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2))) | |
840 .Times(kMaxPendingRequests); | |
841 RegisterMediaRouteProvider(); | |
842 ProcessEventLoop(); | |
843 } | |
844 | |
774 } // namespace media_router | 845 } // namespace media_router |
OLD | NEW |