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

Side by Side Diff: media/remoting/remoting_controller_unittest.cc

Issue 2457563002: Media Remoting: Add remoting control logic for encrypted contents. (Closed)
Patch Set: Rebase Only. Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
(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 PipelineMetadata defaultMetadata() {
25 PipelineMetadata data;
26 data.has_audio = true;
27 data.has_video = true;
28 data.video_decoder_config = VideoDecoderConfig(
29 kCodecVP8, VP8PROFILE_ANY, VideoPixelFormat::PIXEL_FORMAT_I420,
30 ColorSpace::COLOR_SPACE_SD_REC601, kCodedSize, kVisibleRect, kNaturalSize,
31 EmptyExtraData(), Unencrypted());
32 data.audio_decoder_config = AudioDecoderConfig(
33 kCodecOpus, SampleFormat::kSampleFormatU8,
34 ChannelLayout::CHANNEL_LAYOUT_MONO, limits::kMinSampleRate,
35 EmptyExtraData(), Unencrypted());
36 return data;
37 }
38
39 class FakeRemoter final : public mojom::Remoter {
40 public:
41 // |start_will_fail| indicates whether starting remoting will fail.
42 FakeRemoter(mojom::RemotingSourcePtr source, bool start_will_fail)
43 : source_(std::move(source)), start_will_fail_(start_will_fail) {}
44 ~FakeRemoter() override {}
45
46 // mojom::Remoter implementations.
47 void Start() override {
48 if (start_will_fail_) {
49 base::ThreadTaskRunnerHandle::Get()->PostTask(
50 FROM_HERE,
51 base::Bind(&FakeRemoter::StartFailed, base::Unretained(this)));
52 } else {
53 base::ThreadTaskRunnerHandle::Get()->PostTask(
54 FROM_HERE, base::Bind(&FakeRemoter::Started, base::Unretained(this)));
55 }
56 }
57
58 void StartDataStreams(
59 mojo::ScopedDataPipeConsumerHandle audio_pipe,
60 mojo::ScopedDataPipeConsumerHandle video_pipe,
61 mojom::RemotingDataStreamSenderRequest audio_sender_request,
62 mojom::RemotingDataStreamSenderRequest video_sender_request) override {}
63
64 void Stop(mojom::RemotingStopReason reason) override {
65 base::ThreadTaskRunnerHandle::Get()->PostTask(
66 FROM_HERE,
67 base::Bind(&FakeRemoter::Stopped, base::Unretained(this), reason));
68 }
69
70 void SendMessageToSink(const std::vector<uint8_t>& message) override {}
71
72 private:
73 void Started() { source_->OnStarted(); }
74 void StartFailed() {
75 source_->OnStartFailed(mojom::RemotingStartFailReason::ROUTE_TERMINATED);
76 }
77 void Stopped(mojom::RemotingStopReason reason) { source_->OnStopped(reason); }
78
79 mojom::RemotingSourcePtr source_;
80 bool start_will_fail_;
81
82 DISALLOW_COPY_AND_ASSIGN(FakeRemoter);
83 };
84
85 class FakeRemoterFactory final : public mojom::RemoterFactory {
86 public:
87 // |start_will_fail| indicates whether starting remoting will fail.
88 explicit FakeRemoterFactory(bool start_will_fail)
89 : start_will_fail_(start_will_fail) {}
90 ~FakeRemoterFactory() override {}
91
92 void Create(mojom::RemotingSourcePtr source,
93 mojom::RemoterRequest request) override {
94 mojo::MakeStrongBinding(
95 base::MakeUnique<FakeRemoter>(std::move(source), start_will_fail_),
96 std::move(request));
97 }
98
99 private:
100 bool start_will_fail_;
101
102 DISALLOW_COPY_AND_ASSIGN(FakeRemoterFactory);
103 };
104
105 std::unique_ptr<RemotingController> CreateRemotingController(
106 bool start_will_fail) {
107 mojom::RemotingSourcePtr remoting_source;
108 mojom::RemotingSourceRequest remoting_source_request =
109 mojo::GetProxy(&remoting_source);
110 mojom::RemoterPtr remoter;
111 std::unique_ptr<mojom::RemoterFactory> remoter_factory =
112 base::MakeUnique<FakeRemoterFactory>(start_will_fail);
113 remoter_factory->Create(std::move(remoting_source), mojo::GetProxy(&remoter));
114 std::unique_ptr<RemotingController> remoting_controller =
115 base::MakeUnique<RemotingController>(std::move(remoting_source_request),
116 std::move(remoter));
117 return remoting_controller;
118 }
119
120 } // namespace
121
122 class RemotingControllerTest : public ::testing::Test {
123 public:
124 RemotingControllerTest()
125 : remoting_controller_(CreateRemotingController(false)),
126 is_remoting_(false) {
127 remoting_controller_->SetSwitchRendererCallback(base::Bind(
128 &RemotingControllerTest::ToggleRenderer, base::Unretained(this)));
129 }
130 ~RemotingControllerTest() override {}
131
132 void TearDown() final { RunUntilIdle(); }
133
134 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); }
135
136 void ToggleRenderer() { is_remoting_ = remoting_controller_->is_remoting(); }
137
138 base::MessageLoop message_loop_;
139
140 protected:
141 std::unique_ptr<RemotingController> remoting_controller_;
142 bool is_remoting_;
143
144 private:
145 DISALLOW_COPY_AND_ASSIGN(RemotingControllerTest);
146 };
147
148 TEST_F(RemotingControllerTest, ToggleRenderer) {
149 EXPECT_FALSE(is_remoting_);
150 remoting_controller_->OnSinkAvailable();
151 remoting_controller_->OnEnteredFullscreen();
152 EXPECT_FALSE(is_remoting_);
153 remoting_controller_->OnMetadataChanged(defaultMetadata());
154 RunUntilIdle();
155 EXPECT_TRUE(is_remoting_);
156 remoting_controller_->OnExitedFullscreen();
157 RunUntilIdle();
158 EXPECT_FALSE(is_remoting_);
159 }
160
161 TEST_F(RemotingControllerTest, StartFailed) {
162 EXPECT_FALSE(is_remoting_);
163 remoting_controller_ = CreateRemotingController(true);
164 remoting_controller_->SetSwitchRendererCallback(base::Bind(
165 &RemotingControllerTest::ToggleRenderer, base::Unretained(this)));
166 remoting_controller_->OnSinkAvailable();
167 remoting_controller_->OnEnteredFullscreen();
168 remoting_controller_->OnMetadataChanged(defaultMetadata());
169 RunUntilIdle();
170 EXPECT_FALSE(is_remoting_);
171 }
172
173 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698