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" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 audio_manager_.reset(new media::FakeAudioManager( | 67 audio_manager_.reset(new media::FakeAudioManager( |
68 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), | 68 audio_thread_->task_runner(), audio_thread_->worker_task_runner(), |
69 &log_factory_)); | 69 &log_factory_)); |
70 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 70 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
71 media_stream_manager_ = | 71 media_stream_manager_ = |
72 base::MakeUnique<MediaStreamManager>(audio_system_.get()); | 72 base::MakeUnique<MediaStreamManager>(audio_system_.get()); |
73 // Make sure everything is done initializing: | 73 // Make sure everything is done initializing: |
74 SyncWithAllThreads(); | 74 SyncWithAllThreads(); |
75 } | 75 } |
76 | 76 |
77 ~AudioOutputAuthorizationHandlerTest() override { SyncWithAllThreads(); } | 77 ~AudioOutputAuthorizationHandlerTest() override { |
| 78 audio_manager_->GetTaskRunner()->PostTask( |
| 79 FROM_HERE, base::Bind(&media::AudioManager::Shutdown, |
| 80 base::Unretained(audio_manager_.get()))); |
| 81 SyncWithAllThreads(); |
| 82 } |
78 | 83 |
79 protected: | 84 protected: |
80 MediaStreamManager* GetMediaStreamManager() { | 85 MediaStreamManager* GetMediaStreamManager() { |
81 return media_stream_manager_.get(); | 86 return media_stream_manager_.get(); |
82 } | 87 } |
83 | 88 |
84 media::AudioSystem* GetAudioSystem() { return audio_system_.get(); } | 89 media::AudioSystem* GetAudioSystem() { return audio_system_.get(); } |
85 | 90 |
86 void SyncWithAllThreads() { | 91 void SyncWithAllThreads() { |
87 // New tasks might be posted while we are syncing, but in | 92 // 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] | 137 *out = result[MediaDeviceType::MEDIA_DEVICE_TYPE_AUDIO_OUTPUT][1] |
133 .device_id; | 138 .device_id; |
134 }, | 139 }, |
135 base::Unretained(out))); | 140 base::Unretained(out))); |
136 } | 141 } |
137 | 142 |
138 // media_stream_manager must die after threads since it's a | 143 // media_stream_manager must die after threads since it's a |
139 // DestructionObserver. | 144 // DestructionObserver. |
140 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 145 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
141 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; | 146 std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; |
| 147 media::FakeAudioLogFactory log_factory_; |
| 148 std::unique_ptr<media::AudioManager> audio_manager_; |
| 149 std::unique_ptr<media::AudioSystem> audio_system_; |
142 std::unique_ptr<AudioManagerThread> audio_thread_; | 150 std::unique_ptr<AudioManagerThread> audio_thread_; |
143 media::FakeAudioLogFactory log_factory_; | |
144 media::ScopedAudioManagerPtr audio_manager_; | |
145 std::unique_ptr<media::AudioSystem> audio_system_; | |
146 | 151 |
147 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandlerTest); | 152 DISALLOW_COPY_AND_ASSIGN(AudioOutputAuthorizationHandlerTest); |
148 }; | 153 }; |
149 | 154 |
150 TEST_F(AudioOutputAuthorizationHandlerTest, AuthorizeDefaultDevice_Ok) { | 155 TEST_F(AudioOutputAuthorizationHandlerTest, AuthorizeDefaultDevice_Ok) { |
151 MockAuthorizationCallback listener; | 156 MockAuthorizationCallback listener; |
152 EXPECT_CALL(listener, | 157 EXPECT_CALL(listener, |
153 Run(media::OUTPUT_DEVICE_STATUS_OK, false, _, kDefaultDeviceId)) | 158 Run(media::OUTPUT_DEVICE_STATUS_OK, false, _, kDefaultDeviceId)) |
154 .Times(1); | 159 .Times(1); |
155 std::unique_ptr<AudioOutputAuthorizationHandler> handler = | 160 std::unique_ptr<AudioOutputAuthorizationHandler> handler = |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, | 333 (base::Bind(&AudioOutputAuthorizationHandler::RequestDeviceAuthorization, |
329 base::Unretained(handler.get()), kRenderFrameId, kSessionId, | 334 base::Unretained(handler.get()), kRenderFrameId, kSessionId, |
330 std::string(), BadSecurityOrigin(), listener.Get()))); | 335 std::string(), BadSecurityOrigin(), listener.Get()))); |
331 | 336 |
332 SyncWithAllThreads(); | 337 SyncWithAllThreads(); |
333 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); | 338 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, handler.release()); |
334 SyncWithAllThreads(); | 339 SyncWithAllThreads(); |
335 } | 340 } |
336 | 341 |
337 } // namespace content | 342 } // namespace content |
OLD | NEW |