Bug 1527042 [wpt PR 15251] - Update dynamic import tests now HTML event handler functions do not have [[ScriptOrModule]] set, a=testonly
authorJon Coppeard <jonco@pobox.com>
Tue, 19 Feb 2019 11:46:34 +0000
changeset 519220 ee76c6f93764441664903c891a3a238a8be1986a
parent 519219 f52b7a1404d8cd15997cd714e4fca53640c6fb6e
child 519221 a52794d4ba349c03a5438d49293cda0bead134db
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1527042, 15251, 15183
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1527042 [wpt PR 15251] - Update dynamic import tests now HTML event handler functions do not have [[ScriptOrModule]] set, a=testonly Automatic update from web-platform-tests Update dynamic import tests for HTML event handler changes Fixes https://github.com/web-platform-tests/wpt/issues/15183. Follows https://github.com/whatwg/html/pull/4302. This updates paths/expected nonce behavior now some methods of loading are not based off the current script. -- wpt-commits: 8ecb503bc748ded75e7f5c224b95344a2966eeb9 wpt-pr: 15251
testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/Function.js
testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/eval.js
testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/inline-event-handlers-UA-code.js
testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/reflected-inline-event-handlers.js
testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/setTimeout.js
testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-classic.html
testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-module.html
testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-other-document.html
--- a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/Function.js
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/Function.js
@@ -1,1 +1,2 @@
+// import()s in a dynamically created function are resolved relative to the script.
 Function(`import('../../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`)();
--- a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/eval.js
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/eval.js
@@ -1,1 +1,2 @@
+// import()s in eval are resolved relative to the script.
 eval(`import('../../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`);
--- a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/inline-event-handlers-UA-code.js
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/inline-event-handlers-UA-code.js
@@ -1,2 +1,3 @@
-window.dummyDiv.setAttribute("onclick", `import('../../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`);
+// import()s in an event handler are resolved relative to the document base.
+window.dummyDiv.setAttribute("onclick", `import('../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`);
 window.dummyDiv.click(); // different from **on**click()
--- a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/reflected-inline-event-handlers.js
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/reflected-inline-event-handlers.js
@@ -1,2 +1,3 @@
-window.dummyDiv.setAttribute("onclick", `import('../../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`);
+// import()s in an event handler are resolved relative to the document base.
+window.dummyDiv.setAttribute("onclick", `import('../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`);
 window.dummyDiv.onclick();
--- a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/setTimeout.js
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/scripts/setTimeout.js
@@ -1,1 +1,2 @@
+// import()s in a timeout handler are resolved relative to the script.
 setTimeout(`import('../../imports-a.js?label=' + window.label).then(window.continueTest, window.errorTest)`, 0);
--- a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-classic.html
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-classic.html
@@ -32,17 +32,17 @@ function createTestPromise(t) {
 function assertSuccessful(module) {
   assert_true(window.evaluated_imports_a, "The module must have been evaluated");
   assert_equals(module.A.from, "imports-a.js", "The module namespace object must be correct");
 }
 
 promise_test(t => {
   const promise = createTestPromise(t);
 
-  setTimeout(`import('../imports-a.js?label=setTimeout').then(window.unreached, window.continueTest)`, 0);
+  setTimeout(`import('../imports-a.js?label=setTimeout').then(window.continueTest, window.errorTest)`, 0);
 
   return promise.then(assertSuccessful);
 }, "setTimeout must inherit the nonce from the triggering script, thus execute");
 
 promise_test(t => {
   const promise = createTestPromise(t);
 
   eval(`import('../imports-a.js?label=direct eval').then(window.continueTest, window.errorTest)`);
@@ -76,29 +76,29 @@ promise_test(t => {
 
   // This only works because of the 'unsafe-hashes' and the hash in the CSP policy
   dummyDiv.setAttribute(
     "onclick",
     `import('../imports-a.js?label=reflected inline event handlers').then(window.continueTest, window.errorTest)`
   );
   dummyDiv.onclick();
 
-  return promise.then(assertSuccessful);
-}, "reflected inline event handlers must inherit the nonce from the triggering script, thus execute");
+  return promise_rejects(t, new TypeError(), promise);
+}, "reflected inline event handlers must not inherit the nonce from the triggering script, thus fail");
 
 promise_test(t => {
   t.add_cleanup(() => {
     dummyDiv.removeAttribute("onclick");
   });
 
   const promise = createTestPromise(t);
 
   // This only works because of the 'unsafe-hashes' and the hash in the CSP policy
   dummyDiv.setAttribute(
     "onclick",
     `import('../imports-a.js?label=inline event handlers triggered via UA code').then(window.continueTest, window.errorTest)`
   );
   assert_equals(typeof dummyDiv.onclick, "function", "the browser must be able to parse a string containing the import() syntax into a function");
   dummyDiv.click(); // different from **on**click()
 
-  return promise.then(assertSuccessful);
-}, "inline event handlers triggered via UA code must inherit the nonce from the triggering script, thus execute");
+  return promise_rejects(t, new TypeError(), promise);
+}, "inline event handlers triggered via UA code must not inherit the nonce from the triggering script, thus fail");
 </script>
