Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions GoogleSignIn/Sources/GIDApplication/API/GIDApplication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/// The subset of `UIApplication` that Google Sign-In's EMM error handling depends on.
///
/// Production code uses `GIDSharedApplication`, which forwards to
/// `UIApplication.sharedApplication`; tests use `GIDFakeApplication`.
@protocol GIDApplication <NSObject>

/// The window that currently receives keyboard and other non-touch events, if any.
- (nullable UIWindow *)keyWindow;

/// Asks the system to open `url`.
- (void)openURL:(NSURL *)url;

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
41 changes: 41 additions & 0 deletions GoogleSignIn/Sources/GIDApplication/Fake/GIDFakeApplication.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "GoogleSignIn/Sources/GIDApplication/API/GIDApplication.h"

NS_ASSUME_NONNULL_BEGIN

/// An in-memory `GIDApplication` for tests.
@interface GIDFakeApplication : NSObject <GIDApplication>

/// The window returned by `-keyWindow`. Defaults to nil.
@property(nonatomic, strong, nullable) UIWindow *keyWindow;

/// Every URL passed to `-openURL:`, in call order.
@property(nonatomic, readonly) NSArray<NSURL *> *openedURLs;

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
50 changes: 50 additions & 0 deletions GoogleSignIn/Sources/GIDApplication/Fake/GIDFakeApplication.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import "GoogleSignIn/Sources/GIDApplication/Fake/GIDFakeApplication.h"

NS_ASSUME_NONNULL_BEGIN

@implementation GIDFakeApplication {
// Every URL passed to `-openURL:`, in call order.
NSMutableArray<NSURL *> *_openedURLs;
}

- (instancetype)init {
self = [super init];
if (self) {
_openedURLs = [NSMutableArray array];
}
return self;
}

- (NSArray<NSURL *> *)openedURLs {
return [_openedURLs copy];
}

- (void)openURL:(NSURL *)url {
[_openedURLs addObject:url];
}

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import <Foundation/Foundation.h>

#import "GoogleSignIn/Sources/GIDApplication/API/GIDApplication.h"

NS_ASSUME_NONNULL_BEGIN

/// A `GIDApplication` backed by `UIApplication.sharedApplication`.
///
/// `UIApplication.sharedApplication` is looked up on every call rather than captured at
/// initialization, so instances can be created before the application object exists.
@interface GIDSharedApplication : NSObject <GIDApplication>
@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import "GoogleSignIn/Sources/GIDApplication/Implementation/GIDSharedApplication.h"

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@implementation GIDSharedApplication

- (nullable UIWindow *)keyWindow {
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
if ([scene isKindOfClass:[UIWindowScene class]] &&
scene.activationState == UISceneActivationStateForegroundActive) {
return ((UIWindowScene *)scene).keyWindow;
}
}
return nil;
}

- (void)openURL:(NSURL *)url {
[UIApplication.sharedApplication openURL:url options:@{} completionHandler:nil];
}

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Loading