-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[url_launcher] Use url_launcher_platform_interface to handle calls
#2228
Changes from 1 commit
9069f1d
9310d77
6b2cefc
8e4bec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL on Android and iOS. Supports | |
| web, phone, SMS, and email schemes. | ||
| author: Flutter Team <[email protected]> | ||
| homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher | ||
| version: 5.2.3 | ||
| version: 5.2.4 | ||
|
|
||
| flutter: | ||
| plugin: | ||
|
|
@@ -14,10 +14,13 @@ flutter: | |
| dependencies: | ||
| flutter: | ||
| sdk: flutter | ||
| url_launcher_platform_interface: ^1.0.0 | ||
|
|
||
| dev_dependencies: | ||
| flutter_test: | ||
| sdk: flutter | ||
| test: ^1.3.0 | ||
| mockito: ^3.0.0 | ||
|
||
|
|
||
| environment: | ||
| sdk: ">=2.0.0-dev.28.0 <3.0.0" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,50 +2,43 @@ | |
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:mockito/mockito.dart'; | ||
| import 'package:test/test.dart'; | ||
| import 'package:url_launcher/url_launcher.dart'; | ||
| import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; | ||
| import 'package:flutter/services.dart' show PlatformException; | ||
|
|
||
| void main() { | ||
| TestWidgetsFlutterBinding.ensureInitialized(); | ||
| final MockUrlLauncher mock = MockUrlLauncher(); | ||
|
|
||
| const MethodChannel channel = | ||
| MethodChannel('plugins.flutter.io/url_launcher'); | ||
| final List<MethodCall> log = <MethodCall>[]; | ||
| channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
| log.add(methodCall); | ||
| }); | ||
|
|
||
| tearDown(() { | ||
| log.clear(); | ||
| }); | ||
| UrlLauncherPlatform.instance = mock; | ||
|
|
||
| test('canLaunch', () async { | ||
| await canLaunch('http://example.com/'); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('canLaunch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| }) | ||
| ], | ||
| ); | ||
| expect(verify(mock.canLaunch(captureAny)).captured.single, | ||
| 'http://example.com/'); | ||
| }); | ||
|
|
||
| test('launch default behavior', () async { | ||
| await launch('http://example.com/'); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('launch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| 'useSafariVC': true, | ||
| 'useWebView': false, | ||
| 'enableJavaScript': false, | ||
| 'enableDomStorage': false, | ||
| 'universalLinksOnly': false, | ||
| 'headers': <String, String>{}, | ||
| }) | ||
| verify(mock.launch( | ||
| captureAny, | ||
| useSafariVC: captureAnyNamed('useSafariVC'), | ||
| useWebView: captureAnyNamed('useWebView'), | ||
| enableJavaScript: captureAnyNamed('enableJavaScript'), | ||
| enableDomStorage: captureAnyNamed('enableDomStorage'), | ||
| universalLinksOnly: captureAnyNamed('universalLinksOnly'), | ||
| headers: captureAnyNamed('headers'), | ||
| )).captured, | ||
| <dynamic>[ | ||
| 'http://example.com/', | ||
| true, | ||
| false, | ||
| false, | ||
| false, | ||
| false, | ||
| <String, String>{}, | ||
| ], | ||
| ); | ||
| }); | ||
|
|
@@ -56,142 +49,128 @@ void main() { | |
| headers: <String, String>{'key': 'value'}, | ||
| ); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('launch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| 'useSafariVC': true, | ||
| 'useWebView': false, | ||
| 'enableJavaScript': false, | ||
| 'enableDomStorage': false, | ||
| 'universalLinksOnly': false, | ||
| 'headers': <String, String>{'key': 'value'}, | ||
| }) | ||
| ], | ||
| verify(mock.launch( | ||
| any, | ||
| useSafariVC: anyNamed('useSafariVC'), | ||
| useWebView: anyNamed('useWebView'), | ||
| enableJavaScript: anyNamed('enableJavaScript'), | ||
| enableDomStorage: anyNamed('enableDomStorage'), | ||
| universalLinksOnly: anyNamed('universalLinksOnly'), | ||
| headers: captureAnyNamed('headers'), | ||
| )).captured.single, | ||
| <String, String>{'key': 'value'}, | ||
| ); | ||
| }); | ||
|
|
||
| test('launch force SafariVC', () async { | ||
| await launch('http://example.com/', forceSafariVC: true); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('launch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| 'useSafariVC': true, | ||
| 'useWebView': false, | ||
| 'enableJavaScript': false, | ||
| 'enableDomStorage': false, | ||
| 'universalLinksOnly': false, | ||
| 'headers': <String, String>{}, | ||
| }) | ||
| ], | ||
| verify(mock.launch( | ||
| any, | ||
| useSafariVC: captureAnyNamed('useSafariVC'), | ||
| useWebView: anyNamed('useWebView'), | ||
| enableJavaScript: anyNamed('enableJavaScript'), | ||
| enableDomStorage: anyNamed('enableDomStorage'), | ||
| universalLinksOnly: anyNamed('universalLinksOnly'), | ||
| headers: anyNamed('headers'), | ||
| )).captured.single, | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| test('launch universal links only', () async { | ||
| await launch('http://example.com/', | ||
| forceSafariVC: false, universalLinksOnly: true); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('launch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| 'useSafariVC': false, | ||
| 'useWebView': false, | ||
| 'enableJavaScript': false, | ||
| 'enableDomStorage': false, | ||
| 'universalLinksOnly': true, | ||
| 'headers': <String, String>{}, | ||
| }) | ||
| ], | ||
| verify(mock.launch( | ||
| any, | ||
| useSafariVC: captureAnyNamed('useSafariVC'), | ||
| useWebView: anyNamed('useWebView'), | ||
| enableJavaScript: anyNamed('enableJavaScript'), | ||
| enableDomStorage: anyNamed('enableDomStorage'), | ||
| universalLinksOnly: captureAnyNamed('universalLinksOnly'), | ||
| headers: anyNamed('headers'), | ||
| )).captured, | ||
| <bool>[false, true], | ||
| ); | ||
| }); | ||
|
|
||
| test('launch force WebView', () async { | ||
| await launch('http://example.com/', forceWebView: true); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('launch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| 'useSafariVC': true, | ||
| 'useWebView': true, | ||
| 'enableJavaScript': false, | ||
| 'enableDomStorage': false, | ||
| 'universalLinksOnly': false, | ||
| 'headers': <String, String>{}, | ||
| }) | ||
| ], | ||
| verify(mock.launch( | ||
| any, | ||
| useSafariVC: anyNamed('useSafariVC'), | ||
| useWebView: captureAnyNamed('useWebView'), | ||
| enableJavaScript: anyNamed('enableJavaScript'), | ||
| enableDomStorage: anyNamed('enableDomStorage'), | ||
| universalLinksOnly: anyNamed('universalLinksOnly'), | ||
| headers: anyNamed('headers'), | ||
| )).captured.single, | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| test('launch force WebView enable javascript', () async { | ||
| await launch('http://example.com/', | ||
| forceWebView: true, enableJavaScript: true); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('launch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| 'useSafariVC': true, | ||
| 'useWebView': true, | ||
| 'enableJavaScript': true, | ||
| 'enableDomStorage': false, | ||
| 'universalLinksOnly': false, | ||
| 'headers': <String, String>{}, | ||
| }) | ||
| ], | ||
| verify(mock.launch( | ||
| any, | ||
| useSafariVC: anyNamed('useSafariVC'), | ||
| useWebView: captureAnyNamed('useWebView'), | ||
| enableJavaScript: captureAnyNamed('enableJavaScript'), | ||
| enableDomStorage: anyNamed('enableDomStorage'), | ||
| universalLinksOnly: anyNamed('universalLinksOnly'), | ||
| headers: anyNamed('headers'), | ||
| )).captured, | ||
| <bool>[true, true], | ||
| ); | ||
| }); | ||
|
|
||
| test('launch force WebView enable DOM storage', () async { | ||
| await launch('http://example.com/', | ||
| forceWebView: true, enableDomStorage: true); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('launch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| 'useSafariVC': true, | ||
| 'useWebView': true, | ||
| 'enableJavaScript': false, | ||
| 'enableDomStorage': true, | ||
| 'universalLinksOnly': false, | ||
| 'headers': <String, String>{}, | ||
| }) | ||
| ], | ||
| verify(mock.launch( | ||
| any, | ||
| useSafariVC: anyNamed('useSafariVC'), | ||
| useWebView: captureAnyNamed('useWebView'), | ||
| enableJavaScript: anyNamed('enableJavaScript'), | ||
| enableDomStorage: captureAnyNamed('enableDomStorage'), | ||
| universalLinksOnly: anyNamed('universalLinksOnly'), | ||
| headers: anyNamed('headers'), | ||
| )).captured, | ||
| <bool>[true, true], | ||
| ); | ||
| }); | ||
|
|
||
| test('launch force SafariVC to false', () async { | ||
| await launch('http://example.com/', forceSafariVC: false); | ||
| expect( | ||
| log, | ||
| <Matcher>[ | ||
| isMethodCall('launch', arguments: <String, Object>{ | ||
| 'url': 'http://example.com/', | ||
| 'useSafariVC': false, | ||
| 'useWebView': false, | ||
| 'enableJavaScript': false, | ||
| 'enableDomStorage': false, | ||
| 'universalLinksOnly': false, | ||
| 'headers': <String, String>{}, | ||
| }) | ||
| ], | ||
| // ignore: missing_required_param | ||
| verify(mock.launch( | ||
| any, | ||
| useSafariVC: captureAnyNamed('useSafariVC'), | ||
| useWebView: anyNamed('useWebView'), | ||
| enableJavaScript: anyNamed('enableJavaScript'), | ||
| enableDomStorage: anyNamed('enableDomStorage'), | ||
| universalLinksOnly: anyNamed('universalLinksOnly'), | ||
| headers: anyNamed('headers'), | ||
| )).captured.single, | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| test('cannot launch a non-web in webview', () async { | ||
| expect(() async => await launch('tel:555-555-5555', forceWebView: true), | ||
| throwsA(isInstanceOf<PlatformException>())); | ||
| throwsA(isA<PlatformException>())); | ||
| }); | ||
|
|
||
| test('closeWebView default behavior', () async { | ||
| await closeWebView(); | ||
| expect( | ||
| log, | ||
| <Matcher>[isMethodCall('closeWebView', arguments: null)], | ||
| ); | ||
| verify(mock.closeWebView()); | ||
| }); | ||
| } | ||
|
|
||
| class MockUrlLauncher extends Mock implements UrlLauncherPlatform {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a red flag for me as I was planning to enforce that it's not implemented with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this lands after #2230 lets make this ^1.01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.