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

Unified Diff: webrtc/modules/audio_device/ios/objc/RTCAudioSessionTest.mm

Issue 1877643002: Fix RTCAudioSession crash in removeDelegate. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_device/ios/objc/RTCAudioSessionTest.mm
diff --git a/webrtc/modules/audio_device/ios/objc/RTCAudioSessionTest.mm b/webrtc/modules/audio_device/ios/objc/RTCAudioSessionTest.mm
index 603e450c758edf2bfca1910d03c81fed5b6b2ad6..7cbd2a982a95d48a4b6f97e7cfa19b29a3902c7c 100644
--- a/webrtc/modules/audio_device/ios/objc/RTCAudioSessionTest.mm
+++ b/webrtc/modules/audio_device/ios/objc/RTCAudioSessionTest.mm
@@ -46,6 +46,28 @@
@end
+// A delegate that adds itself to the audio session on init and removes itself
+// in its dealloc.
+@interface RTCTestRemoveOnDeallocDelegate : RTCAudioSessionTestDelegate
+@end
+
+@implementation RTCTestRemoveOnDeallocDelegate
+
+- (instancetype)init {
+ if (self = [super init]) {
+ RTCAudioSession *session = [RTCAudioSession sharedInstance];
+ [session addDelegate:self];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ RTCAudioSession *session = [RTCAudioSession sharedInstance];
+ [session removeDelegate:self];
+}
+
+@end
+
@interface RTCAudioSessionTest : NSObject
@@ -142,6 +164,18 @@
EXPECT_TRUE(session.delegates[0]);
}
+// Tests that we don't crash when removing delegates in dealloc.
+// Added as a regression test.
+- (void)testRemoveDelegateOnDealloc {
+ @autoreleasepool {
+ RTCTestRemoveOnDeallocDelegate *delegate =
+ [[RTCTestRemoveOnDeallocDelegate alloc] init];
+ EXPECT_TRUE(delegate);
+ }
+ RTCAudioSession *session = [RTCAudioSession sharedInstance];
+ EXPECT_EQ(0u, session.delegates.size());
+}
+
@end
namespace webrtc {
@@ -176,4 +210,9 @@ TEST_F(AudioSessionTest, ZeroingWeakDelegate) {
[test testZeroingWeakDelegate];
}
+TEST_F(AudioSessionTest, RemoveDelegateOnDealloc) {
+ RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init];
+ [test testRemoveDelegateOnDealloc];
+}
+
} // namespace webrtc
« no previous file with comments | « webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698