[dart2wasm] Make test runner validate `<app>.support.js` code says support is available before running test
This ensures we exercise the `<app>.support.js` code in our tests and
also catch it if a browser doesn't support what's needed (e.g. running
tests on Safari with `js-string` builtin)
Change-Id: Ib8874231d3aa82b598e0e206a2e27cb66775bbec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415882
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
diff --git a/pkg/test_runner/lib/src/browser.dart b/pkg/test_runner/lib/src/browser.dart
index 3f97411..c498599 100644
--- a/pkg/test_runner/lib/src/browser.dart
+++ b/pkg/test_runner/lib/src/browser.dart
@@ -321,7 +321,8 @@
""";
}
-String dart2wasmHtml(String title, String wasmPath, String mjsPath) {
+String dart2wasmHtml(
+ String title, String wasmPath, String mjsPath, String supportJsPath) {
return """
<!DOCTYPE html>
<html>
@@ -344,7 +345,16 @@
src="/root_dart/pkg/test_runner/lib/src/test_controller.js">
</script>
<script type="module">
- async function loadAndRun(mjsPath, wasmPath) {
+ async function loadAndRun(mjsPath, wasmPath, supportJsPath) {
+ const supportJSExpression = await (await fetch(supportJsPath)).text();
+ const support = eval(supportJSExpression);
+ if (support !== true) {
+ dartMainRunner(() => {
+ throw 'This browser does not support the required features to run the dart2wasm compiled app!';
+ });
+ return;
+ }
+
const mjs = await import(mjsPath);
const compiledApp = await mjs.compileStreaming(fetch(wasmPath));
window.loadData = async (relativeToWasmFileUri) => {
@@ -363,7 +373,7 @@
});
}
- loadAndRun('$mjsPath', '$wasmPath');
+ loadAndRun('$mjsPath', '$wasmPath', '$supportJsPath');
</script>
</body>
</html>""";
diff --git a/pkg/test_runner/lib/src/test_suite.dart b/pkg/test_runner/lib/src/test_suite.dart
index 85c7024..887050d 100644
--- a/pkg/test_runner/lib/src/test_suite.dart
+++ b/pkg/test_runner/lib/src/test_suite.dart
@@ -971,8 +971,10 @@
_createUrlPathFromFile(Path('$outputDir/$nameNoExt.wasm'));
final mjsPath =
_createUrlPathFromFile(Path('$outputDir/$nameNoExt.mjs'));
- content =
- dart2wasmHtml(testFile.path.toNativePath(), wasmPath, mjsPath);
+ final supportJsPath =
+ _createUrlPathFromFile(Path('$outputDir/$nameNoExt.support.js'));
+ content = dart2wasmHtml(
+ testFile.path.toNativePath(), wasmPath, mjsPath, supportJsPath);
} else if (configuration.compiler == Compiler.ddc) {
var ddcConfig =
configuration.compilerConfiguration as DevCompilerConfiguration;