mirror of
https://github.com/flutter/flutter
synced 2024-10-14 04:02:56 +00:00
449f4a6673
* Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs
83 lines
2.7 KiB
Dart
83 lines
2.7 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
@TestOn('chrome') // Uses web-only Flutter SDK
|
|
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
|
|
|
class TestPlugin {
|
|
static void registerWith(Registrar registrar) {
|
|
final MethodChannel channel = MethodChannel(
|
|
'test_plugin',
|
|
const StandardMethodCodec(),
|
|
registrar.messenger,
|
|
);
|
|
final TestPlugin testPlugin = TestPlugin();
|
|
channel.setMethodCallHandler(testPlugin.handleMethodCall);
|
|
}
|
|
|
|
static final List<String> calledMethods = <String>[];
|
|
|
|
Future<void> handleMethodCall(MethodCall call) async {
|
|
calledMethods.add(call.method);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
// Disabling tester emulation because this test relies on real message channel communication.
|
|
ui.debugEmulateFlutterTesterEnvironment = false; // ignore: undefined_prefixed_name
|
|
|
|
group('Plugin Registry', () {
|
|
setUp(() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
webPluginRegistry.registerMessageHandler();
|
|
final Registrar registrar = webPluginRegistry.registrarFor(TestPlugin);
|
|
TestPlugin.registerWith(registrar);
|
|
});
|
|
|
|
test('can register a plugin', () {
|
|
TestPlugin.calledMethods.clear();
|
|
|
|
const MethodChannel frameworkChannel =
|
|
MethodChannel('test_plugin', StandardMethodCodec());
|
|
frameworkChannel.invokeMethod<void>('test1');
|
|
|
|
expect(TestPlugin.calledMethods, equals(<String>['test1']));
|
|
});
|
|
|
|
test('can send a message from the plugin to the framework', () async {
|
|
const StandardMessageCodec codec = StandardMessageCodec();
|
|
|
|
final List<String> loggedMessages = <String>[];
|
|
ServicesBinding.instance.defaultBinaryMessenger
|
|
.setMessageHandler('test_send', (ByteData data) {
|
|
loggedMessages.add(codec.decodeMessage(data) as String);
|
|
return null;
|
|
});
|
|
|
|
await pluginBinaryMessenger.send(
|
|
'test_send', codec.encodeMessage('hello'));
|
|
expect(loggedMessages, equals(<String>['hello']));
|
|
|
|
await pluginBinaryMessenger.send(
|
|
'test_send', codec.encodeMessage('world'));
|
|
expect(loggedMessages, equals(<String>['hello', 'world']));
|
|
|
|
ServicesBinding.instance.defaultBinaryMessenger
|
|
.setMessageHandler('test_send', null);
|
|
});
|
|
|
|
test('throws when trying to set a mock handler', () {
|
|
expect(
|
|
() => pluginBinaryMessenger.setMockMessageHandler(
|
|
'test', (ByteData data) async => ByteData(0)),
|
|
throwsFlutterError);
|
|
});
|
|
});
|
|
}
|