Adding a KVO context to avoid issues with future super/sub-classing.
Bug: webrtc:8342 Change-Id: I457858056ffc7f33bbfb261153301ea2ccd71a51 Reviewed-on: https://webrtc-review.googlesource.com/6440 Commit-Queue: Peter Hanspers <peterhanspers@webrtc.org> Reviewed-by: Anders Carlsson <andersc@webrtc.org> Reviewed-by: Daniela Jovanoska Petrenko <denicija@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20389}
This commit is contained in:
committed by
Commit Bot
parent
bd92d8dd2a
commit
47217364f5
@ -18,6 +18,22 @@
|
||||
#import "WebRTC/RTCAudioSession.h"
|
||||
#import "WebRTC/RTCAudioSessionConfiguration.h"
|
||||
|
||||
@interface RTCAudioSession (UnitTesting)
|
||||
|
||||
- (instancetype)initWithAudioSession:(id)audioSession;
|
||||
|
||||
@end
|
||||
|
||||
@interface MockAVAudioSession : NSObject
|
||||
|
||||
@property (nonatomic, readwrite, assign) float outputVolume;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MockAVAudioSession
|
||||
@synthesize outputVolume = _outputVolume;
|
||||
@end
|
||||
|
||||
@interface RTCAudioSessionTestDelegate : NSObject <RTCAudioSessionDelegate>
|
||||
|
||||
@property (nonatomic, readonly) float outputVolume;
|
||||
@ -265,20 +281,16 @@ OCMLocation *OCMMakeLocation(id testCase, const char *fileCString, int line){
|
||||
}
|
||||
|
||||
- (void)testAudioVolumeDidNotify {
|
||||
RTCAudioSession *session = [RTCAudioSession sharedInstance];
|
||||
MockAVAudioSession *mockAVAudioSession = [[MockAVAudioSession alloc] init];
|
||||
RTCAudioSession *session = [[RTCAudioSession alloc] initWithAudioSession:mockAVAudioSession];
|
||||
RTCAudioSessionTestDelegate *delegate =
|
||||
[[RTCAudioSessionTestDelegate alloc] init];
|
||||
[session addDelegate:delegate];
|
||||
|
||||
[session observeValueForKeyPath:@"outputVolume"
|
||||
ofObject:[AVAudioSession sharedInstance]
|
||||
change:
|
||||
@{NSKeyValueChangeNewKey :
|
||||
@([AVAudioSession sharedInstance].outputVolume) }
|
||||
context:nil];
|
||||
float expectedVolume = 0.75;
|
||||
mockAVAudioSession.outputVolume = expectedVolume;
|
||||
|
||||
EXPECT_NE(delegate.outputVolume, -1);
|
||||
EXPECT_EQ([AVAudioSession sharedInstance].outputVolume, delegate.outputVolume);
|
||||
EXPECT_EQ(expectedVolume, delegate.outputVolume);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user