OLD | NEW |
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_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" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 std::move(request)); | 96 std::move(request)); |
97 } | 97 } |
98 | 98 |
99 private: | 99 private: |
100 bool start_will_fail_; | 100 bool start_will_fail_; |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(FakeRemoterFactory); | 102 DISALLOW_COPY_AND_ASSIGN(FakeRemoterFactory); |
103 }; | 103 }; |
104 | 104 |
105 std::unique_ptr<RemotingController> CreateRemotingController( | 105 std::unique_ptr<RemotingController> CreateRemotingController( |
106 mojom::RemoterFactory* remoter_factory) { | 106 bool start_will_fail) { |
107 mojom::RemotingSourcePtr remoting_source; | 107 mojom::RemotingSourcePtr remoting_source; |
108 mojom::RemotingSourceRequest remoting_source_request = | 108 mojom::RemotingSourceRequest remoting_source_request = |
109 mojo::GetProxy(&remoting_source); | 109 mojo::GetProxy(&remoting_source); |
110 mojom::RemoterPtr remoter; | 110 mojom::RemoterPtr remoter; |
| 111 std::unique_ptr<mojom::RemoterFactory> remoter_factory = |
| 112 base::MakeUnique<FakeRemoterFactory>(start_will_fail); |
111 remoter_factory->Create(std::move(remoting_source), mojo::GetProxy(&remoter)); | 113 remoter_factory->Create(std::move(remoting_source), mojo::GetProxy(&remoter)); |
112 std::unique_ptr<RemotingController> remoting_controller = | 114 std::unique_ptr<RemotingController> remoting_controller = |
113 base::MakeUnique<RemotingController>(std::move(remoting_source_request), | 115 base::MakeUnique<RemotingController>(std::move(remoting_source_request), |
114 std::move(remoter)); | 116 std::move(remoter)); |
115 return remoting_controller; | 117 return remoting_controller; |
116 } | 118 } |
117 | 119 |
118 } // namespace | 120 } // namespace |
119 | 121 |
120 class RemotingControllerTest : public ::testing::Test { | 122 class RemotingControllerTest : public ::testing::Test { |
121 public: | 123 public: |
122 RemotingControllerTest() | 124 RemotingControllerTest() |
123 : remoting_controller_( | 125 : remoting_controller_(CreateRemotingController(false)), |
124 CreateRemotingController(new FakeRemoterFactory(false))), | |
125 is_remoting_(false) { | 126 is_remoting_(false) { |
126 remoting_controller_->SetSwitchRendererCallback(base::Bind( | 127 remoting_controller_->SetSwitchRendererCallback(base::Bind( |
127 &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); | 128 &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); |
128 } | 129 } |
129 ~RemotingControllerTest() override {} | 130 ~RemotingControllerTest() override {} |
130 | 131 |
131 void TearDown() final { RunUntilIdle(); } | 132 void TearDown() final { RunUntilIdle(); } |
132 | 133 |
133 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } | 134 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } |
134 | 135 |
(...skipping 17 matching lines...) Expand all Loading... |
152 remoting_controller_->OnMetadataChanged(defaultMetadata()); | 153 remoting_controller_->OnMetadataChanged(defaultMetadata()); |
153 RunUntilIdle(); | 154 RunUntilIdle(); |
154 EXPECT_TRUE(is_remoting_); | 155 EXPECT_TRUE(is_remoting_); |
155 remoting_controller_->OnExitedFullscreen(); | 156 remoting_controller_->OnExitedFullscreen(); |
156 RunUntilIdle(); | 157 RunUntilIdle(); |
157 EXPECT_FALSE(is_remoting_); | 158 EXPECT_FALSE(is_remoting_); |
158 } | 159 } |
159 | 160 |
160 TEST_F(RemotingControllerTest, StartFailed) { | 161 TEST_F(RemotingControllerTest, StartFailed) { |
161 EXPECT_FALSE(is_remoting_); | 162 EXPECT_FALSE(is_remoting_); |
162 remoting_controller_ = CreateRemotingController(new FakeRemoterFactory(true)); | 163 remoting_controller_ = CreateRemotingController(true); |
163 remoting_controller_->SetSwitchRendererCallback(base::Bind( | 164 remoting_controller_->SetSwitchRendererCallback(base::Bind( |
164 &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); | 165 &RemotingControllerTest::ToggleRenderer, base::Unretained(this))); |
165 remoting_controller_->OnSinkAvailable(); | 166 remoting_controller_->OnSinkAvailable(); |
166 remoting_controller_->OnEnteredFullscreen(); | 167 remoting_controller_->OnEnteredFullscreen(); |
167 remoting_controller_->OnMetadataChanged(defaultMetadata()); | 168 remoting_controller_->OnMetadataChanged(defaultMetadata()); |
168 RunUntilIdle(); | 169 RunUntilIdle(); |
169 EXPECT_FALSE(is_remoting_); | 170 EXPECT_FALSE(is_remoting_); |
170 } | 171 } |
171 | 172 |
172 } // namespace media | 173 } // namespace media |
OLD | NEW |