Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5495)

Unified Diff: chrome/browser/media/router/media_router_mojo_impl_unittest.cc

Issue 1419853003: [Media Router] Connection reattempt logic and bound pending request queue size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media/router/media_router_mojo_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/router/media_router_mojo_impl_unittest.cc
diff --git a/chrome/browser/media/router/media_router_mojo_impl_unittest.cc b/chrome/browser/media/router/media_router_mojo_impl_unittest.cc
index 32fd0d5140662156134923222622131ccdd34a9c..f5128fb63dd574ed987a9abcd5b6321387977ee1 100644
--- a/chrome/browser/media/router/media_router_mojo_impl_unittest.cc
+++ b/chrome/browser/media/router/media_router_mojo_impl_unittest.cc
@@ -771,4 +771,75 @@ TEST_F(MediaRouterMojoExtensionTest, DeferredBindingAndSuspension) {
ProcessEventLoop();
}
+TEST_F(MediaRouterMojoExtensionTest, AttemptedWakeupTooManyTimes) {
+ BindMediaRouteProvider();
+
+ // CloseRoute is called while extension is suspended. It should be queued.
+ // Schedule a component extension wakeup.
+ EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId))
+ .WillOnce(Return(true));
+ EXPECT_CALL(*process_manager_, WakeEventPage(kExtensionId, _))
+ .WillOnce(testing::DoAll(media::RunCallback<1>(true), Return(true)));
+ media_router_->CloseRoute(kRouteId);
+ EXPECT_EQ(1u, media_router_->pending_requests_.size());
+
+ // Media route provider fails to connect to media router before extension is
+ // suspended again, and |OnConnectionError| is invoked. Retry the wakeup.
+ for (int i = 0; i < MediaRouterMojoImpl::kMaxWakeupAttemptCount - 1; ++i) {
+ 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.
+ .WillOnce(testing::DoAll(media::RunCallback<1>(true), Return(true)));
+ media_router_->OnConnectionError();
+ }
+
+ // We have already tried |kMaxWakeupAttemptCount| times. If we get an error
+ // again, we will give up and the pending request queue will be drained.
+ media_router_->OnConnectionError();
+ 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.
+}
+
+TEST_F(MediaRouterMojoExtensionTest, WakeupFailedDrainsQueue) {
+ BindMediaRouteProvider();
+
+ // CloseRoute is called while extension is suspended. It should be queued.
+ // Schedule a component extension wakeup.
+ EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId))
+ .WillOnce(Return(true));
+ base::Callback<void(bool)> extension_wakeup_callback;
+ EXPECT_CALL(*process_manager_, WakeEventPage(kExtensionId, _))
+ .WillOnce(
+ testing::DoAll(SaveArg<1>(&extension_wakeup_callback), Return(true)));
+ media_router_->CloseRoute(kRouteId);
+ EXPECT_EQ(1u, media_router_->pending_requests_.size());
+
+ // Extension wakeup callback returning false is an non-retryable error.
+ // Queue should be drained.
+ extension_wakeup_callback.Run(false);
+ EXPECT_TRUE(media_router_->pending_requests_.empty());
+}
+
+TEST_F(MediaRouterMojoExtensionTest, DropOldestPendingRequest) {
+ const size_t kMaxPendingRequests = MediaRouterMojoImpl::kMaxPendingRequests;
+
+ // Request is queued.
+ media_router_->CloseRoute(kRouteId);
+ EXPECT_EQ(1u, media_router_->pending_requests_.size());
+
+ for (size_t i = 0; i < kMaxPendingRequests; ++i)
+ media_router_->CloseRoute(kRouteId2);
+
+ // The request queue size should not exceed |kMaxPendingRequests|.
+ EXPECT_EQ(kMaxPendingRequests, media_router_->pending_requests_.size());
+
+ // The oldest request should have been dropped, so we don't expect to see
+ // CloseRoute(kRouteId) here.
+ BindMediaRouteProvider();
+ EXPECT_CALL(provide_handler_, Invoke(testing::Not("")));
+ EXPECT_CALL(*process_manager_, IsEventPageSuspended(kExtensionId))
+ .WillOnce(Return(false));
+ EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId2)))
+ .Times(kMaxPendingRequests);
+ RegisterMediaRouteProvider();
+ ProcessEventLoop();
+}
+
} // namespace media_router
« no previous file with comments | « chrome/browser/media/router/media_router_mojo_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698