2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- @ import Flutter;
5
+ # import " FLTGoogleSignInPlugin_Private.h "
6
6
7
+ @import Flutter;
7
8
@import XCTest;
8
9
@import google_sign_in;
9
10
@import GoogleSignIn;
@@ -16,7 +17,7 @@ @interface FLTGoogleSignInPluginTest : XCTestCase
16
17
@property (strong , nonatomic ) NSObject <FlutterBinaryMessenger> *mockBinaryMessenger;
17
18
@property (strong , nonatomic ) NSObject <FlutterPluginRegistrar> *mockPluginRegistrar;
18
19
@property (strong , nonatomic ) FLTGoogleSignInPlugin *plugin;
19
- @property (strong , nonatomic ) id mockSharedInstance ;
20
+ @property (strong , nonatomic ) id mockSignIn ;
20
21
21
22
@end
22
23
@@ -27,17 +28,16 @@ - (void)setUp {
27
28
self.mockBinaryMessenger = OCMProtocolMock (@protocol (FlutterBinaryMessenger));
28
29
self.mockPluginRegistrar = OCMProtocolMock (@protocol (FlutterPluginRegistrar));
29
30
30
- id mockSharedInstance = OCMClassMock ([GIDSignIn class ]);
31
- OCMStub ([mockSharedInstance sharedInstance ]).andReturn (mockSharedInstance);
32
- self.mockSharedInstance = mockSharedInstance;
31
+ id mockSignIn = OCMClassMock ([GIDSignIn class ]);
32
+ self.mockSignIn = mockSignIn;
33
33
34
34
OCMStub (self.mockPluginRegistrar .messenger ).andReturn (self.mockBinaryMessenger );
35
- self.plugin = [[FLTGoogleSignInPlugin alloc ] init ];
35
+ self.plugin = [[FLTGoogleSignInPlugin alloc ] initW ];
36
36
[FLTGoogleSignInPlugin registerWithRegistrar: self .mockPluginRegistrar];
37
37
}
38
38
39
39
- (void )tearDown {
40
- [self .mockSharedInstance stopMocking ];
40
+ [self .mockSignIn stopMocking ];
41
41
[super tearDown ];
42
42
}
43
43
@@ -65,7 +65,7 @@ - (void)testSignOut {
65
65
[expectation fulfill ];
66
66
}];
67
67
[self waitForExpectationsWithTimeout: 5.0 handler: nil ];
68
- OCMVerify ([self .mockSharedInstance signOut ]);
68
+ OCMVerify ([self .mockSignIn signOut ]);
69
69
}
70
70
71
71
- (void )testDisconnect {
@@ -75,7 +75,7 @@ - (void)testDisconnect {
75
75
[self .plugin handleMethodCall: methodCall
76
76
result: ^(id result){
77
77
}];
78
- OCMVerify ([self .mockSharedInstance disconnect ]);
78
+ OCMVerify ([self .mockSignIn disconnect ]);
79
79
}
80
80
81
81
- (void )testClearAuthCache {
@@ -120,14 +120,14 @@ - (void)testInitGoogleServiceInfoPlist {
120
120
}];
121
121
[self waitForExpectationsWithTimeout: 5.0 handler: nil ];
122
122
123
- id mockSharedInstance = self.mockSharedInstance ;
124
- OCMVerify ([mockSharedInstance setScopes: @[ @" mockScope1" ]]);
125
- OCMVerify ([mockSharedInstance setHostedDomain: @" example.com" ]);
123
+ id mockSignIn = self.mockSignIn ;
124
+ OCMVerify ([mockSignIn setScopes: @[ @" mockScope1" ]]);
125
+ OCMVerify ([mockSignIn setHostedDomain: @" example.com" ]);
126
126
127
127
// Set in example app GoogleService-Info.plist.
128
- OCMVerify ([mockSharedInstance
128
+ OCMVerify ([mockSignIn
129
129
setClientID: @" 479882132969-9i9aqik3jfjd7qhci1nqf0bm2g71rm1u.apps.googleusercontent.com" ]);
130
- OCMVerify ([mockSharedInstance setServerClientID: @" YOUR_SERVER_CLIENT_ID" ]);
130
+ OCMVerify ([mockSignIn setServerClientID: @" YOUR_SERVER_CLIENT_ID" ]);
131
131
}
132
132
133
133
- (void )testInitNullDomain {
@@ -141,7 +141,7 @@ - (void)testInitNullDomain {
141
141
[expectation fulfill ];
142
142
}];
143
143
[self waitForExpectationsWithTimeout: 5.0 handler: nil ];
144
- OCMVerify ([self .mockSharedInstance setHostedDomain: nil ]);
144
+ OCMVerify ([self .mockSignIn setHostedDomain: nil ]);
145
145
}
146
146
147
147
- (void )testInitDynamicClientId {
@@ -155,13 +155,13 @@ - (void)testInitDynamicClientId {
155
155
[expectation fulfill ];
156
156
}];
157
157
[self waitForExpectationsWithTimeout: 5.0 handler: nil ];
158
- OCMVerify ([self .mockSharedInstance setClientID: @" mockClientId" ]);
158
+ OCMVerify ([self .mockSignIn setClientID: @" mockClientId" ]);
159
159
}
160
160
161
161
#pragma mark - Is signed in
162
162
163
163
- (void )testIsNotSignedIn {
164
- OCMStub ([self .mockSharedInstance hasPreviousSignIn ]).andReturn (NO );
164
+ OCMStub ([self .mockSignIn hasPreviousSignIn ]).andReturn (NO );
165
165
166
166
FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName: @" isSignedIn"
167
167
arguments: nil ];
@@ -176,7 +176,7 @@ - (void)testIsNotSignedIn {
176
176
}
177
177
178
178
- (void )testIsSignedIn {
179
- OCMStub ([self .mockSharedInstance hasPreviousSignIn ]).andReturn (YES );
179
+ OCMStub ([self .mockSignIn hasPreviousSignIn ]).andReturn (YES );
180
180
181
181
FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName: @" isSignedIn"
182
182
arguments: nil ];
@@ -193,15 +193,15 @@ - (void)testIsSignedIn {
193
193
#pragma mark - Sign in silently
194
194
195
195
- (void )testSignInSilently {
196
- OCMExpect ([self .mockSharedInstance restorePreviousSignIn ]);
196
+ OCMExpect ([self .mockSignIn restorePreviousSignIn ]);
197
197
198
198
FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName: @" signInSilently"
199
199
arguments: nil ];
200
200
201
201
[self .plugin handleMethodCall: methodCall
202
202
result: ^(id result){
203
203
}];
204
- OCMVerifyAll (self.mockSharedInstance );
204
+ OCMVerifyAll (self.mockSignIn );
205
205
}
206
206
207
207
- (void )testSignInSilentlyFailsConcurrently {
@@ -210,7 +210,7 @@ - (void)testSignInSilentlyFailsConcurrently {
210
210
211
211
XCTestExpectation *expectation = [self expectationWithDescription: @" expect result returns true" ];
212
212
213
- OCMExpect ([self .mockSharedInstance restorePreviousSignIn ]).andDo (^(NSInvocation *invocation) {
213
+ OCMExpect ([self .mockSignIn restorePreviousSignIn ]).andDo (^(NSInvocation *invocation) {
214
214
// Simulate calling the same method while the previous one is in flight.
215
215
[self .plugin handleMethodCall: methodCall
216
216
result: ^(FlutterError *result) {
@@ -236,16 +236,16 @@ - (void)testSignIn {
236
236
result: ^(NSNumber *result){
237
237
}];
238
238
239
- id mockSharedInstance = self.mockSharedInstance ;
240
- OCMVerify ([mockSharedInstance
239
+ id mockSignIn = self.mockSignIn ;
240
+ OCMVerify ([mockSignIn
241
241
setPresentingViewController: [OCMArg isKindOfClass: [FlutterViewController class ]]]);
242
- OCMVerify ([mockSharedInstance signIn ]);
242
+ OCMVerify ([mockSignIn signIn ]);
243
243
}
244
244
245
245
- (void )testSignInExecption {
246
246
FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName: @" signIn"
247
247
arguments: nil ];
248
- OCMExpect ([self .mockSharedInstance signIn ])
248
+ OCMExpect ([self .mockSignIn signIn ])
249
249
.andThrow ([NSException exceptionWithName: @" MockName" reason: @" MockReason" userInfo: nil ]);
250
250
251
251
__block FlutterError *error;
@@ -263,7 +263,7 @@ - (void)testSignInExecption {
263
263
264
264
- (void )testGetTokens {
265
265
id mockUser = OCMClassMock ([GIDGoogleUser class ]);
266
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
266
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
267
267
268
268
id mockAuthentication = OCMClassMock ([GIDAuthentication class ]);
269
269
OCMStub ([mockAuthentication idToken ]).andReturn (@" mockIdToken" );
@@ -287,7 +287,7 @@ - (void)testGetTokens {
287
287
288
288
- (void )testGetTokensNoAuthKeychainError {
289
289
id mockUser = OCMClassMock ([GIDGoogleUser class ]);
290
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
290
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
291
291
292
292
id mockAuthentication = OCMClassMock ([GIDAuthentication class ]);
293
293
NSError *error = [NSError errorWithDomain: kGIDSignInErrorDomain
@@ -312,7 +312,7 @@ - (void)testGetTokensNoAuthKeychainError {
312
312
313
313
- (void )testGetTokensCancelledError {
314
314
id mockUser = OCMClassMock ([GIDGoogleUser class ]);
315
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
315
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
316
316
317
317
id mockAuthentication = OCMClassMock ([GIDAuthentication class ]);
318
318
NSError *error = [NSError errorWithDomain: kGIDSignInErrorDomain
@@ -337,7 +337,7 @@ - (void)testGetTokensCancelledError {
337
337
338
338
- (void )testGetTokensURLError {
339
339
id mockUser = OCMClassMock ([GIDGoogleUser class ]);
340
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
340
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
341
341
342
342
id mockAuthentication = OCMClassMock ([GIDAuthentication class ]);
343
343
NSError *error = [NSError errorWithDomain: NSURLErrorDomain code: NSURLErrorTimedOut userInfo: nil ];
@@ -360,7 +360,7 @@ - (void)testGetTokensURLError {
360
360
361
361
- (void )testGetTokensUnknownError {
362
362
id mockUser = OCMClassMock ([GIDGoogleUser class ]);
363
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
363
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
364
364
365
365
id mockAuthentication = OCMClassMock ([GIDAuthentication class ]);
366
366
NSError *error = [NSError errorWithDomain: @" BogusDomain" code: 42 userInfo: nil ];
@@ -384,7 +384,7 @@ - (void)testGetTokensUnknownError {
384
384
#pragma mark - Request scopes
385
385
386
386
- (void )testRequestScopesResultErrorIfNotSignedIn {
387
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (nil );
387
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (nil );
388
388
389
389
FlutterMethodCall *methodCall =
390
390
[FlutterMethodCall methodCallWithMethodName: @" requestScopes"
@@ -402,7 +402,7 @@ - (void)testRequestScopesResultErrorIfNotSignedIn {
402
402
- (void )testRequestScopesIfNoMissingScope {
403
403
// Mock Google Signin internal calls
404
404
GIDGoogleUser *mockUser = OCMClassMock ([GIDGoogleUser class ]);
405
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
405
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
406
406
NSArray *requestedScopes = @[ @" mockScope1" ];
407
407
OCMStub (mockUser.grantedScopes ).andReturn (requestedScopes);
408
408
FlutterMethodCall *methodCall =
@@ -421,11 +421,11 @@ - (void)testRequestScopesIfNoMissingScope {
421
421
- (void )testRequestScopesRequestsIfNotGranted {
422
422
// Mock Google Signin internal calls
423
423
GIDGoogleUser *mockUser = OCMClassMock ([GIDGoogleUser class ]);
424
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
424
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
425
425
NSArray *requestedScopes = @[ @" mockScope1" ];
426
426
OCMStub (mockUser.grantedScopes ).andReturn (@[]);
427
- id mockSharedInstance = self.mockSharedInstance ;
428
- OCMStub ([mockSharedInstance scopes ]).andReturn (@[]);
427
+ id mockSignIn = self.mockSignIn ;
428
+ OCMStub ([mockSignIn scopes ]).andReturn (@[]);
429
429
430
430
FlutterMethodCall *methodCall =
431
431
[FlutterMethodCall methodCallWithMethodName: @" requestScopes"
@@ -435,19 +435,19 @@ - (void)testRequestScopesRequestsIfNotGranted {
435
435
result: ^(id r){
436
436
}];
437
437
438
- OCMVerify ([mockSharedInstance setScopes: @[ @" mockScope1" ]]);
439
- OCMVerify ([mockSharedInstance signIn ]);
438
+ OCMVerify ([mockSignIn setScopes: @[ @" mockScope1" ]]);
439
+ OCMVerify ([mockSignIn signIn ]);
440
440
}
441
441
442
442
- (void )testRequestScopesReturnsFalseIfNotGranted {
443
443
// Mock Google Signin internal calls
444
444
GIDGoogleUser *mockUser = OCMClassMock ([GIDGoogleUser class ]);
445
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
445
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
446
446
NSArray *requestedScopes = @[ @" mockScope1" ];
447
447
OCMStub (mockUser.grantedScopes ).andReturn (@[]);
448
448
449
- OCMStub ([self .mockSharedInstance signIn ]).andDo (^(NSInvocation *invocation) {
450
- [((NSObject <GIDSignInDelegate> *)self .plugin) signIn: self .mockSharedInstance
449
+ OCMStub ([self .mockSignIn signIn ]).andDo (^(NSInvocation *invocation) {
450
+ [((NSObject <GIDSignInDelegate> *)self .plugin) signIn: self .mockSignIn
451
451
didSignInForUser: mockUser
452
452
withError: nil ];
453
453
});
@@ -468,14 +468,14 @@ - (void)testRequestScopesReturnsFalseIfNotGranted {
468
468
- (void )testRequestScopesReturnsTrueIfGranted {
469
469
// Mock Google Signin internal calls
470
470
GIDGoogleUser *mockUser = OCMClassMock ([GIDGoogleUser class ]);
471
- OCMStub ([self .mockSharedInstance currentUser ]).andReturn (mockUser);
471
+ OCMStub ([self .mockSignIn currentUser ]).andReturn (mockUser);
472
472
NSArray *requestedScopes = @[ @" mockScope1" ];
473
473
NSMutableArray *availableScopes = [NSMutableArray new ];
474
474
OCMStub (mockUser.grantedScopes ).andReturn (availableScopes);
475
475
476
- OCMStub ([self .mockSharedInstance signIn ]).andDo (^(NSInvocation *invocation) {
476
+ OCMStub ([self .mockSignIn signIn ]).andDo (^(NSInvocation *invocation) {
477
477
[availableScopes addObject: @" mockScope1" ];
478
- [((NSObject <GIDSignInDelegate> *)self .plugin) signIn: self .mockSharedInstance
478
+ [((NSObject <GIDSignInDelegate> *)self .plugin) signIn: self .mockSignIn
479
479
didSignInForUser: mockUser
480
480
withError: nil ];
481
481
});
0 commit comments