OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "content/renderer/media/mojo_audio_output_ipc.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <utility> |
| 11 |
| 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/optional.h" |
| 14 #include "base/run_loop.h" |
| 15 #include "base/test/gtest_util.h" |
| 16 #include "media/audio/audio_device_description.h" |
| 17 #include "media/base/audio_parameters.h" |
| 18 #include "mojo/public/cpp/bindings/binding.h" |
| 19 #include "mojo/public/cpp/system/platform_handle.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "url/origin.h" |
| 23 |
| 24 using testing::_; |
| 25 using testing::AtLeast; |
| 26 using testing::Mock; |
| 27 using testing::StrictMock; |
| 28 |
| 29 namespace content { |
| 30 |
| 31 namespace { |
| 32 |
| 33 const int kSessionId = 1234; |
| 34 const size_t kMemoryLength = 4321; |
| 35 const char kDeviceId[] = "device_id"; |
| 36 const char kReturnedDeviceId[] = "returned_device_id"; |
| 37 const double kNewVolume = 0.271828; |
| 38 |
| 39 url::Origin Origin() { |
| 40 return {}; |
| 41 } |
| 42 |
| 43 media::AudioParameters Params() { |
| 44 return media::AudioParameters::UnavailableDeviceParams(); |
| 45 } |
| 46 |
| 47 MojoAudioOutputIPC::FactoryAccessorCB NullAccessor() { |
| 48 return base::BindRepeating( |
| 49 []() -> mojom::RendererAudioOutputStreamFactory* { return nullptr; }); |
| 50 } |
| 51 |
| 52 class TestRemoteFactory : public mojom::RendererAudioOutputStreamFactory { |
| 53 public: |
| 54 TestRemoteFactory() |
| 55 : expect_request_(false), |
| 56 binding_(this, mojo::MakeRequest(&this_proxy_)) {} |
| 57 |
| 58 ~TestRemoteFactory() override {} |
| 59 |
| 60 void RequestDeviceAuthorization( |
| 61 media::mojom::AudioOutputStreamProviderRequest stream_provider_request, |
| 62 int64_t session_id, |
| 63 const std::string& device_id, |
| 64 RequestDeviceAuthorizationCallback callback) override { |
| 65 EXPECT_EQ(session_id, expected_session_id_); |
| 66 EXPECT_EQ(device_id, expected_device_id_); |
| 67 EXPECT_TRUE(expect_request_); |
| 68 if (provider_) { |
| 69 std::move(callback).Run( |
| 70 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, Params(), |
| 71 std::string(kReturnedDeviceId)); |
| 72 provider_binding_.emplace(provider_.get(), |
| 73 std::move(stream_provider_request)); |
| 74 } else { |
| 75 std::move(callback).Run( |
| 76 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, |
| 77 Params(), std::string("")); |
| 78 } |
| 79 expect_request_ = false; |
| 80 } |
| 81 |
| 82 void PrepareProviderForAuthorization( |
| 83 int64_t session_id, |
| 84 const std::string& device_id, |
| 85 std::unique_ptr<media::mojom::AudioOutputStreamProvider> provider) { |
| 86 EXPECT_FALSE(expect_request_); |
| 87 expect_request_ = true; |
| 88 expected_session_id_ = session_id; |
| 89 expected_device_id_ = device_id; |
| 90 provider_binding_.reset(); |
| 91 std::swap(provider_, provider); |
| 92 } |
| 93 |
| 94 void RefuseNextRequest(int64_t session_id, const std::string& device_id) { |
| 95 EXPECT_FALSE(expect_request_); |
| 96 expect_request_ = true; |
| 97 expected_session_id_ = session_id; |
| 98 expected_device_id_ = device_id; |
| 99 } |
| 100 |
| 101 void Disconnect() { |
| 102 binding_.Close(); |
| 103 this_proxy_.reset(); |
| 104 binding_.Bind(mojo::MakeRequest(&this_proxy_)); |
| 105 provider_binding_.reset(); |
| 106 provider_.reset(); |
| 107 expect_request_ = false; |
| 108 } |
| 109 |
| 110 MojoAudioOutputIPC::FactoryAccessorCB GetAccessor() { |
| 111 return base::BindRepeating(&TestRemoteFactory::get, base::Unretained(this)); |
| 112 } |
| 113 |
| 114 private: |
| 115 mojom::RendererAudioOutputStreamFactory* get() { return this_proxy_.get(); } |
| 116 |
| 117 bool expect_request_; |
| 118 int64_t expected_session_id_; |
| 119 std::string expected_device_id_; |
| 120 |
| 121 mojom::RendererAudioOutputStreamFactoryPtr this_proxy_; |
| 122 mojo::Binding<mojom::RendererAudioOutputStreamFactory> binding_; |
| 123 std::unique_ptr<media::mojom::AudioOutputStreamProvider> provider_; |
| 124 base::Optional<mojo::Binding<media::mojom::AudioOutputStreamProvider>> |
| 125 provider_binding_; |
| 126 }; |
| 127 |
| 128 class TestStreamProvider : public media::mojom::AudioOutputStreamProvider { |
| 129 public: |
| 130 explicit TestStreamProvider(media::mojom::AudioOutputStream* stream) |
| 131 : stream_(stream) {} |
| 132 |
| 133 ~TestStreamProvider() override { |
| 134 // If we expected a stream to be acquired, make sure it is so. |
| 135 if (stream_) |
| 136 EXPECT_TRUE(binding_); |
| 137 } |
| 138 |
| 139 void Acquire(media::mojom::AudioOutputStreamRequest stream_request, |
| 140 const media::AudioParameters& params, |
| 141 const AcquireCallback& callback) override { |
| 142 EXPECT_EQ(binding_, base::nullopt); |
| 143 EXPECT_NE(stream_, nullptr); |
| 144 binding_.emplace(stream_, std::move(stream_request)); |
| 145 base::CancelableSyncSocket foreign_socket; |
| 146 EXPECT_TRUE( |
| 147 base::CancelableSyncSocket::CreatePair(&socket_, &foreign_socket)); |
| 148 std::move(callback).Run(mojo::SharedBufferHandle::Create(kMemoryLength), |
| 149 mojo::WrapPlatformFile(foreign_socket.Release())); |
| 150 } |
| 151 |
| 152 private: |
| 153 media::mojom::AudioOutputStream* stream_; |
| 154 base::Optional<mojo::Binding<media::mojom::AudioOutputStream>> binding_; |
| 155 base::CancelableSyncSocket socket_; |
| 156 }; |
| 157 |
| 158 class MockStream : public media::mojom::AudioOutputStream { |
| 159 public: |
| 160 MOCK_METHOD0(Play, void()); |
| 161 MOCK_METHOD0(Pause, void()); |
| 162 MOCK_METHOD1(SetVolume, void(double)); |
| 163 }; |
| 164 |
| 165 class MockDelegate : public media::AudioOutputIPCDelegate { |
| 166 public: |
| 167 MockDelegate() {} |
| 168 ~MockDelegate() override {} |
| 169 |
| 170 void OnStreamCreated(base::SharedMemoryHandle mem_handle, |
| 171 base::SyncSocket::Handle socket_handle, |
| 172 int length) { |
| 173 base::SharedMemory sh_mem( |
| 174 mem_handle, /*read_only*/ false); // Releases the shared memory handle. |
| 175 base::SyncSocket socket(socket_handle); // Releases the socket descriptor. |
| 176 GotOnStreamCreated(length); |
| 177 } |
| 178 |
| 179 MOCK_METHOD0(OnError, void()); |
| 180 MOCK_METHOD3(OnDeviceAuthorized, |
| 181 void(media::OutputDeviceStatus device_status, |
| 182 const media::AudioParameters& output_params, |
| 183 const std::string& matched_device_id)); |
| 184 MOCK_METHOD1(GotOnStreamCreated, void(int length)); |
| 185 MOCK_METHOD0(OnIPCClosed, void()); |
| 186 }; |
| 187 |
| 188 } // namespace |
| 189 |
| 190 TEST(MojoAudioOutputIPC, AuthorizeWithoutFactory_CallsOnIPCClosed) { |
| 191 base::MessageLoopForIO message_loop; |
| 192 StrictMock<MockDelegate> delegate; |
| 193 |
| 194 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 195 base::MakeUnique<MojoAudioOutputIPC>(NullAccessor()); |
| 196 |
| 197 EXPECT_CALL(delegate, OnIPCClosed()); |
| 198 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 199 base::RunLoop().RunUntilIdle(); |
| 200 } |
| 201 |
| 202 TEST(MojoAudioOutputIPC, CreateWithoutFactoryOrAuthorization_CallsOnIPCClosed) { |
| 203 base::MessageLoopForIO message_loop; |
| 204 StrictMock<MockDelegate> delegate; |
| 205 |
| 206 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 207 base::MakeUnique<MojoAudioOutputIPC>(NullAccessor()); |
| 208 |
| 209 EXPECT_CALL(delegate, OnIPCClosed()); |
| 210 ipc->CreateStream(&delegate, Params()); |
| 211 base::RunLoop().RunUntilIdle(); |
| 212 } |
| 213 |
| 214 TEST(MojoAudioOutputIPC, DeviceAuthorized_Propagates) { |
| 215 base::MessageLoopForIO message_loop; |
| 216 TestRemoteFactory stream_factory; |
| 217 StrictMock<MockDelegate> delegate; |
| 218 |
| 219 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 220 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 221 stream_factory.PrepareProviderForAuthorization( |
| 222 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(nullptr)); |
| 223 |
| 224 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 225 |
| 226 EXPECT_CALL(delegate, OnDeviceAuthorized( |
| 227 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 228 _, std::string(kReturnedDeviceId))); |
| 229 base::RunLoop().RunUntilIdle(); |
| 230 |
| 231 ipc->CloseStream(); |
| 232 base::RunLoop().RunUntilIdle(); |
| 233 } |
| 234 |
| 235 TEST(MojoAudioOutputIPC, OnDeviceCreated_Propagates) { |
| 236 base::MessageLoopForIO message_loop; |
| 237 TestRemoteFactory stream_factory; |
| 238 StrictMock<MockStream> stream; |
| 239 StrictMock<MockDelegate> delegate; |
| 240 |
| 241 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 242 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 243 stream_factory.PrepareProviderForAuthorization( |
| 244 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(&stream)); |
| 245 |
| 246 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 247 ipc->CreateStream(&delegate, Params()); |
| 248 |
| 249 EXPECT_CALL(delegate, OnDeviceAuthorized( |
| 250 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 251 _, std::string(kReturnedDeviceId))); |
| 252 EXPECT_CALL(delegate, GotOnStreamCreated(kMemoryLength)); |
| 253 base::RunLoop().RunUntilIdle(); |
| 254 |
| 255 ipc->CloseStream(); |
| 256 base::RunLoop().RunUntilIdle(); |
| 257 } |
| 258 |
| 259 TEST(MojoAudioOutputIPC, |
| 260 CreateWithoutAuthorization_RequestsAuthorizationFirst) { |
| 261 base::MessageLoopForIO message_loop; |
| 262 TestRemoteFactory stream_factory; |
| 263 StrictMock<MockStream> stream; |
| 264 StrictMock<MockDelegate> delegate; |
| 265 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 266 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 267 |
| 268 // Note: This call implicitly EXPECTs that authorization is requested, |
| 269 // and constructing the TestStreamProvider with a |&stream| EXPECTs that the |
| 270 // stream is created. This implicit request should always be for the default |
| 271 // device and no session id. |
| 272 stream_factory.PrepareProviderForAuthorization( |
| 273 0, std::string(media::AudioDeviceDescription::kDefaultDeviceId), |
| 274 base::MakeUnique<TestStreamProvider>(&stream)); |
| 275 |
| 276 ipc->CreateStream(&delegate, Params()); |
| 277 |
| 278 EXPECT_CALL(delegate, GotOnStreamCreated(kMemoryLength)); |
| 279 base::RunLoop().RunUntilIdle(); |
| 280 |
| 281 ipc->CloseStream(); |
| 282 base::RunLoop().RunUntilIdle(); |
| 283 } |
| 284 |
| 285 TEST(MojoAudioOutputIPC, IsReusable) { |
| 286 base::MessageLoopForIO message_loop; |
| 287 TestRemoteFactory stream_factory; |
| 288 StrictMock<MockStream> stream; |
| 289 StrictMock<MockDelegate> delegate; |
| 290 |
| 291 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 292 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 293 |
| 294 for (int i = 0; i < 5; ++i) { |
| 295 stream_factory.PrepareProviderForAuthorization( |
| 296 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(&stream)); |
| 297 |
| 298 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 299 ipc->CreateStream(&delegate, Params()); |
| 300 |
| 301 EXPECT_CALL( |
| 302 delegate, |
| 303 OnDeviceAuthorized(media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 304 _, std::string(kReturnedDeviceId))); |
| 305 EXPECT_CALL(delegate, GotOnStreamCreated(kMemoryLength)); |
| 306 base::RunLoop().RunUntilIdle(); |
| 307 Mock::VerifyAndClearExpectations(&delegate); |
| 308 |
| 309 ipc->CloseStream(); |
| 310 base::RunLoop().RunUntilIdle(); |
| 311 } |
| 312 } |
| 313 |
| 314 TEST(MojoAudioOutputIPC, IsReusableAfterError) { |
| 315 base::MessageLoopForIO message_loop; |
| 316 TestRemoteFactory stream_factory; |
| 317 StrictMock<MockStream> stream; |
| 318 StrictMock<MockDelegate> delegate; |
| 319 |
| 320 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 321 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 322 |
| 323 stream_factory.PrepareProviderForAuthorization( |
| 324 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(nullptr)); |
| 325 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 326 |
| 327 EXPECT_CALL(delegate, OnDeviceAuthorized( |
| 328 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 329 _, std::string(kReturnedDeviceId))); |
| 330 base::RunLoop().RunUntilIdle(); |
| 331 Mock::VerifyAndClearExpectations(&delegate); |
| 332 |
| 333 EXPECT_CALL(delegate, OnError()).Times(AtLeast(1)); |
| 334 stream_factory.Disconnect(); |
| 335 base::RunLoop().RunUntilIdle(); |
| 336 Mock::VerifyAndClearExpectations(&delegate); |
| 337 |
| 338 ipc->CloseStream(); |
| 339 base::RunLoop().RunUntilIdle(); |
| 340 |
| 341 for (int i = 0; i < 5; ++i) { |
| 342 stream_factory.PrepareProviderForAuthorization( |
| 343 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(&stream)); |
| 344 |
| 345 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 346 ipc->CreateStream(&delegate, Params()); |
| 347 |
| 348 EXPECT_CALL( |
| 349 delegate, |
| 350 OnDeviceAuthorized(media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 351 _, std::string(kReturnedDeviceId))); |
| 352 EXPECT_CALL(delegate, GotOnStreamCreated(kMemoryLength)); |
| 353 base::RunLoop().RunUntilIdle(); |
| 354 Mock::VerifyAndClearExpectations(&delegate); |
| 355 |
| 356 ipc->CloseStream(); |
| 357 base::RunLoop().RunUntilIdle(); |
| 358 } |
| 359 } |
| 360 |
| 361 TEST(MojoAudioOutputIPC, DeviceNotAuthorized_Propagates) { |
| 362 base::MessageLoopForIO message_loop; |
| 363 TestRemoteFactory stream_factory; |
| 364 StrictMock<MockDelegate> delegate; |
| 365 |
| 366 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 367 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 368 stream_factory.RefuseNextRequest(kSessionId, kDeviceId); |
| 369 |
| 370 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 371 |
| 372 EXPECT_CALL( |
| 373 delegate, |
| 374 OnDeviceAuthorized( |
| 375 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, |
| 376 _, std::string())); |
| 377 EXPECT_CALL(delegate, OnError()).Times(AtLeast(0)); |
| 378 base::RunLoop().RunUntilIdle(); |
| 379 |
| 380 ipc->CloseStream(); |
| 381 base::RunLoop().RunUntilIdle(); |
| 382 } |
| 383 |
| 384 TEST(MojoAudioOutputIPC, |
| 385 FactoryDisconnectedBeforeAuthorizationReply_CallsAuthorizedAnyways) { |
| 386 // The authorization IPC message might be aborted by the remote end |
| 387 // disconnecting. In this case, the MojoAudioOutputIPC object must still |
| 388 // send a notification to unblock the AudioOutputIPCDelegate. |
| 389 base::MessageLoopForIO message_loop; |
| 390 TestRemoteFactory stream_factory; |
| 391 StrictMock<MockDelegate> delegate; |
| 392 |
| 393 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 394 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 395 |
| 396 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 397 |
| 398 EXPECT_CALL( |
| 399 delegate, |
| 400 OnDeviceAuthorized( |
| 401 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_ERROR_INTERNAL, _, |
| 402 std::string())); |
| 403 stream_factory.Disconnect(); |
| 404 EXPECT_CALL(delegate, OnError()); |
| 405 base::RunLoop().RunUntilIdle(); |
| 406 |
| 407 ipc->CloseStream(); |
| 408 base::RunLoop().RunUntilIdle(); |
| 409 } |
| 410 |
| 411 TEST(MojoAudioOutputIPC, |
| 412 FactoryDisconnectedAfterAuthorizationReply_CallsAuthorizedOnlyOnce) { |
| 413 // This test makes sure that the MojoAudioOutputIPC doesn't callback for |
| 414 // authorization when the factory disconnects if it already got a callback |
| 415 // for authorization. |
| 416 base::MessageLoopForIO message_loop; |
| 417 TestRemoteFactory stream_factory; |
| 418 stream_factory.PrepareProviderForAuthorization( |
| 419 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(nullptr)); |
| 420 StrictMock<MockDelegate> delegate; |
| 421 |
| 422 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 423 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 424 |
| 425 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 426 |
| 427 EXPECT_CALL(delegate, OnDeviceAuthorized( |
| 428 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 429 _, std::string(kReturnedDeviceId))); |
| 430 base::RunLoop().RunUntilIdle(); |
| 431 |
| 432 stream_factory.Disconnect(); |
| 433 EXPECT_CALL(delegate, OnError()); |
| 434 base::RunLoop().RunUntilIdle(); |
| 435 |
| 436 ipc->CloseStream(); |
| 437 base::RunLoop().RunUntilIdle(); |
| 438 } |
| 439 |
| 440 TEST(MojoAudioOutputIPC, AuthorizeNoClose_DCHECKs) { |
| 441 base::MessageLoopForIO message_loop; |
| 442 TestRemoteFactory stream_factory; |
| 443 StrictMock<MockDelegate> delegate; |
| 444 |
| 445 stream_factory.PrepareProviderForAuthorization( |
| 446 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(nullptr)); |
| 447 |
| 448 std::unique_ptr<media::AudioOutputIPC> ipc = |
| 449 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 450 |
| 451 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 452 EXPECT_DCHECK_DEATH(ipc.reset()); |
| 453 ipc->CloseStream(); |
| 454 ipc.reset(); |
| 455 base::RunLoop().RunUntilIdle(); |
| 456 } |
| 457 |
| 458 TEST(MojoAudioOutputIPC, CreateNoClose_DCHECKs) { |
| 459 base::MessageLoopForIO message_loop; |
| 460 TestRemoteFactory stream_factory; |
| 461 StrictMock<MockDelegate> delegate; |
| 462 StrictMock<MockStream> stream; |
| 463 |
| 464 stream_factory.PrepareProviderForAuthorization( |
| 465 0, std::string(media::AudioDeviceDescription::kDefaultDeviceId), |
| 466 base::MakeUnique<TestStreamProvider>(&stream)); |
| 467 |
| 468 std::unique_ptr<media::AudioOutputIPC> ipc = |
| 469 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 470 |
| 471 ipc->CreateStream(&delegate, Params()); |
| 472 EXPECT_DCHECK_DEATH(ipc.reset()); |
| 473 ipc->CloseStream(); |
| 474 ipc.reset(); |
| 475 base::RunLoop().RunUntilIdle(); |
| 476 } |
| 477 |
| 478 TEST(MojoAudioOutputIPC, Play_Plays) { |
| 479 base::MessageLoopForIO message_loop; |
| 480 TestRemoteFactory stream_factory; |
| 481 StrictMock<MockStream> stream; |
| 482 StrictMock<MockDelegate> delegate; |
| 483 |
| 484 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 485 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 486 stream_factory.PrepareProviderForAuthorization( |
| 487 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(&stream)); |
| 488 |
| 489 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 490 ipc->CreateStream(&delegate, Params()); |
| 491 ipc->PlayStream(); |
| 492 |
| 493 EXPECT_CALL(delegate, OnDeviceAuthorized( |
| 494 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 495 _, std::string(kReturnedDeviceId))); |
| 496 EXPECT_CALL(delegate, GotOnStreamCreated(kMemoryLength)); |
| 497 EXPECT_CALL(stream, Play()); |
| 498 base::RunLoop().RunUntilIdle(); |
| 499 |
| 500 ipc->CloseStream(); |
| 501 base::RunLoop().RunUntilIdle(); |
| 502 } |
| 503 |
| 504 TEST(MojoAudioOutputIPC, Pause_Pauses) { |
| 505 base::MessageLoopForIO message_loop; |
| 506 TestRemoteFactory stream_factory; |
| 507 StrictMock<MockStream> stream; |
| 508 StrictMock<MockDelegate> delegate; |
| 509 |
| 510 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 511 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 512 stream_factory.PrepareProviderForAuthorization( |
| 513 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(&stream)); |
| 514 |
| 515 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 516 ipc->CreateStream(&delegate, Params()); |
| 517 ipc->PauseStream(); |
| 518 |
| 519 EXPECT_CALL(delegate, OnDeviceAuthorized( |
| 520 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 521 _, std::string(kReturnedDeviceId))); |
| 522 EXPECT_CALL(delegate, GotOnStreamCreated(kMemoryLength)); |
| 523 EXPECT_CALL(stream, Pause()); |
| 524 base::RunLoop().RunUntilIdle(); |
| 525 |
| 526 ipc->CloseStream(); |
| 527 base::RunLoop().RunUntilIdle(); |
| 528 } |
| 529 |
| 530 TEST(MojoAudioOutputIPC, SetVolume_SetsVolume) { |
| 531 base::MessageLoopForIO message_loop; |
| 532 TestRemoteFactory stream_factory; |
| 533 StrictMock<MockStream> stream; |
| 534 StrictMock<MockDelegate> delegate; |
| 535 |
| 536 const std::unique_ptr<media::AudioOutputIPC> ipc = |
| 537 base::MakeUnique<MojoAudioOutputIPC>(stream_factory.GetAccessor()); |
| 538 stream_factory.PrepareProviderForAuthorization( |
| 539 kSessionId, kDeviceId, base::MakeUnique<TestStreamProvider>(&stream)); |
| 540 |
| 541 ipc->RequestDeviceAuthorization(&delegate, kSessionId, kDeviceId, Origin()); |
| 542 ipc->CreateStream(&delegate, Params()); |
| 543 ipc->SetVolume(kNewVolume); |
| 544 |
| 545 EXPECT_CALL(delegate, OnDeviceAuthorized( |
| 546 media::OutputDeviceStatus::OUTPUT_DEVICE_STATUS_OK, |
| 547 _, std::string(kReturnedDeviceId))); |
| 548 EXPECT_CALL(delegate, GotOnStreamCreated(kMemoryLength)); |
| 549 EXPECT_CALL(stream, SetVolume(kNewVolume)); |
| 550 base::RunLoop().RunUntilIdle(); |
| 551 |
| 552 ipc->CloseStream(); |
| 553 base::RunLoop().RunUntilIdle(); |
| 554 } |
| 555 |
| 556 } // namespace content |
OLD | NEW |