Chromium Code Reviews| Index: media/remoting/remoting_controller_unittest.cc |
| diff --git a/media/remoting/remoting_controller_unittest.cc b/media/remoting/remoting_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1128fc46ae14b38c6bac8906a4ac520682289399 |
| --- /dev/null |
| +++ b/media/remoting/remoting_controller_unittest.cc |
| @@ -0,0 +1,147 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/remoting/remoting_controller.h" |
| + |
| +#include "base/callback.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "media/base/audio_decoder_config.h" |
| +#include "media/base/limits.h" |
| +#include "media/base/media_util.h" |
| +#include "media/base/video_decoder_config.h" |
| +#include "mojo/public/cpp/bindings/strong_binding.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace media { |
| +namespace { |
| + |
| +constexpr gfx::Size kCodedSize(320, 240); |
| +constexpr gfx::Rect kVisibleRect(320, 240); |
| +constexpr gfx::Size kNaturalSize(320, 240); |
| + |
| +AudioDecoderConfig defaultAudioConfig() { |
| + AudioDecoderConfig config(kCodecOpus, SampleFormat::kSampleFormatU8, |
| + ChannelLayout::CHANNEL_LAYOUT_MONO, |
| + limits::kMinSampleRate, EmptyExtraData(), |
| + Unencrypted()); |
| + return config; |
| +} |
| + |
| +VideoDecoderConfig defaultVideoConfig() { |
| + VideoDecoderConfig config( |
| + kCodecVP8, VP8PROFILE_ANY, VideoPixelFormat::PIXEL_FORMAT_I420, |
| + ColorSpace::COLOR_SPACE_SD_REC601, kCodedSize, kVisibleRect, kNaturalSize, |
| + EmptyExtraData(), Unencrypted()); |
| + return config; |
| +} |
| + |
| +class FakeRemoter final : public mojom::Remoter { |
| + public: |
| + FakeRemoter(mojom::RemotingSourcePtr source, bool enable_remoting) |
|
miu
2016/09/30 08:12:10
naming nit: Instead of |enable_remoting|, this is
xjz
2016/10/01 00:28:41
Renamed as |start_will_fail|.
|
| + : source_(std::move(source)), enable_remoting_(enable_remoting) {} |
| + ~FakeRemoter() override {} |
| + |
| + // mojom::Remoter implementations. |
| + void Start() override { |
| + if (enable_remoting_) |
| + source_->OnStarted(); |
|
miu
2016/09/30 08:12:10
Because OnStarted() is called later, on a reply IP
xjz
2016/10/01 00:28:41
Done.
|
| + else |
| + source_->OnStartFailed(mojom::RemotingStartFailReason::ROUTE_TERMINATED); |
|
miu
2016/09/30 08:12:10
ditto here: post task
xjz
2016/10/01 00:28:41
Done.
|
| + } |
| + |
| + void StartDataStreams( |
| + mojo::ScopedDataPipeConsumerHandle audio_pipe, |
| + mojo::ScopedDataPipeConsumerHandle video_pipe, |
| + mojom::RemotingDataStreamSenderRequest audio_sender_request, |
| + mojom::RemotingDataStreamSenderRequest video_sender_request) override {} |
| + |
| + void Stop(mojom::RemotingStopReason reason) override { |
| + source_->OnStopped(mojom::RemotingStopReason::LOCAL_PLAYBACK); |
|
miu
2016/09/30 08:12:10
ditto here: post task
xjz
2016/10/01 00:28:41
Done.
|
| + } |
| + |
| + void SendMessageToSink(const std::vector<uint8_t>& message) override {} |
| + |
| + private: |
| + mojom::RemotingSourcePtr source_; |
| + bool enable_remoting_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FakeRemoter); |
| +}; |
| + |
| +class FakeRemoterFactory final : public mojom::RemoterFactory { |
| + public: |
| + FakeRemoterFactory(bool enable_remoting) |
|
miu
2016/09/30 08:12:10
explicit
xjz
2016/10/01 00:28:41
Done.
|
| + : enable_remoting_(enable_remoting) {} |
| + ~FakeRemoterFactory() override {} |
| + |
| + void Create(mojom::RemotingSourcePtr source, |
| + mojom::RemoterRequest request) override { |
| + mojo::MakeStrongBinding( |
| + base::MakeUnique<FakeRemoter>(std::move(source), enable_remoting_), |
| + std::move(request)); |
| + } |
| + |
| + private: |
| + bool enable_remoting_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FakeRemoterFactory); |
| +}; |
| + |
| +} // namespace |
| + |
| +class RemotingControllerTest : public ::testing::Test { |
| + public: |
| + RemotingControllerTest() |
| + : remoting_controller_( |
| + new RemotingController(new FakeRemoterFactory(true))), |
| + is_remoting_(false) { |
| + remoting_controller_->SetSwitchRenderCallback(base::Bind( |
| + &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); |
| + } |
| + ~RemotingControllerTest() override {} |
| + |
| + void TearDown() final { RunUntilIdle(); } |
| + |
| + static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } |
| + |
| + void ToggleRenderer() { is_remoting_ = !is_remoting_; } |
| + |
| + base::MessageLoop message_loop_; |
| + |
| + protected: |
| + std::unique_ptr<RemotingController> remoting_controller_; |
| + bool is_remoting_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(RemotingControllerTest); |
| +}; |
| + |
| +TEST_F(RemotingControllerTest, ToggleRenderer) { |
| + EXPECT_FALSE(is_remoting_); |
| + remoting_controller_->OnSinkAvailable(); |
| + remoting_controller_->OnEnteredFullscreen(); |
| + EXPECT_FALSE(is_remoting_); |
| + remoting_controller_->OnDecoderConfigChanged(defaultAudioConfig(), |
| + defaultVideoConfig()); |
| + RunUntilIdle(); |
| + EXPECT_TRUE(is_remoting_); |
| + remoting_controller_->OnExitedFullscreen(); |
| + RunUntilIdle(); |
| + EXPECT_FALSE(is_remoting_); |
| +} |
| + |
| +TEST_F(RemotingControllerTest, StartFailed) { |
| + EXPECT_FALSE(is_remoting_); |
| + remoting_controller_.reset( |
| + new RemotingController(new FakeRemoterFactory(false))); |
| + remoting_controller_->OnSinkAvailable(); |
| + remoting_controller_->OnEnteredFullscreen(); |
| + remoting_controller_->OnDecoderConfigChanged(defaultAudioConfig(), |
| + defaultVideoConfig()); |
| + RunUntilIdle(); |
| + EXPECT_FALSE(is_remoting_); |
| +} |
| + |
| +} // namespace media |