Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@amirh
Copy link
Contributor

@amirh amirh commented Aug 30, 2018

The focus of this CL is the overall widget/controller structure, and
test plumbing.
The API surface is just the bare minimum at this point (only loadUrl).

The focus of this CL is the overall widget/controller structure, and
test plumbing.
The API surface is just the bare minimum at this point (only loadUrl).
Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

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

LGTM

class WebViewController {
WebViewController._(int id) {
_channel = new MethodChannel(
'plugins.flutter.io/webview_$id', const StandardMethodCodec());
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: StandardMethodCodec() is the default value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

'plugins.flutter.io/webview_$id', const StandardMethodCodec());
}

MethodChannel _channel;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can make this final MethodChannel _channel; by changing the constructor to:

WebViewController._(int id) : _channel = new MethodChannel(
        'plugins.flutter.io/webview_$id', const StandardMethodCodec());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

});
}

class FakePlatformWebView {
Copy link
Contributor

Choose a reason for hiding this comment

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

This way of testing works too, but you could avoid making a Mock class by doing something similar in firebase_performance.

We started testing plugins by making the MethodChannel public and using the @visibleForTesting annotation. It lets us test the actual class instead of having to always make a Fake one for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fake class is faking the Java implementation, the test is testing the real Dart WebView implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking of something along the lines of:

    final List<MethodCall> log = <MethodCall>[];
    WebViewController controller;
    
    Future<dynamic> methodCallHandler(MethodCall methodCall) async {
      log.add(methodCall);

      switch (methodCall.method) {
        case 'loadUrl':
          return null;
        default:
          return null;
      }
    }

    testWidgets('loadUrl', (WidgetTester tester) async {
      await tester.pumpWidget(
        WebView(
          onWebViewCreated: (WebViewController webViewController) {
            controller = webViewController;
          },
        ),
      );
      
      expect(controller, isNotNull);

      controller.channel.setMethodCallHandler(methodCallHandler);
      log.clear();

      controller.loadUrl('https://flutter.io');

      expect(log, <Matcher>[
        isMethodCall(
          'loadUrl',
          arguments: 'https://flutter.io',
        )
      ]);
    });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following offline discussion we decided we're happy with the fake approach here.

Copy link
Contributor Author

@amirh amirh left a comment

Choose a reason for hiding this comment

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

Thanks!

class WebViewController {
WebViewController._(int id) {
_channel = new MethodChannel(
'plugins.flutter.io/webview_$id', const StandardMethodCodec());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

'plugins.flutter.io/webview_$id', const StandardMethodCodec());
}

MethodChannel _channel;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

});
}

class FakePlatformWebView {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fake class is faking the Java implementation, the test is testing the real Dart WebView implementation.

@amirh amirh merged commit 15ef622 into flutter:master Aug 31, 2018
nichtverstehen pushed a commit to nichtverstehen/plugins that referenced this pull request Sep 6, 2018
The focus of this CL is the overall widget/controller structure, and
test plumbing.
The API surface is just the bare minimum at this point (only loadUrl).
andreidiaconu pushed a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
The focus of this CL is the overall widget/controller structure, and
test plumbing.
The API surface is just the bare minimum at this point (only loadUrl).
andreidiaconu added a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants