Index: chrome/browser/media/cast_remoting_connector_unittest.cc |
diff --git a/chrome/browser/media/cast_remoting_connector_unittest.cc b/chrome/browser/media/cast_remoting_connector_unittest.cc |
index a258a7ae1273400677d7c8bad6b3ceb6af5fa83b..9f0af26323016f7749f63f232cab38fc2a4fe7b7 100644 |
--- a/chrome/browser/media/cast_remoting_connector_unittest.cc |
+++ b/chrome/browser/media/cast_remoting_connector_unittest.cc |
@@ -8,16 +8,15 @@ |
#include <vector> |
#include "base/callback.h" |
+#include "base/memory/ptr_util.h" |
#include "base/memory/weak_ptr.h" |
#include "base/run_loop.h" |
-#include "chrome/browser/media/router/media_routes_observer.h" |
#include "chrome/browser/media/router/mock_media_router.h" |
-#include "chrome/browser/media/router/route_message_observer.h" |
#include "chrome/common/media_router/media_route.h" |
#include "chrome/common/media_router/media_source.h" |
-#include "chrome/common/media_router/route_message.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
+#include "media/mojo/interfaces/mirror_service_remoting.mojom.h" |
#include "media/mojo/interfaces/remoting.mojom.h" |
#include "mojo/public/cpp/bindings/binding.h" |
#include "testing/gmock/include/gmock/gmock.h" |
@@ -32,28 +31,17 @@ using media::mojom::RemotingSourcePtr; |
using media::mojom::RemotingSourceRequest; |
using media::mojom::RemotingStartFailReason; |
using media::mojom::RemotingStopReason; |
- |
-using media_router::MediaRoutesObserver; |
-using media_router::MediaRoute; |
-using media_router::MediaSource; |
-using media_router::RouteMessage; |
-using media_router::RouteMessageObserver; |
+using media::mojom::MirrorServiceRemoterPtr; |
+using media::mojom::MirrorServiceRemoterRequest; |
+using media::mojom::MirrorServiceRemotingSourcePtr; |
+using media::mojom::MirrorServiceRemotingSourceRequest; |
using ::testing::_; |
using ::testing::AtLeast; |
namespace { |
-constexpr char kRemotingMediaSource[] = |
- "urn:x-org.chromium.media:source:tab_content_remoting:123"; |
-constexpr char kRemotingMediaSink[] = "wiggles"; |
-constexpr char kRemotingMediaRoute[] = |
- "urn:x-org.chromium:media:route:garbly_gook_ssi7m4oa8oma7rasd/cast-wiggles"; |
- |
-constexpr char kTabMirroringMediaSource[] = |
- "urn:x-org.chromium.media:source:tab:123"; |
-constexpr char kTabMirroringMediaRoute[] = |
- "urn:x-org.chromium:media:route:bloopity_blop_ohun48i56nh9oid/cast-wiggles"; |
+constexpr int32_t kRemotingTabId = 2; |
constexpr RemotingSinkCapabilities kAllCapabilities = |
RemotingSinkCapabilities::CONTENT_DECRYPTION_AND_RENDERING; |
@@ -63,153 +51,40 @@ constexpr RemotingSinkCapabilities kAllCapabilities = |
// if any methods were called that should not have been called. |
class FakeMediaRouter : public media_router::MockMediaRouter { |
public: |
- FakeMediaRouter() |
- : routes_observer_(nullptr), message_observer_(nullptr), |
- weak_factory_(this) {} |
+ FakeMediaRouter() : weak_factory_(this) {} |
~FakeMediaRouter() final {} |
- // |
- // These methods are called by test code to create/destroy a media route and |
- // pass messages in both directions. |
- // |
- |
- void OnRemotingRouteExists(bool exists) { |
- routes_.clear(); |
- |
- // Always add a non-remoting route to make sure CastRemotingConnector |
- // ignores non-remoting routes. |
- routes_.push_back(MediaRoute( |
- kTabMirroringMediaRoute, MediaSource(kTabMirroringMediaSource), |
- kRemotingMediaSink, "Cast Tab Mirroring", false, "", false)); |
- |
- if (exists) { |
- routes_.push_back(MediaRoute( |
- kRemotingMediaRoute, MediaSource(kRemotingMediaSource), |
- kRemotingMediaSink, "Cast Media Remoting", false, "", false)); |
- } else { |
- // Cancel delivery of all messages in both directions. |
- inbound_messages_.clear(); |
- for (auto& entry : outbound_messages_) { |
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
- base::BindOnce(std::move(entry.second), false)); |
- } |
- outbound_messages_.clear(); |
- } |
- |
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
- base::BindOnce(&FakeMediaRouter::DoUpdateRoutes, |
- weak_factory_.GetWeakPtr())); |
- } |
- |
- void OnMessageFromProvider(const std::string& message) { |
- inbound_messages_.push_back(RouteMessage()); |
- inbound_messages_.back().type = RouteMessage::TEXT; |
- inbound_messages_.back().text = message; |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- base::BindOnce(&FakeMediaRouter::DoDeliverInboundMessages, |
- weak_factory_.GetWeakPtr())); |
- } |
- |
- void OnBinaryMessageFromProvider(const std::vector<uint8_t>& message) { |
- inbound_messages_.push_back(RouteMessage()); |
- inbound_messages_.back().type = RouteMessage::BINARY; |
- inbound_messages_.back().binary = std::vector<uint8_t>(message); |
- BrowserThread::PostTask( |
- BrowserThread::UI, FROM_HERE, |
- base::BindOnce(&FakeMediaRouter::DoDeliverInboundMessages, |
- weak_factory_.GetWeakPtr())); |
- } |
- |
- void TakeMessagesSentToProvider(RouteMessage::Type type, |
- std::vector<RouteMessage>* messages) { |
- decltype(outbound_messages_) untaken_messages; |
- for (auto& entry : outbound_messages_) { |
- if (entry.first.type == type) { |
- messages->push_back(entry.first); |
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
- base::BindOnce(std::move(entry.second), true)); |
- } else { |
- untaken_messages.push_back(std::move(entry)); |
- } |
- } |
- outbound_messages_.swap(untaken_messages); |
- } |
- |
- protected: |
- void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) final { |
- CHECK(!routes_observer_); |
- routes_observer_ = observer; |
- CHECK(routes_observer_); |
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
- base::BindOnce(&FakeMediaRouter::DoUpdateRoutes, |
- weak_factory_.GetWeakPtr())); |
- } |
- |
- void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) final { |
- CHECK_EQ(routes_observer_, observer); |
- routes_observer_ = nullptr; |
+ void RegisterRemotingSource(int32_t tab_id, |
+ CastRemotingConnector* remoting_source) final { |
+ DCHECK_EQ(-1, tab_id_); |
+ tab_id_ = tab_id; |
+ connector_ = remoting_source; |
} |
- void RegisterRouteMessageObserver(RouteMessageObserver* observer) final { |
- CHECK(!message_observer_); |
- message_observer_ = observer; |
- CHECK(message_observer_); |
+ void UnregisterRemotingSource(int32_t tab_id) final { |
+ DCHECK_EQ(tab_id, tab_id_); |
+ tab_id_ = -1; |
+ connector_ = nullptr; |
} |
- void UnregisterRouteMessageObserver(RouteMessageObserver* observer) final { |
- CHECK_EQ(message_observer_, observer); |
- message_observer_ = nullptr; |
- } |
+ void OnMediaRemoterCreated( |
+ int32_t tab_id, |
+ MirrorServiceRemoterPtr remoter, |
+ MirrorServiceRemotingSourceRequest remoting_source) { |
+ if (tab_id != tab_id_) |
+ return; |
- void SendRouteMessage(const MediaRoute::Id& route_id, |
- const std::string& text, |
- SendRouteMessageCallback callback) final { |
- EXPECT_EQ(message_observer_->route_id(), route_id); |
- ASSERT_FALSE(callback.is_null()); |
- RouteMessage message; |
- message.type = RouteMessage::TEXT; |
- message.text = text; |
- outbound_messages_.push_back(std::make_pair(message, std::move(callback))); |
+ DCHECK(connector_); |
+ connector_->ConnectToService(std::move(remoting_source), |
+ std::move(remoter)); |
} |
- void SendRouteBinaryMessage(const MediaRoute::Id& route_id, |
- std::unique_ptr<std::vector<uint8_t>> data, |
- SendRouteMessageCallback callback) final { |
- EXPECT_EQ(message_observer_->route_id(), route_id); |
- ASSERT_TRUE(!!data); |
- ASSERT_FALSE(callback.is_null()); |
- RouteMessage message; |
- message.type = RouteMessage::BINARY; |
- message.binary = std::move(*data); |
- outbound_messages_.push_back(std::make_pair(message, std::move(callback))); |
- } |
+ // Get the registered tab ID. |
+ int32_t tab_id() { return tab_id_; } |
private: |
- // Asynchronous callback to notify the MediaRoutesObserver of a change in |
- // routes. |
- void DoUpdateRoutes() { |
- if (routes_observer_) |
- routes_observer_->OnRoutesUpdated(routes_, std::vector<MediaRoute::Id>()); |
- } |
- |
- // Asynchronous callback to deliver messages to the RouteMessageObserver. |
- void DoDeliverInboundMessages() { |
- if (message_observer_) |
- message_observer_->OnMessagesReceived(inbound_messages_); |
- inbound_messages_.clear(); |
- } |
- |
- MediaRoutesObserver* routes_observer_; |
- RouteMessageObserver* message_observer_; |
- |
- std::vector<MediaRoute> routes_; |
- // Messages from Cast Provider to the connector. |
- std::vector<RouteMessage> inbound_messages_; |
- // Messages from the connector to the Cast Provider. |
- using OutboundMessageAndCallback = |
- std::pair<RouteMessage, SendRouteMessageCallback>; |
- std::vector<OutboundMessageAndCallback> outbound_messages_; |
+ int32_t tab_id_ = -1; |
+ CastRemotingConnector* connector_; |
base::WeakPtrFactory<FakeMediaRouter> weak_factory_; |
}; |
@@ -234,15 +109,56 @@ class MockRemotingSource : public media::mojom::RemotingSource { |
mojo::Binding<media::mojom::RemotingSource> binding_; |
}; |
+class MockMediaRemoter : public media::mojom::MirrorServiceRemoter { |
+ public: |
+ explicit MockMediaRemoter(FakeMediaRouter* media_router) : binding_(this) { |
+ MirrorServiceRemoterPtr remoter; |
+ binding_.Bind(mojo::MakeRequest(&remoter)); |
+ media_router->OnMediaRemoterCreated(kRemotingTabId, std::move(remoter), |
+ mojo::MakeRequest(&source_)); |
+ } |
+ ~MockMediaRemoter() final {} |
+ |
+ void OnSinkAvailable() { |
+ if (source_) |
+ source_->OnSinkAvailable(kAllCapabilities); |
+ } |
+ |
+ void SendMessageToSource(const std::vector<uint8_t>& message) { |
+ if (source_) |
+ source_->OnMessageFromSink(message); |
+ } |
+ |
+ void OnStopped(RemotingStopReason reason) { |
+ if (source_) |
+ source_->OnStopped(reason); |
+ } |
+ |
+ void OnError() { |
+ if (source_) |
+ source_->OnError(); |
+ } |
+ |
+ MOCK_METHOD0(Start, void()); |
+ MOCK_METHOD2(StartDataStreams, void(bool, bool)); |
+ MOCK_METHOD1(Stop, void(RemotingStopReason)); |
+ MOCK_METHOD1(SendMessageToSink, void(const std::vector<uint8_t>&)); |
+ |
+ private: |
+ mojo::Binding<media::mojom::MirrorServiceRemoter> binding_; |
+ MirrorServiceRemotingSourcePtr source_; |
+}; |
+ |
} // namespace |
class CastRemotingConnectorTest : public ::testing::Test { |
public: |
- CastRemotingConnectorTest() |
- : connector_(&media_router_, kRemotingMediaSource) { |
+ CastRemotingConnectorTest() : connector_(&media_router_, kRemotingTabId) { |
// HACK: Override feature flags for testing. |
const_cast<RemotingSinkCapabilities&>(connector_.enabled_features_) = |
kAllCapabilities; |
+ |
+ EXPECT_EQ(kRemotingTabId, media_router_.tab_id()); |
} |
void TearDown() final { |
@@ -262,77 +178,14 @@ class CastRemotingConnectorTest : public ::testing::Test { |
return remoter_ptr; |
} |
- void ProviderDiscoversSink() { |
- media_router_.OnRemotingRouteExists(true); |
- } |
- |
- void ProviderLosesSink() { |
- media_router_.OnRemotingRouteExists(false); |
- } |
- |
- void ConnectorSentMessageToProvider(const std::string& expected_message) { |
- std::vector<RouteMessage> messages; |
- media_router_.TakeMessagesSentToProvider(RouteMessage::TEXT, &messages); |
- bool did_see_expected_message = false; |
- for (const RouteMessage& message : messages) { |
- if (message.text && expected_message == *message.text) { |
- did_see_expected_message = true; |
- } else { |
- ADD_FAILURE() |
- << "Unexpected message: " << message.ToHumanReadableString(); |
- } |
- } |
- EXPECT_TRUE(did_see_expected_message); |
- } |
- |
- void ConnectorSentMessageToSink( |
- const std::vector<uint8_t>& expected_message) { |
- std::vector<RouteMessage> messages; |
- media_router_.TakeMessagesSentToProvider(RouteMessage::BINARY, &messages); |
- bool did_see_expected_message = false; |
- for (const RouteMessage& message : messages) { |
- if (message.binary && expected_message == *message.binary) { |
- did_see_expected_message = true; |
- } else { |
- ADD_FAILURE() |
- << "Unexpected message: " << message.ToHumanReadableString(); |
- } |
- } |
- EXPECT_TRUE(did_see_expected_message); |
- } |
- |
- void ConnectorSentNoMessagesToProvider() { |
- std::vector<RouteMessage> messages; |
- media_router_.TakeMessagesSentToProvider(RouteMessage::TEXT, &messages); |
- EXPECT_TRUE(messages.empty()); |
- } |
- |
- void ConnectorSentNoMessagesToSink() { |
- std::vector<RouteMessage> messages; |
- media_router_.TakeMessagesSentToProvider(RouteMessage::BINARY, &messages); |
- EXPECT_TRUE(messages.empty()); |
- } |
- |
- void ProviderPassesMessageFromSink( |
- const std::vector<uint8_t>& message) { |
- media_router_.OnBinaryMessageFromProvider(message); |
- } |
- |
- void ProviderSaysToRemotingConnector(const std::string& message) { |
- media_router_.OnMessageFromProvider(message); |
- } |
- |
- void MediaRouterTerminatesRoute() { |
- media_router_.OnRemotingRouteExists(false); |
- } |
- |
static void RunUntilIdle() { |
base::RunLoop().RunUntilIdle(); |
} |
+ FakeMediaRouter media_router_; |
+ |
private: |
content::TestBrowserThreadBundle browser_thread_bundle_; |
- FakeMediaRouter media_router_; |
CastRemotingConnector connector_; |
}; |
@@ -349,12 +202,15 @@ TEST_F(CastRemotingConnectorTest, NotifiesWhenSinkIsAvailableAndThenGone) { |
MockRemotingSource source; |
RemoterPtr remoter = CreateRemoter(&source); |
+ std::unique_ptr<MockMediaRemoter> media_remoter = |
+ base::MakeUnique<MockMediaRemoter>(&media_router_); |
+ |
EXPECT_CALL(source, OnSinkAvailable(kAllCapabilities)).Times(1); |
- ProviderDiscoversSink(); |
+ media_remoter->OnSinkAvailable(); |
RunUntilIdle(); |
EXPECT_CALL(source, OnSinkGone()).Times(AtLeast(1)); |
- ProviderLosesSink(); |
+ media_remoter.reset(); |
RunUntilIdle(); |
} |
@@ -365,14 +221,17 @@ TEST_F(CastRemotingConnectorTest, |
MockRemotingSource source2; |
RemoterPtr remoter2 = CreateRemoter(&source2); |
+ std::unique_ptr<MockMediaRemoter> media_remoter = |
+ base::MakeUnique<MockMediaRemoter>(&media_router_); |
+ |
EXPECT_CALL(source1, OnSinkAvailable(kAllCapabilities)).Times(1); |
EXPECT_CALL(source2, OnSinkAvailable(kAllCapabilities)).Times(1); |
- ProviderDiscoversSink(); |
+ media_remoter->OnSinkAvailable(); |
RunUntilIdle(); |
EXPECT_CALL(source1, OnSinkGone()).Times(AtLeast(1)); |
EXPECT_CALL(source2, OnSinkGone()).Times(AtLeast(1)); |
- ProviderLosesSink(); |
+ media_remoter.reset(); |
RunUntilIdle(); |
} |
@@ -380,8 +239,11 @@ TEST_F(CastRemotingConnectorTest, HandlesTeardownOfRemotingSourceFirst) { |
std::unique_ptr<MockRemotingSource> source(new MockRemotingSource); |
RemoterPtr remoter = CreateRemoter(source.get()); |
+ std::unique_ptr<MockMediaRemoter> media_remoter = |
+ base::MakeUnique<MockMediaRemoter>(&media_router_); |
+ |
EXPECT_CALL(*source, OnSinkAvailable(kAllCapabilities)).Times(1); |
- ProviderDiscoversSink(); |
+ media_remoter->OnSinkAvailable(); |
RunUntilIdle(); |
source.reset(); |
@@ -392,14 +254,28 @@ TEST_F(CastRemotingConnectorTest, HandlesTeardownOfRemoterFirst) { |
MockRemotingSource source; |
RemoterPtr remoter = CreateRemoter(&source); |
+ std::unique_ptr<MockMediaRemoter> media_remoter = |
+ base::MakeUnique<MockMediaRemoter>(&media_router_); |
+ |
EXPECT_CALL(source, OnSinkAvailable(kAllCapabilities)).Times(1); |
- ProviderDiscoversSink(); |
+ media_remoter->OnSinkAvailable(); |
RunUntilIdle(); |
remoter.reset(); |
RunUntilIdle(); |
} |
+TEST_F(CastRemotingConnectorTest, NoConnectedMediaRemoter) { |
+ MockRemotingSource source; |
+ RemoterPtr remoter = CreateRemoter(&source); |
+ |
+ EXPECT_CALL(source, |
+ OnStartFailed(RemotingStartFailReason::SERVICE_NOT_CONNECTED)) |
+ .Times(1); |
+ remoter->Start(); |
+ RunUntilIdle(); |
+} |
+ |
namespace { |
// The possible ways a remoting session may be terminated in the "full |
@@ -429,6 +305,8 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
RemoterPtr remoter = CreateRemoter(source.get()); |
std::unique_ptr<MockRemotingSource> other_source(new MockRemotingSource()); |
RemoterPtr other_remoter = CreateRemoter(other_source.get()); |
+ std::unique_ptr<MockMediaRemoter> media_remoter = |
+ base::MakeUnique<MockMediaRemoter>(&media_router_); |
// Throughout this test |other_source| should not participate in the |
// remoting session, and so these method calls should never occur: |
@@ -442,7 +320,7 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
.RetiresOnSaturation(); |
EXPECT_CALL(*other_source, OnSinkAvailable(kAllCapabilities)).Times(1) |
.RetiresOnSaturation(); |
- ProviderDiscoversSink(); |
+ media_remoter->OnSinkAvailable(); |
RunUntilIdle(); |
// When |source| starts a remoting session, |other_source| is notified the |
@@ -450,24 +328,28 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
// and |source| is notified that its request was successful. |
EXPECT_CALL(*source, OnStarted()).Times(1).RetiresOnSaturation(); |
EXPECT_CALL(*other_source, OnSinkGone()).Times(1).RetiresOnSaturation(); |
+ EXPECT_CALL(*media_remoter, Start()).Times(1).RetiresOnSaturation(); |
remoter->Start(); |
RunUntilIdle(); |
- ConnectorSentMessageToProvider("START_CAST_REMOTING:session=1"); |
// The |source| should now be able to send binary messages to the sink. |
// |other_source| should not! |
const std::vector<uint8_t> message_to_sink = { 3, 1, 4, 1, 5, 9 }; |
+ EXPECT_CALL(*media_remoter, SendMessageToSink(message_to_sink)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
remoter->SendMessageToSink(message_to_sink); |
const std::vector<uint8_t> ignored_message_to_sink = { 1, 2, 3 }; |
+ EXPECT_CALL(*media_remoter, SendMessageToSink(ignored_message_to_sink)) |
+ .Times(0); |
other_remoter->SendMessageToSink(ignored_message_to_sink); |
RunUntilIdle(); |
- ConnectorSentMessageToSink(message_to_sink); |
// The sink should also be able to send binary messages to the |source|. |
const std::vector<uint8_t> message_to_source = { 2, 7, 1, 8, 2, 8 }; |
EXPECT_CALL(*source, OnMessageFromSink(message_to_source)).Times(1) |
.RetiresOnSaturation(); |
- ProviderPassesMessageFromSink(message_to_source); |
+ media_remoter->SendMessageToSource(message_to_source); |
RunUntilIdle(); |
// The |other_source| should not be allowed to start a remoting session. |
@@ -476,7 +358,6 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
.Times(1).RetiresOnSaturation(); |
other_remoter->Start(); |
RunUntilIdle(); |
- ConnectorSentNoMessagesToProvider(); |
// What happens from here depends on how this remoting session will end... |
switch (how_it_ends()) { |
@@ -487,19 +368,19 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
const RemotingStopReason reason = RemotingStopReason::LOCAL_PLAYBACK; |
EXPECT_CALL(*source, OnSinkGone()).Times(1).RetiresOnSaturation(); |
EXPECT_CALL(*source, OnStopped(reason)).Times(1).RetiresOnSaturation(); |
+ EXPECT_CALL(*media_remoter, Stop(reason)).Times(1).RetiresOnSaturation(); |
remoter->Stop(reason); |
RunUntilIdle(); |
- ConnectorSentMessageToProvider("STOP_CAST_REMOTING:session=1"); |
// Since remoting is stopped, any further messaging in either direction |
// must be dropped. |
const std::vector<uint8_t> message_to_sink = { 1, 6, 1, 8, 0, 3 }; |
const std::vector<uint8_t> message_to_source = { 6, 2, 8, 3, 1, 8 }; |
EXPECT_CALL(*source, OnMessageFromSink(_)).Times(0); |
+ EXPECT_CALL(*media_remoter, SendMessageToSink(_)).Times(0); |
remoter->SendMessageToSink(message_to_sink); |
- ProviderPassesMessageFromSink(message_to_source); |
+ media_remoter->SendMessageToSource(message_to_source); |
RunUntilIdle(); |
- ConnectorSentNoMessagesToSink(); |
// When the sink is ready, the Cast Provider sends a notification to the |
// connector. The connector will notify both sources that a sink is once |
@@ -508,14 +389,14 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
.RetiresOnSaturation(); |
EXPECT_CALL(*other_source, OnSinkAvailable(kAllCapabilities)).Times(1) |
.RetiresOnSaturation(); |
- ProviderSaysToRemotingConnector("STOPPED_CAST_REMOTING:session=1"); |
+ media_remoter->OnStopped(reason); |
RunUntilIdle(); |
// When the sink is no longer available, the Cast Provider notifies the |
// connector, and both sources are then notified the sink is gone. |
EXPECT_CALL(*source, OnSinkGone()).Times(AtLeast(1)); |
EXPECT_CALL(*other_source, OnSinkGone()).Times(AtLeast(1)); |
- ProviderLosesSink(); |
+ media_remoter.reset(); |
RunUntilIdle(); |
break; |
@@ -524,23 +405,17 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
case MOJO_PIPE_CLOSES: |
// When the Mojo pipes for |other_source| close, this should not affect |
// the current remoting session. |
+ EXPECT_CALL(*media_remoter, Stop(_)).Times(0); |
other_source.reset(); |
other_remoter.reset(); |
RunUntilIdle(); |
- ConnectorSentNoMessagesToProvider(); |
// Now, when the Mojo pipes for |source| close, the Cast Provider will be |
// notified that the session has stopped. |
+ EXPECT_CALL(*media_remoter, Stop(_)).Times(1).RetiresOnSaturation(); |
source.reset(); |
remoter.reset(); |
RunUntilIdle(); |
- ConnectorSentMessageToProvider("STOP_CAST_REMOTING:session=1"); |
- |
- // The Cast Provider will detect when the sink is ready for the next |
- // remoting session, and then notify the connector. However, there are no |
- // sources to propagate this notification to. |
- ProviderSaysToRemotingConnector("STOPPED_CAST_REMOTING:session=1"); |
- RunUntilIdle(); |
break; |
@@ -549,20 +424,14 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
// terminated the route from the UI), the source and sink are immediately |
// cut off from one another. |
EXPECT_CALL(*source, OnSinkGone()).Times(AtLeast(1)); |
- EXPECT_CALL(*source, OnStopped(RemotingStopReason::ROUTE_TERMINATED)) |
- .Times(1).RetiresOnSaturation(); |
EXPECT_CALL(*other_source, OnSinkGone()).Times(AtLeast(0)); |
- MediaRouterTerminatesRoute(); |
- RunUntilIdle(); |
- ConnectorSentNoMessagesToProvider(); |
- |
// Furthermore, the connector and Cast Provider are also cut off from one |
// another and should not be able to exchange messages anymore. Therefore, |
// the connector will never try to notify the sources that the sink is |
// available again. |
EXPECT_CALL(*source, OnSinkAvailable(_)).Times(0); |
EXPECT_CALL(*other_source, OnSinkAvailable(_)).Times(0); |
- ProviderSaysToRemotingConnector("STOPPED_CAST_REMOTING:session=1"); |
+ media_remoter.reset(); |
RunUntilIdle(); |
break; |
@@ -574,7 +443,10 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
EXPECT_CALL(*source, OnSinkGone()).Times(1).RetiresOnSaturation(); |
EXPECT_CALL(*source, OnStopped(RemotingStopReason::UNEXPECTED_FAILURE)) |
.Times(1).RetiresOnSaturation(); |
- ProviderSaysToRemotingConnector("FAILED_CAST_REMOTING:session=1"); |
+ EXPECT_CALL(*media_remoter, Stop(RemotingStopReason::UNEXPECTED_FAILURE)) |
+ .Times(1) |
+ .RetiresOnSaturation(); |
+ media_remoter->OnError(); |
RunUntilIdle(); |
// Since remoting is stopped, any further messaging in either direction |
@@ -582,10 +454,10 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
const std::vector<uint8_t> message_to_sink = { 1, 6, 1, 8, 0, 3 }; |
const std::vector<uint8_t> message_to_source = { 6, 2, 8, 3, 1, 8 }; |
EXPECT_CALL(*source, OnMessageFromSink(_)).Times(0); |
+ EXPECT_CALL(*media_remoter, SendMessageToSink(_)).Times(0); |
remoter->SendMessageToSink(message_to_sink); |
- ProviderPassesMessageFromSink(message_to_source); |
+ media_remoter->SendMessageToSource(message_to_source); |
RunUntilIdle(); |
- ConnectorSentNoMessagesToSink(); |
// Later, if whatever caused the external failure has resolved, the Cast |
// Provider will notify the connector that the sink is available one |
@@ -594,14 +466,14 @@ TEST_P(CastRemotingConnectorFullSessionTest, GoesThroughAllTheMotions) { |
.RetiresOnSaturation(); |
EXPECT_CALL(*other_source, OnSinkAvailable(kAllCapabilities)).Times(1) |
.RetiresOnSaturation(); |
- ProviderSaysToRemotingConnector("STOPPED_CAST_REMOTING:session=1"); |
+ media_remoter->OnStopped(RemotingStopReason::UNEXPECTED_FAILURE); |
RunUntilIdle(); |
// When the sink is no longer available, the Cast Provider notifies the |
// connector, and both sources are then notified the sink is gone. |
EXPECT_CALL(*source, OnSinkGone()).Times(AtLeast(1)); |
EXPECT_CALL(*other_source, OnSinkGone()).Times(AtLeast(1)); |
- ProviderLosesSink(); |
+ media_remoter.reset(); |
RunUntilIdle(); |
break; |