flutter test --wasm support (#145347)

* Adds support for `flutter test --wasm`.
  * The test compilation flow is a bit different now, so that it supports compilers other than DDC. Specifically, when we run a set of unit tests, we generate a "switchboard" main function that imports each unit test and runs the main function for a specific one based off of a value set by the JS bootstrapping code. This way, there is one compile step and the same compile output is invoked for each unit test file.
* Also, removes all references to `dart:html` from flutter/flutter.
* Adds CI steps for running the framework unit tests with dart2wasm+skwasm
  * These steps are marked as `bringup: true`, so we don't know what kind of failures they will result in. Any failures they have will not block the tree at all yet while we're still in `bringup: true`. Once this PR is merged, I plan on looking at any failures and either fixing them or disabling them so we can get these CI steps running on presubmit.

This fixes https://github.com/flutter/flutter/issues/126692
This commit is contained in:
Jackson Gardner
2024-03-21 13:08:07 -07:00
committed by GitHub
parent 98d10b6211
commit 31209d04ff
62 changed files with 953 additions and 365 deletions

View File

@@ -242,6 +242,8 @@ Future<void> main(List<String> args) async {
'web_tests': _runWebHtmlUnitTests,
// All the unit/widget tests run using `flutter test --platform=chrome --web-renderer=canvaskit`
'web_canvaskit_tests': _runWebCanvasKitUnitTests,
// All the unit/widget tests run using `flutter test --platform=chrome --wasm --web-renderer=skwasm`
'web_skwasm_tests': _runWebSkwasmUnitTests,
// All web integration tests
'web_long_running_tests': _runWebLongRunningTests,
'flutter_plugins': _runFlutterPackagesTests,
@@ -1117,14 +1119,18 @@ Future<void> _runFrameworkCoverage() async {
}
Future<void> _runWebHtmlUnitTests() {
return _runWebUnitTests('html');
return _runWebUnitTests('html', false);
}
Future<void> _runWebCanvasKitUnitTests() {
return _runWebUnitTests('canvaskit');
return _runWebUnitTests('canvaskit', false);
}
Future<void> _runWebUnitTests(String webRenderer) async {
Future<void> _runWebSkwasmUnitTests() {
return _runWebUnitTests('skwasm', true);
}
Future<void> _runWebUnitTests(String webRenderer, bool useWasm) async {
final Map<String, ShardRunner> subshards = <String, ShardRunner>{};
final Directory flutterPackageDirectory = Directory(path.join(flutterRoot, 'packages', 'flutter'));
@@ -1160,6 +1166,7 @@ Future<void> _runWebUnitTests(String webRenderer) async {
index * testsPerShard,
(index + 1) * testsPerShard,
),
useWasm,
);
}
@@ -1175,16 +1182,19 @@ Future<void> _runWebUnitTests(String webRenderer) async {
(webShardCount - 1) * testsPerShard,
allTests.length,
),
useWasm,
);
await _runFlutterWebTest(
webRenderer,
path.join(flutterRoot, 'packages', 'flutter_web_plugins'),
<String>['test'],
useWasm,
);
await _runFlutterWebTest(
webRenderer,
path.join(flutterRoot, 'packages', 'flutter_driver'),
<String>[path.join('test', 'src', 'web_tests', 'web_extension_test.dart')],
useWasm,
);
};
@@ -1333,11 +1343,19 @@ Future<void> _runWebLongRunningTests() async {
'html',
path.join(flutterRoot, 'packages', 'integration_test'),
<String>['test/web_extension_test.dart'],
false,
),
() => _runFlutterWebTest(
'canvaskit',
path.join(flutterRoot, 'packages', 'integration_test'),
<String>['test/web_extension_test.dart'],
false,
),
() => _runFlutterWebTest(
'skwasm',
path.join(flutterRoot, 'packages', 'integration_test'),
<String>['test/web_extension_test.dart'],
true,
),
];
@@ -2302,13 +2320,19 @@ Future<void> _runWebDebugTest(String target, {
}
}
Future<void> _runFlutterWebTest(String webRenderer, String workingDirectory, List<String> tests) async {
Future<void> _runFlutterWebTest(
String webRenderer,
String workingDirectory,
List<String> tests,
bool useWasm,
) async {
await runCommand(
flutter,
<String>[
'test',
'-v',
'--platform=chrome',
if (useWasm) '--wasm',
'--web-renderer=$webRenderer',
'--dart-define=DART_HHH_BOT=$_runningInDartHHHBot',
...flutterTestArgs,

View File

@@ -2,11 +2,12 @@
// 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_interop';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:meta/dart2js.dart';
import 'package:web/web.dart' as web;
// Tests that the framework prints stack traces in all build modes.
//
@@ -35,10 +36,12 @@ Future<void> main() async {
}
print(output);
html.HttpRequest.request(
'/test-result',
method: 'POST',
sendData: '$output',
web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: '$output'.toJS,
)
);
}

View File

@@ -2,10 +2,13 @@
// 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_interop';
import 'package:web/web.dart' as web;
Future<void> main() async {
await html.window.navigator.serviceWorker?.ready;
const String response = 'CLOSE?version=1';
await html.HttpRequest.getString(response);
html.document.body?.appendHtml(response);
await web.window.navigator.serviceWorker.ready.toDart;
final JSString response = 'CLOSE?version=1'.toJS;
await web.window.fetch(response).toDart;
web.document.body?.append(response);
}

View File

@@ -2,9 +2,12 @@
// 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_interop';
import 'package:web/web.dart' as web;
Future<void> main() async {
const String response = 'CLOSE?version=1';
await html.HttpRequest.getString(response);
html.document.body?.appendHtml(response);
final JSString response = 'CLOSE?version=1'.toJS;
await web.window.fetch(response).toDart;
web.document.body?.append(response);
}

View File

@@ -4,7 +4,9 @@
// @dart = 2.12
import 'dart:html' as html;
import 'dart:js_interop';
import 'package:web/web.dart' as web;
// Verify that web applications can be run in sound mode.
void main() {
@@ -16,9 +18,11 @@ void main() {
output = '--- TEST SUCCEEDED ---';
}
print(output);
html.HttpRequest.request(
'/test-result',
method: 'POST',
sendData: output,
web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: output.toJS,
)
);
}

View File

@@ -2,11 +2,12 @@
// 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_interop';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:meta/dart2js.dart';
import 'package:web/web.dart' as web;
/// Expected sequence of method calls.
const List<String> callChain = <String>['baz', 'bar', 'foo'];
@@ -32,7 +33,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
packageScheme: 'package',
package: 'packages',
packagePath: 'web_integration/stack_trace.dart',
line: 119,
line: 122,
column: 3,
className: '<unknown>',
method: 'baz',
@@ -43,7 +44,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
packageScheme: 'package',
package: 'packages',
packagePath: 'web_integration/stack_trace.dart',
line: 114,
line: 117,
column: 3,
className: '<unknown>',
method: 'bar',
@@ -54,7 +55,7 @@ const List<StackFrame> expectedDebugStackFrames = <StackFrame>[
packageScheme: 'package',
package: 'packages',
packagePath: 'web_integration/stack_trace.dart',
line: 109,
line: 112,
column: 3,
className: '<unknown>',
method: 'foo',
@@ -97,10 +98,12 @@ void main() {
output.writeln('--- TEST FAILED ---');
}
print(output);
html.HttpRequest.request(
'/test-result',
method: 'POST',
sendData: '$output',
web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: '$output'.toJS,
)
);
}

