flutter_webview_plugin_test.dart 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:flutter/services.dart';
  2. import 'package:flutter_test/flutter_test.dart';
  3. import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
  4. import 'package:mockito/mockito.dart';
  5. void main() {
  6. MockMethodChannel methodChannel;
  7. FlutterWebviewPlugin webview;
  8. setUp(() {
  9. methodChannel = MockMethodChannel();
  10. webview = new FlutterWebviewPlugin.private(methodChannel);
  11. });
  12. group('Method channel invoke', () {
  13. test('Should invoke close', () async {
  14. webview.close();
  15. verify(methodChannel.invokeMethod('close')).called(1);
  16. });
  17. test('Should invoke reload', () async {
  18. webview.reload();
  19. verify(methodChannel.invokeMethod('reload')).called(1);
  20. });
  21. test('Should invoke goBack', () async {
  22. webview.goBack();
  23. verify(methodChannel.invokeMethod('back')).called(1);
  24. });
  25. test('Should invoke goForward', () async {
  26. webview.goForward();
  27. verify(methodChannel.invokeMethod('forward')).called(1);
  28. });
  29. test('Should invoke hide', () async {
  30. webview.hide();
  31. verify(methodChannel.invokeMethod('hide')).called(1);
  32. });
  33. test('Should invoke show', () async {
  34. webview.show();
  35. verify(methodChannel.invokeMethod('show')).called(1);
  36. });
  37. test('Should invoke canGoBack', () async {
  38. webview.canGoBack();
  39. verify(methodChannel.invokeMethod('canGoBack')).called(1);
  40. });
  41. test('Should invoke canGoForward', () async {
  42. webview.canGoForward();
  43. verify(methodChannel.invokeMethod('canGoForward')).called(1);
  44. });
  45. });
  46. }
  47. class MockMethodChannel extends Mock implements MethodChannel {}