[web] Migrate Flutter Web DOM usage to JS static interop - 40. (flutter/engine#33376)

This commit is contained in:
joshualitt
2022-06-28 10:53:15 -07:00
committed by GitHub
parent 3e6c1ed814
commit 249ae96480
17 changed files with 110 additions and 124 deletions

View File

@@ -797,6 +797,7 @@ DomFontFace createDomFontFace(String family, Object source,
extension DomFontFaceExtension on DomFontFace {
Future<DomFontFace> load() =>
js_util.promiseToFuture(js_util.callMethod(this, 'load', <Object>[]));
external String? get family;
}
@JS()
@@ -806,8 +807,12 @@ class DomFontFaceSet extends DomEventTarget {}
extension DomFontFaceSetExtension on DomFontFaceSet {
external DomFontFaceSet? add(DomFontFace font);
external void clear();
external void forEach(DomFontFaceSetForEachCallback callback);
}
typedef DomFontFaceSetForEachCallback = void Function(
DomFontFace fontFace, DomFontFace fontFaceAgain, DomFontFaceSet set);
@JS()
@staticInterop
class DomVisualViewport extends DomEventTarget {}

View File

@@ -557,7 +557,7 @@ bool unsafeIsNull(dynamic object) {
return object == null;
}
/// A typed variant of [html.Window.fetch].
/// A typed variant of [domWindow.fetch].
Future<DomResponse> httpFetch(String url) async {
final Object? result = await domWindow.fetch(url);
return result! as DomResponse;

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
@@ -41,12 +40,12 @@ void testMain() {
// The platform view is now split in two parts. The contents live
// as a child of the glassPane, and the slot lives in the glassPane
// shadow root. The slot is the one that has pointer events auto.
final html.Element contents = flutterViewEmbedder.glassPaneElement!
.querySelector('#view-0')! as html.Element;
final html.Element slot = flutterViewEmbedder.sceneElement!
.querySelector('slot')! as html.Element;
final html.Element contentsHost = contents.parent!;
final html.Element slotHost = slot.parent!;
final DomElement contents = flutterViewEmbedder.glassPaneElement!
.querySelector('#view-0')!;
final DomElement slot = flutterViewEmbedder.sceneElement!
.querySelector('slot')!;
final DomElement contentsHost = contents.parent!;
final DomElement slotHost = slot.parent!;
expect(contents, isNotNull,
reason: 'The view from the factory is injected in the DOM.');
@@ -120,8 +119,8 @@ void testMain() {
dispatcher.rasterizer!.draw(sb.build().layerTree);
// Transformations happen on the slot element.
final html.Element slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')! as html.Element;
final DomElement slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')!;
expect(
slotHost.style.transform,
@@ -145,15 +144,15 @@ void testMain() {
sb.addPlatformView(0, offset: const ui.Offset(3, 4), width: 5, height: 6);
dispatcher.rasterizer!.draw(sb.build().layerTree);
final html.Element slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')! as html.Element;
final html.CssStyleDeclaration style = slotHost.style;
final DomElement slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')!;
final DomCSSStyleDeclaration style = slotHost.style;
expect(style.transform, 'matrix(1, 0, 0, 1, 3, 4)');
expect(style.width, '5px');
expect(style.height, '6px');
final html.Rectangle<num> slotRect = slotHost.getBoundingClientRect();
final DomRect slotRect = slotHost.getBoundingClientRect();
expect(slotRect.left, 3);
expect(slotRect.top, 4);
expect(slotRect.right, 8);
@@ -162,9 +161,9 @@ void testMain() {
// Returns the list of CSS transforms applied to the ancestor chain of
// elements starting from `viewHost`, up until and excluding <flt-scene>.
List<String> getTransformChain(html.Element viewHost) {
List<String> getTransformChain(DomElement viewHost) {
final List<String> chain = <String>[];
html.Element? element = viewHost;
DomElement? element = viewHost;
while (element != null && element.tagName.toLowerCase() != 'flt-scene') {
chain.add(element.style.transform);
element = element.parent;
@@ -190,8 +189,8 @@ void testMain() {
dispatcher.rasterizer!.draw(sb.build().layerTree);
// Transformations happen on the slot element.
html.Element slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')! as html.Element;
DomElement slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')!;
expect(
getTransformChain(slotHost),
@@ -212,7 +211,7 @@ void testMain() {
// Transformations happen on the slot element.
slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')! as html.Element;
.querySelector('flt-platform-view-slot')!;
expect(
getTransformChain(slotHost),
@@ -242,8 +241,8 @@ void testMain() {
dispatcher.rasterizer!.draw(sb.build().layerTree);
// Transformations happen on the slot element.
final html.Element slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')! as html.Element;
final DomElement slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')!;
expect(
getTransformChain(slotHost),
@@ -271,8 +270,8 @@ void testMain() {
dispatcher.rasterizer!.draw(sb.build().layerTree);
// Transformations happen on the slot element.
final html.Element slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')! as html.Element;
final DomElement slotHost = flutterViewEmbedder.sceneElement!
.querySelector('flt-platform-view-slot')!;
expect(
getTransformChain(slotHost),
@@ -704,8 +703,8 @@ void testMain() {
dispatcher.rasterizer!.draw(sb.build().layerTree);
}
final html.Node skPathDefs = flutterViewEmbedder.sceneElement!
.querySelector('#sk_path_defs')! as html.Node;
final DomNode skPathDefs = flutterViewEmbedder.sceneElement!
.querySelector('#sk_path_defs')!;
expect(skPathDefs.childNodes, hasLength(0));

View File

@@ -4,8 +4,6 @@
@JS()
library embedder_test; // We need this to mess with the ShadowDOM.
import 'dart:html' as html;
import 'package:js/js.dart';
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
@@ -18,24 +16,24 @@ void main() {
void testMain() {
test('populates flt-renderer and flt-build-mode', () {
FlutterViewEmbedder();
expect(html.document.body!.attributes['flt-renderer'],
expect(domDocument.body!.getAttribute('flt-renderer'),
'html (requested explicitly)');
expect(html.document.body!.attributes['flt-build-mode'], 'debug');
expect(domDocument.body!.getAttribute('flt-build-mode'), 'debug');
});
test('innerHeight/innerWidth are equal to visualViewport height and width',
() {
if (html.window.visualViewport != null) {
expect(html.window.visualViewport!.width, html.window.innerWidth);
expect(html.window.visualViewport!.height, html.window.innerHeight);
if (domWindow.visualViewport != null) {
expect(domWindow.visualViewport!.width, domWindow.innerWidth);
expect(domWindow.visualViewport!.height, domWindow.innerHeight);
}
});
test('replaces viewport meta tags during style reset', () {
final html.MetaElement existingMeta = html.MetaElement()
final DomHTMLMetaElement existingMeta = createDomHTMLMetaElement()
..name = 'viewport'
..content = 'foo=bar';
html.document.head!.append(existingMeta);
domDocument.head!.append(existingMeta);
expect(existingMeta.isConnected, isTrue);
final FlutterViewEmbedder embedder = FlutterViewEmbedder();
@@ -58,7 +56,7 @@ void testMain() {
test('renders a shadowRoot by default', () {
final FlutterViewEmbedder embedder = FlutterViewEmbedder();
final HostNode hostNode = embedder.glassPaneShadow!;
expect(hostNode.node, isA<html.ShadowRoot>());
expect(domInstanceOfString(hostNode.node, 'ShadowRoot'), isTrue);
});
test('starts without shadowDom available too', () {
@@ -69,9 +67,9 @@ void testMain() {
final FlutterViewEmbedder embedder = FlutterViewEmbedder();
final HostNode hostNode = embedder.glassPaneShadow!;
expect(hostNode.node, isA<html.Element>());
expect(domInstanceOfString(hostNode.node, 'Element'), isTrue);
expect(
(hostNode.node as html.Element).tagName,
(hostNode.node as DomElement).tagName,
equalsIgnoringCase('flt-element-host-node'),
);
attachShadow = oldAttachShadow; // Restore ShadowDOM
@@ -79,39 +77,39 @@ void testMain() {
test('should add/remove global resource', () {
final FlutterViewEmbedder embedder = FlutterViewEmbedder();
final html.DivElement resource = html.DivElement();
embedder.addResource(resource as DomHTMLDivElement);
final html.Element? resourceRoot = resource.parent;
final DomHTMLDivElement resource = createDomHTMLDivElement();
embedder.addResource(resource);
final DomElement? resourceRoot = resource.parent;
expect(resourceRoot, isNotNull);
expect(resourceRoot!.childNodes.length, 1);
embedder.removeResource(resource as DomHTMLDivElement);
embedder.removeResource(resource);
expect(resourceRoot.childNodes.length, 0);
});
test('hide placeholder text for textfield', () {
final FlutterViewEmbedder embedder = FlutterViewEmbedder();
final html.InputElement regularTextField = html.InputElement();
final DomHTMLInputElement regularTextField = createDomHTMLInputElement();
regularTextField.placeholder = 'Now you see me';
embedder.addResource(regularTextField as DomHTMLInputElement);
embedder.addResource(regularTextField);
regularTextField.focus();
html.CssStyleDeclaration? style = domWindow.getComputedStyle(
DomCSSStyleDeclaration? style = domWindow.getComputedStyle(
embedder.glassPaneShadow!.querySelector('input')!,
'::placeholder') as html.CssStyleDeclaration?;
'::placeholder');
expect(style, isNotNull);
expect(style?.opacity, isNot('0'));
expect(style.opacity, isNot('0'));
final html.InputElement textField = html.InputElement();
final DomHTMLInputElement textField = createDomHTMLInputElement();
textField.placeholder = 'Now you dont';
textField.classes.add('flt-text-editing');
embedder.addResource(textField as DomHTMLInputElement);
textField.classList.add('flt-text-editing');
embedder.addResource(textField);
textField.focus();
style = domWindow.getComputedStyle(
embedder.glassPaneShadow!.querySelector('input.flt-text-editing')!,
'::placeholder') as html.CssStyleDeclaration?;
'::placeholder');
expect(style, isNotNull);
expect(style?.opacity, '0');
expect(style.opacity, '0');
}, skip: browserEngine != BrowserEngine.firefox);
}

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:html' as html;
import 'dart:js_util' as js_util;
import 'dart:typed_data';
@@ -61,8 +60,8 @@ void testMain() {
() async {
// Patch browser so that clipboard api is not available.
final Object? originalClipboard =
js_util.getProperty<Object?>(html.window.navigator, 'clipboard');
js_util.setProperty(html.window.navigator, 'clipboard', null);
js_util.getProperty<Object?>(domWindow.navigator, 'clipboard');
js_util.setProperty(domWindow.navigator, 'clipboard', null);
const MethodCodec codec = JSONMethodCodec();
final Completer<ByteData?> completer = Completer<ByteData?>();
ui.PlatformDispatcher.instance.sendPlatformMessage(
@@ -80,13 +79,13 @@ void testMain() {
);
}
js_util.setProperty(
html.window.navigator, 'clipboard', originalClipboard);
domWindow.navigator, 'clipboard', originalClipboard);
});
test('can find text scale factor', () async {
const double deltaTolerance = 1e-5;
final html.Element root = html.document.documentElement!;
final DomElement root = domDocument.documentElement!;
final String oldFontSize = root.style.fontSize;
addTearDown(() {
@@ -108,14 +107,14 @@ void testMain() {
root.style.fontSize = '12.8px';
expect(findBrowserTextScaleFactor(), closeTo(0.8, deltaTolerance));
root.style.fontSize = null;
root.style.fontSize = '';
expect(findBrowserTextScaleFactor(), 1.0);
});
test(
'calls onTextScaleFactorChanged when the <html> element\'s font-size changes',
() async {
final html.Element root = html.document.documentElement!;
final DomElement root = domDocument.documentElement!;
final String oldFontSize = root.style.fontSize;
final ui.VoidCallback? oldCallback = ui.PlatformDispatcher.instance.onTextScaleFactorChanged;

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'dart:js' as js;
import 'dart:js_util' as js_util;
@@ -160,7 +159,7 @@ class BenchmarkDatapoint {
void jsOnBenchmark(dynamic listener) {
js_util.setProperty(
html.window,
domWindow,
'_flutter_internal_on_benchmark',
listener is Function
? js.allowInterop(listener)

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:html' as html;
import 'dart:js_util' as js_util;
import 'dart:typed_data';
@@ -302,7 +301,7 @@ Future<void> testMain() async {
/// Regression test for https://github.com/flutter/flutter/issues/66128.
test('setPreferredOrientation responds even if browser doesn\'t support api', () async {
final html.Screen screen = html.window.screen!;
final DomScreen screen = domWindow.screen!;
js_util.setProperty(screen, 'orientation', null);
final Completer<bool> completer = Completer<bool>();
@@ -343,14 +342,15 @@ Future<void> testMain() async {
expect(window.locales, isEmpty);
expect(window.locale, equals(const ui.Locale.fromSubtags()));
expect(localeChangedCount, 0);
html.window.dispatchEvent(html.Event('languagechange'));
domWindow.dispatchEvent(createDomEvent('Event', 'languagechange'));
expect(window.locales, isNotEmpty);
expect(localeChangedCount, 1);
});
test('dispatches browser event on flutter/service_worker channel', () async {
final Completer<void> completer = Completer<void>();
html.window.addEventListener('flutter-first-frame', completer.complete);
domWindow.addEventListener('flutter-first-frame',
allowInterop(completer.complete));
final Zone innerZone = Zone.current.fork();
innerZone.runGuarded(() {

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'dart:math' as math;
import 'package:test/bootstrap/browser.dart';
@@ -24,16 +23,15 @@ Future<void> testMain() async {
void appendToScene() {
// Create a <flt-scene> element to make sure our CSS reset applies correctly.
final html.Element testScene = html.Element.tag('flt-scene');
final DomElement testScene = createDomElement('flt-scene');
if (isIosSafari) {
// Shrink to fit on the iPhone screen.
testScene.style.position = 'absolute';
testScene.style.transformOrigin = '0 0 0';
testScene.style.transform = 'scale(0.3)';
}
testScene.append(canvas.rootElement as html.Node);
flutterViewEmbedder.glassPaneShadow!.querySelector('flt-scene-host')!.append(testScene
as DomElement);
testScene.append(canvas.rootElement);
flutterViewEmbedder.glassPaneShadow!.querySelector('flt-scene-host')!.append(testScene);
}
setUpStableTestFonts();

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart' as engine;
@@ -32,7 +30,7 @@ Future<void> testMain() async {
rc.apply(engineCanvas, screenRect);
// Wrap in <flt-scene> so that our CSS selectors kick in.
final html.Element sceneElement = html.Element.tag('flt-scene');
final engine.DomElement sceneElement = engine.createDomElement('flt-scene');
if (isIosSafari) {
// Shrink to fit on the iPhone screen.
sceneElement.style.position = 'absolute';
@@ -41,8 +39,8 @@ Future<void> testMain() async {
}
try {
sceneElement.append(engineCanvas.rootElement as html.Element);
html.document.body!.append(sceneElement);
sceneElement.append(engineCanvas.rootElement);
engine.domDocument.body!.append(sceneElement);
// TODO(yjbanov): 10% diff rate is excessive. Update goldens.
await matchGoldenFile('$fileName.png', region: region);
} finally {

View File

@@ -691,8 +691,8 @@ void _testCullRectComputation() {
.toFloat64());
// TODO(yjbanov): see the TODO below.
// final double screenWidth = html.window.innerWidth.toDouble();
// final double screenHeight = html.window.innerHeight.toDouble();
// final double screenWidth = domWindow.innerWidth.toDouble();
// final double screenHeight = domWindow.innerHeight.toDouble();
final Matrix4 scaleTransform = Matrix4.identity().scaled(0.5, 0.2);
builder.pushTransform(

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
@@ -25,7 +23,7 @@ Future<void> testMain() async {
});
tearDown(() {
for (final html.Node scene in html.document.querySelectorAll('flt-scene')) {
for (final DomNode scene in domDocument.querySelectorAll('flt-scene')) {
scene.remove();
}
});

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:web_gl';
@@ -392,8 +391,8 @@ Future<void> testMain() async {
test('Creating lots of gradients doesn\'t create too many webgl contexts',
() async {
final html.CanvasElement sideCanvas =
html.CanvasElement(width: 5, height: 5);
final DomCanvasElement sideCanvas =
createDomCanvasElement(width: 5, height: 5);
final RenderingContext? context =
sideCanvas.getContext('webgl') as RenderingContext?;
expect(context, isNotNull);

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart'
@@ -38,8 +36,8 @@ Future<void> testMain() async {
setUp(() async {
SurfaceSceneBuilder.debugForgetFrameScene();
for (final html.Node scene in
flutterViewEmbedder.sceneHostElement!.querySelectorAll('flt-scene').cast<html.Node>()) {
for (final DomNode scene in
flutterViewEmbedder.sceneHostElement!.querySelectorAll('flt-scene').cast<DomNode>()) {
scene.remove();
}
initWebGl();

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:html' as html;
import 'dart:js_util' as js_util;
import 'dart:typed_data';
import 'package:test/bootstrap/browser.dart';
@@ -412,7 +411,7 @@ void testMain() {
// Regression test for https://github.com/flutter/flutter/issues/44470
test('Should handle contains for devicepixelratio != 1.0', () {
js_util.setProperty(html.window, 'devicePixelRatio', 4.0);
js_util.setProperty(domWindow, 'devicePixelRatio', 4.0);
window.debugOverrideDevicePixelRatio(4.0);
final Path path = Path()
..moveTo(50, 0)
@@ -421,7 +420,7 @@ void testMain() {
..lineTo(50, 0)
..close();
expect(path.contains(const Offset(50, 50)), isTrue);
js_util.setProperty(html.window, 'devicePixelRatio', 1.0);
js_util.setProperty(domWindow, 'devicePixelRatio', 1.0);
window.debugOverrideDevicePixelRatio(1.0);
// TODO(ferhat): Investigate failure on CI. Locally this passes.
// [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)"

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
@@ -23,7 +21,7 @@ void testMain() {
});
tearDown(() {
html.document.fonts!.clear();
domDocument.fonts!.clear();
});
group('regular special characters', () {
@@ -34,10 +32,10 @@ void testMain() {
fontManager.registerAsset(
_testFontFamily, 'url($_testFontUrl)', const <String, String>{});
await fontManager.ensureFontsLoaded();
html.document.fonts!
.forEach((html.FontFace f, html.FontFace f2, html.FontFaceSet s) {
domDocument.fonts!
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
fontFamilyList.add(f.family!);
});
}));
expect(fontFamilyList.length, equals(1));
expect(fontFamilyList.first, 'Ahem');
@@ -52,10 +50,10 @@ void testMain() {
fontManager.registerAsset(
_testFontFamily, 'url($_testFontUrl)', const <String, String>{});
await fontManager.ensureFontsLoaded();
html.document.fonts!
.forEach((html.FontFace f, html.FontFace f2, html.FontFaceSet s) {
domDocument.fonts!
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
fontFamilyList.add(f.family!);
});
}));
expect(fontFamilyList.length, equals(1));
expect(fontFamilyList.first, 'Ahem ahem ahem');
@@ -72,10 +70,10 @@ void testMain() {
fontManager.registerAsset(
_testFontFamily, 'url($_testFontUrl)', const <String, String>{});
await fontManager.ensureFontsLoaded();
html.document.fonts!
.forEach((html.FontFace f, html.FontFace f2, html.FontFaceSet s) {
domDocument.fonts!
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
fontFamilyList.add(f.family!);
});
}));
expect(fontFamilyList.length, equals(1));
expect(fontFamilyList.first, 'AhEm');
@@ -92,10 +90,10 @@ void testMain() {
fontManager.registerAsset(
_testFontFamily, 'url($_testFontUrl)', const <String, String>{});
await fontManager.ensureFontsLoaded();
html.document.fonts!
.forEach((html.FontFace f, html.FontFace f2, html.FontFaceSet s) {
domDocument.fonts!
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
fontFamilyList.add(f.family!);
});
}));
if (browserEngine != BrowserEngine.firefox) {
expect(fontFamilyList.length, equals(2));
@@ -118,10 +116,10 @@ void testMain() {
fontManager.registerAsset(
_testFontFamily, 'url($_testFontUrl)', const <String, String>{});
await fontManager.ensureFontsLoaded();
html.document.fonts!
.forEach((html.FontFace f, html.FontFace f2, html.FontFaceSet s) {
domDocument.fonts!
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
fontFamilyList.add(f.family!);
});
}));
if (browserEngine != BrowserEngine.firefox) {
expect(fontFamilyList.length, equals(2));
@@ -144,10 +142,10 @@ void testMain() {
fontManager.registerAsset(
_testFontFamily, 'url($_testFontUrl)', const <String, String>{});
await fontManager.ensureFontsLoaded();
html.document.fonts!
.forEach((html.FontFace f, html.FontFace f2, html.FontFaceSet s) {
domDocument.fonts!
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
fontFamilyList.add(f.family!);
});
}));
if (browserEngine != BrowserEngine.firefox) {
expect(fontFamilyList.length, equals(2));
@@ -171,10 +169,10 @@ void testMain() {
fontManager.registerAsset(
testFontFamily, 'url($_testFontUrl)', const <String, String>{});
await fontManager.ensureFontsLoaded();
html.document.fonts!
.forEach((html.FontFace f, html.FontFace f2, html.FontFaceSet s) {
domDocument.fonts!
.forEach(allowInterop((DomFontFace f, DomFontFace f2, DomFontFaceSet s) {
fontFamilyList.add(f.family!);
});
}));
if (browserEngine != BrowserEngine.firefox) {
expect(fontFamilyList.length, equals(2));

View File

@@ -4,7 +4,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:html' as html;
import 'dart:typed_data';
import 'package:test/bootstrap/browser.dart';
@@ -22,7 +21,7 @@ Future<void> testMain() async {
const String _testFontUrl = '/assets/fonts/ahem.ttf';
tearDown(() {
html.document.fonts!.clear();
domDocument.fonts!.clear();
});
test('surfaces error from invalid font buffer', () async {
@@ -38,7 +37,7 @@ Future<void> testMain() async {
test('loads Blehm font from buffer', () async {
expect(_containsFontFamily('Blehm'), isFalse);
final html.HttpRequest response = await html.HttpRequest.request(
final DomXMLHttpRequest response = await domHttpRequest(
_testFontUrl,
responseType: 'arraybuffer');
await ui.loadFontFromList(Uint8List.view(response.response as ByteBuffer),
@@ -64,7 +63,7 @@ Future<void> testMain() async {
// Now, loads a new font using loadFontFromList. This should clear the
// cache
final html.HttpRequest response = await html.HttpRequest.request(
final DomXMLHttpRequest response = await domHttpRequest(
_testFontUrl,
responseType: 'arraybuffer');
await ui.loadFontFromList(Uint8List.view(response.response as ByteBuffer),
@@ -91,13 +90,13 @@ Future<void> testMain() async {
buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
message = utf8.decode(list);
};
final html.HttpRequest response = await html.HttpRequest.request(
final DomXMLHttpRequest response = await domHttpRequest(
_testFontUrl,
responseType: 'arraybuffer');
await ui.loadFontFromList(Uint8List.view(response.response as ByteBuffer),
fontFamily: 'Blehm');
final Completer<void> completer = Completer<void>();
html.window.requestAnimationFrame( (_) { completer.complete(); } );
domWindow.requestAnimationFrame(allowInterop((_) { completer.complete();}) );
await (completer.future); // ignore: unnecessary_parenthesis
window.onPlatformMessage = oldHandler;
expect(actualName, 'flutter/system');
@@ -112,11 +111,11 @@ Future<void> testMain() async {
bool _containsFontFamily(String family) {
bool found = false;
html.document.fonts!.forEach((html.FontFace fontFace,
html.FontFace fontFaceAgain, html.FontFaceSet fontFaceSet) {
domDocument.fonts!.forEach(allowInterop((DomFontFace fontFace,
DomFontFace fontFaceAgain, DomFontFaceSet fontFaceSet) {
if (fontFace.family == family) {
found = true;
}
});
}));
return found;
}

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:html' as html;
import 'dart:js_util' as js_util;
import 'package:test/bootstrap/browser.dart';
@@ -472,7 +471,7 @@ void testMain() {
void jsSetUrlStrategy(dynamic strategy) {
js_util.callMethod<void>(
html.window,
domWindow,
'_flutter_web_set_location_strategy',
<dynamic>[strategy],
);