20
20
#import < objc/runtime.h>
21
21
22
22
#import " FIRAuthAppDelegateProxy.h"
23
+ #import < GoogleUtilities/GULAppDelegateSwizzler.h>
24
+
23
25
#import < OCMock/OCMock.h>
24
26
25
27
NS_ASSUME_NONNULL_BEGIN
26
28
29
+ @interface GULAppDelegateSwizzler (FIRAuthAppDelegateProxyTests)
30
+ + (void )proxyAppDelegate : (id <UIApplicationDelegate>)appDelegate ;
31
+ @end
32
+
27
33
/* * @class FIRAuthEmptyAppDelegate
28
34
@brief A @c UIApplicationDelegate implementation that does nothing.
29
35
*/
@@ -208,56 +214,6 @@ - (void)testSharedInstance {
208
214
XCTAssertEqual (proxy1, proxy2);
209
215
}
210
216
211
- /* * @fn testNilApplication
212
- @brief Tests that initialization fails if the application is nil.
213
- */
214
- - (void )testNilApplication {
215
- XCTAssertNil ([[FIRAuthAppDelegateProxy alloc ] initWithApplication: nil ]);
216
- }
217
-
218
- /* * @fn testNilDelegate
219
- @brief Tests that initialization fails if the application's delegate is nil.
220
- */
221
- - (void )testNilDelegate {
222
- OCMExpect ([_mockApplication delegate ]).andReturn (nil );
223
- XCTAssertNil ([[FIRAuthAppDelegateProxy alloc ] initWithApplication: _mockApplication]);
224
- }
225
-
226
- /* * @fn testNonconformingDelegate
227
- @brief Tests that initialization fails if the application's delegate does not conform to
228
- @c UIApplicationDelegate protocol.
229
- */
230
- - (void )testNonconformingDelegate {
231
- OCMExpect ([_mockApplication delegate ]).andReturn (@" abc" );
232
- XCTAssertNil ([[FIRAuthAppDelegateProxy alloc ] initWithApplication: _mockApplication]);
233
- }
234
-
235
- /* * @fn testDisabledByBundleEntry
236
- @brief Tests that initialization fails if the proxy is disabled by a bundle entry.
237
- */
238
- - (void )testDisabledByBundleEntry {
239
- // Swizzle NSBundle's objectForInfoDictionaryKey to return @NO for the specific key.
240
- Method method = class_getInstanceMethod ([NSBundle class ], @selector (objectForInfoDictionaryKey: ));
241
- __block IMP originalImplementation;
242
- IMP newImplmentation = imp_implementationWithBlock (^id (id object, NSString *key) {
243
- if ([key isEqualToString: @" FirebaseAppDelegateProxyEnabled" ]) {
244
- return @NO ;
245
- }
246
- typedef id (*Implementation)(id object, SEL cmd, NSString *key);
247
- return ((Implementation)originalImplementation)(object, @selector (objectForInfoDictionaryKey: ),
248
- key);
249
- });
250
- originalImplementation = method_setImplementation (method, newImplmentation);
251
-
252
- // Verify that initialization fails.
253
- FIRAuthEmptyAppDelegate *delegate = [[FIRAuthEmptyAppDelegate alloc ] init ];
254
- OCMStub ([_mockApplication delegate ]).andReturn (delegate);
255
- XCTAssertNil ([[FIRAuthAppDelegateProxy alloc ] initWithApplication: _mockApplication]);
256
-
257
- // Unswizzle.
258
- imp_removeBlock (method_setImplementation (method, originalImplementation));
259
- }
260
-
261
217
// Deprecated methods are call intentionally in tests to verify behaviors on older iOS systems.
262
218
#pragma clang diagnostic push
263
219
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@@ -268,10 +224,14 @@ - (void)testDisabledByBundleEntry {
268
224
- (void )testEmptyDelegateOneHandler {
269
225
FIRAuthEmptyAppDelegate *delegate = [[FIRAuthEmptyAppDelegate alloc ] init ];
270
226
OCMExpect ([_mockApplication delegate ]).andReturn (delegate);
227
+
228
+ [GULAppDelegateSwizzler proxyAppDelegate: delegate];
229
+
271
230
__weak id weakProxy;
272
231
@autoreleasepool {
273
- FIRAuthAppDelegateProxy *proxy =
274
- [[FIRAuthAppDelegateProxy alloc ] initWithApplication: _mockApplication];
232
+ FIRAuthAppDelegateProxy *proxy = [[FIRAuthAppDelegateProxy alloc ] init ];
233
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: proxy];
234
+
275
235
XCTAssertNotNil (proxy);
276
236
277
237
// Verify certain methods are swizzled while others are not.
@@ -391,10 +351,13 @@ - (void)testEmptyDelegateOneHandler {
391
351
- (void )testLegacyDelegateTwoHandlers {
392
352
FIRAuthLegacyAppDelegate *delegate = [[FIRAuthLegacyAppDelegate alloc ] init ];
393
353
OCMExpect ([_mockApplication delegate ]).andReturn (delegate);
354
+
355
+ [GULAppDelegateSwizzler proxyAppDelegate: delegate];
356
+
394
357
__weak id weakProxy;
395
358
@autoreleasepool {
396
- FIRAuthAppDelegateProxy *proxy =
397
- [[FIRAuthAppDelegateProxy alloc ] initWithApplication: _mockApplication ];
359
+ FIRAuthAppDelegateProxy *proxy = [[FIRAuthAppDelegateProxy alloc ] init ];
360
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: proxy ];
398
361
XCTAssertNotNil (proxy);
399
362
400
363
// Verify certain methods are swizzled while others are not.
@@ -539,10 +502,13 @@ - (void)testModernDelegateWithUnaffectedInstance {
539
502
FIRAuthModernAppDelegate *delegate = [[FIRAuthModernAppDelegate alloc ] init ];
540
503
OCMExpect ([_mockApplication delegate ]).andReturn (delegate);
541
504
FIRAuthModernAppDelegate *unaffectedDelegate = [[FIRAuthModernAppDelegate alloc ] init ];
505
+
506
+ [GULAppDelegateSwizzler proxyAppDelegate: delegate];
507
+
542
508
__weak id weakProxy;
543
509
@autoreleasepool {
544
- FIRAuthAppDelegateProxy *proxy =
545
- [[FIRAuthAppDelegateProxy alloc ] initWithApplication: _mockApplication ];
510
+ FIRAuthAppDelegateProxy *proxy = [[FIRAuthAppDelegateProxy alloc ] init ];
511
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: proxy ];
546
512
XCTAssertNotNil (proxy);
547
513
548
514
// Verify certain methods are swizzled while others are not.
@@ -703,10 +669,12 @@ - (void)testModernDelegateWithUnaffectedInstance {
703
669
- (void )testOtherLegacyDelegateHandleOpenURL {
704
670
FIRAuthOtherLegacyAppDelegate *delegate = [[FIRAuthOtherLegacyAppDelegate alloc ] init ];
705
671
OCMExpect ([_mockApplication delegate ]).andReturn (delegate);
672
+ [GULAppDelegateSwizzler proxyAppDelegate: delegate];
673
+
706
674
__weak id weakProxy;
707
675
@autoreleasepool {
708
- FIRAuthAppDelegateProxy *proxy =
709
- [[FIRAuthAppDelegateProxy alloc ] initWithApplication: _mockApplication ];
676
+ FIRAuthAppDelegateProxy *proxy = [[FIRAuthAppDelegateProxy alloc ] init ];
677
+ [GULAppDelegateSwizzler registerAppDelegateInterceptor: proxy ];
710
678
XCTAssertNotNil (proxy);
711
679
712
680
// Verify certain methods are swizzled while others are not.
0 commit comments