[web] Move web-only initialization APIs to dart:ui_web (flutter/engine#43111)
| Old API in `dart:ui` | New API in `dart:ui_web` | |-|-| | ~`webOnlyInitializePlatform`~ | ~`ui_web.initializePlatform`~ | | `webOnlyWarmupEngine` | `ui_web.bootstrapEngine` | | `debugEmulateFlutterTesterEnvironment` | `ui_web.debugEmulateFlutterTesterEnvironment` | | `webOnlySetPluginHandler` | `ui_web.setPluginHandler` | Part of https://github.com/flutter/flutter/issues/126831
This commit is contained in:
@@ -2110,9 +2110,12 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/tile_mode.dart + ../../../flutter/LICENS
|
|||||||
ORIGIN: ../../../flutter/lib/web_ui/lib/ui.dart + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui.dart + ../../../flutter/LICENSE
|
||||||
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web.dart + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web.dart + ../../../flutter/LICENSE
|
||||||
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/asset_manager.dart + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/asset_manager.dart + ../../../flutter/LICENSE
|
||||||
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/initialization.dart + ../../../flutter/LICENSE
|
||||||
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/platform_location.dart + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/platform_location.dart + ../../../flutter/LICENSE
|
||||||
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/url_strategy.dart + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/url_strategy.dart + ../../../flutter/LICENSE
|
||||||
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/platform_view_registry.dart + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/platform_view_registry.dart + ../../../flutter/LICENSE
|
||||||
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/plugins.dart + ../../../flutter/LICENSE
|
||||||
|
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/testing.dart + ../../../flutter/LICENSE
|
||||||
ORIGIN: ../../../flutter/lib/web_ui/lib/window.dart + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/lib/window.dart + ../../../flutter/LICENSE
|
||||||
ORIGIN: ../../../flutter/lib/web_ui/skwasm/canvas.cpp + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/skwasm/canvas.cpp + ../../../flutter/LICENSE
|
||||||
ORIGIN: ../../../flutter/lib/web_ui/skwasm/contour_measure.cpp + ../../../flutter/LICENSE
|
ORIGIN: ../../../flutter/lib/web_ui/skwasm/contour_measure.cpp + ../../../flutter/LICENSE
|
||||||
@@ -4791,9 +4794,12 @@ FILE: ../../../flutter/lib/web_ui/lib/tile_mode.dart
|
|||||||
FILE: ../../../flutter/lib/web_ui/lib/ui.dart
|
FILE: ../../../flutter/lib/web_ui/lib/ui.dart
|
||||||
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web.dart
|
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web.dart
|
||||||
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/asset_manager.dart
|
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/asset_manager.dart
|
||||||
|
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/initialization.dart
|
||||||
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/platform_location.dart
|
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/platform_location.dart
|
||||||
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/url_strategy.dart
|
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/url_strategy.dart
|
||||||
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/platform_view_registry.dart
|
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/platform_view_registry.dart
|
||||||
|
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/plugins.dart
|
||||||
|
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/testing.dart
|
||||||
FILE: ../../../flutter/lib/web_ui/lib/window.dart
|
FILE: ../../../flutter/lib/web_ui/lib/window.dart
|
||||||
FILE: ../../../flutter/lib/web_ui/skwasm/canvas.cpp
|
FILE: ../../../flutter/lib/web_ui/skwasm/canvas.cpp
|
||||||
FILE: ../../../flutter/lib/web_ui/skwasm/contour_measure.cpp
|
FILE: ../../../flutter/lib/web_ui/skwasm/contour_measure.cpp
|
||||||
|
|||||||
@@ -28,89 +28,59 @@ part of ui;
|
|||||||
///
|
///
|
||||||
/// This is only available on the Web, as native Flutter configures the
|
/// This is only available on the Web, as native Flutter configures the
|
||||||
/// environment in the native embedder.
|
/// environment in the native embedder.
|
||||||
|
// TODO(mdebbar): Deprecate this and remove it.
|
||||||
|
// https://github.com/flutter/flutter/issues/127395
|
||||||
Future<void> webOnlyInitializePlatform() async {
|
Future<void> webOnlyInitializePlatform() async {
|
||||||
await engine.initializeEngine();
|
await engine.initializeEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initializes essential bits of the engine before it fully initializes.
|
// TODO(mdebbar): Deprecate this and remove it.
|
||||||
/// When [didCreateEngineInitializer] is set, it delegates engine initialization
|
// https://github.com/flutter/flutter/issues/127395
|
||||||
/// and app startup to the programmer.
|
|
||||||
/// Else, it immediately triggers the full engine + app bootstrap.
|
|
||||||
///
|
|
||||||
/// This method is called by the flutter_tools package, from the entrypoint that
|
|
||||||
/// it generates around the main method provided by the programmer. See:
|
|
||||||
/// * https://github.com/flutter/flutter/blob/2bd3e0d914854aa8c12e933f25c5fd8532ae5571/packages/flutter_tools/lib/src/build_system/targets/web.dart#L135-L163
|
|
||||||
/// * https://github.com/flutter/flutter/blob/61fb2de52c7bdac19b7f2f74eaf3f11237e1e91d/packages/flutter_tools/lib/src/isolated/resident_web_runner.dart#L460-L485
|
|
||||||
///
|
|
||||||
/// This function first calls [engine.initializeEngineServices] so the engine
|
|
||||||
/// can prepare the js-interop layer that is used by web apps (instead of the
|
|
||||||
/// old `ui.webOnlyFoo` methods/getters).
|
|
||||||
///
|
|
||||||
/// It then creates a JsObject that is passed to the [didCreateEngineInitializer]
|
|
||||||
/// JS callback, to delegate bootstrapping the app to the programmer.
|
|
||||||
///
|
|
||||||
/// If said callback is not defined, this assumes that the Flutter Web app is
|
|
||||||
/// initializing "automatically", as was normal before this feature was
|
|
||||||
/// introduced. This will immediately run the initEngine and runApp methods
|
|
||||||
/// (via [engine.AppBootstrap.now]).
|
|
||||||
///
|
|
||||||
/// This is the only bit of `dart:ui` that should be directly called by Flutter
|
|
||||||
/// web apps. Everything else should go through the JS-interop layer created in
|
|
||||||
/// `engine.warmup`.
|
|
||||||
///
|
|
||||||
/// This method should NOT trigger the download of any additional resources
|
|
||||||
/// (except when the app is in "autoStart" mode).
|
|
||||||
Future<void> webOnlyWarmupEngine({
|
Future<void> webOnlyWarmupEngine({
|
||||||
Function? registerPlugins,
|
VoidCallback? registerPlugins,
|
||||||
Function? runApp,
|
VoidCallback? runApp,
|
||||||
}) async {
|
}) {
|
||||||
// Create the object that knows how to bootstrap an app from JS and Dart.
|
assert(() {
|
||||||
final engine.AppBootstrap bootstrap = engine.AppBootstrap(
|
engine.printWarning(
|
||||||
initializeEngine: ([engine.JsFlutterConfiguration? configuration]) async {
|
'The webOnlyWarmupEngine API is deprecated and will be removed in a '
|
||||||
await engine.initializeEngineServices(jsConfiguration: configuration);
|
'future release. Please use `bootstrapEngine` from `dart:ui_web` instead.',
|
||||||
}, runApp: () async {
|
);
|
||||||
if (registerPlugins != null) {
|
return true;
|
||||||
registerPlugins();
|
}());
|
||||||
}
|
return ui_web.bootstrapEngine(
|
||||||
await engine.initializeEngineUi();
|
registerPlugins: registerPlugins,
|
||||||
if (runApp != null) {
|
runApp: runApp,
|
||||||
runApp();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final engine.FlutterLoader? loader = engine.flutter?.loader;
|
|
||||||
if (loader == null || loader.isAutoStart) {
|
|
||||||
// The user does not want control of the app, bootstrap immediately.
|
|
||||||
engine.domWindow.console.debug('Flutter Web Bootstrap: Auto.');
|
|
||||||
await bootstrap.autoStart();
|
|
||||||
} else {
|
|
||||||
// Yield control of the bootstrap procedure to the user.
|
|
||||||
engine.domWindow.console.debug('Flutter Web Bootstrap: Programmatic.');
|
|
||||||
loader.didCreateEngineInitializer(bootstrap.prepareEngineInitializer());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emulates the `flutter test` environment.
|
// TODO(mdebbar): Deprecate this and remove it.
|
||||||
///
|
// https://github.com/flutter/flutter/issues/127395
|
||||||
/// When set to true, the engine will emulate a specific screen size, and always
|
bool get debugEmulateFlutterTesterEnvironment {
|
||||||
/// use the "Ahem" font to reduce test flakiness and dependence on the test
|
assert(() {
|
||||||
/// environment.
|
engine.printWarning(
|
||||||
bool get debugEmulateFlutterTesterEnvironment =>
|
'The debugEmulateFlutterTesterEnvironment getter is deprecated and will '
|
||||||
_debugEmulateFlutterTesterEnvironment;
|
'be removed in a future release. Please use '
|
||||||
|
'`debugEmulateFlutterTesterEnvironment` from `dart:ui_web` instead.',
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
|
return ui_web.debugEmulateFlutterTesterEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(mdebbar): Deprecate this and remove it.
|
||||||
|
// https://github.com/flutter/flutter/issues/127395
|
||||||
set debugEmulateFlutterTesterEnvironment(bool value) {
|
set debugEmulateFlutterTesterEnvironment(bool value) {
|
||||||
_debugEmulateFlutterTesterEnvironment = value;
|
assert(() {
|
||||||
if (_debugEmulateFlutterTesterEnvironment) {
|
engine.printWarning(
|
||||||
const Size logicalSize = Size(800.0, 600.0);
|
'The debugEmulateFlutterTesterEnvironment setter is deprecated and will '
|
||||||
engine.window.webOnlyDebugPhysicalSizeOverride =
|
'be removed in a future release. Please use '
|
||||||
logicalSize * window.devicePixelRatio;
|
'`debugEmulateFlutterTesterEnvironment` from `dart:ui_web` instead.',
|
||||||
}
|
);
|
||||||
engine.debugDisableFontFallbacks = value;
|
return true;
|
||||||
|
}());
|
||||||
|
ui_web.debugEmulateFlutterTesterEnvironment = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _debugEmulateFlutterTesterEnvironment = false;
|
|
||||||
|
|
||||||
/// Provides the asset manager.
|
|
||||||
// TODO(mdebbar): Deprecate this and remove it.
|
// TODO(mdebbar): Deprecate this and remove it.
|
||||||
// https://github.com/flutter/flutter/issues/127395
|
// https://github.com/flutter/flutter/issues/127395
|
||||||
ui_web.AssetManager get webOnlyAssetManager {
|
ui_web.AssetManager get webOnlyAssetManager {
|
||||||
@@ -124,12 +94,17 @@ ui_web.AssetManager get webOnlyAssetManager {
|
|||||||
return ui_web.assetManager;
|
return ui_web.assetManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the handler that forwards platform messages to web plugins.
|
// TODO(mdebbar): Deprecate this and remove it.
|
||||||
///
|
// https://github.com/flutter/flutter/issues/127395
|
||||||
/// This function exists because unlike mobile, on the web plugins are also
|
void webOnlySetPluginHandler(PlatformMessageCallback handler) {
|
||||||
/// implemented using Dart code, and that code needs a way to receive messages.
|
assert(() {
|
||||||
void webOnlySetPluginHandler(Future<void> Function(String, ByteData?, PlatformMessageResponseCallback?) handler) {
|
engine.printWarning(
|
||||||
engine.pluginMessageCallHandler = handler;
|
'The webOnlySetPluginHandler API is deprecated and will be removed in a '
|
||||||
|
'future release. Please use `setPluginHandler` from `dart:ui_web` instead.',
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
|
ui_web.setPluginHandler(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(mdebbar): Deprecate this and remove it.
|
// TODO(mdebbar): Deprecate this and remove it.
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ import 'dart:typed_data';
|
|||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
final bool _ckRequiresClientICU = canvasKit.ParagraphBuilder.RequiresClientICU();
|
final bool _ckRequiresClientICU = canvasKit.ParagraphBuilder.RequiresClientICU();
|
||||||
|
|
||||||
final List<String> _testFonts = <String>['FlutterTest', 'Ahem'];
|
final List<String> _testFonts = <String>['FlutterTest', 'Ahem'];
|
||||||
String? _effectiveFontFamily(String? fontFamily) {
|
String? _effectiveFontFamily(String? fontFamily) {
|
||||||
return ui.debugEmulateFlutterTesterEnvironment && !_testFonts.contains(fontFamily)
|
return ui_web.debugEmulateFlutterTesterEnvironment && !_testFonts.contains(fontFamily)
|
||||||
? _testFonts.first
|
? _testFonts.first
|
||||||
: fontFamily;
|
: fontFamily;
|
||||||
}
|
}
|
||||||
@@ -231,7 +232,7 @@ class CkTextStyle implements ui.TextStyle {
|
|||||||
fontStyle,
|
fontStyle,
|
||||||
textBaseline,
|
textBaseline,
|
||||||
_effectiveFontFamily(fontFamily),
|
_effectiveFontFamily(fontFamily),
|
||||||
ui.debugEmulateFlutterTesterEnvironment ? null : fontFamilyFallback,
|
ui_web.debugEmulateFlutterTesterEnvironment ? null : fontFamilyFallback,
|
||||||
fontSize,
|
fontSize,
|
||||||
letterSpacing,
|
letterSpacing,
|
||||||
wordSpacing,
|
wordSpacing,
|
||||||
@@ -481,7 +482,7 @@ class CkStrutStyle implements ui.StrutStyle {
|
|||||||
ui.FontStyle? fontStyle,
|
ui.FontStyle? fontStyle,
|
||||||
bool? forceStrutHeight,
|
bool? forceStrutHeight,
|
||||||
}) : _fontFamily = _effectiveFontFamily(fontFamily),
|
}) : _fontFamily = _effectiveFontFamily(fontFamily),
|
||||||
_fontFamilyFallback = ui.debugEmulateFlutterTesterEnvironment ? null : fontFamilyFallback,
|
_fontFamilyFallback = ui_web.debugEmulateFlutterTesterEnvironment ? null : fontFamilyFallback,
|
||||||
_fontSize = fontSize,
|
_fontSize = fontSize,
|
||||||
_height = height,
|
_height = height,
|
||||||
_leadingDistribution = leadingDistribution,
|
_leadingDistribution = leadingDistribution,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import '../../engine.dart' show kProfileApplyFrame, kProfilePrerollFrame;
|
import '../../engine.dart' show kProfileApplyFrame, kProfilePrerollFrame;
|
||||||
import '../dom.dart';
|
import '../dom.dart';
|
||||||
@@ -111,7 +112,7 @@ class SurfaceSceneBuilder implements ui.SceneBuilder {
|
|||||||
// Top level transform contains view configuration to scale
|
// Top level transform contains view configuration to scale
|
||||||
// scene to devicepixelratio. Use identity instead since CSS uses
|
// scene to devicepixelratio. Use identity instead since CSS uses
|
||||||
// logical device pixels.
|
// logical device pixels.
|
||||||
if (!ui.debugEmulateFlutterTesterEnvironment) {
|
if (!ui_web.debugEmulateFlutterTesterEnvironment) {
|
||||||
assert(matrix4[0] == window.devicePixelRatio &&
|
assert(matrix4[0] == window.devicePixelRatio &&
|
||||||
matrix4[5] == window.devicePixelRatio);
|
matrix4[5] == window.devicePixelRatio);
|
||||||
}
|
}
|
||||||
@@ -383,7 +384,7 @@ class SurfaceSceneBuilder implements ui.SceneBuilder {
|
|||||||
void _addTexture(double dx, double dy, double width, double height,
|
void _addTexture(double dx, double dy, double width, double height,
|
||||||
int textureId, ui.FilterQuality filterQuality) {
|
int textureId, ui.FilterQuality filterQuality) {
|
||||||
// In test mode, allow this to be a no-op.
|
// In test mode, allow this to be a no-op.
|
||||||
if (!ui.debugEmulateFlutterTesterEnvironment) {
|
if (!ui_web.debugEmulateFlutterTesterEnvironment) {
|
||||||
throw UnimplementedError('Textures are not supported in Flutter Web');
|
throw UnimplementedError('Textures are not supported in Flutter Web');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ void _setAssetManager(ui_web.AssetManager assetManager) {
|
|||||||
Future<void> _downloadAssetFonts() async {
|
Future<void> _downloadAssetFonts() async {
|
||||||
renderer.fontCollection.clear();
|
renderer.fontCollection.clear();
|
||||||
|
|
||||||
if (ui.debugEmulateFlutterTesterEnvironment) {
|
if (ui_web.debugEmulateFlutterTesterEnvironment) {
|
||||||
// Load the embedded test font before loading fonts from the assets so that
|
// Load the embedded test font before loading fonts from the assets so that
|
||||||
// the embedded test font is the default (first) font.
|
// the embedded test font is the default (first) font.
|
||||||
await renderer.fontCollection.loadFontFromList(
|
await renderer.fontCollection.loadFontFromList(
|
||||||
|
|||||||
@@ -472,7 +472,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
|
|||||||
// In widget tests we want to bypass processing of platform messages.
|
// In widget tests we want to bypass processing of platform messages.
|
||||||
bool returnImmediately = false;
|
bool returnImmediately = false;
|
||||||
assert(() {
|
assert(() {
|
||||||
if (ui.debugEmulateFlutterTesterEnvironment) {
|
if (ui_web.debugEmulateFlutterTesterEnvironment) {
|
||||||
returnImmediately = true;
|
returnImmediately = true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
// 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:typed_data';
|
|
||||||
|
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
|
||||||
Future<void> Function(String, ByteData?, ui.PlatformMessageResponseCallback?)? pluginMessageCallHandler;
|
ui.PlatformMessageCallback? pluginMessageCallHandler;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'dart:typed_data';
|
|||||||
|
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import '../../engine.dart' show registerHotRestartListener;
|
import '../../engine.dart' show registerHotRestartListener;
|
||||||
import '../alarm_clock.dart';
|
import '../alarm_clock.dart';
|
||||||
@@ -2116,7 +2117,7 @@ class EngineSemanticsOwner {
|
|||||||
/// Updates the semantics tree from data in the [uiUpdate].
|
/// Updates the semantics tree from data in the [uiUpdate].
|
||||||
void updateSemantics(ui.SemanticsUpdate uiUpdate) {
|
void updateSemantics(ui.SemanticsUpdate uiUpdate) {
|
||||||
if (!_semanticsEnabled) {
|
if (!_semanticsEnabled) {
|
||||||
if (ui.debugEmulateFlutterTesterEnvironment) {
|
if (ui_web.debugEmulateFlutterTesterEnvironment) {
|
||||||
// Running Flutter widget tests in a fake environment. Don't enable
|
// Running Flutter widget tests in a fake environment. Don't enable
|
||||||
// engine semantics. Test semantics trees violate invariants in ways
|
// engine semantics. Test semantics trees violate invariants in ways
|
||||||
// production implementation isn't built to handle. For example, tests
|
// production implementation isn't built to handle. For example, tests
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import '../browser_detection.dart';
|
import '../browser_detection.dart';
|
||||||
import '../dom.dart';
|
import '../dom.dart';
|
||||||
@@ -473,7 +474,7 @@ class EngineTextStyle implements ui.TextStyle {
|
|||||||
// This makes widget tests predictable and less flaky.
|
// This makes widget tests predictable and less flaky.
|
||||||
String result = fontFamily;
|
String result = fontFamily;
|
||||||
assert(() {
|
assert(() {
|
||||||
if (ui.debugEmulateFlutterTesterEnvironment && !_testFonts.contains(fontFamily)) {
|
if (ui_web.debugEmulateFlutterTesterEnvironment && !_testFonts.contains(fontFamily)) {
|
||||||
result = _testFonts.first;
|
result = _testFonts.first;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -820,7 +821,7 @@ void applyTextStyleToElement({
|
|||||||
}
|
}
|
||||||
// For test environment use effectiveFontFamily since we need to
|
// For test environment use effectiveFontFamily since we need to
|
||||||
// consistently use the correct test font.
|
// consistently use the correct test font.
|
||||||
if (ui.debugEmulateFlutterTesterEnvironment) {
|
if (ui_web.debugEmulateFlutterTesterEnvironment) {
|
||||||
cssStyle.fontFamily = canonicalizeFontFamily(style.effectiveFontFamily)!;
|
cssStyle.fontFamily = canonicalizeFontFamily(style.effectiveFontFamily)!;
|
||||||
} else {
|
} else {
|
||||||
cssStyle.fontFamily = canonicalizeFontFamily(style.fontFamily)!;
|
cssStyle.fontFamily = canonicalizeFontFamily(style.fontFamily)!;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import '../browser_detection.dart';
|
import '../browser_detection.dart';
|
||||||
import '../dom.dart';
|
import '../dom.dart';
|
||||||
@@ -144,7 +145,7 @@ class TextDimensions {
|
|||||||
if (browserEngine == BrowserEngine.firefox &&
|
if (browserEngine == BrowserEngine.firefox &&
|
||||||
// In the flutter tester environment, we use a predictable-size for font
|
// In the flutter tester environment, we use a predictable-size for font
|
||||||
// measurement tests.
|
// measurement tests.
|
||||||
!ui.debugEmulateFlutterTesterEnvironment) {
|
!ui_web.debugEmulateFlutterTesterEnvironment) {
|
||||||
// See subpixel rounding bug :
|
// See subpixel rounding bug :
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=442139
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=442139
|
||||||
// This causes bottom of letters such as 'y' to be cutoff and
|
// This causes bottom of letters such as 'y' to be cutoff and
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
library ui_web;
|
library ui_web;
|
||||||
|
|
||||||
export 'ui_web/asset_manager.dart';
|
export 'ui_web/asset_manager.dart';
|
||||||
|
export 'ui_web/initialization.dart';
|
||||||
export 'ui_web/navigation/platform_location.dart';
|
export 'ui_web/navigation/platform_location.dart';
|
||||||
export 'ui_web/navigation/url_strategy.dart';
|
export 'ui_web/navigation/url_strategy.dart';
|
||||||
export 'ui_web/platform_view_registry.dart';
|
export 'ui_web/platform_view_registry.dart';
|
||||||
|
export 'ui_web/plugins.dart';
|
||||||
|
export 'ui_web/testing.dart';
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2013 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.
|
||||||
|
|
||||||
|
import 'package:ui/src/engine.dart';
|
||||||
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
|
||||||
|
/// Bootstraps the Flutter Web engine and app.
|
||||||
|
///
|
||||||
|
/// If the app uses plugins, then the [registerPlugins] callback can be provided
|
||||||
|
/// to register those plugins. This is done typically by calling
|
||||||
|
/// `registerPlugins` from the auto-generated `web_plugin_registrant.dart` file.
|
||||||
|
///
|
||||||
|
/// The [runApp] callback is invoked to run the app after the engine is fully
|
||||||
|
/// initialized.
|
||||||
|
///
|
||||||
|
/// For more information, see what the `flutter_tools` does in the entrypoint
|
||||||
|
/// that it generates around the app's main method:
|
||||||
|
///
|
||||||
|
/// * https://github.com/flutter/flutter/blob/95be76ab7e3dca2def54454313e97f94f4ac4582/packages/flutter_tools/lib/src/web/file_generators/main_dart.dart#L14-L43
|
||||||
|
///
|
||||||
|
/// By default, engine initialization and app startup occur immediately and back
|
||||||
|
/// to back. They can be programmatically controlled by setting
|
||||||
|
/// `FlutterLoader.didCreateEngineInitializer`. For more information, see how
|
||||||
|
/// `flutter.js` does it:
|
||||||
|
///
|
||||||
|
/// * https://github.com/flutter/flutter/blob/95be76ab7e3dca2def54454313e97f94f4ac4582/packages/flutter_tools/lib/src/web/file_generators/js/flutter.js
|
||||||
|
Future<void> bootstrapEngine({
|
||||||
|
ui.VoidCallback? registerPlugins,
|
||||||
|
ui.VoidCallback? runApp,
|
||||||
|
}) async {
|
||||||
|
// Create the object that knows how to bootstrap an app from JS and Dart.
|
||||||
|
final AppBootstrap bootstrap = AppBootstrap(
|
||||||
|
initializeEngine: ([JsFlutterConfiguration? configuration]) async {
|
||||||
|
await initializeEngineServices(jsConfiguration: configuration);
|
||||||
|
}, runApp: () async {
|
||||||
|
if (registerPlugins != null) {
|
||||||
|
registerPlugins();
|
||||||
|
}
|
||||||
|
await initializeEngineUi();
|
||||||
|
if (runApp != null) {
|
||||||
|
runApp();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
final FlutterLoader? loader = flutter?.loader;
|
||||||
|
if (loader == null || loader.isAutoStart) {
|
||||||
|
// The user does not want control of the app, bootstrap immediately.
|
||||||
|
domWindow.console.debug('Flutter Web Bootstrap: Auto.');
|
||||||
|
await bootstrap.autoStart();
|
||||||
|
} else {
|
||||||
|
// Yield control of the bootstrap procedure to the user.
|
||||||
|
domWindow.console.debug('Flutter Web Bootstrap: Programmatic.');
|
||||||
|
loader.didCreateEngineInitializer(bootstrap.prepareEngineInitializer());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,9 +8,10 @@ import 'package:meta/meta.dart';
|
|||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
|
||||||
|
import '../testing.dart';
|
||||||
import 'platform_location.dart';
|
import 'platform_location.dart';
|
||||||
|
|
||||||
UrlStrategy _realDefaultUrlStrategy = ui.debugEmulateFlutterTesterEnvironment
|
UrlStrategy _realDefaultUrlStrategy = debugEmulateFlutterTesterEnvironment
|
||||||
? TestUrlStrategy.fromEntry(const TestHistoryEntry('default', null, '/'))
|
? TestUrlStrategy.fromEntry(const TestHistoryEntry('default', null, '/'))
|
||||||
: const HashUrlStrategy();
|
: const HashUrlStrategy();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2013 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.
|
||||||
|
|
||||||
|
import 'package:ui/src/engine.dart';
|
||||||
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
|
||||||
|
/// Sets the handler that forwards platform messages to web plugins.
|
||||||
|
///
|
||||||
|
/// This function exists because unlike mobile, on the web plugins are also
|
||||||
|
/// implemented using Dart code, and that code needs a way to receive messages.
|
||||||
|
void setPluginHandler(ui.PlatformMessageCallback handler) {
|
||||||
|
pluginMessageCallHandler = handler;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2013 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.
|
||||||
|
|
||||||
|
import 'package:ui/src/engine.dart';
|
||||||
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
|
||||||
|
/// Whether the Flutter engine is running in `flutter test` emulation mode.
|
||||||
|
///
|
||||||
|
/// When true, the engine will emulate a specific screen size, and always
|
||||||
|
/// use the "Ahem" font to reduce test flakiness and dependence on the test
|
||||||
|
/// environment.
|
||||||
|
bool get debugEmulateFlutterTesterEnvironment =>
|
||||||
|
_debugEmulateFlutterTesterEnvironment;
|
||||||
|
|
||||||
|
/// Sets whether the Flutter engine is running in `flutter test` emulation mode.
|
||||||
|
set debugEmulateFlutterTesterEnvironment(bool value) {
|
||||||
|
_debugEmulateFlutterTesterEnvironment = value;
|
||||||
|
if (_debugEmulateFlutterTesterEnvironment) {
|
||||||
|
const ui.Size logicalSize = ui.Size(800.0, 600.0);
|
||||||
|
window.webOnlyDebugPhysicalSizeOverride =
|
||||||
|
logicalSize * window.devicePixelRatio;
|
||||||
|
}
|
||||||
|
debugDisableFontFallbacks = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _debugEmulateFlutterTesterEnvironment = false;
|
||||||
@@ -6,6 +6,7 @@ import 'package:test/bootstrap/browser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ void main() {
|
|||||||
const ui.Rect kDefaultRegion = ui.Rect.fromLTRB(0, 0, 500, 250);
|
const ui.Rect kDefaultRegion = ui.Rect.fromLTRB(0, 0, 500, 250);
|
||||||
|
|
||||||
void testMain() {
|
void testMain() {
|
||||||
ui.debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
|
|
||||||
group('flutter_tester emulation', () {
|
group('flutter_tester emulation', () {
|
||||||
setUpCanvasKitTest();
|
setUpCanvasKitTest();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:test/bootstrap/browser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
@@ -94,9 +95,9 @@ void testMain() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('test fonts in flutterTester environment', () {
|
group('test fonts in flutterTester environment', () {
|
||||||
final bool resetValue = ui.debugEmulateFlutterTesterEnvironment;
|
final bool resetValue = ui_web.debugEmulateFlutterTesterEnvironment;
|
||||||
ui.debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
tearDownAll(() => ui.debugEmulateFlutterTesterEnvironment = resetValue);
|
tearDownAll(() => ui_web.debugEmulateFlutterTesterEnvironment = resetValue);
|
||||||
const List<String> testFonts = <String>['FlutterTest', 'Ahem'];
|
const List<String> testFonts = <String>['FlutterTest', 'Ahem'];
|
||||||
|
|
||||||
test('The default test font is used when a non-test fontFamily is specified', () {
|
test('The default test font is used when a non-test fontFamily is specified', () {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'dart:js_util' as js_util;
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart' as engine;
|
import 'package:ui/src/engine.dart' as engine;
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import 'fake_asset_manager.dart';
|
import 'fake_asset_manager.dart';
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ void setUpUnitTests({
|
|||||||
late final FakeAssetScope debugFontsScope;
|
late final FakeAssetScope debugFontsScope;
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
if (emulateTesterEnvironment) {
|
if (emulateTesterEnvironment) {
|
||||||
ui.debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some of our tests rely on color emoji
|
// Some of our tests rely on color emoji
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import 'dart:typed_data';
|
|||||||
import 'package:test/bootstrap/browser.dart';
|
import 'package:test/bootstrap/browser.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
|
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import 'package:js/js_util.dart' as js_util;
|
|||||||
import 'package:test/bootstrap/browser.dart';
|
import 'package:test/bootstrap/browser.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart' as engine;
|
import 'package:ui/src/engine.dart' as engine;
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
@JS('_flutter')
|
@JS('_flutter')
|
||||||
external set _loader(JSAny? loader);
|
external set _loader(JSAny? loader);
|
||||||
@@ -28,7 +28,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void testMain() {
|
void testMain() {
|
||||||
test('webOnlyWarmupEngine calls _flutter.loader.didCreateEngineInitializer callback', () async {
|
test('bootstrapEngine calls _flutter.loader.didCreateEngineInitializer callback', () async {
|
||||||
Object? engineInitializer;
|
Object? engineInitializer;
|
||||||
|
|
||||||
void didCreateEngineInitializerMock(Object? obj) {
|
void didCreateEngineInitializerMock(Object? obj) {
|
||||||
@@ -41,7 +41,7 @@ void testMain() {
|
|||||||
// Reset the engine
|
// Reset the engine
|
||||||
engine.debugResetEngineInitializationState();
|
engine.debugResetEngineInitializationState();
|
||||||
|
|
||||||
await ui.webOnlyWarmupEngine(
|
await ui_web.bootstrapEngine(
|
||||||
registerPlugins: () {},
|
registerPlugins: () {},
|
||||||
runApp: () {},
|
runApp: () {},
|
||||||
);
|
);
|
||||||
@@ -52,7 +52,7 @@ void testMain() {
|
|||||||
expect(js_util.hasProperty(engineInitializer!, 'autoStart'), isTrue, reason: 'Missing FlutterEngineInitializer method: autoStart.');
|
expect(js_util.hasProperty(engineInitializer!, 'autoStart'), isTrue, reason: 'Missing FlutterEngineInitializer method: autoStart.');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('webOnlyWarmupEngine does auto-start when _flutter.loader.didCreateEngineInitializer does not exist', () async {
|
test('bootstrapEngine does auto-start when _flutter.loader.didCreateEngineInitializer does not exist', () async {
|
||||||
loader = null;
|
loader = null;
|
||||||
|
|
||||||
bool pluginsRegistered = false;
|
bool pluginsRegistered = false;
|
||||||
@@ -67,7 +67,7 @@ void testMain() {
|
|||||||
// Reset the engine
|
// Reset the engine
|
||||||
engine.debugResetEngineInitializationState();
|
engine.debugResetEngineInitializationState();
|
||||||
|
|
||||||
await ui.webOnlyWarmupEngine(
|
await ui_web.bootstrapEngine(
|
||||||
registerPlugins: registerPluginsMock,
|
registerPlugins: registerPluginsMock,
|
||||||
runApp: runAppMock,
|
runApp: runAppMock,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:test/bootstrap/browser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
internalBootstrapBrowserTest(() => testMain);
|
internalBootstrapBrowserTest(() => testMain);
|
||||||
@@ -25,7 +26,7 @@ Future<void> testMain() async {
|
|||||||
group('Title and Primary Color/Theme meta', () {
|
group('Title and Primary Color/Theme meta', () {
|
||||||
test('is set on the document by platform message', () {
|
test('is set on the document by platform message', () {
|
||||||
// Run the unit test without emulating Flutter tester environment.
|
// Run the unit test without emulating Flutter tester environment.
|
||||||
ui.debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
|
|
||||||
// TODO(yjbanov): https://github.com/flutter/flutter/issues/39159
|
// TODO(yjbanov): https://github.com/flutter/flutter/issues/39159
|
||||||
domDocument.title = '';
|
domDocument.title = '';
|
||||||
@@ -69,7 +70,7 @@ Future<void> testMain() async {
|
|||||||
|
|
||||||
test('supports null title and primaryColor', () {
|
test('supports null title and primaryColor', () {
|
||||||
// Run the unit test without emulating Flutter tester environment.
|
// Run the unit test without emulating Flutter tester environment.
|
||||||
ui.debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
|
|
||||||
const ui.Color expectedNullColor = ui.Color(0xFF000000);
|
const ui.Color expectedNullColor = ui.Color(0xFF000000);
|
||||||
// TODO(yjbanov): https://github.com/flutter/flutter/issues/39159
|
// TODO(yjbanov): https://github.com/flutter/flutter/issues/39159
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:test/bootstrap/browser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
internalBootstrapBrowserTest(() => testMain);
|
internalBootstrapBrowserTest(() => testMain);
|
||||||
@@ -38,7 +39,7 @@ void testMain() {
|
|||||||
group('SystemUIOverlayStyle', () {
|
group('SystemUIOverlayStyle', () {
|
||||||
test('theme color is set / removed by platform message', () {
|
test('theme color is set / removed by platform message', () {
|
||||||
// Run the unit test without emulating Flutter tester environment.
|
// Run the unit test without emulating Flutter tester environment.
|
||||||
ui.debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
|
|
||||||
expect(getCssThemeColor(), null);
|
expect(getCssThemeColor(), null);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import 'package:test/bootstrap/browser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart';
|
import 'package:ui/ui.dart';
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import 'package:web_engine_tester/golden_tester.dart';
|
import 'package:web_engine_tester/golden_tester.dart';
|
||||||
|
|
||||||
@@ -318,7 +319,7 @@ Future<void> testMain() async {
|
|||||||
// Cyan text should be above everything.
|
// Cyan text should be above everything.
|
||||||
test('Paints text above and below image', () async {
|
test('Paints text above and below image', () async {
|
||||||
// Use a non-Ahem font so that text is visible.
|
// Use a non-Ahem font so that text is visible.
|
||||||
debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
final RecordingCanvas rc =
|
final RecordingCanvas rc =
|
||||||
RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300));
|
RecordingCanvas(const Rect.fromLTRB(0, 0, 400, 300));
|
||||||
rc.save();
|
rc.save();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:test/bootstrap/browser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart';
|
import 'package:ui/ui.dart';
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import '../../common/test_initialization.dart';
|
import '../../common/test_initialization.dart';
|
||||||
import '../paragraph/helper.dart';
|
import '../paragraph/helper.dart';
|
||||||
@@ -414,7 +415,7 @@ Future<void> testMain() async {
|
|||||||
// Paragraphs and spans force the FlutterTest font in test mode. We need to
|
// Paragraphs and spans force the FlutterTest font in test mode. We need to
|
||||||
// trick them into thinking they are not in test mode, so they use the
|
// trick them into thinking they are not in test mode, so they use the
|
||||||
// provided font family.
|
// provided font family.
|
||||||
debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
final EngineParagraphStyle style = EngineParagraphStyle(fontSize: 12.0, fontFamily: 'first');
|
final EngineParagraphStyle style = EngineParagraphStyle(fontSize: 12.0, fontFamily: 'first');
|
||||||
final CanvasParagraphBuilder builder = CanvasParagraphBuilder(style);
|
final CanvasParagraphBuilder builder = CanvasParagraphBuilder(style);
|
||||||
|
|
||||||
@@ -454,7 +455,7 @@ Future<void> testMain() async {
|
|||||||
// measurements.
|
// measurements.
|
||||||
ignorePositions: true,
|
ignorePositions: true,
|
||||||
);
|
);
|
||||||
debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Regression test for https://github.com/flutter/flutter/issues/108431.
|
// Regression test for https://github.com/flutter/flutter/issues/108431.
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:test/bootstrap/browser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart' as ui;
|
import 'package:ui/ui.dart' as ui;
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import '../../common/test_initialization.dart';
|
import '../../common/test_initialization.dart';
|
||||||
import '../paragraph/helper.dart';
|
import '../paragraph/helper.dart';
|
||||||
@@ -714,7 +715,7 @@ Future<void> testMain() async {
|
|||||||
|
|
||||||
test('does not leak styles across spanometers', () {
|
test('does not leak styles across spanometers', () {
|
||||||
// This prevents the Ahem font from being forced in all paragraphs.
|
// This prevents the Ahem font from being forced in all paragraphs.
|
||||||
ui.debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
|
|
||||||
final CanvasParagraph p1 = plain(
|
final CanvasParagraph p1 = plain(
|
||||||
EngineParagraphStyle(
|
EngineParagraphStyle(
|
||||||
@@ -750,6 +751,6 @@ Future<void> testMain() async {
|
|||||||
expect(textContext.font, contains('40px'));
|
expect(textContext.font, contains('40px'));
|
||||||
expect(textContext.font, contains('FontFamily2'));
|
expect(textContext.font, contains('FontFamily2'));
|
||||||
|
|
||||||
ui.debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import 'package:test/bootstrap/browser.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:ui/src/engine.dart';
|
import 'package:ui/src/engine.dart';
|
||||||
import 'package:ui/ui.dart';
|
import 'package:ui/ui.dart';
|
||||||
|
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
|
||||||
|
|
||||||
import '../common/matchers.dart';
|
import '../common/matchers.dart';
|
||||||
import '../common/test_initialization.dart';
|
import '../common/test_initialization.dart';
|
||||||
@@ -236,7 +237,7 @@ Future<void> testMain() async {
|
|||||||
|
|
||||||
test('adds Arial and sans-serif as fallback fonts', () {
|
test('adds Arial and sans-serif as fallback fonts', () {
|
||||||
// Set this to false so it doesn't default to the test font.
|
// Set this to false so it doesn't default to the test font.
|
||||||
debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
|
|
||||||
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
|
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
|
||||||
fontFamily: 'SomeFont',
|
fontFamily: 'SomeFont',
|
||||||
@@ -247,14 +248,14 @@ Future<void> testMain() async {
|
|||||||
expect(paragraph.toDomElement().children.single.style.fontFamily,
|
expect(paragraph.toDomElement().children.single.style.fontFamily,
|
||||||
'SomeFont, $fallback, sans-serif');
|
'SomeFont, $fallback, sans-serif');
|
||||||
|
|
||||||
debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
},
|
},
|
||||||
// TODO(mdebbar): https://github.com/flutter/flutter/issues/46638
|
// TODO(mdebbar): https://github.com/flutter/flutter/issues/46638
|
||||||
skip: browserEngine == BrowserEngine.firefox);
|
skip: browserEngine == BrowserEngine.firefox);
|
||||||
|
|
||||||
test('does not add fallback fonts to generic families', () {
|
test('does not add fallback fonts to generic families', () {
|
||||||
// Set this to false so it doesn't default to the default test font.
|
// Set this to false so it doesn't default to the default test font.
|
||||||
debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
|
|
||||||
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
|
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
|
||||||
fontFamily: 'serif',
|
fontFamily: 'serif',
|
||||||
@@ -264,12 +265,12 @@ Future<void> testMain() async {
|
|||||||
paragraph.layout(constrain(double.infinity));
|
paragraph.layout(constrain(double.infinity));
|
||||||
expect(paragraph.toDomElement().children.single.style.fontFamily, 'serif');
|
expect(paragraph.toDomElement().children.single.style.fontFamily, 'serif');
|
||||||
|
|
||||||
debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can set font families that need to be quoted', () {
|
test('can set font families that need to be quoted', () {
|
||||||
// Set this to false so it doesn't default to the default test font.
|
// Set this to false so it doesn't default to the default test font.
|
||||||
debugEmulateFlutterTesterEnvironment = false;
|
ui_web.debugEmulateFlutterTesterEnvironment = false;
|
||||||
|
|
||||||
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
|
final CanvasParagraph paragraph = plain(EngineParagraphStyle(
|
||||||
fontFamily: 'MyFont 2000',
|
fontFamily: 'MyFont 2000',
|
||||||
@@ -280,7 +281,7 @@ Future<void> testMain() async {
|
|||||||
expect(paragraph.toDomElement().children.single.style.fontFamily,
|
expect(paragraph.toDomElement().children.single.style.fontFamily,
|
||||||
'"MyFont 2000", $fallback, sans-serif');
|
'"MyFont 2000", $fallback, sans-serif');
|
||||||
|
|
||||||
debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
group('TextRange', () {
|
group('TextRange', () {
|
||||||
@@ -360,9 +361,9 @@ Future<void> testMain() async {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('test fonts in flutterTester environment', () {
|
group('test fonts in flutterTester environment', () {
|
||||||
final bool resetValue = debugEmulateFlutterTesterEnvironment;
|
final bool resetValue = ui_web.debugEmulateFlutterTesterEnvironment;
|
||||||
debugEmulateFlutterTesterEnvironment = true;
|
ui_web.debugEmulateFlutterTesterEnvironment = true;
|
||||||
tearDownAll(() => debugEmulateFlutterTesterEnvironment = resetValue);
|
tearDownAll(() => ui_web.debugEmulateFlutterTesterEnvironment = resetValue);
|
||||||
const List<String> testFonts = <String>['FlutterTest', 'Ahem'];
|
const List<String> testFonts = <String>['FlutterTest', 'Ahem'];
|
||||||
|
|
||||||
test('The default test font is used when a non-test fontFamily is specified, or fontFamily is not specified', () {
|
test('The default test font is used when a non-test fontFamily is specified, or fontFamily is not specified', () {
|
||||||
|
|||||||
Reference in New Issue
Block a user