| 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 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" | 
| 15 | 15 | 
| 16 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" | 16 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" | 
| 17 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h" | 17 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h" | 
| 18 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h" | 18 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h" | 
| 19 | 19 | 
| 20 @interface RTCAudioSessionTestDelegate : NSObject <RTCAudioSessionDelegate> | 20 @interface RTCAudioSessionTestDelegate : NSObject <RTCAudioSessionDelegate> | 
|  | 21 | 
|  | 22 @property (nonatomic, readonly) float outputVolume; | 
|  | 23 | 
| 21 @end | 24 @end | 
| 22 | 25 | 
| 23 @implementation RTCAudioSessionTestDelegate | 26 @implementation RTCAudioSessionTestDelegate | 
| 24 | 27 | 
|  | 28 @synthesize outputVolume = _outputVolume; | 
|  | 29 | 
|  | 30 - (instancetype)init { | 
|  | 31   if (self = [super init]) { | 
|  | 32     _outputVolume = -1; | 
|  | 33   } | 
|  | 34   return self; | 
|  | 35 } | 
|  | 36 | 
| 25 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session { | 37 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session { | 
| 26 } | 38 } | 
| 27 | 39 | 
| 28 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session | 40 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session | 
| 29                    shouldResumeSession:(BOOL)shouldResumeSession { | 41                    shouldResumeSession:(BOOL)shouldResumeSession { | 
| 30 } | 42 } | 
| 31 | 43 | 
| 32 - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session | 44 - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session | 
| 33            reason:(AVAudioSessionRouteChangeReason)reason | 45            reason:(AVAudioSessionRouteChangeReason)reason | 
| 34     previousRoute:(AVAudioSessionRouteDescription *)previousRoute { | 46     previousRoute:(AVAudioSessionRouteDescription *)previousRoute { | 
| 35 } | 47 } | 
| 36 | 48 | 
| 37 - (void)audioSessionMediaServerTerminated:(RTCAudioSession *)session { | 49 - (void)audioSessionMediaServerTerminated:(RTCAudioSession *)session { | 
| 38 } | 50 } | 
| 39 | 51 | 
| 40 - (void)audioSessionMediaServerReset:(RTCAudioSession *)session { | 52 - (void)audioSessionMediaServerReset:(RTCAudioSession *)session { | 
| 41 } | 53 } | 
| 42 | 54 | 
| 43 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session { | 55 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session { | 
| 44 } | 56 } | 
| 45 | 57 | 
| 46 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session { | 58 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session { | 
| 47 } | 59 } | 
| 48 | 60 | 
|  | 61 - (void)audioSession:(RTCAudioSession *)audioSession | 
|  | 62     didChangeOutputVolume:(float)outputVolume { | 
|  | 63   _outputVolume = outputVolume; | 
|  | 64 } | 
|  | 65 | 
| 49 @end | 66 @end | 
| 50 | 67 | 
| 51 // A delegate that adds itself to the audio session on init and removes itself | 68 // A delegate that adds itself to the audio session on init and removes itself | 
| 52 // in its dealloc. | 69 // in its dealloc. | 
| 53 @interface RTCTestRemoveOnDeallocDelegate : RTCAudioSessionTestDelegate | 70 @interface RTCTestRemoveOnDeallocDelegate : RTCAudioSessionTestDelegate | 
| 54 @end | 71 @end | 
| 55 | 72 | 
| 56 @implementation RTCTestRemoveOnDeallocDelegate | 73 @implementation RTCTestRemoveOnDeallocDelegate | 
| 57 | 74 | 
| 58 - (instancetype)init { | 75 - (instancetype)init { | 
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 239   [audioSession unlockForConfiguration]; | 256   [audioSession unlockForConfiguration]; | 
| 240 | 257 | 
| 241   OCMVerify([mockAudioSession session]); | 258   OCMVerify([mockAudioSession session]); | 
| 242   OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption
     s:0 error:&error]); | 259   OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption
     s:0 error:&error]); | 
| 243   OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions
     :0 error:&error]); | 260   OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions
     :0 error:&error]); | 
| 244 | 261 | 
| 245   [mockAVAudioSession stopMocking]; | 262   [mockAVAudioSession stopMocking]; | 
| 246   [mockAudioSession stopMocking]; | 263   [mockAudioSession stopMocking]; | 
| 247 } | 264 } | 
| 248 | 265 | 
|  | 266 - (void)testAudioVolumeDidNotify { | 
|  | 267   RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 
|  | 268   RTCAudioSessionTestDelegate *delegate = | 
|  | 269       [[RTCAudioSessionTestDelegate alloc] init]; | 
|  | 270   [session addDelegate:delegate]; | 
|  | 271 | 
|  | 272   [session observeValueForKeyPath:@"outputVolume" | 
|  | 273                          ofObject:[AVAudioSession sharedInstance] | 
|  | 274                            change: | 
|  | 275         @{NSKeyValueChangeNewKey : | 
|  | 276             @([AVAudioSession sharedInstance].outputVolume) } | 
|  | 277                           context:nil]; | 
|  | 278 | 
|  | 279   EXPECT_NE(delegate.outputVolume, -1); | 
|  | 280   EXPECT_EQ([AVAudioSession sharedInstance].outputVolume, delegate.outputVolume)
     ; | 
|  | 281 } | 
|  | 282 | 
| 249 @end | 283 @end | 
| 250 | 284 | 
| 251 namespace webrtc { | 285 namespace webrtc { | 
| 252 | 286 | 
| 253 class AudioSessionTest : public ::testing::Test { | 287 class AudioSessionTest : public ::testing::Test { | 
| 254  protected: | 288  protected: | 
| 255   void TearDown() { | 289   void TearDown() { | 
| 256     RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 290     RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 
| 257     for (id<RTCAudioSessionDelegate> delegate : session.delegates) { | 291     for (id<RTCAudioSessionDelegate> delegate : session.delegates) { | 
| 258       [session removeDelegate:delegate]; | 292       [session removeDelegate:delegate]; | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 288 TEST_F(AudioSessionTest, AudioSessionActivation) { | 322 TEST_F(AudioSessionTest, AudioSessionActivation) { | 
| 289   RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 323   RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 
| 290   [test testAudioSessionActivation]; | 324   [test testAudioSessionActivation]; | 
| 291 } | 325 } | 
| 292 | 326 | 
| 293 TEST_F(AudioSessionTest, ConfigureWebRTCSession) { | 327 TEST_F(AudioSessionTest, ConfigureWebRTCSession) { | 
| 294   RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 328   RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 
| 295   [test testConfigureWebRTCSession]; | 329   [test testConfigureWebRTCSession]; | 
| 296 } | 330 } | 
| 297 | 331 | 
|  | 332 TEST_F(AudioSessionTest, AudioVolumeDidNotify) { | 
|  | 333   RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 
|  | 334   [test testAudioVolumeDidNotify]; | 
|  | 335 } | 
|  | 336 | 
| 298 }  // namespace webrtc | 337 }  // namespace webrtc | 
| OLD | NEW | 
|---|