View File

@@ -2,7 +2,9 @@
// 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_interop';
import 'package:web/web.dart' as web;
Future<void> main() async {
final StringBuffer output = StringBuffer();
@@ -16,9 +18,11 @@ Future<void> main() async {
print('--- TEST FAILED ---');
}
html.HttpRequest.request(
'/test-result',
method: 'POST',
sendData: '$output',
web.window.fetch(
'/test-result'.toJS,
web.RequestInit(
method: 'POST',
body: '$output'.toJS,
)
);
}

View File

@@ -2,16 +2,20 @@
// 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_interop';
import 'package:web/web.dart' as web;
// Attempt to load a file that is hosted in the applications's `web/` directory.
Future<void> main() async {
try {
final html.HttpRequest request = await html.HttpRequest.request(
'/example',
method: 'GET',
);
final String? body = request.responseText;
final web.Response response = await web.window.fetch(
'/example'.toJS,
web.RequestInit(
method: 'GET',
),
).toDart;
final String body = (await response.text().toDart).toDart;
if (body == 'This is an Example') {
print('--- TEST SUCCEEDED ---');
} else {

View File

@@ -2,7 +2,9 @@
// 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_interop';
import 'package:web/web.dart' as web;
// Attempt to load CanvasKit resources hosted on gstatic.
Future<void> main() async {
@@ -12,12 +14,13 @@ Future<void> main() async {
return;
}
try {
final html.HttpRequest request = await html.HttpRequest.request(
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.js',
method: 'GET',
);
final dynamic response = request.response;
if (response != null) {
final web.Response response = await web.window.fetch(
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.js'.toJS,
web.RequestInit(
method: 'GET',
),
).toDart;
if (response.ok) {
print('--- TEST SUCCEEDED ---');
} else {
print('--- TEST FAILED ---');
@@ -27,12 +30,13 @@ Future<void> main() async {
print('--- TEST FAILED ---');
}
try {
final html.HttpRequest request = await html.HttpRequest.request(
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.wasm',
method: 'GET',
);
final dynamic response = request.response;
if (response != null) {
final web.Response response = await web.window.fetch(
'https://www.gstatic.com/flutter-canvaskit/$engineVersion/canvaskit.wasm'.toJS,
web.RequestInit(
method: 'GET',
)
).toDart;
if (response.ok) {
print('--- TEST SUCCEEDED ---');
} else {
print('--- TEST FAILED ---');

View File

@@ -14,10 +14,12 @@ dependencies:
flutter:
sdk: flutter
web: 0.5.1
characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
collection: 1.18.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
meta: 1.12.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM: 6f95
# PUBSPEC CHECKSUM: 8d22

View File

@@ -5,7 +5,7 @@
import 'package:web_integration/a.dart'
if (dart.library.io) 'package:web_integration/b.dart' as message1;
import 'package:web_integration/c.dart'
if (dart.library.html) 'package:web_integration/d.dart' as message2;
if (dart.library.js_interop) 'package:web_integration/d.dart' as message2;
void main() {
if (message1.message == 'a' && message2.message == 'd') {

View File

@@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html';
import 'package:flutter_test/flutter_test.dart';
import 'package:web/web.dart' as web;
/// Whether the current browser is Firefox.
bool get isFirefox => window.navigator.userAgent.toLowerCase().contains('firefox');
bool get isFirefox => web.window.navigator.userAgent.toLowerCase().contains('firefox');
/// Finds elements in the DOM tree rendered by the Flutter Web engine.
///
@@ -15,8 +14,8 @@ bool get isFirefox => window.navigator.userAgent.toLowerCase().contains('firefox
/// `<flt-glass-pane>` element. Otherwise, looks under `<flt-glass-pane>`
/// without penetrating the shadow DOM. In the latter case, if the application
/// creates platform views, this will also find platform view elements.
List<Node> findElements(String selector) {
final Element? flutterView = document.querySelector('flutter-view');
web.NodeList findElements(String selector) {
final web.Element? flutterView = web.document.querySelector('flutter-view');
if (flutterView == null) {
fail(

View File

@@ -2,10 +2,10 @@
// 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:flutter/material.dart';
import 'package:web/web.dart' as web;
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
@@ -79,29 +79,25 @@ abstract class DeltaMode {
void dispatchMouseWheelEvent(int mouseX, int mouseY,
int deltaMode, double deltaX, double deltaY) {
final html.EventTarget target = html.document.elementFromPoint(mouseX, mouseY)!;
final web.EventTarget target = web.document.elementFromPoint(mouseX, mouseY)!;
target.dispatchEvent(html.MouseEvent('mouseover',
target.dispatchEvent(web.MouseEvent('mouseover', web.MouseEventInit(
screenX: mouseX,
screenY: mouseY,
clientX: mouseX,
clientY: mouseY,
));
)));
target.dispatchEvent(html.MouseEvent('mousemove',
target.dispatchEvent(web.MouseEvent('mousemove', web.MouseEventInit(
screenX: mouseX,
screenY: mouseY,
clientX: mouseX,
clientY: mouseY,
));
)));
target.dispatchEvent(html.WheelEvent('wheel',
screenX: mouseX,
screenY: mouseY,
clientX: mouseX,
clientY: mouseY,
target.dispatchEvent(web.WheelEvent('wheel', web.WheelEventInit(
deltaMode: deltaMode,
deltaX : deltaX,
deltaY : deltaY,
));
)));
}

View File

@@ -21,6 +21,7 @@ dependencies:
integration_test:
sdk: flutter
flutter_gallery_assets: 1.0.2
web: 0.5.1
async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -82,7 +83,6 @@ dev_dependencies:
test_core: 0.6.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
typed_data: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
watcher: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.5.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web_socket_channel: 2.4.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"

View File

@@ -2,13 +2,13 @@
// 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:ui_web' as ui_web;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:web/web.dart' as web;
import 'package:web_e2e_tests/platform_messages_main.dart' as app;
void main() {
@@ -27,7 +27,7 @@ void main() {
await tester.tap(find.byKey(const Key('input')));
// Focus in input, otherwise clipboard will fail with
// 'document is not focused' platform exception.
html.document.querySelector('input')?.focus();
(web.document.querySelector('input') as web.HTMLElement?)?.focus();
await Clipboard.setData(const ClipboardData(text: 'sample text'));
}, skip: true); // https://github.com/flutter/flutter/issues/54296
@@ -38,7 +38,7 @@ void main() {
platformViewsRegistry.getNextPlatformViewId();
ui_web.platformViewRegistry.registerViewFactory('MyView', (int viewId) {
viewInstanceCount += 1;
return html.DivElement();
return web.HTMLDivElement();
});
app.main();

View File

@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html';
import 'dart:js_util' as js_util;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:web/web.dart' as web;
import 'package:web_e2e_tests/common.dart';
import 'package:web_e2e_tests/text_editing_main.dart' as app;
@@ -26,9 +26,9 @@ void main() {
await tester.tap(find.byKey(const Key('input')));
// A native input element will be appended to the DOM.
final List<Node> nodeList = findElements('input');
final web.NodeList nodeList = findElements('input');
expect(nodeList.length, equals(1));
final InputElement input = nodeList[0] as InputElement;
final web.HTMLInputElement input = nodeList.item(0)! as web.HTMLInputElement;
// The element's value will be the same as the textFormField's value.
expect(input.value, 'Text1');
@@ -50,9 +50,9 @@ void main() {
await tester.tap(find.byKey(const Key('empty-input')));
// A native input element will be appended to the DOM.
final List<Node> nodeList = findElements('input');
final web.NodeList nodeList = findElements('input');
expect(nodeList.length, equals(1));
final InputElement input = nodeList[0] as InputElement;
final web.HTMLInputElement input = nodeList.item(0)! as web.HTMLInputElement;
// The element's value will be empty.
expect(input.value, '');
@@ -81,7 +81,7 @@ void main() {
await tester.tap(find.byKey(const Key('input2')));
// Press Tab. This should trigger `onFieldSubmitted` of TextField.
final InputElement input = findElements('input')[0] as InputElement;
final web.HTMLInputElement input = findElements('input').item(0)! as web.HTMLInputElement;
dispatchKeyboardEvent(input, 'keydown', <String, dynamic>{
'keyCode': 13, // Enter.
'cancelable': true,
@@ -111,9 +111,9 @@ void main() {
await tester.tap(find.byKey(const Key('input')));
// A native input element will be appended to the DOM.
final List<Node> nodeList = findElements('input');
final web.NodeList nodeList = findElements('input');
expect(nodeList.length, equals(1));
final InputElement input = nodeList[0] as InputElement;
final web.HTMLInputElement input = nodeList.item(0)! as web.HTMLInputElement;
// Press Tab. The focus should move to the next TextFormField.
dispatchKeyboardEvent(input, 'keydown', <String, dynamic>{
@@ -136,7 +136,7 @@ void main() {
// A native input element for the next TextField should be attached to the
// DOM.
final InputElement input2 = findElements('input')[0] as InputElement;
final web.HTMLInputElement input2 = findElements('input').item(0)! as web.HTMLInputElement;
expect(input2.value, 'Text2');
}, semanticsEnabled: false);
@@ -150,9 +150,9 @@ void main() {
await tester.tap(find.byKey(const Key('input')));
// A native input element will be appended to the DOM.
final List<Node> nodeList = findElements('input');
final web.NodeList nodeList = findElements('input');
expect(nodeList.length, equals(1));
final InputElement input = nodeList[0] as InputElement;
final web.HTMLInputElement input = nodeList.item(0)! as web.HTMLInputElement;
// Press and release CapsLock.
dispatchKeyboardEvent(input, 'keydown', <String, dynamic>{
@@ -191,7 +191,7 @@ void main() {
// A native input element for the next TextField should be attached to the
// DOM.
final InputElement input2 = findElements('input')[0] as InputElement;
final web.HTMLInputElement input2 = findElements('input').item(0)! as web.HTMLInputElement;
expect(input2.value, 'Text2');
}, semanticsEnabled: false);
@@ -215,16 +215,16 @@ void main() {
await gesture.up();
// A native input element will be appended to the DOM.
final List<Node> nodeList = findElements('textarea');
final web.NodeList nodeList = findElements('textarea');
expect(nodeList.length, equals(1));
final TextAreaElement input = nodeList[0] as TextAreaElement;
final web.HTMLTextAreaElement input = nodeList.item(0)! as web.HTMLTextAreaElement;
// The element's value should contain the selectable text.
expect(input.value, text);
expect(input.hasAttribute('readonly'), isTrue);
// Make sure the entire text is selected.
TextRange? range =
TextRange(start: input.selectionStart!, end: input.selectionEnd!);
TextRange(start: input.selectionStart, end: input.selectionEnd);
expect(range.textInside(text), text);
// Double tap to select the first word.
@@ -236,7 +236,7 @@ void main() {
await gesture.up();
await gesture.down(firstWordOffset);
await gesture.up();
range = TextRange(start: input.selectionStart!, end: input.selectionEnd!);
range = TextRange(start: input.selectionStart, end: input.selectionEnd);
expect(range.textInside(text), 'Lorem');
// Double tap to select the last word.
@@ -248,21 +248,21 @@ void main() {
await gesture.up();
await gesture.down(lastWordOffset);
await gesture.up();
range = TextRange(start: input.selectionStart!, end: input.selectionEnd!);
range = TextRange(start: input.selectionStart, end: input.selectionEnd);
expect(range.textInside(text), 'amet');
}, semanticsEnabled: false);
}
KeyboardEvent dispatchKeyboardEvent(
EventTarget target, String type, Map<String, dynamic> args) {
final Object jsKeyboardEvent = js_util.getProperty(window, 'KeyboardEvent') as Object;
web.KeyboardEvent dispatchKeyboardEvent(
web.EventTarget target, String type, Map<String, dynamic> args) {
final Object jsKeyboardEvent = js_util.getProperty(web.window, 'KeyboardEvent') as Object;
final List<dynamic> eventArgs = <dynamic>[
type,
args,
];
final KeyboardEvent event = js_util.callConstructor(
final web.KeyboardEvent event = js_util.callConstructor(
jsKeyboardEvent, js_util.jsify(eventArgs) as List<dynamic>)
as KeyboardEvent;
as web.KeyboardEvent;
target.dispatchEvent(event);
return event;

View File

@@ -3,13 +3,16 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:html' as html;
import 'dart:js_interop';
import 'dart:ui' as ui;
import 'dart:ui_web';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:integration_test/integration_test.dart';
import 'package:web/helpers.dart';
import 'package:web/web.dart' as web;
import 'package:web_e2e_tests/url_strategy_main.dart' as app;
void main() {
@@ -56,7 +59,7 @@ class TestUrlStrategy extends UrlStrategy {
String getPath() => currentEntry.url;
@override
dynamic getState() => currentEntry.state;
Object? getState() => currentEntry.state;
int _currentEntryIndex;
final List<TestHistoryEntry> history;
@@ -111,10 +114,10 @@ class TestUrlStrategy extends UrlStrategy {
});
}
final List<html.EventListener> listeners = <html.EventListener>[];
final List<PopStateListener> listeners = <PopStateListener>[];
@override
ui.VoidCallback addPopStateListener(html.EventListener fn) {
ui.VoidCallback addPopStateListener(PopStateListener fn) {
listeners.add(fn);
return () {
// Schedule a micro task here to avoid removing the listener during
@@ -134,9 +137,9 @@ class TestUrlStrategy extends UrlStrategy {
/// like a real browser.
void _firePopStateEvent() {
assert(withinAppHistory);
final html.PopStateEvent event = html.PopStateEvent(
final web.PopStateEvent event = web.PopStateEvent(
'popstate',
<String, dynamic>{'state': currentEntry.state},
PopStateEventInit(state: currentEntry.state?.toJSBox),
);
for (int i = 0; i < listeners.length; i++) {
listeners[i](event);
@@ -160,7 +163,7 @@ class TestUrlStrategy extends UrlStrategy {
class TestHistoryEntry {
const TestHistoryEntry(this.state, this.title, this.url);
final dynamic state;
final Object? state;
final String? title;
final String url;