|
| 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 'package:android_intent/flag.dart'; |
| 6 | +import 'package:flutter/services.dart'; |
| 7 | +import 'package:flutter_test/flutter_test.dart'; |
| 8 | +import 'package:android_intent/android_intent.dart'; |
| 9 | +import 'package:mockito/mockito.dart'; |
| 10 | +import 'package:platform/platform.dart'; |
| 11 | + |
| 12 | +void main() { |
| 13 | + AndroidIntent androidIntent; |
| 14 | + MockMethodChannel mockChannel; |
| 15 | + setUp(() { |
| 16 | + mockChannel = MockMethodChannel(); |
| 17 | + }); |
| 18 | + group('AndroidIntent', () { |
| 19 | + test('pass right params', () async { |
| 20 | + androidIntent = AndroidIntent.private( |
| 21 | + action: 'action_view', |
| 22 | + data: Uri.encodeFull('https://flutter.io'), |
| 23 | + flags: <int>[Flag.FLAG_ACTIVITY_NEW_TASK], |
| 24 | + channel: mockChannel, |
| 25 | + platform: FakePlatform(operatingSystem: 'android')); |
| 26 | + androidIntent.launch(); |
| 27 | + verify(mockChannel.invokeMethod<void>('launch', <String, Object>{ |
| 28 | + 'action': 'action_view', |
| 29 | + 'data': Uri.encodeFull('https://flutter.io'), |
| 30 | + 'flags': androidIntent.convertFlags(<int>[Flag.FLAG_ACTIVITY_NEW_TASK]), |
| 31 | + })); |
| 32 | + }); |
| 33 | + test('pass null value to action param', () async { |
| 34 | + androidIntent = AndroidIntent.private( |
| 35 | + action: null, |
| 36 | + channel: mockChannel, |
| 37 | + platform: FakePlatform(operatingSystem: 'android')); |
| 38 | + androidIntent.launch(); |
| 39 | + verify(mockChannel.invokeMethod<void>('launch', <String, Object>{ |
| 40 | + 'action': null, |
| 41 | + })); |
| 42 | + }); |
| 43 | + |
| 44 | + test('call in ios platform', () async { |
| 45 | + androidIntent = AndroidIntent.private( |
| 46 | + action: null, |
| 47 | + channel: mockChannel, |
| 48 | + platform: FakePlatform(operatingSystem: 'ios')); |
| 49 | + androidIntent.launch(); |
| 50 | + verifyZeroInteractions(mockChannel); |
| 51 | + }); |
| 52 | + }); |
| 53 | + group('convertFlags ', () { |
| 54 | + androidIntent = const AndroidIntent( |
| 55 | + action: 'action_view', |
| 56 | + ); |
| 57 | + test('add filled flag list', () async { |
| 58 | + final List<int> flags = <int>[]; |
| 59 | + flags.add(Flag.FLAG_ACTIVITY_NEW_TASK); |
| 60 | + flags.add(Flag.FLAG_ACTIVITY_NEW_DOCUMENT); |
| 61 | + expect( |
| 62 | + androidIntent.convertFlags(flags), |
| 63 | + 268959744, |
| 64 | + ); |
| 65 | + }); |
| 66 | + test('add flags whose values are not power of 2', () async { |
| 67 | + final List<int> flags = <int>[]; |
| 68 | + flags.add(100); |
| 69 | + flags.add(10); |
| 70 | + expect( |
| 71 | + () => androidIntent.convertFlags(flags), |
| 72 | + throwsArgumentError, |
| 73 | + ); |
| 74 | + }); |
| 75 | + test('add empty flag list', () async { |
| 76 | + final List<int> flags = <int>[]; |
| 77 | + expect( |
| 78 | + androidIntent.convertFlags(flags), |
| 79 | + 0, |
| 80 | + ); |
| 81 | + }); |
| 82 | + }); |
| 83 | +} |
| 84 | + |
| 85 | +class MockMethodChannel extends Mock implements MethodChannel {} |
0 commit comments