| 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 // Unit tests for AudioOutputAuthorizationHandler. | 5 // Unit tests for AudioOutputAuthorizationHandler. |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/media/audio_output_authorization_handler
.h" | 7 #include "content/browser/renderer_host/media/audio_output_authorization_handler
.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "content/browser/audio_device_thread.h" | 12 #include "content/browser/audio_manager_thread.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/test/mock_render_process_host.h" | 15 #include "content/public/test/mock_render_process_host.h" |
| 16 #include "content/public/test/test_browser_context.h" | 16 #include "content/public/test/test_browser_context.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "media/audio/audio_device_description.h" | 18 #include "media/audio/audio_device_description.h" |
| 19 #include "media/audio/fake_audio_log_factory.h" | 19 #include "media/audio/fake_audio_log_factory.h" |
| 20 #include "media/audio/fake_audio_manager.h" | 20 #include "media/audio/fake_audio_manager.h" |
| 21 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 class AudioOutputAuthorizationHandlerTest : public testing::Test { | 65 class AudioOutputAuthorizationHandlerTest : public testing::Test { |
| 66 public: | 66 public: |
| 67 AudioOutputAuthorizationHandlerTest() { | 67 AudioOutputAuthorizationHandlerTest() { |
| 68 // Not threadsafe, thus set before threads are started: | 68 // Not threadsafe, thus set before threads are started: |
| 69 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 69 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 70 switches::kUseFakeDeviceForMediaStream); | 70 switches::kUseFakeDeviceForMediaStream); |
| 71 | 71 |
| 72 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( | 72 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( |
| 73 TestBrowserThreadBundle::Options::REAL_IO_THREAD); | 73 TestBrowserThreadBundle::Options::REAL_IO_THREAD); |
| 74 audio_thread_ = base::MakeUnique<AudioDeviceThread>(); | 74 audio_thread_ = base::MakeUnique<AudioManagerThread>(); |
| 75 audio_manager_.reset(new media::FakeAudioManager( | 75 audio_manager_.reset(new media::FakeAudioManager( |
| 76 audio_thread_->GetTaskRunner(), audio_thread_->worker_task_runner(), | 76 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), |
| 77 &log_factory_)); | 77 &log_factory_)); |
| 78 media_stream_manager_ = | 78 media_stream_manager_ = |
| 79 base::MakeUnique<MediaStreamManager>(audio_manager_.get()); | 79 base::MakeUnique<MediaStreamManager>(audio_manager_.get()); |
| 80 // Make sure everything is done initializing: | 80 // Make sure everything is done initializing: |
| 81 SyncWithAllThreads(); | 81 SyncWithAllThreads(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 ~AudioOutputAuthorizationHandlerTest() override { SyncWithAllThreads(); } | 84 ~AudioOutputAuthorizationHandlerTest() override { SyncWithAllThreads(); } |
| 85 | 85 |
| 86 protected: | 86 protected: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 *out = result[MediaDeviceType::MEDIA_DEVICE_TYPE_AUDIO_OUTPUT][1] | 139 *out = result[MediaDeviceType::MEDIA_DEVICE_TYPE_AUDIO_OUTPUT][1] |
| 140 .device_id; | 140 .device_id; |
| 141 }, | 141 }, |
| 142 base::Unretained(out))); | 142 base::Unretained(out))); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // media_stream_manager must die after threads since it's a | 145 // media_stream_manager must die after threads since it's a |
| 146 // DestructionObserver. | 146 // DestructionObserver. |
| 147 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 147 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
| 148 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; | 148 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; |
| 149 std::unique_ptr<AudioDeviceThread> audio_thread_; | 149 std::unique_ptr<AudioManagerThread> audio_thread_; |
| 150 media::FakeAudioLogFactory log_factory_; | 150 media::FakeAudioLogFactory log_factory_; |
| 151 media::ScopedAudioManagerPtr audio_manager_; | 151 media::ScopedAudioManagerPtr audio_manager_; |
| 152 | 152 |
| 153 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandlerTest); | 153 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandlerTest); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 TEST_F(AudioOutputAuthorizationHandlerTest, AuthorizeDefaultDevice_Ok) { | 156 TEST_F(AudioOutputAuthorizationHandlerTest, AuthorizeDefaultDevice_Ok) { |
| 157 MockListener listener; | 157 MockListener listener; |
| 158 EXPECT_CALL(listener, | 158 EXPECT_CALL(listener, |
| 159 MockAuthorizationCallback(media::OUTPUT_DEVICE_STATUS_OK, false, | 159 MockAuthorizationCallback(media::OUTPUT_DEVICE_STATUS_OK, false, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, | 340 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, |
| 341 base::Unretained(handler.get()), kRenderFrameId, kSessionId, | 341 base::Unretained(handler.get()), kRenderFrameId, kSessionId, |
| 342 std::string(), BadSecurityOrigin(), listener.GetCallback()))); | 342 std::string(), BadSecurityOrigin(), listener.GetCallback()))); |
| 343 | 343 |
| 344 SyncWithAllThreads(); | 344 SyncWithAllThreads(); |
| 345 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); | 345 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); |
| 346 SyncWithAllThreads(); | 346 SyncWithAllThreads(); |
| 347 } | 347 } |
| 348 | 348 |
| 349 } // namespace content | 349 } // namespace content |
| OLD | NEW |