[dart2js] Test for trusted script URLs
Change-Id: Ib4726fc522756f9a7cc860aaa09c6b0037a85c70
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237638
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/tests/web/deferred/trusted_script_url/lib.dart b/tests/web/deferred/trusted_script_url/lib.dart
new file mode 100644
index 0000000..d4933a8
--- /dev/null
+++ b/tests/web/deferred/trusted_script_url/lib.dart
@@ -0,0 +1,13 @@
+// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
+// for details. 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:expect/expect.dart';
+
+class _Thing {}
+
+Object create() => _Thing();
+
+void check(Object o) {
+ Expect.isTrue(o is _Thing);
+}
diff --git a/tests/web/deferred/trusted_script_url/trusted_script_url_test.dart b/tests/web/deferred/trusted_script_url/trusted_script_url_test.dart
new file mode 100644
index 0000000..b7c0f71
--- /dev/null
+++ b/tests/web/deferred/trusted_script_url/trusted_script_url_test.dart
@@ -0,0 +1,16 @@
+// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
+// for details. 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:expect/expect.dart';
+
+import 'lib.dart' deferred as lib;
+
+void main() {
+ lib.loadLibrary().then((_) {
+ lib.check(dontInline(lib.create()));
+ });
+}
+
+@pragma('dart2js:noInline')
+Object dontInline(Object x) => x;
diff --git a/tests/web/deferred/trusted_script_url/trusted_script_url_test.html b/tests/web/deferred/trusted_script_url/trusted_script_url_test.html
new file mode 100644
index 0000000..6d8895a
--- /dev/null
+++ b/tests/web/deferred/trusted_script_url/trusted_script_url_test.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="dart.unittest" content="full-stack-traces">
+ <!-- The following line forces the use of TrustedScriptURLs.
+ This is the key difference between this file and
+ default generated html file.
+ -->
+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'">
+ <title> trusted_script_url_test </title>
+ <style>
+ .unittest-table { font-family:monospace; border:1px; }
+ .unittest-pass { background: #6b3;}
+ .unittest-fail { background: #d55;}
+ .unittest-error { background: #a11;}
+ </style>
+</head>
+<body>
+ <h1> Running trusted_script_url_test </h1>
+ <script type="text/javascript"
+ src="/root_dart/pkg/test_runner/lib/src/test_controller.js"></script>
+ %TEST_SCRIPTS%
+</body>
+</html>