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; | |
tkchin_webrtc
2017/05/25 20:24:33
spaces
| |
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)audioVolumeDidChange:(float)volume { | |
62 _outputVolume = volume; | |
63 } | |
64 | |
49 @end | 65 @end |
50 | 66 |
51 // A delegate that adds itself to the audio session on init and removes itself | 67 // A delegate that adds itself to the audio session on init and removes itself |
52 // in its dealloc. | 68 // in its dealloc. |
53 @interface RTCTestRemoveOnDeallocDelegate : RTCAudioSessionTestDelegate | 69 @interface RTCTestRemoveOnDeallocDelegate : RTCAudioSessionTestDelegate |
54 @end | 70 @end |
55 | 71 |
56 @implementation RTCTestRemoveOnDeallocDelegate | 72 @implementation RTCTestRemoveOnDeallocDelegate |
57 | 73 |
58 - (instancetype)init { | 74 - (instancetype)init { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 [audioSession unlockForConfiguration]; | 255 [audioSession unlockForConfiguration]; |
240 | 256 |
241 OCMVerify([mockAudioSession session]); | 257 OCMVerify([mockAudioSession session]); |
242 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption s:0 error:&error]); | 258 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption s:0 error:&error]); |
243 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions :0 error:&error]); | 259 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions :0 error:&error]); |
244 | 260 |
245 [mockAVAudioSession stopMocking]; | 261 [mockAVAudioSession stopMocking]; |
246 [mockAudioSession stopMocking]; | 262 [mockAudioSession stopMocking]; |
247 } | 263 } |
248 | 264 |
265 - (void)testAudioVolumeDidNotify { | |
266 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | |
267 RTCAudioSessionTestDelegate *delegate = | |
268 [[RTCAudioSessionTestDelegate alloc] init]; | |
269 [session addDelegate:delegate]; | |
270 | |
271 [session observeValueForKeyPath:@"outputVolume" | |
272 ofObject:[AVAudioSession sharedInstance] | |
273 change: | |
274 @{NSKeyValueChangeNewKey : @([AVAudioSession sharedInstance].outputVolum e) } | |
tkchin_webrtc
2017/05/25 20:24:33
run git clang-format with the .clang-format file i
| |
275 context:nil]; | |
276 | |
277 EXPECT_NE(delegate.outputVolume, -1); | |
278 EXPECT_EQ([AVAudioSession sharedInstance].outputVolume, delegate.outputVolume) ; | |
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, AudioVolumeDidNotify) { | |
331 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | |
332 [test testAudioVolumeDidNotify]; | |
333 } | |
334 | |
298 } // namespace webrtc | 335 } // namespace webrtc |
OLD | NEW |