Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host_unittest.cc

Issue 2396463002: Remove dangerous CHECK. Add unit test. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/renderer_host/media/audio_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_renderer_host.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 host_->OnChannelClosing(); 213 host_->OnChannelClosing();
214 SyncWithAudioThread(); 214 SyncWithAudioThread();
215 215
216 // Release the reference to the mock object. The object will be destructed 216 // Release the reference to the mock object. The object will be destructed
217 // on message_loop_. 217 // on message_loop_.
218 host_ = NULL; 218 host_ = NULL;
219 } 219 }
220 220
221 protected: 221 protected:
222 void Create() { 222 void Create() {
223 Create(false, kDefaultDeviceId, url::Origin(GURL(kSecurityOrigin))); 223 Create(false, kDefaultDeviceId, url::Origin(GURL(kSecurityOrigin)), true);
224 } 224 }
225 225
226 void Create(bool unified_stream, 226 void Create(bool unified_stream,
227 const std::string& device_id, 227 const std::string& device_id,
228 const url::Origin& security_origin) { 228 const url::Origin& security_origin,
229 bool wait_for_auth) {
229 media::OutputDeviceStatus expected_device_status = 230 media::OutputDeviceStatus expected_device_status =
230 device_id == kDefaultDeviceId 231 device_id == kDefaultDeviceId
231 ? media::OUTPUT_DEVICE_STATUS_OK 232 ? media::OUTPUT_DEVICE_STATUS_OK
232 : device_id == kBadDeviceId 233 : device_id == kBadDeviceId
233 ? media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED 234 ? media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED
234 : media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; 235 : media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND;
235 236
236 EXPECT_CALL(*host_.get(), 237 EXPECT_CALL(*host_.get(),
237 OnDeviceAuthorized(kStreamId, expected_device_status, _, _)); 238 OnDeviceAuthorized(kStreamId, expected_device_status, _, _));
238 239
(...skipping 11 matching lines...) Expand all
250 media::AudioParameters::kAudioCDSampleRate, 16, 251 media::AudioParameters::kAudioCDSampleRate, 16,
251 media::AudioParameters::kAudioCDSampleRate / 10); 252 media::AudioParameters::kAudioCDSampleRate / 10);
252 int session_id = 0; 253 int session_id = 0;
253 if (unified_stream) { 254 if (unified_stream) {
254 // Use AudioInputDeviceManager::kFakeOpenSessionId as the session id to 255 // Use AudioInputDeviceManager::kFakeOpenSessionId as the session id to
255 // pass the permission check. 256 // pass the permission check.
256 session_id = AudioInputDeviceManager::kFakeOpenSessionId; 257 session_id = AudioInputDeviceManager::kFakeOpenSessionId;
257 } 258 }
258 host_->OnRequestDeviceAuthorization(kStreamId, kRenderFrameId, session_id, 259 host_->OnRequestDeviceAuthorization(kStreamId, kRenderFrameId, session_id,
259 device_id, security_origin); 260 device_id, security_origin);
260 auth_run_loop_.Run(); 261 if (wait_for_auth)
261 if (expected_device_status == media::OUTPUT_DEVICE_STATUS_OK) { 262 auth_run_loop_.Run();
263
264 if (!wait_for_auth ||
265 expected_device_status == media::OUTPUT_DEVICE_STATUS_OK)
262 host_->OnCreateStream(kStreamId, kRenderFrameId, params); 266 host_->OnCreateStream(kStreamId, kRenderFrameId, params);
263 267
268 if (expected_device_status == media::OUTPUT_DEVICE_STATUS_OK)
264 // At some point in the future, a corresponding RemoveDiverter() call must 269 // At some point in the future, a corresponding RemoveDiverter() call must
265 // be made. 270 // be made.
266 EXPECT_CALL(mirroring_manager_, RemoveDiverter(NotNull())) 271 EXPECT_CALL(mirroring_manager_, RemoveDiverter(NotNull()))
267 .RetiresOnSaturation(); 272 .RetiresOnSaturation();
268 }
269 SyncWithAudioThread(); 273 SyncWithAudioThread();
270 } 274 }
271 275
276 void CreateWithoutWaitingForAuth(const std::string& device_id) {
277 EXPECT_CALL(*host_, OnStreamError(kStreamId));
278 Create(false, device_id, url::Origin(GURL(kSecurityOrigin)), false);
279 }
280
272 void CreateWithInvalidRenderFrameId() { 281 void CreateWithInvalidRenderFrameId() {
273 // When creating a stream with an invalid render frame ID, the host will 282 // When creating a stream with an invalid render frame ID, the host will
274 // reply with a stream error message. 283 // reply with a stream error message.
275 EXPECT_CALL(*host_, OnStreamError(kStreamId)); 284 EXPECT_CALL(*host_, OnStreamError(kStreamId));
276 285
277 // However, validation does not block stream creation, so these method calls 286 // However, validation does not block stream creation, so these method calls
278 // might be made: 287 // might be made:
279 EXPECT_CALL(*host_, OnStreamCreated(kStreamId, _)).Times(AtLeast(0)); 288 EXPECT_CALL(*host_, OnStreamCreated(kStreamId, _)).Times(AtLeast(0));
280 EXPECT_CALL(mirroring_manager_, AddDiverter(_, _, _)).Times(AtLeast(0)); 289 EXPECT_CALL(mirroring_manager_, AddDiverter(_, _, _)).Times(AtLeast(0));
281 EXPECT_CALL(mirroring_manager_, RemoveDiverter(_)).Times(AtLeast(0)); 290 EXPECT_CALL(mirroring_manager_, RemoveDiverter(_)).Times(AtLeast(0));
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // the audio device is closed but the render process try to close the 419 // the audio device is closed but the render process try to close the
411 // audio stream again. 420 // audio stream again.
412 TEST_F(AudioRendererHostTest, SimulateErrorAndClose) { 421 TEST_F(AudioRendererHostTest, SimulateErrorAndClose) {
413 Create(); 422 Create();
414 Play(); 423 Play();
415 SimulateError(); 424 SimulateError();
416 Close(); 425 Close();
417 } 426 }
418 427
419 TEST_F(AudioRendererHostTest, CreateUnifiedStreamAndClose) { 428 TEST_F(AudioRendererHostTest, CreateUnifiedStreamAndClose) {
420 Create(true, kDefaultDeviceId, url::Origin(GURL(kSecurityOrigin))); 429 Create(true, kDefaultDeviceId, url::Origin(GURL(kSecurityOrigin)), true);
421 Close(); 430 Close();
422 } 431 }
423 432
424 TEST_F(AudioRendererHostTest, CreateUnauthorizedDevice) { 433 TEST_F(AudioRendererHostTest, CreateUnauthorizedDevice) {
425 Create(false, kBadDeviceId, url::Origin(GURL(kSecurityOrigin))); 434 Create(false, kBadDeviceId, url::Origin(GURL(kSecurityOrigin)), true);
435 Close();
436 }
437
438 TEST_F(AudioRendererHostTest, CreateDeviceWithAuthorizationPendingIsError) {
439 CreateWithoutWaitingForAuth(kBadDeviceId);
426 Close(); 440 Close();
427 } 441 }
428 442
429 TEST_F(AudioRendererHostTest, CreateInvalidDevice) { 443 TEST_F(AudioRendererHostTest, CreateInvalidDevice) {
430 Create(false, kInvalidDeviceId, url::Origin(GURL(kSecurityOrigin))); 444 Create(false, kInvalidDeviceId, url::Origin(GURL(kSecurityOrigin)), true);
431 Close(); 445 Close();
432 } 446 }
433 447
434 TEST_F(AudioRendererHostTest, CreateFailsForInvalidRenderFrame) { 448 TEST_F(AudioRendererHostTest, CreateFailsForInvalidRenderFrame) {
435 CreateWithInvalidRenderFrameId(); 449 CreateWithInvalidRenderFrameId();
436 Close(); 450 Close();
437 } 451 }
438 452
439 // TODO(hclam): Add tests for data conversation in low latency mode. 453 // TODO(hclam): Add tests for data conversation in low latency mode.
440 454
441 } // namespace content 455 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698