Unverified Commit 87d5214d authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

[web] Migrate web-only initialization APIs (#129856)

- `ui_web.warmupEngine`
- `ui_web.setPluginHandler`
- `ui_web.debugEmulateFlutterTesterEnvironment`
parent 157660af
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui; import 'dart:ui_web' as ui_web;
import '../services/dom.dart'; import '../services/dom.dart';
...@@ -23,9 +23,7 @@ platform.TargetPlatform get defaultTargetPlatform { ...@@ -23,9 +23,7 @@ platform.TargetPlatform get defaultTargetPlatform {
final platform.TargetPlatform? _testPlatform = () { final platform.TargetPlatform? _testPlatform = () {
platform.TargetPlatform? result; platform.TargetPlatform? result;
assert(() { assert(() {
// This member is only available in the web's dart:ui implementation. if (ui_web.debugEmulateFlutterTesterEnvironment) {
// ignore: undefined_prefixed_name
if (ui.debugEmulateFlutterTesterEnvironment as bool) {
result = platform.TargetPlatform.android; result = platform.TargetPlatform.android;
} }
return true; return true;
......
...@@ -219,6 +219,7 @@ String generateTestEntrypoint({ ...@@ -219,6 +219,7 @@ String generateTestEntrypoint({
// @dart = ${languageVersion.major}.${languageVersion.minor} // @dart = ${languageVersion.major}.${languageVersion.minor}
import 'org-dartlang-app:///$relativeTestPath' as test; import 'org-dartlang-app:///$relativeTestPath' as test;
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'dart:ui_web' as ui_web;
import 'dart:html'; import 'dart:html';
import 'dart:js'; import 'dart:js';
${testConfigPath != null ? "import '${Uri.file(testConfigPath)}' as test_config;" : ""} ${testConfigPath != null ? "import '${Uri.file(testConfigPath)}' as test_config;" : ""}
...@@ -227,7 +228,7 @@ String generateTestEntrypoint({ ...@@ -227,7 +228,7 @@ String generateTestEntrypoint({
import 'package:test_api/backend.dart'; import 'package:test_api/backend.dart';
Future<void> main() async { Future<void> main() async {
ui.debugEmulateFlutterTesterEnvironment = true; ui_web.debugEmulateFlutterTesterEnvironment = true;
await ui.webOnlyInitializePlatform(); await ui.webOnlyInitializePlatform();
webGoldenComparator = DefaultWebGoldenComparator(Uri.parse('${Uri.file(absolutePath)}')); webGoldenComparator = DefaultWebGoldenComparator(Uri.parse('${Uri.file(absolutePath)}'));
(ui.window as dynamic).debugOverrideDevicePixelRatio(3.0); (ui.window as dynamic).debugOverrideDevicePixelRatio(3.0);
......
...@@ -19,7 +19,7 @@ String generateMainDartFile(String appEntrypoint, { ...@@ -19,7 +19,7 @@ String generateMainDartFile(String appEntrypoint, {
'', '',
'// ignore_for_file: type=lint', '// ignore_for_file: type=lint',
'', '',
"import 'dart:ui' as ui;", "import 'dart:ui_web' as ui_web;",
"import 'dart:async';", "import 'dart:async';",
'', '',
"import '$appEntrypoint' as entrypoint;", "import '$appEntrypoint' as entrypoint;",
...@@ -29,7 +29,7 @@ String generateMainDartFile(String appEntrypoint, { ...@@ -29,7 +29,7 @@ String generateMainDartFile(String appEntrypoint, {
'typedef _NullaryFunction = dynamic Function();', 'typedef _NullaryFunction = dynamic Function();',
'', '',
'Future<void> main() async {', 'Future<void> main() async {',
' await ui.webOnlyWarmupEngine(', ' await ui_web.bootstrapEngine(',
' runApp: () {', ' runApp: () {',
' if (entrypoint.main is _UnaryFunction) {', ' if (entrypoint.main is _UnaryFunction) {',
' return (entrypoint.main as _UnaryFunction)(<String>[]);', ' return (entrypoint.main as _UnaryFunction)(<String>[]);',
......
...@@ -118,7 +118,7 @@ void main() { ...@@ -118,7 +118,7 @@ void main() {
expect(generated, contains("import 'package:foo/main.dart' as entrypoint;")); expect(generated, contains("import 'package:foo/main.dart' as entrypoint;"));
// Main // Main
expect(generated, contains('ui.webOnlyWarmupEngine(')); expect(generated, contains('ui_web.bootstrapEngine('));
expect(generated, contains('entrypoint.main as _')); expect(generated, contains('entrypoint.main as _'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
TemplateRenderer: () => const MustacheTemplateRenderer(), TemplateRenderer: () => const MustacheTemplateRenderer(),
...@@ -270,7 +270,7 @@ void main() { ...@@ -270,7 +270,7 @@ void main() {
expect(generated, contains("import 'package:foo/main.dart' as entrypoint;")); expect(generated, contains("import 'package:foo/main.dart' as entrypoint;"));
// Main // Main
expect(generated, contains('ui.webOnlyWarmupEngine(')); expect(generated, contains('ui_web.bootstrapEngine('));
expect(generated, contains('entrypoint.main as _')); expect(generated, contains('entrypoint.main as _'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Platform: () => windows, Platform: () => windows,
...@@ -295,7 +295,7 @@ void main() { ...@@ -295,7 +295,7 @@ void main() {
expect(generated, contains("import 'package:foo/main.dart' as entrypoint;")); expect(generated, contains("import 'package:foo/main.dart' as entrypoint;"));
// Main // Main
expect(generated, contains('ui.webOnlyWarmupEngine(')); expect(generated, contains('ui_web.bootstrapEngine('));
expect(generated, contains('entrypoint.main as _')); expect(generated, contains('entrypoint.main as _'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
TemplateRenderer: () => const MustacheTemplateRenderer(), TemplateRenderer: () => const MustacheTemplateRenderer(),
...@@ -351,7 +351,7 @@ void main() { ...@@ -351,7 +351,7 @@ void main() {
expect(generated, contains("import 'package:foo/main.dart' as entrypoint;")); expect(generated, contains("import 'package:foo/main.dart' as entrypoint;"));
// Main // Main
expect(generated, contains('ui.webOnlyWarmupEngine(')); expect(generated, contains('ui_web.bootstrapEngine('));
expect(generated, contains('entrypoint.main as _')); expect(generated, contains('entrypoint.main as _'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
TemplateRenderer: () => const MustacheTemplateRenderer(), TemplateRenderer: () => const MustacheTemplateRenderer(),
......
...@@ -730,8 +730,8 @@ void main() { ...@@ -730,8 +730,8 @@ void main() {
final String entrypointContents = final String entrypointContents =
fileSystem.file(webDevFS.mainUri).readAsStringSync(); fileSystem.file(webDevFS.mainUri).readAsStringSync();
expect(entrypointContents, contains('// Flutter web bootstrap script')); expect(entrypointContents, contains('// Flutter web bootstrap script'));
expect(entrypointContents, contains("import 'dart:ui' as ui;")); expect(entrypointContents, contains("import 'dart:ui_web' as ui_web;"));
expect(entrypointContents, contains('await ui.webOnlyWarmupEngine(')); expect(entrypointContents, contains('await ui_web.bootstrapEngine('));
expect(logger.statusText, contains('Restarted application in')); expect(logger.statusText, contains('Restarted application in'));
expect(result.code, 0); expect(result.code, 0);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'dart:ui_web' as ui_web;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -57,13 +58,11 @@ class Registrar extends BinaryMessenger { ...@@ -57,13 +58,11 @@ class Registrar extends BinaryMessenger {
/// previously-registered handler and replaces it with the handler /// previously-registered handler and replaces it with the handler
/// from this object. /// from this object.
/// ///
/// This method uses a function called `webOnlySetPluginHandler` in /// This method uses a function called `setPluginHandler` in
/// the [dart:ui] library. That function is only available when /// the [dart:ui_web] library. That function is only available when
/// compiling for the web. /// compiling for the web.
void registerMessageHandler() { void registerMessageHandler() {
// The `ui.webOnlySetPluginHandler` function below is only defined in the Web dart:ui. ui_web.setPluginHandler(handleFrameworkMessage);
// ignore: undefined_function, avoid_dynamic_calls
ui.webOnlySetPluginHandler(handleFrameworkMessage);
} }
/// Receives a platform message from the framework. /// Receives a platform message from the framework.
...@@ -101,7 +100,7 @@ class Registrar extends BinaryMessenger { ...@@ -101,7 +100,7 @@ class Registrar extends BinaryMessenger {
/// the following: /// the following:
/// ///
/// ```dart /// ```dart
/// ui.webOnlySetPluginHandler(webPluginRegistrar.handleFrameworkMessage); /// ui_web.setPluginHandler(handleFrameworkMessage);
/// ``` /// ```
Future<void> handleFrameworkMessage( Future<void> handleFrameworkMessage(
String channel, String channel,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
library; library;
import 'dart:async'; import 'dart:async';
import 'dart:ui' as ui; import 'dart:ui_web' as ui_web;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -14,7 +14,7 @@ import 'package:flutter_web_plugins/flutter_web_plugins.dart'; ...@@ -14,7 +14,7 @@ import 'package:flutter_web_plugins/flutter_web_plugins.dart';
void main() { void main() {
// Disabling tester emulation because this test relies on real message channel communication. // Disabling tester emulation because this test relies on real message channel communication.
ui.debugEmulateFlutterTesterEnvironment = false; // ignore: undefined_prefixed_name ui_web.debugEmulateFlutterTesterEnvironment = false;
group('Plugin Event Channel', () { group('Plugin Event Channel', () {
setUp(() { setUp(() {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
@TestOn('chrome') // Uses web-only Flutter SDK @TestOn('chrome') // Uses web-only Flutter SDK
library; library;
import 'dart:ui' as ui; import 'dart:ui_web' as ui_web;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -31,7 +31,7 @@ class TestPlugin { ...@@ -31,7 +31,7 @@ class TestPlugin {
void main() { void main() {
// Disabling tester emulation because this test relies on real message channel communication. // Disabling tester emulation because this test relies on real message channel communication.
ui.debugEmulateFlutterTesterEnvironment = false; // ignore: undefined_prefixed_name ui_web.debugEmulateFlutterTesterEnvironment = false;
group('Plugin Registry', () { group('Plugin Registry', () {
setUp(() { setUp(() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment