Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #import <Foundation/Foundation.h> | 11 #import <Foundation/Foundation.h> |
| 12 #import <OCMock/OCMock.h> | 12 #import <OCMock/OCMock.h> |
| 13 | 13 |
| 14 // Allow private members to be accessed for testing purposes | |
| 15 #define private public | |
|
tkchin_webrtc
2017/05/09 17:48:25
oof. Don't do this - not good to redefine keywords
| |
| 16 #include "webrtc/modules/audio_device/ios/audio_device_ios.h" | |
| 14 #include "webrtc/test/gtest.h" | 17 #include "webrtc/test/gtest.h" |
| 15 | 18 |
| 16 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" | 19 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" |
| 17 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h" | 20 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h" |
| 18 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h" | 21 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h" |
| 19 | 22 |
| 20 @interface RTCAudioSessionTestDelegate : NSObject <RTCAudioSessionDelegate> | 23 @interface RTCAudioSessionTestDelegate : NSObject <RTCAudioSessionDelegate> |
| 21 @end | 24 @end |
| 22 | 25 |
| 23 @implementation RTCAudioSessionTestDelegate | 26 @implementation RTCAudioSessionTestDelegate |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 [audioSession unlockForConfiguration]; | 242 [audioSession unlockForConfiguration]; |
| 240 | 243 |
| 241 OCMVerify([mockAudioSession session]); | 244 OCMVerify([mockAudioSession session]); |
| 242 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption s:0 error:&error]); | 245 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption s:0 error:&error]); |
| 243 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions :0 error:&error]); | 246 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions :0 error:&error]); |
| 244 | 247 |
| 245 [mockAVAudioSession stopMocking]; | 248 [mockAVAudioSession stopMocking]; |
| 246 [mockAudioSession stopMocking]; | 249 [mockAudioSession stopMocking]; |
| 247 } | 250 } |
| 248 | 251 |
| 252 - (void)testInterruptedAudioSession { | |
|
tkchin_webrtc
2017/05/09 17:48:25
this belongs in:
https://cs.chromium.org/chromium/
| |
| 253 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | |
| 254 webrtc::AudioDeviceIOS *audioDevice = new webrtc::AudioDeviceIOS(); | |
| 255 webrtc::AudioDeviceBuffer *audioBuffer = new webrtc::AudioDeviceBuffer(); | |
| 256 audioDevice->AttachAudioBuffer(audioBuffer); | |
| 257 audioDevice->Init(); | |
| 258 audioDevice->InitPlayout(); | |
| 259 [session notifyDidBeginInterruption]; // force interruption | |
| 260 | |
| 261 // Wait for notification to propagate | |
| 262 rtc::MessageQueueManager::ProcessAllMessageQueues(); | |
| 263 EXPECT_TRUE(audioDevice->is_interrupted_); | |
| 264 | |
| 265 audioDevice->playing_ = false; // force it for testing | |
| 266 audioDevice->ShutdownPlayOrRecord(); | |
| 267 audioDevice->audio_is_initialized_ = false; // force it for testing | |
| 268 | |
| 269 [session notifyDidEndInterruptionWithShouldResumeSession:YES]; | |
| 270 // Wait for notification to propagate | |
| 271 rtc::MessageQueueManager::ProcessAllMessageQueues(); | |
| 272 EXPECT_TRUE(audioDevice->is_interrupted_); | |
| 273 | |
| 274 audioDevice->Init(); | |
| 275 audioDevice->InitPlayout(); | |
| 276 EXPECT_FALSE(audioDevice->is_interrupted_); | |
| 277 delete audioBuffer; | |
|
tkchin_webrtc
2017/05/09 17:48:25
fyi it is extremely rare to use delete now since u
jtt_webrtc
2017/05/09 19:07:45
Done.
| |
| 278 delete audioDevice; | |
| 279 } | |
| 280 | |
| 249 @end | 281 @end |
| 250 | 282 |
| 251 namespace webrtc { | 283 namespace webrtc { |
| 252 | 284 |
| 253 class AudioSessionTest : public ::testing::Test { | 285 class AudioSessionTest : public ::testing::Test { |
| 254 protected: | 286 protected: |
| 255 void TearDown() { | 287 void TearDown() { |
| 256 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 288 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
| 257 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { | 289 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { |
| 258 [session removeDelegate:delegate]; | 290 [session removeDelegate:delegate]; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 288 TEST_F(AudioSessionTest, AudioSessionActivation) { | 320 TEST_F(AudioSessionTest, AudioSessionActivation) { |
| 289 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 321 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
| 290 [test testAudioSessionActivation]; | 322 [test testAudioSessionActivation]; |
| 291 } | 323 } |
| 292 | 324 |
| 293 TEST_F(AudioSessionTest, ConfigureWebRTCSession) { | 325 TEST_F(AudioSessionTest, ConfigureWebRTCSession) { |
| 294 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 326 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
| 295 [test testConfigureWebRTCSession]; | 327 [test testConfigureWebRTCSession]; |
| 296 } | 328 } |
| 297 | 329 |
| 330 TEST_F(AudioSessionTest, testInterruptedAudioSession) { | |
| 331 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | |
| 332 [test testInterruptedAudioSession]; | |
| 333 } | |
| 334 | |
| 298 } // namespace webrtc | 335 } // namespace webrtc |
| OLD | NEW |