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

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

Issue 2406483002: WIP - Add EME (Closed)
Patch Set: Rebase. Split RemotingSourceImpl. Addressed comments. Created 4 years, 2 months 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/remoting/remoting_controller.h" 5 #include "media/remoting/remoting_renderer_controller.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "media/base/audio_decoder_config.h" 10 #include "media/base/audio_decoder_config.h"
11 #include "media/base/limits.h" 11 #include "media/base/limits.h"
12 #include "media/base/media_util.h" 12 #include "media/base/media_util.h"
13 #include "media/base/video_decoder_config.h" 13 #include "media/base/video_decoder_config.h"
14 #include "mojo/public/cpp/bindings/strong_binding.h" 14 #include "mojo/public/cpp/bindings/strong_binding.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 17 matching lines...) Expand all
33 kCodecOpus, SampleFormat::kSampleFormatU8, 33 kCodecOpus, SampleFormat::kSampleFormatU8,
34 ChannelLayout::CHANNEL_LAYOUT_MONO, limits::kMinSampleRate, 34 ChannelLayout::CHANNEL_LAYOUT_MONO, limits::kMinSampleRate,
35 EmptyExtraData(), Unencrypted()); 35 EmptyExtraData(), Unencrypted());
36 return data; 36 return data;
37 } 37 }
38 38
39 class FakeRemoter final : public mojom::Remoter { 39 class FakeRemoter final : public mojom::Remoter {
40 public: 40 public:
41 // |start_will_fail| indicates whether starting remoting will fail. 41 // |start_will_fail| indicates whether starting remoting will fail.
42 FakeRemoter(mojom::RemotingSourcePtr source, bool start_will_fail) 42 FakeRemoter(mojom::RemotingSourcePtr source, bool start_will_fail)
43 : source_(std::move(source)), start_will_fail_(start_will_fail) {} 43 : source_(std::move(source)),
44 start_will_fail_(start_will_fail),
45 weak_factory_(this) {}
44 ~FakeRemoter() override {} 46 ~FakeRemoter() override {}
45 47
46 // mojom::Remoter implementations. 48 // mojom::Remoter implementations.
47 void Start() override { 49 void Start() override {
48 if (start_will_fail_) { 50 if (start_will_fail_) {
49 base::ThreadTaskRunnerHandle::Get()->PostTask( 51 base::ThreadTaskRunnerHandle::Get()->PostTask(
50 FROM_HERE, 52 FROM_HERE,
51 base::Bind(&FakeRemoter::StartFailed, base::Unretained(this))); 53 base::Bind(&FakeRemoter::StartFailed, weak_factory_.GetWeakPtr()));
52 } else { 54 } else {
53 base::ThreadTaskRunnerHandle::Get()->PostTask( 55 base::ThreadTaskRunnerHandle::Get()->PostTask(
54 FROM_HERE, base::Bind(&FakeRemoter::Started, base::Unretained(this))); 56 FROM_HERE,
57 base::Bind(&FakeRemoter::Started, weak_factory_.GetWeakPtr()));
55 } 58 }
56 } 59 }
57 60
58 void StartDataStreams( 61 void StartDataStreams(
59 mojo::ScopedDataPipeConsumerHandle audio_pipe, 62 mojo::ScopedDataPipeConsumerHandle audio_pipe,
60 mojo::ScopedDataPipeConsumerHandle video_pipe, 63 mojo::ScopedDataPipeConsumerHandle video_pipe,
61 mojom::RemotingDataStreamSenderRequest audio_sender_request, 64 mojom::RemotingDataStreamSenderRequest audio_sender_request,
62 mojom::RemotingDataStreamSenderRequest video_sender_request) override {} 65 mojom::RemotingDataStreamSenderRequest video_sender_request) override {}
63 66
64 void Stop(mojom::RemotingStopReason reason) override { 67 void Stop(mojom::RemotingStopReason reason) override {
65 base::ThreadTaskRunnerHandle::Get()->PostTask( 68 base::ThreadTaskRunnerHandle::Get()->PostTask(
66 FROM_HERE, 69 FROM_HERE,
67 base::Bind(&FakeRemoter::Stopped, base::Unretained(this), reason)); 70 base::Bind(&FakeRemoter::Stopped, weak_factory_.GetWeakPtr(), reason));
68 } 71 }
69 72
70 void SendMessageToSink(const std::vector<uint8_t>& message) override {} 73 void SendMessageToSink(const std::vector<uint8_t>& message) override {}
71 74
72 private: 75 private:
73 void Started() { source_->OnStarted(); } 76 void Started() { source_->OnStarted(); }
74 void StartFailed() { 77 void StartFailed() {
75 source_->OnStartFailed(mojom::RemotingStartFailReason::ROUTE_TERMINATED); 78 source_->OnStartFailed(mojom::RemotingStartFailReason::ROUTE_TERMINATED);
76 } 79 }
77 void Stopped(mojom::RemotingStopReason reason) { source_->OnStopped(reason); } 80 void Stopped(mojom::RemotingStopReason reason) { source_->OnStopped(reason); }
78 81
79 mojom::RemotingSourcePtr source_; 82 const mojom::RemotingSourcePtr source_;
80 bool start_will_fail_; 83 bool start_will_fail_;
81 84
85 base::WeakPtrFactory<FakeRemoter> weak_factory_;
86
82 DISALLOW_COPY_AND_ASSIGN(FakeRemoter); 87 DISALLOW_COPY_AND_ASSIGN(FakeRemoter);
83 }; 88 };
84 89
85 class FakeRemoterFactory final : public mojom::RemoterFactory { 90 class FakeRemoterFactory final : public mojom::RemoterFactory {
86 public: 91 public:
87 // |start_will_fail| indicates whether starting remoting will fail. 92 // |start_will_fail| indicates whether starting remoting will fail.
88 explicit FakeRemoterFactory(bool start_will_fail) 93 explicit FakeRemoterFactory(bool start_will_fail)
89 : start_will_fail_(start_will_fail) {} 94 : start_will_fail_(start_will_fail) {}
90 ~FakeRemoterFactory() override {} 95 ~FakeRemoterFactory() override {}
91 96
92 void Create(mojom::RemotingSourcePtr source, 97 void Create(mojom::RemotingSourcePtr source,
93 mojom::RemoterRequest request) override { 98 mojom::RemoterRequest request) override {
94 mojo::MakeStrongBinding( 99 mojo::MakeStrongBinding(
95 base::MakeUnique<FakeRemoter>(std::move(source), start_will_fail_), 100 base::MakeUnique<FakeRemoter>(std::move(source), start_will_fail_),
96 std::move(request)); 101 std::move(request));
97 } 102 }
98 103
99 private: 104 private:
100 bool start_will_fail_; 105 bool start_will_fail_;
101 106
102 DISALLOW_COPY_AND_ASSIGN(FakeRemoterFactory); 107 DISALLOW_COPY_AND_ASSIGN(FakeRemoterFactory);
103 }; 108 };
104 109
105 std::unique_ptr<RemotingController> CreateRemotingController( 110 scoped_refptr<RemotingSourceImpl> CreateRemotingSourceImpl(
106 mojom::RemoterFactory* remoter_factory) { 111 bool start_will_fail) {
107 mojom::RemotingSourcePtr remoting_source; 112 mojom::RemotingSourcePtr remoting_source;
108 mojom::RemotingSourceRequest remoting_source_request = 113 mojom::RemotingSourceRequest remoting_source_request =
109 mojo::GetProxy(&remoting_source); 114 mojo::GetProxy(&remoting_source);
110 mojom::RemoterPtr remoter; 115 mojom::RemoterPtr remoter;
116 std::unique_ptr<mojom::RemoterFactory> remoter_factory =
117 base::MakeUnique<FakeRemoterFactory>(start_will_fail);
111 remoter_factory->Create(std::move(remoting_source), mojo::GetProxy(&remoter)); 118 remoter_factory->Create(std::move(remoting_source), mojo::GetProxy(&remoter));
112 std::unique_ptr<RemotingController> remoting_controller = 119 return new RemotingSourceImpl(std::move(remoting_source_request),
113 base::MakeUnique<RemotingController>(std::move(remoting_source_request), 120 std::move(remoter));
114 std::move(remoter));
115 return remoting_controller;
116 } 121 }
117 122
118 } // namespace 123 } // namespace
119 124
120 class RemotingControllerTest : public ::testing::Test { 125 class RemotingRendererControllerTest : public ::testing::Test {
121 public: 126 public:
122 RemotingControllerTest() 127 RemotingRendererControllerTest() : is_remoting_(false) {}
123 : remoting_controller_( 128 ~RemotingRendererControllerTest() override {}
124 CreateRemotingController(new FakeRemoterFactory(false))),
125 is_remoting_(false) {
126 remoting_controller_->SetSwitchRendererCallback(base::Bind(
127 &RemotingControllerTest::ToggleRenderer, base::Unretained(this)));
128 }
129 ~RemotingControllerTest() override {}
130 129
131 void TearDown() final { RunUntilIdle(); } 130 void TearDown() final { RunUntilIdle(); }
132 131
133 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } 132 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); }
134 133
135 void ToggleRenderer() { is_remoting_ = remoting_controller_->is_remoting(); } 134 void ToggleRenderer() { is_remoting_ = remoting_controller_->IsRemoting(); }
136 135
137 base::MessageLoop message_loop_; 136 base::MessageLoop message_loop_;
138 137
139 protected: 138 protected:
140 std::unique_ptr<RemotingController> remoting_controller_; 139 std::unique_ptr<RemotingRendererController> remoting_controller_;
141 bool is_remoting_; 140 bool is_remoting_;
142 141
143 private: 142 private:
144 DISALLOW_COPY_AND_ASSIGN(RemotingControllerTest); 143 DISALLOW_COPY_AND_ASSIGN(RemotingRendererControllerTest);
145 }; 144 };
146 145
147 TEST_F(RemotingControllerTest, ToggleRenderer) { 146 TEST_F(RemotingRendererControllerTest, ToggleRenderer) {
148 EXPECT_FALSE(is_remoting_); 147 EXPECT_FALSE(is_remoting_);
149 remoting_controller_->OnSinkAvailable(); 148 scoped_refptr<RemotingSourceImpl> remoting_source_impl =
149 CreateRemotingSourceImpl(false);
150 remoting_controller_ =
151 base::MakeUnique<RemotingRendererController>(remoting_source_impl);
152 remoting_controller_->SetSwitchRendererCallback(base::Bind(
153 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this)));
154 remoting_source_impl->OnSinkAvailable();
miu 2016/10/25 04:21:26 You should add a call to RunUntilIdle() and EXPECT
xjz 2016/10/26 22:00:26 Done.
150 remoting_controller_->OnEnteredFullscreen(); 155 remoting_controller_->OnEnteredFullscreen();
151 EXPECT_FALSE(is_remoting_); 156 EXPECT_FALSE(is_remoting_);
152 remoting_controller_->OnMetadataChanged(defaultMetadata()); 157 remoting_controller_->OnMetadataChanged(defaultMetadata());
153 RunUntilIdle(); 158 RunUntilIdle();
154 EXPECT_TRUE(is_remoting_); 159 EXPECT_TRUE(is_remoting_);
155 remoting_controller_->OnExitedFullscreen(); 160 remoting_controller_->OnExitedFullscreen();
156 RunUntilIdle(); 161 RunUntilIdle();
157 EXPECT_FALSE(is_remoting_); 162 EXPECT_FALSE(is_remoting_);
158 } 163 }
159 164
160 TEST_F(RemotingControllerTest, StartFailed) { 165 TEST_F(RemotingRendererControllerTest, StartFailed) {
161 EXPECT_FALSE(is_remoting_); 166 EXPECT_FALSE(is_remoting_);
162 remoting_controller_ = CreateRemotingController(new FakeRemoterFactory(true)); 167 scoped_refptr<RemotingSourceImpl> remoting_source_impl =
168 CreateRemotingSourceImpl(true);
169 remoting_controller_ =
170 base::MakeUnique<RemotingRendererController>(remoting_source_impl);
163 remoting_controller_->SetSwitchRendererCallback(base::Bind( 171 remoting_controller_->SetSwitchRendererCallback(base::Bind(
164 &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); 172 &RemotingRendererControllerTest::ToggleRenderer, base::Unretained(this)));
165 remoting_controller_->OnSinkAvailable(); 173 remoting_source_impl->OnSinkAvailable();
166 remoting_controller_->OnEnteredFullscreen(); 174 remoting_controller_->OnEnteredFullscreen();
167 remoting_controller_->OnMetadataChanged(defaultMetadata()); 175 remoting_controller_->OnMetadataChanged(defaultMetadata());
168 RunUntilIdle(); 176 RunUntilIdle();
169 EXPECT_FALSE(is_remoting_); 177 EXPECT_FALSE(is_remoting_);
170 } 178 }
171 179
172 } // namespace media 180 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698