Commit 23e80815 authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

Enable MirroringService by default

Enable the feature and remove some CastRemotingConnector tests that are
deprecated.

Bug: 956609
Change-Id: I4e5931ff0b2b8b1c455c53d9f1e2e865004d3095
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929398Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723024}
parent c50865f6
......@@ -334,7 +334,7 @@ void CastRemotingConnector::StartRemoting(RemotingBridge* bridge) {
if (remoting_allowed_.has_value()) {
StartRemotingIfPermitted();
} else {
base::OnceCallback<void(bool)> dialog_result_callback(base::BindOnce(
PermissionResultCallback dialog_result_callback(base::BindOnce(
[](base::WeakPtr<CastRemotingConnector> connector, bool is_allowed) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!connector)
......
......@@ -261,7 +261,6 @@ class CastRemotingConnectorTest : public ::testing::Test {
return CastRemotingConnector::CancelPermissionRequestCallback();
},
remoting_allowed)));
EXPECT_EQ(kRemotingTabId, media_router_.tab_id());
}
CastRemotingConnector* GetConnector() const { return connector_.get(); }
......@@ -391,11 +390,10 @@ TEST_F(CastRemotingConnectorTest, NoPermissionToStart) {
MockRemotingSource source;
mojo::Remote<media::mojom::Remoter> remoter(CreateRemoter(&source));
std::unique_ptr<MockMediaRemoter> media_remoter =
std::make_unique<MockMediaRemoter>(GetMediaRouter());
std::make_unique<MockMediaRemoter>(GetConnector());
EXPECT_CALL(source, OnStartFailed(RemotingStartFailReason::ROUTE_TERMINATED))
.Times(1);
EXPECT_CALL(source, OnSinkGone()).Times(AtLeast(1));
remoter->Start();
RunUntilIdle();
}
......@@ -629,316 +627,3 @@ INSTANTIATE_TEST_SUITE_P(All,
ROUTE_TERMINATES,
EXTERNAL_FAILURE,
USER_DISABLED));
// TODO(crbug.com/1015486): Remove the following tests after Mirroring Service
// is launched.
TEST_F(CastRemotingConnectorTest,
DeprecatedNotifiesWhenSinkIsAvailableAndThenGone) {
MockRemotingSource source;
mojo::Remote<media::mojom::Remoter> remoter(CreateRemoter(&source));
std::unique_ptr<MockMediaRemoter> media_remoter =
std::make_unique<MockMediaRemoter>(GetMediaRouter());
EXPECT_CALL(source, OnSinkAvailable(_)).Times(1);
media_remoter->OnSinkAvailable();
RunUntilIdle();
EXPECT_CALL(source, OnSinkGone()).Times(AtLeast(1));
media_remoter.reset();
RunUntilIdle();
}
TEST_F(CastRemotingConnectorTest,
DeprecatedNotifiesMultipleSourcesWhenSinkIsAvailableAndThenGone) {
MockRemotingSource source1;
mojo::Remote<media::mojom::Remoter> remoter1(CreateRemoter(&source1));
MockRemotingSource source2;
mojo::Remote<media::mojom::Remoter> remoter2(CreateRemoter(&source2));
std::unique_ptr<MockMediaRemoter> media_remoter =
std::make_unique<MockMediaRemoter>(GetMediaRouter());
EXPECT_CALL(source1, OnSinkAvailable(_)).Times(1);
EXPECT_CALL(source2, OnSinkAvailable(_)).Times(1);
media_remoter->OnSinkAvailable();
RunUntilIdle();
EXPECT_CALL(source1, OnSinkGone()).Times(AtLeast(1));
EXPECT_CALL(source2, OnSinkGone()).Times(AtLeast(1));
media_remoter.reset();
RunUntilIdle();
}
TEST_F(CastRemotingConnectorTest,
DeprecatedHandlesTeardownOfRemotingSourceFirst) {
std::unique_ptr<MockRemotingSource> source(new MockRemotingSource);
mojo::Remote<media::mojom::Remoter> remoter(CreateRemoter(source.get()));
std::unique_ptr<MockMediaRemoter> media_remoter =
std::make_unique<MockMediaRemoter>(GetMediaRouter());
EXPECT_CALL(*source, OnSinkAvailable(_)).Times(1);
media_remoter->OnSinkAvailable();
RunUntilIdle();
source.reset();
RunUntilIdle();
}
TEST_F(CastRemotingConnectorTest, DeprecatedHandlesTeardownOfRemoterFirst) {
MockRemotingSource source;
mojo::Remote<media::mojom::Remoter> remoter(CreateRemoter(&source));
std::unique_ptr<MockMediaRemoter> media_remoter =
std::make_unique<MockMediaRemoter>(GetMediaRouter());
EXPECT_CALL(source, OnSinkAvailable(_)).Times(1);
media_remoter->OnSinkAvailable();
RunUntilIdle();
remoter.reset();
RunUntilIdle();
}
TEST_F(CastRemotingConnectorTest, DeprecatedUserDisableRemoting) {
MockRemotingSource source1;
mojo::Remote<media::mojom::Remoter> remoter1(CreateRemoter(&source1));
MockRemotingSource source2;
mojo::Remote<media::mojom::Remoter> remoter2(CreateRemoter(&source2));
std::unique_ptr<MockMediaRemoter> media_remoter =
std::make_unique<MockMediaRemoter>(GetMediaRouter());
EXPECT_CALL(source1, OnSinkAvailable(_)).Times(1);
EXPECT_CALL(source2, OnSinkAvailable(_)).Times(1);
media_remoter->OnSinkAvailable();
RunUntilIdle();
// All sources will get notified that sink is gone when user explicitly
// disabled media remoting.
EXPECT_CALL(source1, OnSinkGone()).Times(AtLeast(1));
EXPECT_CALL(source2, OnSinkGone()).Times(AtLeast(1));
DisableRemoting();
RunUntilIdle();
}
class DeprecatedCastRemotingConnectorFullSessionTest
: public CastRemotingConnectorTest,
public ::testing::WithParamInterface<HowItEnds> {
public:
HowItEnds how_it_ends() const { return GetParam(); }
};
// Performs a full run-through of starting and stopping remoting, with
// communications between source and sink established at the correct times, and
// tests that end-to-end behavior is correct depending on what caused the
// remoting session to end.
TEST_P(DeprecatedCastRemotingConnectorFullSessionTest,
GoesThroughAllTheMotions) {
std::unique_ptr<MockRemotingSource> source(new MockRemotingSource());
mojo::Remote<media::mojom::Remoter> remoter(CreateRemoter(source.get()));
std::unique_ptr<MockRemotingSource> other_source(new MockRemotingSource());
mojo::Remote<media::mojom::Remoter> other_remoter(
CreateRemoter(other_source.get()));
std::unique_ptr<MockMediaRemoter> media_remoter =
std::make_unique<MockMediaRemoter>(GetMediaRouter());
// Throughout this test |other_source| should not participate in the
// remoting session, and so these method calls should never occur:
EXPECT_CALL(*other_source, OnStarted()).Times(0);
EXPECT_CALL(*other_source, OnStopped(_)).Times(0);
EXPECT_CALL(*other_source, OnMessageFromSink(_)).Times(0);
// Both sinks should be notified when the Cast Provider tells the connector
// a remoting sink is available.
EXPECT_CALL(*source, OnSinkAvailable(_)).Times(1);
EXPECT_CALL(*other_source, OnSinkAvailable(_)).Times(1);
media_remoter->OnSinkAvailable();
RunUntilIdle();
// When |source| starts a remoting session, |other_source| is notified the
// sink is gone, the Cast Provider is notified that remoting has started,
// 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, RequestStart()).Times(1).RetiresOnSaturation();
remoter->Start();
RunUntilIdle();
// 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();
// 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();
media_remoter->SendMessageToSource(message_to_source);
RunUntilIdle();
// The |other_source| should not be allowed to start a remoting session.
EXPECT_CALL(*other_source,
OnStartFailed(RemotingStartFailReason::CANNOT_START_MULTIPLE))
.Times(1)
.RetiresOnSaturation();
other_remoter->Start();
RunUntilIdle();
// What happens from here depends on how this remoting session will end...
switch (how_it_ends()) {
case SOURCE_TERMINATES: {
// When the |source| stops the remoting session, the Cast Provider is
// notified the session has stopped, and the |source| receives both an
// OnStopped() and an OnSinkGone() notification.
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();
// 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);
media_remoter->SendMessageToSource(message_to_source);
RunUntilIdle();
// 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
// again available.
EXPECT_CALL(*source, OnSinkAvailable(_)).Times(1);
EXPECT_CALL(*other_source, OnSinkAvailable(_)).Times(1);
media_remoter->OnSinkAvailable();
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));
media_remoter.reset();
RunUntilIdle();
break;
}
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();
// 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();
break;
case ROUTE_TERMINATES:
// When the Media Router terminates the route (e.g., because a user
// 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(*other_source, OnSinkGone()).Times(AtLeast(0));
// 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);
EXPECT_CALL(*source, OnStopped(RemotingStopReason::SERVICE_GONE))
.Times(1)
.RetiresOnSaturation();
media_remoter.reset();
RunUntilIdle();
break;
case EXTERNAL_FAILURE: {
// When the Cast Provider is cut-off from the sink, it sends a fail
// notification to the connector. The connector, in turn, force-stops the
// remoting session and notifies the |source|.
EXPECT_CALL(*source, OnSinkGone()).Times(1).RetiresOnSaturation();
EXPECT_CALL(*source, OnStopped(RemotingStopReason::UNEXPECTED_FAILURE))
.Times(1)
.RetiresOnSaturation();
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
// 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);
media_remoter->SendMessageToSource(message_to_source);
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));
media_remoter.reset();
RunUntilIdle();
break;
}
case USER_DISABLED: {
// When user explicitly disabled remoting, the active remoting session
// will be stopped.
EXPECT_CALL(*source, OnSinkGone()).Times(AtLeast(1));
EXPECT_CALL(*other_source, OnSinkGone()).Times(0);
EXPECT_CALL(*source, OnSinkAvailable(_)).Times(0);
EXPECT_CALL(*other_source, OnSinkAvailable(_)).Times(0);
EXPECT_CALL(*source, OnStopped(RemotingStopReason::USER_DISABLED))
.Times(1);
EXPECT_CALL(*media_remoter, Stop(RemotingStopReason::USER_DISABLED))
.Times(1);
DisableRemoting();
// All sources will get notified that sink is gone, and no further
// remoting sessions can be initiated before user re-enables remoting.
RunUntilIdle();
EXPECT_CALL(*source, OnSinkGone()).Times(AtLeast(1));
EXPECT_CALL(*other_source, OnSinkGone()).Times(AtLeast(1));
EXPECT_CALL(*source, OnSinkAvailable(_)).Times(0);
EXPECT_CALL(*other_source, OnSinkAvailable(_)).Times(0);
media_remoter->OnStopped(RemotingStopReason::USER_DISABLED);
RunUntilIdle();
break;
}
}
}
INSTANTIATE_TEST_SUITE_P(All,
DeprecatedCastRemotingConnectorFullSessionTest,
::testing::Values(SOURCE_TERMINATES,
MOJO_PIPE_CLOSES,
ROUTE_TERMINATES,
EXTERNAL_FAILURE,
USER_DISABLED));
......@@ -9,7 +9,7 @@ namespace features {
// Enables or disables Mirroring Service.
const base::Feature kMirroringService{"MirroringService",
base::FEATURE_DISABLED_BY_DEFAULT};
base::FEATURE_ENABLED_BY_DEFAULT};
} // namespace features
} // namespace mirroring
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment