Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[local_auth_darwin] MacOS Support #6267

Open
wants to merge 119 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
532ed7f
Beginning of macos support
alexrabin-sentracam Mar 5, 2024
0eb64ee
Merge branch 'flutter:main' into macos-support
alexrabin-sentracam Mar 5, 2024
25ca34e
Made macos deployment target 10.15
alexrabin-sentracam Mar 5, 2024
c57ac02
Merge branch 'macos-support' of https://github.com/alexrabin-sentraca…
alexrabin-sentracam Mar 5, 2024
00bd678
Separate ios and macos code
alexrabin-sentracam Mar 5, 2024
509708f
Adjusted format
alexrabin-sentracam Mar 5, 2024
fd6c539
Updated change log
alexrabin-sentracam Mar 5, 2024
44dd8c8
Removed duplicated analysis_options.yaml
Mar 5, 2024
4f68b52
Removed unnecessary widget_test in darwin
Mar 5, 2024
8646867
Added license blocks in macos example files
Mar 5, 2024
676b0eb
Changed iOSAuthMessages to DarwinAuthMessages
Mar 5, 2024
bcee2e7
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 5, 2024
4aab9d8
Added macos comment
Mar 5, 2024
1bded66
Changed macOS capitalization
Mar 5, 2024
7335837
Removed unnecessary test, added comment, and changed version number
Mar 5, 2024
849c07b
Removed prettier ignore
Mar 5, 2024
c810eb4
Reset upgrade version
Mar 5, 2024
6867b3a
Revert "Changed iOSAuthMessages to DarwinAuthMessages" and add MacOSA…
Mar 5, 2024
995f41d
Changed podspec to use ios deployment_target
Mar 5, 2024
8ab5d09
Checks if macos is 10.15 or higher before checking for faceid
Mar 5, 2024
507470e
Shows correct window for registrar
Mar 5, 2024
05b52ae
Changed wording
Mar 5, 2024
8f35101
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 5, 2024
2b0e6d6
Combined @available statements and renamed keywindow
Mar 6, 2024
c808c82
Created initWithRegistrar initializer
Mar 6, 2024
64bd0b7
Moved runner tests
Mar 6, 2024
7dab5b4
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 6, 2024
7ff9871
Fixed format issues
Mar 6, 2024
04f6a76
Revert "Moved runner tests"
Mar 6, 2024
04c8f12
Fixed tests and platform available check
Mar 6, 2024
64366dd
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 6, 2024
7babc9c
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 7, 2024
b71f172
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 7, 2024
cfabac0
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 8, 2024
5bc080e
Added macos tests
Mar 8, 2024
d794eb9
Fixed format
Mar 8, 2024
74ae648
Added info.plist key and added license heading
Mar 8, 2024
2374375
Added xml language to readme
Mar 8, 2024
f053fce
Upgraded project settings
Mar 8, 2024
04049a3
Reset example macos project
Mar 8, 2024
9be16c3
Fixed macos tests
Mar 8, 2024
ff533bc
Removed settings button on macos due to no native support from Apple …
Mar 8, 2024
783b0cc
Added @available check
Mar 8, 2024
5e9b627
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 11, 2024
1748039
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 11, 2024
ebdb5f1
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 11, 2024
b73254a
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 12, 2024
c4c9f3b
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 12, 2024
6ca1476
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 18, 2024
69db0ec
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 18, 2024
a39e82a
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 19, 2024
59ce98a
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 19, 2024
e54c7ea
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 19, 2024
b8ca53a
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 20, 2024
018fe8f
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 20, 2024
ff38a26
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 21, 2024
e76f6bc
Addressed additional feedback
Mar 25, 2024
72b8212
Fixed plugin tests
Mar 25, 2024
113195e
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 25, 2024
7525f01
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 26, 2024
6330a9e
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 26, 2024
79ebae9
Made initWithRegistrar the designated initializer
Mar 26, 2024
0c84f2b
Merge branch 'macos-support' of https://github.com/alexrabin-sentraca…
Mar 26, 2024
c84a376
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 27, 2024
5dc7c75
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 29, 2024
c33ed13
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 1, 2024
186d89c
Updated messaging
Apr 1, 2024
f9e11db
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 4, 2024
c45084b
Remove gotosettingsbutton on macos and didn't make it required
Apr 4, 2024
7003142
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 9, 2024
18453dc
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 11, 2024
fc14107
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 18, 2024
5840a73
Merge branch 'flutter:main' into macos-support
alexrabin-sentracam Apr 22, 2024
ce1fa37
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 24, 2024
ad83e24
Adjusted format
Apr 24, 2024
8beb6dd
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 24, 2024
067a0c0
Added initWithContextFactoryAndRegistrar since tests failing due to m…
Apr 24, 2024
e3e89d4
Fixed mock test error
Apr 24, 2024
a9167cc
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 25, 2024
0f56ad6
Created base StubAlertFactory
Apr 25, 2024
17bd1c7
Merge branch 'macos-support' of https://github.com/alexrabin-sentraca…
Apr 25, 2024
2441440
Added test to check if the alert window is using the registrar window
Apr 25, 2024
8af7ec7
Added overridemacosmessages
Apr 25, 2024
4fcbc5d
Removes default false for overrideUseMacOSAuthMessages
Apr 25, 2024
8bd0531
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 26, 2024
44e5ae3
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 29, 2024
51b3b02
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 29, 2024
6d0684f
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 29, 2024
ca5789f
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 29, 2024
6d5a0c6
Merge branch 'main' into macos-support
alexrabin-sentracam May 7, 2024
11e6991
Merge branch 'main' into macos-support
alexrabin-sentracam May 8, 2024
316bb68
Updated method names
May 8, 2024
3728490
Fixed comment format
May 8, 2024
5b72aea
Fixed macos tests
May 8, 2024
6dd9092
Merge branch 'main' into macos-support
alexrabin-sentracam May 8, 2024
b5ea028
Merge branch 'main' into macos-support
alexrabin-sentracam May 9, 2024
dd545e5
Merge branch 'main' of https://github.com/flutter/packages into macos…
May 15, 2024
85678af
Upgraded version to 1.4.0
May 15, 2024
679854a
Removed copy property
May 15, 2024
464ae48
Checks parent window correctly and uses nsa;ert object
May 15, 2024
05bc529
Merge branch 'main' into macos-support
alexrabin-sentracam May 16, 2024
d3ce499
Merge branch 'main' into macos-support
alexrabin-sentracam May 20, 2024
57c50d3
Added nonnulll keyword
May 20, 2024
860d198
Updated format
May 20, 2024
9224412
Added nonnull
May 20, 2024
9c345f9
Added non null to create alert
May 20, 2024
71a2824
Merge branch 'main' into macos-support
alexrabin-sentracam May 20, 2024
0d420c5
Updated elif check
May 20, 2024
3415984
Merge branch 'macos-support' of https://github.com/alexrabin-sentraca…
May 20, 2024
09236d6
Added target conditionals import
May 20, 2024
b0de86c
Added declaration comments
May 20, 2024
288b04b
Merge branch 'main' into macos-support
alexrabin-sentracam May 21, 2024
23305d0
Merge remote-tracking branch 'upstream/main' into macos-support
May 29, 2024
2293ff6
Merge branch 'main' into macos-support
alexrabin-sentracam May 29, 2024
46ce252
Merge branch 'main' into macos-support
alexrabin-sentracam May 29, 2024
0f7dac8
Merge branch 'main' into macos-support
alexrabin-sentracam May 29, 2024
a91e4e9
Fixed swift tests
May 30, 2024
e5c9b97
Merge branch 'main' into macos-support
alexrabin-sentracam May 30, 2024
f90387f
Merge branch 'main' into macos-support
alexrabin-sentracam May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ Amir Panahandeh <amirpanahandeh@gmail.com>
Daniele Cambi <dancam.dev@gmail.com>
Michele Benedetti <michelebenx98@gmail.com>
Taskulu LDA <contributions@taskulu.com>
Alexander Rabin <alex.rabin@sentracam.com>
LinXunFeng <linxunfeng@yeah.net>
Hashir Shoaib <hashirshoaeb@gmail.com>
3 changes: 3 additions & 0 deletions packages/local_auth/local_auth_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.4.0

* Adds macOS support.
## 1.3.1

* Adjusts implementation for improved testability, and removes use of OCMock.
Expand Down
4 changes: 2 additions & 2 deletions packages/local_auth/local_auth_darwin/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# local_auth_darwin

The iOS implementation of [`local_auth`][1].
The iOS and macOS implementation of [`local_auth`][1].

## Usage

Expand All @@ -12,4 +12,4 @@ However, if you `import` this package to use any of its APIs directly, you
should add it to your `pubspec.yaml` as usual.

[1]: https://pub.dev/packages/local_auth
[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin
[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import Flutter
import XCTest

@testable import local_auth_darwin

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if os(iOS)
import Flutter
#else
import FlutterMacOS
#endif

// Set a long timeout to avoid flake due to slow CI.
private let timeout: TimeInterval = 30.0

/// A context factory that returns preset contexts.
final class StubAuthContextFactory: NSObject, FLADAuthContextFactory {

var contexts: [FLADAuthContext]
init(contexts: [FLADAuthContext]) {
self.contexts = contexts
Expand All @@ -23,6 +28,35 @@ final class StubAuthContextFactory: NSObject, FLADAuthContextFactory {
}
}

final class StubAlertFactory: NSObject, FLADAlertFactory {

#if os(macOS)
var alert: NSAlert
#else
var alertController: UIAlertController
#endif

#if os(macOS)
init(alert: NSAlert) {
self.alert = alert
}

func createAlert() -> NSAlert {
return self.alert
}
#else
init(alertController: UIAlertController) {
self.alertController = alertController
}

func createAlertController(
withTitle title: String?, message: String?, preferredStyle: UIAlertController.Style
) -> UIAlertController {
return self.alertController
}
#endif
}

final class StubAuthContext: NSObject, FLADAuthContext {
/// Whether calls to this stub are expected to be for biometric authentication.
///
Expand Down Expand Up @@ -75,8 +109,12 @@ class FLALocalAuthPluginTests: XCTestCase {

func testSuccessfullAuthWithBiometrics() throws {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)

let strings = createAuthStrings()
stubAuthContext.expectBiometrics = true
Expand All @@ -99,9 +137,13 @@ class FLALocalAuthPluginTests: XCTestCase {

func testSuccessfullAuthWithoutBiometrics() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()

let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
let strings = createAuthStrings()
stubAuthContext.evaluateResponse = true

Expand All @@ -123,8 +165,12 @@ class FLALocalAuthPluginTests: XCTestCase {

func testFailedAuthWithBiometrics() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)

let strings = createAuthStrings()
stubAuthContext.expectBiometrics = true
Expand Down Expand Up @@ -153,9 +199,12 @@ class FLALocalAuthPluginTests: XCTestCase {

func testFailedWithUnknownErrorCode() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
let strings = createAuthStrings()
stubAuthContext.evaluateError = NSError(domain: "error", code: 99)

Expand All @@ -177,9 +226,12 @@ class FLALocalAuthPluginTests: XCTestCase {

func testSystemCancelledWithoutStickyAuth() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
let strings = createAuthStrings()
stubAuthContext.evaluateError = NSError(domain: "error", code: LAError.systemCancel.rawValue)

Expand All @@ -201,9 +253,12 @@ class FLALocalAuthPluginTests: XCTestCase {

func testFailedAuthWithoutBiometrics() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
let strings = createAuthStrings()
stubAuthContext.evaluateError = NSError(
domain: "error", code: LAError.authenticationFailed.rawValue)
Expand All @@ -230,9 +285,12 @@ class FLALocalAuthPluginTests: XCTestCase {

func testLocalizedFallbackTitle() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
let strings = createAuthStrings()
strings.localizedFallbackTitle = "a title"
stubAuthContext.evaluateResponse = true
Expand All @@ -255,9 +313,12 @@ class FLALocalAuthPluginTests: XCTestCase {

func testSkippedLocalizedFallbackTitle() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
let strings = createAuthStrings()
strings.localizedFallbackTitle = nil
stubAuthContext.evaluateResponse = true
Expand All @@ -278,9 +339,12 @@ class FLALocalAuthPluginTests: XCTestCase {

func testDeviceSupportsBiometrics_withEnrolledHardware() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()
let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
stubAuthContext.expectBiometrics = true

var error: FlutterError?
Expand All @@ -291,9 +355,13 @@ class FLALocalAuthPluginTests: XCTestCase {

func testDeviceSupportsBiometrics_withNonEnrolledHardware() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()

let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
stubAuthContext.expectBiometrics = true
stubAuthContext.canEvaluateError = NSError(
domain: "error", code: LAError.biometryNotEnrolled.rawValue)
Expand All @@ -306,9 +374,13 @@ class FLALocalAuthPluginTests: XCTestCase {

func testDeviceSupportsBiometrics_withNoBiometricHardware() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()

let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
stubAuthContext.expectBiometrics = true
stubAuthContext.canEvaluateError = NSError(domain: "error", code: 0)

Expand All @@ -320,11 +392,18 @@ class FLALocalAuthPluginTests: XCTestCase {

func testGetEnrolledBiometricsWithFaceID() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()
let registrar: FlutterPluginRegistrar = createRegistrar()

let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)
stubAuthContext.expectBiometrics = true
stubAuthContext.biometryType = .faceID
if #available(iOS 11, macOS 10.15, *) {
stubAuthContext.biometryType = .faceID

}

var error: FlutterError?
let result = plugin.getEnrolledBiometricsWithError(&error)
Expand All @@ -335,8 +414,14 @@ class FLALocalAuthPluginTests: XCTestCase {

func testGetEnrolledBiometricsWithTouchID() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()

let registrar: FlutterPluginRegistrar = createRegistrar()

let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)

stubAuthContext.expectBiometrics = true
stubAuthContext.biometryType = .touchID
Expand All @@ -350,8 +435,14 @@ class FLALocalAuthPluginTests: XCTestCase {

func testGetEnrolledBiometricsWithoutEnrolledHardware() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()

let registrar: FlutterPluginRegistrar = createRegistrar()

let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)

stubAuthContext.expectBiometrics = true
stubAuthContext.canEvaluateError = NSError(
Expand All @@ -365,8 +456,14 @@ class FLALocalAuthPluginTests: XCTestCase {

func testIsDeviceSupportedHandlesSupported() {
let stubAuthContext = StubAuthContext()
let alertFactory = createStubAlertFactory()

let registrar: FlutterPluginRegistrar = createRegistrar()

let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)

var error: FlutterError?
let result = plugin.isDeviceSupportedWithError(&error)
Expand All @@ -378,8 +475,14 @@ class FLALocalAuthPluginTests: XCTestCase {
let stubAuthContext = StubAuthContext()
// An arbitrary error to cause canEvaluatePolicy to return false.
stubAuthContext.canEvaluateError = NSError(domain: "error", code: 1)
let alertFactory = createStubAlertFactory()

let registrar: FlutterPluginRegistrar = createRegistrar()

let plugin = FLALocalAuthPlugin(
contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]))

contextFactory: StubAuthContextFactory(contexts: [stubAuthContext]), registrar: registrar,
alertFactory: alertFactory)

var error: FlutterError?
let result = plugin.isDeviceSupportedWithError(&error)
Expand All @@ -394,4 +497,24 @@ class FLALocalAuthPluginTests: XCTestCase {
goToSettingsDescription: "Settings", cancelButton: "Cancel", localizedFallbackTitle: nil)
}

func createStubAlertFactory() -> StubAlertFactory {
var alertFactory: StubAlertFactory
#if os(macOS)
let alert = NSAlert()
alertFactory = StubAlertFactory(alert: alert)
#else
let mock = OCSwiftClassMock<UIAlertController>(UIAlertController.self)!
let alertController = mock.object!
alertFactory = StubAlertFactory(alertController: alertController)

#endif
return alertFactory
}

func createRegistrar() -> FlutterPluginRegistrar {
let mock = OCSwiftProtocolMock<FlutterPluginRegistrar>(FlutterPluginRegistrar.self)!
let registrar = mock.protocol!
return registrar
}

}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not re-introduce OCMock; I removed it intentionally. New mocks/stubs should use the same pattern the other tests now use, which is to introduce a protocol that has the desired methods, and then have tests implement that protocol. See here, here, and here for an example of the pattern. (I would expect the new wrappers you would need to be simpler than that one.)

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

@interface OCSwiftProtocolMock<MockType> : NSObject

@property(nonatomic, readonly) MockType protocol;

- (instancetype)init:(Protocol *)mockProtocol;

@end

@interface OCSwiftClassMock<MockType> : NSObject

@property(nonatomic, readonly) MockType object;

- (instancetype)init:(Class)classObject;

@end