|
| 1 | +// Copyright 2019 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:async'; |
| 6 | + |
| 7 | +import 'package:flutter/services.dart'; |
| 8 | +import 'package:flutter_test/flutter_test.dart'; |
| 9 | +import 'package:local_auth/auth_strings.dart'; |
| 10 | +import 'package:local_auth/local_auth.dart'; |
| 11 | +import 'package:platform/platform.dart'; |
| 12 | + |
| 13 | +void main() { |
| 14 | + TestWidgetsFlutterBinding.ensureInitialized(); |
| 15 | + |
| 16 | + group('LocalAuth', () { |
| 17 | + const MethodChannel channel = MethodChannel( |
| 18 | + 'plugins.flutter.io/local_auth', |
| 19 | + ); |
| 20 | + |
| 21 | + final List<MethodCall> log = <MethodCall>[]; |
| 22 | + LocalAuthentication localAuthentication; |
| 23 | + |
| 24 | + setUp(() { |
| 25 | + channel.setMockMethodCallHandler((MethodCall methodCall) { |
| 26 | + log.add(methodCall); |
| 27 | + return Future<dynamic>.value(true); |
| 28 | + }); |
| 29 | + localAuthentication = LocalAuthentication(); |
| 30 | + log.clear(); |
| 31 | + }); |
| 32 | + |
| 33 | + test('authenticate with no args on Android.', () async { |
| 34 | + setMockPathProviderPlatform(FakePlatform(operatingSystem: 'android')); |
| 35 | + await localAuthentication.authenticateWithBiometrics( |
| 36 | + localizedReason: 'Needs secure'); |
| 37 | + expect( |
| 38 | + log, |
| 39 | + <Matcher>[ |
| 40 | + isMethodCall('authenticateWithBiometrics', |
| 41 | + arguments: <String, dynamic>{ |
| 42 | + 'localizedReason': 'Needs secure', |
| 43 | + 'useErrorDialogs': true, |
| 44 | + 'stickyAuth': false, |
| 45 | + 'sensitiveTransaction': true, |
| 46 | + }..addAll(const AndroidAuthMessages().args)), |
| 47 | + ], |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + test('authenticate with no args on iOS.', () async { |
| 52 | + setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios')); |
| 53 | + await localAuthentication.authenticateWithBiometrics( |
| 54 | + localizedReason: 'Needs secure'); |
| 55 | + expect( |
| 56 | + log, |
| 57 | + <Matcher>[ |
| 58 | + isMethodCall('authenticateWithBiometrics', |
| 59 | + arguments: <String, dynamic>{ |
| 60 | + 'localizedReason': 'Needs secure', |
| 61 | + 'useErrorDialogs': true, |
| 62 | + 'stickyAuth': false, |
| 63 | + 'sensitiveTransaction': true, |
| 64 | + }..addAll(const IOSAuthMessages().args)), |
| 65 | + ], |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + test('authenticate with no sensitive transaction.', () async { |
| 70 | + setMockPathProviderPlatform(FakePlatform(operatingSystem: 'android')); |
| 71 | + await localAuthentication.authenticateWithBiometrics( |
| 72 | + localizedReason: 'Insecure', |
| 73 | + sensitiveTransaction: false, |
| 74 | + useErrorDialogs: false, |
| 75 | + ); |
| 76 | + expect( |
| 77 | + log, |
| 78 | + <Matcher>[ |
| 79 | + isMethodCall('authenticateWithBiometrics', |
| 80 | + arguments: <String, dynamic>{ |
| 81 | + 'localizedReason': 'Insecure', |
| 82 | + 'useErrorDialogs': false, |
| 83 | + 'stickyAuth': false, |
| 84 | + 'sensitiveTransaction': false, |
| 85 | + }..addAll(const AndroidAuthMessages().args)), |
| 86 | + ], |
| 87 | + ); |
| 88 | + }); |
| 89 | + }); |
| 90 | +} |
0 commit comments