--- a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-module.html
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-module.html
@@ -31,17 +31,17 @@ function createTestPromise(t) {
 function assertSuccessful(module) {
   assert_true(window.evaluated_imports_a, "The module must have been evaluated");
   assert_equals(module.A.from, "imports-a.js", "The module namespace object must be correct");
 }
 
 promise_test(t => {
   const promise = createTestPromise(t);
 
-  setTimeout(`import('../imports-a.js?label=setTimeout').then(window.unreached, window.continueTest)`, 0);
+  setTimeout(`import('../imports-a.js?label=setTimeout').then(window.continueTest, window.errorTest)`, 0);
 
   return promise.then(assertSuccessful);
 }, "setTimeout must inherit the nonce from the triggering script, thus execute");
 
 promise_test(t => {
   const promise = createTestPromise(t);
 
   eval(`import('../imports-a.js?label=direct eval').then(window.continueTest, window.errorTest)`);
@@ -75,29 +75,29 @@ promise_test(t => {
 
   // This only works because of the 'unsafe-hashes' and the hash in the CSP policy
   dummyDiv.setAttribute(
     "onclick",
     `import('../imports-a.js?label=reflected inline event handlers').then(window.continueTest, window.errorTest)`
   );
   dummyDiv.onclick();
 
-  return promise.then(assertSuccessful);
-}, "reflected inline event handlers must inherit the nonce from the triggering script, thus execute");
+  return promise_rejects(t, new TypeError(), promise);
+}, "reflected inline event handlers must not inherit the nonce from the triggering script, thus fail");
 
 promise_test(t => {
   t.add_cleanup(() => {
     dummyDiv.removeAttribute("onclick");
   });
 
   const promise = createTestPromise(t);
 
   // This only works because of the 'unsafe-hashes' and the hash in the CSP policy
   dummyDiv.setAttribute(
     "onclick",
     `import('../imports-a.js?label=inline event handlers triggered via UA code').then(window.continueTest, window.errorTest)`
   );
   assert_equals(typeof dummyDiv.onclick, 'function', "the browser must be able to parse a string containing the import() syntax into a function");
   dummyDiv.click(); // different from **on**click()
 
-  return promise.then(assertSuccessful);
-}, "inline event handlers triggered via UA code must inherit the nonce from the triggering script, thus execute");
+  return promise_rejects(t, new TypeError(), promise);
+}, "inline event handlers triggered via UA code must not inherit the nonce from the triggering script, thus fail");
 </script>
--- a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-other-document.html
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-other-document.html
@@ -21,24 +21,16 @@ function startTest() {
   }
 
   const evaluators = {
     eval: otherWindow.eval,
     setTimeout: otherWindow.setTimeout,
     "the Function constructor"(x) {
       otherWindow.Function(x)();
     },
-    "reflected inline event handlers"(x) {
-      otherDiv.setAttribute("onclick", x);
-      otherDiv.onclick();
-    },
-    "inline event handlers triggered by JS"(x) {
-      otherDiv.setAttribute("onclick", x);
-      otherDiv.click(); // different from .**on**click()
-    }
   };
 
   for (const [label, evaluator] of Object.entries(evaluators)) {
     promise_test(t => {
       t.add_cleanup(() => {
         otherDiv.removeAttribute("onclick");
         delete otherWindow.evaluated_imports_a;
       });
@@ -48,11 +40,40 @@ function startTest() {
       evaluator(`import('../imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`);
 
       return promise.then(module => {
         assert_true(otherWindow.evaluated_imports_a, "The module must have been evaluated");
         assert_equals(module.A.from, "imports-a.js", "The module namespace object must be correct");
       });
     }, label + " should successfully import");
   };
+
+  const eventHandlerEvaluators = {
+    "reflected inline event handlers"(x) {
+      otherDiv.setAttribute("onclick", x);
+      otherDiv.onclick();
+    },
+    "inline event handlers triggered by JS"(x) {
+      otherDiv.setAttribute("onclick", x);
+      otherDiv.click(); // different from .**on**click()
+    }
+  };
+
+  for (const [label, evaluator] of Object.entries(eventHandlerEvaluators)) {
+    promise_test(t => {
+      t.add_cleanup(() => {
+        otherDiv.removeAttribute("onclick");
+        delete otherWindow.evaluated_imports_a;
+      });
+
+      const promise = createTestPromise();
+
+      evaluator(`import('../../imports-a.js?label=${label}').then(window.continueTest, window.errorTest);`);
+
+      return promise.then(module => {
+        assert_true(otherWindow.evaluated_imports_a, "The module must have been evaluated");
+        assert_equals(module.A.from, "imports-a.js", "The module namespace object must be correct");
+      });
+    }, label + " should successfully import");
+  };
 }
 </script>
 <body onLoad="startTest()"></body>