Skip to content

[google_sign_in] Increase iOS coverage tests - #12484

Open
victogomez-cs wants to merge 1 commit into
flutter:mainfrom
victogomez-cs:google_sign_in_ios_coverage_tests
Open

[google_sign_in] Increase iOS coverage tests#12484
victogomez-cs wants to merge 1 commit into
flutter:mainfrom
victogomez-cs:google_sign_in_ios_coverage_tests

Conversation

@victogomez-cs

@victogomez-cs victogomez-cs commented Aug 17, 2026

Copy link
Copy Markdown

Adds native unit tests for previously untested paths in FLTGoogleSignInPlugin.m before the Objective-C → Swift migration. Production code is unchanged.

This is a tests-only change, so it does not bump the package version or CHANGELOG.

Native unit tests go from 21 tests / 6 suites to 31 tests / 11 suites.

New test cases

urlHandling (iOS / Mac Catalyst only) — these APIs do not exist on macOS (handleOpenURLs: is the macOS path):

  • applicationOpenURLapplication:openURL:options: forwards the URL to GID and returns true
  • applicationOpenURLReturnsHandleResult — same path returns false when GID does
  • sceneOpenURLContextsscene:openURLContexts: forwards the URL from a UIOpenURLContext stand-in

errorMapping:

  • mapsRemainingGIDSignInErrorCodes (parameterized):
    • GIDSignInError.keychainFSIGoogleSignInErrorCode.keychainError
    • GIDSignInError.EMMFSIGoogleSignInErrorCode.eemError
    • GIDSignInError.unknownFSIGoogleSignInErrorCode.unknown
    • unrecognized SDK code (12345) → FSIGoogleSignInErrorCode.unknown
  • sanitizesComplexUserInfoInFlutterErrorFSISanitizedUserInfo keeps strings/numbers/URLs/arrays/dicts/nested errors and stringifies unsupported types (e.g. Date)

disconnect:

  • disconnectReturnsFlutterErrorOnFailure — a GID disconnect failure is returned as a Flutter error with domain/code and userInfo

userData:

  • signInWithoutProfileImageOmitsPhotoUrl — a user with no profile photo gets photoUrl == nil and still maps displayName

topViewController (iOS / Mac Catalyst only) — macOS presents with NSWindow, not a UIViewController hierarchy:

  • usesNavigationControllerVisibleController — presents from the nav stack’s top VC
  • usesTabBarControllerSelectedController — presents from the selected tab VC
  • usesPresentedViewController — presents from a presented VC

Also records URLs passed to TestSignIn.handle(_:) so the URL-handling cases can assert the fake was called.

First part of Swift migration to backfill code coverage for flutter/flutter#119103

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@google-cla

google-cla Bot commented Aug 17, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a comprehensive suite of Swift unit tests for the iOS Google Sign-In plugin, covering URL handling, error mapping, disconnect scenarios, user data parsing, and top view controller resolution. The review feedback suggests passing nil instead of a scene instance in the sceneOpenURLContexts test to prevent potential test failures in headless CI environments where connected scenes may be empty.

Comment on lines +731 to +743
@Test func sceneOpenURLContexts() throws {
let (plugin, fakeSignIn) = createTestPlugin()
let url = URL(string: "com.googleusercontent.apps.test:/oauthredirect")!
let scene = try #require(UIApplication.shared.connectedScenes.first)
let fakeContext = FakeOpenURLContext(url: url)

plugin.perform(
NSSelectorFromString("scene:openURLContexts:"),
with: scene,
with: NSSet(object: fakeContext))

#expect(fakeSignIn.handledURLs == [url])
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In headless unit test environments (such as CI runners), UIApplication.shared.connectedScenes can be empty, which causes try #require(UIApplication.shared.connectedScenes.first) to throw and fail the test. Since the scene parameter is completely unused in the plugin's implementation of scene:openURLContexts:, we can pass nil instead and make the test more robust and independent of the application's scene state.

      @Test func sceneOpenURLContexts() {
        let (plugin, fakeSignIn) = createTestPlugin()
        let url = URL(string: "com.googleusercontent.apps.test:/oauthredirect")!
        let fakeContext = FakeOpenURLContext(url: url)

        plugin.perform(
          NSSelectorFromString("scene:openURLContexts:"),
          with: nil,
          with: NSSet(object: fakeContext))

        #expect(fakeSignIn.handledURLs == [url])
      }

@jmagman jmagman added the triage-ios Should be looked at in iOS triage label Aug 17, 2026
Add URL handling, error mapping, disconnect, and topViewController cases so FLTGoogleSignInPlugin.m is covered before the Obj-C to Swift migration.
@victogomez-cs
victogomez-cs force-pushed the google_sign_in_ios_coverage_tests branch from e37d0b6 to 2dccfa6 Compare August 17, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants