Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/remoting/remoting_controller.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "media/base/audio_decoder_config.h" | |
| 11 #include "media/base/limits.h" | |
| 12 #include "media/base/media_util.h" | |
| 13 #include "media/base/video_decoder_config.h" | |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 namespace media { | |
| 18 namespace { | |
| 19 | |
| 20 constexpr gfx::Size kCodedSize(320, 240); | |
| 21 constexpr gfx::Rect kVisibleRect(320, 240); | |
| 22 constexpr gfx::Size kNaturalSize(320, 240); | |
| 23 | |
| 24 AudioDecoderConfig defaultAudioConfig() { | |
| 25 AudioDecoderConfig config(kCodecOpus, SampleFormat::kSampleFormatU8, | |
| 26 ChannelLayout::CHANNEL_LAYOUT_MONO, | |
| 27 limits::kMinSampleRate, EmptyExtraData(), | |
| 28 Unencrypted()); | |
| 29 return config; | |
| 30 } | |
| 31 | |
| 32 VideoDecoderConfig defaultVideoConfig() { | |
| 33 VideoDecoderConfig config( | |
| 34 kCodecVP8, VP8PROFILE_ANY, VideoPixelFormat::PIXEL_FORMAT_I420, | |
| 35 ColorSpace::COLOR_SPACE_SD_REC601, kCodedSize, kVisibleRect, kNaturalSize, | |
| 36 EmptyExtraData(), Unencrypted()); | |
| 37 return config; | |
| 38 } | |
| 39 | |
| 40 class FakeRemoter final : public mojom::Remoter { | |
| 41 public: | |
| 42 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|.
| |
| 43 : source_(std::move(source)), enable_remoting_(enable_remoting) {} | |
| 44 ~FakeRemoter() override {} | |
| 45 | |
| 46 // mojom::Remoter implementations. | |
| 47 void Start() override { | |
| 48 if (enable_remoting_) | |
| 49 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.
| |
| 50 else | |
| 51 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.
| |
| 52 } | |
| 53 | |
| 54 void StartDataStreams( | |
| 55 mojo::ScopedDataPipeConsumerHandle audio_pipe, | |
| 56 mojo::ScopedDataPipeConsumerHandle video_pipe, | |
| 57 mojom::RemotingDataStreamSenderRequest audio_sender_request, | |
| 58 mojom::RemotingDataStreamSenderRequest video_sender_request) override {} | |
| 59 | |
| 60 void Stop(mojom::RemotingStopReason reason) override { | |
| 61 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.
| |
| 62 } | |
| 63 | |
| 64 void SendMessageToSink(const std::vector<uint8_t>& message) override {} | |
| 65 | |
| 66 private: | |
| 67 mojom::RemotingSourcePtr source_; | |
| 68 bool enable_remoting_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(FakeRemoter); | |
| 71 }; | |
| 72 | |
| 73 class FakeRemoterFactory final : public mojom::RemoterFactory { | |
| 74 public: | |
| 75 FakeRemoterFactory(bool enable_remoting) | |
|
miu
2016/09/30 08:12:10
explicit
xjz
2016/10/01 00:28:41
Done.
| |
| 76 : enable_remoting_(enable_remoting) {} | |
| 77 ~FakeRemoterFactory() override {} | |
| 78 | |
| 79 void Create(mojom::RemotingSourcePtr source, | |
| 80 mojom::RemoterRequest request) override { | |
| 81 mojo::MakeStrongBinding( | |
| 82 base::MakeUnique<FakeRemoter>(std::move(source), enable_remoting_), | |
| 83 std::move(request)); | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 bool enable_remoting_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(FakeRemoterFactory); | |
| 90 }; | |
| 91 | |
| 92 } // namespace | |
| 93 | |
| 94 class RemotingControllerTest : public ::testing::Test { | |
| 95 public: | |
| 96 RemotingControllerTest() | |
| 97 : remoting_controller_( | |
| 98 new RemotingController(new FakeRemoterFactory(true))), | |
| 99 is_remoting_(false) { | |
| 100 remoting_controller_->SetSwitchRenderCallback(base::Bind( | |
| 101 &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); | |
| 102 } | |
| 103 ~RemotingControllerTest() override {} | |
| 104 | |
| 105 void TearDown() final { RunUntilIdle(); } | |
| 106 | |
| 107 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } | |
| 108 | |
| 109 void ToggleRenderer() { is_remoting_ = !is_remoting_; } | |
| 110 | |
| 111 base::MessageLoop message_loop_; | |
| 112 | |
| 113 protected: | |
| 114 std::unique_ptr<RemotingController> remoting_controller_; | |
| 115 bool is_remoting_; | |
| 116 | |
| 117 private: | |
| 118 DISALLOW_COPY_AND_ASSIGN(RemotingControllerTest); | |
| 119 }; | |
| 120 | |
| 121 TEST_F(RemotingControllerTest, ToggleRenderer) { | |
| 122 EXPECT_FALSE(is_remoting_); | |
| 123 remoting_controller_->OnSinkAvailable(); | |
| 124 remoting_controller_->OnEnteredFullscreen(); | |
| 125 EXPECT_FALSE(is_remoting_); | |
| 126 remoting_controller_->OnDecoderConfigChanged(defaultAudioConfig(), | |
| 127 defaultVideoConfig()); | |
| 128 RunUntilIdle(); | |
| 129 EXPECT_TRUE(is_remoting_); | |
| 130 remoting_controller_->OnExitedFullscreen(); | |
| 131 RunUntilIdle(); | |
| 132 EXPECT_FALSE(is_remoting_); | |
| 133 } | |
| 134 | |
| 135 TEST_F(RemotingControllerTest, StartFailed) { | |
| 136 EXPECT_FALSE(is_remoting_); | |
| 137 remoting_controller_.reset( | |
| 138 new RemotingController(new FakeRemoterFactory(false))); | |
| 139 remoting_controller_->OnSinkAvailable(); | |
| 140 remoting_controller_->OnEnteredFullscreen(); | |
| 141 remoting_controller_->OnDecoderConfigChanged(defaultAudioConfig(), | |
| 142 defaultVideoConfig()); | |
| 143 RunUntilIdle(); | |
| 144 EXPECT_FALSE(is_remoting_); | |
| 145 } | |
| 146 | |
| 147 } // namespace media | |
| OLD | NEW |