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/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/test/mock_callback.h" | 13 #include "base/test/mock_callback.h" |
14 #include "content/browser/audio_manager_thread.h" | |
15 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/test/mock_render_process_host.h" | 16 #include "content/public/test/mock_render_process_host.h" |
18 #include "content/public/test/test_browser_context.h" | 17 #include "content/public/test/test_browser_context.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "media/audio/audio_device_description.h" | 19 #include "media/audio/audio_device_description.h" |
21 #include "media/audio/audio_system_impl.h" | 20 #include "media/audio/audio_system_impl.h" |
| 21 #include "media/audio/audio_thread_impl.h" |
22 #include "media/audio/fake_audio_log_factory.h" | 22 #include "media/audio/fake_audio_log_factory.h" |
23 #include "media/audio/fake_audio_manager.h" | 23 #include "media/audio/fake_audio_manager.h" |
24 #include "media/base/media_switches.h" | 24 #include "media/base/media_switches.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
28 #include "url/origin.h" | 28 #include "url/origin.h" |
29 | 29 |
30 using ::testing::_; | 30 using ::testing::_; |
31 | 31 |
(...skipping 24 matching lines...) Expand all Loading... |
56 | 56 |
57 class AudioOutputAuthorizationHandlerTest : public testing::Test { | 57 class AudioOutputAuthorizationHandlerTest : public testing::Test { |
58 public: | 58 public: |
59 AudioOutputAuthorizationHandlerTest() { | 59 AudioOutputAuthorizationHandlerTest() { |
60 // Not threadsafe, thus set before threads are started: | 60 // Not threadsafe, thus set before threads are started: |
61 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 61 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
62 switches::kUseFakeDeviceForMediaStream); | 62 switches::kUseFakeDeviceForMediaStream); |
63 | 63 |
64 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( | 64 thread_bundle_ = base::MakeUnique<TestBrowserThreadBundle>( |
65 TestBrowserThreadBundle::Options::REAL_IO_THREAD); | 65 TestBrowserThreadBundle::Options::REAL_IO_THREAD); |
66 audio_thread_ = base::MakeUnique<AudioManagerThread>(); | |
67 audio_manager_.reset(new media::FakeAudioManager( | 66 audio_manager_.reset(new media::FakeAudioManager( |
68 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), | 67 base::MakeUnique<media::AudioThreadImpl>(), &log_factory_)); |
69 &log_factory_)); | |
70 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 68 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
71 media_stream_manager_ = | 69 media_stream_manager_ = |
72 base::MakeUnique<MediaStreamManager>(audio_system_.get()); | 70 base::MakeUnique<MediaStreamManager>(audio_system_.get()); |
73 // Make sure everything is done initializing: | 71 // Make sure everything is done initializing: |
74 SyncWithAllThreads(); | 72 SyncWithAllThreads(); |
75 } | 73 } |
76 | 74 |
77 ~AudioOutputAuthorizationHandlerTest() override { SyncWithAllThreads(); } | 75 ~AudioOutputAuthorizationHandlerTest() override { |
| 76 SyncWithAllThreads(); |
| 77 audio_manager_->Shutdown(); |
| 78 } |
78 | 79 |
79 protected: | 80 protected: |
80 MediaStreamManager* GetMediaStreamManager() { | 81 MediaStreamManager* GetMediaStreamManager() { |
81 return media_stream_manager_.get(); | 82 return media_stream_manager_.get(); |
82 } | 83 } |
83 | 84 |
84 media::AudioSystem* GetAudioSystem() { return audio_system_.get(); } | 85 media::AudioSystem* GetAudioSystem() { return audio_system_.get(); } |
85 | 86 |
86 void SyncWithAllThreads() { | 87 void SyncWithAllThreads() { |
87 // New tasks might be posted while we are syncing, but in | 88 // New tasks might be posted while we are syncing, but in |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 *out = result[MediaDeviceType::MEDIA_DEVICE_TYPE_AUDIO_OUTPUT][1] | 133 *out = result[MediaDeviceType::MEDIA_DEVICE_TYPE_AUDIO_OUTPUT][1] |
133 .device_id; | 134 .device_id; |
134 }, | 135 }, |
135 base::Unretained(out))); | 136 base::Unretained(out))); |
136 } | 137 } |
137 | 138 |
138 // media_stream_manager must die after threads since it's a | 139 // media_stream_manager must die after threads since it's a |
139 // DestructionObserver. | 140 // DestructionObserver. |
140 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 141 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
141 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; | 142 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; |
142 std::unique_ptr<AudioManagerThread> audio_thread_; | |
143 media::FakeAudioLogFactory log_factory_; | 143 media::FakeAudioLogFactory log_factory_; |
144 media::ScopedAudioManagerPtr audio_manager_; | 144 std::unique_ptr<media::AudioManager> audio_manager_; |
145 std::unique_ptr<media::AudioSystem> audio_system_; | 145 std::unique_ptr<media::AudioSystem> audio_system_; |
146 | 146 |
147 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandlerTest); | 147 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandlerTest); |
148 }; | 148 }; |
149 | 149 |
150 TEST_F(AudioOutputAuthorizationHandlerTest, AuthorizeDefaultDevice_Ok) { | 150 TEST_F(AudioOutputAuthorizationHandlerTest, AuthorizeDefaultDevice_Ok) { |
151 MockAuthorizationCallback listener; | 151 MockAuthorizationCallback listener; |
152 EXPECT_CALL(listener, | 152 EXPECT_CALL(listener, |
153 Run(media::OUTPUT_DEVICE_STATUS_OK, false, _, kDefaultDeviceId)) | 153 Run(media::OUTPUT_DEVICE_STATUS_OK, false, _, kDefaultDeviceId)) |
154 .Times(1); | 154 .Times(1); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, | 329 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, |
330 base::Unretained(handler.get()), kRenderFrameId, kSessionId, | 330 base::Unretained(handler.get()), kRenderFrameId, kSessionId, |
331 std::string(), BadSecurityOrigin(), listener.Get()))); | 331 std::string(), BadSecurityOrigin(), listener.Get()))); |
332 | 332 |
333 SyncWithAllThreads(); | 333 SyncWithAllThreads(); |
334 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); | 334 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); |
335 SyncWithAllThreads(); | 335 SyncWithAllThreads(); |
336 } | 336 } |
337 | 337 |
338 } // namespace content | 338 } // namespace content |
OLD | NEW |