Skip to content

Commit

Permalink
Add ECMAScript 6 Modules test cases
Browse files Browse the repository at this point in the history
Microsoft Edge's current set of tests for an ECMAScript6 Modules
implementation via the script element (<script type="module">).
  • Loading branch information
AtOMiCNebula committed Nov 10, 2016
1 parent deb24b8 commit e6fdc7d
Show file tree
Hide file tree
Showing 41 changed files with 539 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
document._log = [];
window.addEventListener("error", function (ev) {
var errorSerialized = ev.lineno + "-" + ev.colno;
document._log.push(errorSerialized);
});
window.addEventListener("load", function () {
document._log = document._log.join(",");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>html-script-module-crossOrigin-import-NoCORS</title>
<script src="crossorigin-common.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin-import-NoCORS</h1>
<script type="module">

import { foo } from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/crossorigin-scripterror.js";

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>html-script-module-crossOrigin-root-BlockedMissingHeader</title>
<script src="crossorigin-common.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin-root-BlockedMissingHeader</h1>
<script type="module" onerror="document._log.push('error');" crossorigin>

import { foo } from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/crossorigin-scripterror.js";

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>html-script-module-crossOrigin-root-WithCORS</title>
<script src="crossorigin-common.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin-root-WithCORS</h1>
<script type="module" crossorigin>

import { foo } from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/crossorigin-scripterror.js?pipe=header(Access-Control-Allow-Origin,*)";

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>html-script-module-crossOrigin-root-BlockedWrongHeader</title>
<script src="crossorigin-common.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin-root-BlockedWrongHeader</h1>
<script type="module" onerror="document._log.push('error');" crossorigin>

import { foo } from "http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/crossorigin-scripterror.js?pipe=header(Access-Control-Allow-Origin,http://{{domains[www2]}}:{{ports[http][0]}})";

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>html-script-module-crossOrigin-root-NoCORS</title>
<script src="crossorigin-common.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin-root-NoCORS</h1>
<script type="module" src="http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/crossorigin-scripterror.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>html-script-module-crossOrigin-root-BlockedMissingHeader</title>
<script src="crossorigin-common.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin-root-BlockedMissingHeader</h1>
<script type="module" src="http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/crossorigin-scripterror.js" onerror="document._log.push('error');" crossorigin></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>html-script-module-crossOrigin-root-WithCORS</title>
<script src="crossorigin-common.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin-root-WithCORS</h1>
<script type="module" src="http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/crossorigin-scripterror.js?pipe=header(Access-Control-Allow-Origin,*)" crossorigin></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>html-script-module-crossOrigin-root-BlockedWrongHeader</title>
<script src="crossorigin-common.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin-root-BlockedWrongHeader</h1>
<script type="module" src="http://{{domains[www2]}}:{{ports[http][0]}}/html/semantics/scripting-1/the-script-element/module/crossorigin-scripterror.js?pipe=header(Access-Control-Allow-Origin,http://{{domains[www2]}}:{{ports[http][0]}})" onerror="document._log.push('error');" crossorigin></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export var foo = {};

// Push an event to the log indicating that the script was executed.
document._log.push("running");

// Deliberately trigger an error to test what details of the error
// the (possibly) cross-origin parent can listen to.
nonExistentMethod();
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!doctype html>
<html>
<head>
<title>html-script-module-crossOrigin</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>html-script-module-crossOrigin</h1>
<iframe id="root-NoCORS" src="crossorigin-root-different.sub.html"></iframe>
<iframe id="root-WithCORS" src="crossorigin-root-same.sub.html"></iframe>
<iframe id="root-BlockedMissingHeader" src="crossorigin-root-missingheader.sub.html"></iframe>
<iframe id="root-BlockedWrongHeader" src="crossorigin-root-wrongheader.sub.html"></iframe>
<iframe id="import-NoCORS" src="crossorigin-import-different.sub.html"></iframe>
<iframe id="import-WithCORS" src="crossorigin-import-same.sub.html"></iframe>
<iframe id="import-BlockedMissingHeader" src="crossorigin-import-missingheader.sub.html"></iframe>
<iframe id="import-BlockedWrongHeader" src="crossorigin-import-wrongheader.sub.html"></iframe>
<script>

var tests = [
{ "obj": async_test("Root module, Error in CORS-different-origin script"), "id": "root-NoCORS", "expected": "running,0-0" },
{ "obj": async_test("Root module, Error in CORS-same-origin script"), "id": "root-WithCORS", "expected": "running,8-1" },
{ "obj": async_test("Root module, Blocked script download, missing CORS ACAO header"), "id": "root-BlockedMissingHeader", "expected": "error" },
{ "obj": async_test("Root module, Blocked script download, mismatched CORS ACAO header"), "id": "root-BlockedWrongHeader", "expected": "error" },
{ "obj": async_test("Imported module, Error in CORS-different-origin script"), "id": "import-NoCORS", "expected": "running,0-0" },
{ "obj": async_test("Imported module, Error in CORS-same-origin script"), "id": "import-WithCORS", "expected": "running,8-1" },
{ "obj": async_test("Imported module, Blocked script download, missing CORS ACAO header"), "id": "import-BlockedMissingHeader", "expected": "error" },
{ "obj": async_test("Imported module, Blocked script download, mismatched CORS ACAO header"), "id": "import-BlockedWrongHeader", "expected": "error" },
];

window.addEventListener("load", function () {
tests.forEach(function (test) {
var target = document.getElementById(test.id);
test.obj.step(function () {
assert_equals(target.contentDocument._log, test.expected, "Unexpected _log value");
});
test.obj.done();
});
});

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function errorHandler(ev)
{
document._errorReported.push("error");
}

document._errorReported = [];
window.addEventListener("error", errorHandler);
window.addEventListener("load", function () {
document._errorReported = document._errorReported.join(",");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<title>html-script-module-errorHandling-parseError-Dependent</title>
<script src="errorhandling-parseerror-common.js"></script>
</head>
<body>
<script type="module" onerror="errorHandler(event);">

// No parse errors in the root module, just in the dependent module
import test from "./errorhandling-parseerror-dependent.js";
document._errorReported = "shouldn't have run dependent module";

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Parse error in a dependent module
1A
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html>
<head>
<title>html-script-module-errorHandling-parseError-DependentMultiple</title>
<script src="errorhandling-parseerror-common.js"></script>
</head>
<body>
<script type="module" onerror="errorHandler(event);createSecondDependentRoot();">

// No parse errors in the root module, just in the dependent module
import test from "./errorhandling-parseerror-dependentmultiple.js";
document._errorReported = "shouldn't have run dependent module";

</script>
<script>

function createSecondDependentRoot()
{
// With the broken dependent module already acquired, try to import it
// again from another root. This root should be unwound appropriately.
var script = document.createElement("script");
script.type = "module";
script.textContent = "import test from './errorhandling-parseerror-dependentmultiple.js';" +
"document._errorReported = 'really shouldn\\'t have run dependent module';";
script.addEventListener("error", errorHandler);
document.body.appendChild(script);
}

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Parse error in a dependent module
1A
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<title>html-script-module-errorHandling-parseError-Root</title>
<script src="errorhandling-parseerror-common.js"></script>
</head>
<body>
<script type="module">

// Parse error in a root module
1A

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import foo from "./errorhandling-wrongMimetype.js?pipe=header(X-Content-Type-Options,nosniff),header(Content-Type,text/plain)";

// We don't expect this code to run, the import above should fail!
// If we do run though, don't trigger an error that the testharness
// might misinterpret as the import itself failing to load.

var A = null;
export { A };
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This is a plain JavaScript file, but since it will only be accessed with
// a Content-Type of text/plain and nosniff, it will be seen as invalid.
// The file itself will have no errors/effects, so if it does actually run,
// no error will be detected, and the test will fail.

var foo = null;
export foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<html>
<head>
<title>html-script-module-errorHandling</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>

iframe
{ display: none; }

</style>
</head>
<body>
<h1>html-script-module-errorHandling</h1>
<iframe id="iframe_parseError_Root" src="errorhandling-parseerror-root.html"></iframe>
<iframe id="iframe_parseError_Dependent" src="errorhandling-parseerror-dependent.html"></iframe>
<iframe id="iframe_parseError_DependentMultiple" src="errorhandling-parseerror-dependentmultiple.html"></iframe>
<script>

var tests = [
{ "id": "iframe_parseError_Root", "expected": "error" },
{ "id": "iframe_parseError_Dependent", "expected": "error" },
{ "id": "iframe_parseError_DependentMultiple", "expected": "error,error" },
];
tests.forEach(function (testObj) {
var testHandle = async_test("IFrame test: '" + testObj.id + "'");
var testTarget = document.getElementById(testObj.id);
testTarget.addEventListener("load", testHandle.step_func(function () {
assert_equals(testTarget.contentDocument._errorReported, testObj.expected, "Unexpected _errorReported value");
testHandle.done();
}));
});

var test_wrongMimetype_root = async_test("External root module with non-script mimetype");
var script_wrongMimetype_root = document.createElement("script");
script_wrongMimetype_root.type = "module";
script_wrongMimetype_root.src = "errorhandling-wrongMimetype.js?pipe=header(Content-Type,text/plain),header(X-Content-Type-Options,nosniff)";
script_wrongMimetype_root.addEventListener("error", test_wrongMimetype_root.step_func(function () {
test_wrongMimetype_root.done();
}));
script_wrongMimetype_root.addEventListener("load", test_wrongMimetype_root.step_func(function () {
assert_unreached("This script should not have loaded!");
}));
document.body.appendChild(script_wrongMimetype_root);

var test_wrongMimetype_import = async_test("Module with imported non-script mimetype");
var script_wrongMimetype_import = document.createElement("script");
script_wrongMimetype_import.type = "module";
script_wrongMimetype_import.src = "errorhandling-wrongMimetype-import.js";
script_wrongMimetype_import.addEventListener("error", test_wrongMimetype_import.step_func(function () {
test_wrongMimetype_import.done();
}));
script_wrongMimetype_import.addEventListener("load", test_wrongMimetype_import.step_func(function () {
assert_unreached("This script should not have loaded!");
}));
document.body.appendChild(script_wrongMimetype_import);

</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_dynamicOrdered.step(function() {
assert_execCount(1, 2, "External script element (#1) should have fired second");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_dynamicOrdered.step(function() {
assert_execCount(1, 3, "External script element (#2) should have fired third");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_dynamicOrdered.step(function() {
assert_execCount(1, 4, "External script element (#3) should have fired fourth");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_dynamicUnordered1.step(function() {
test_dynamicUnordered1.done();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_dynamicUnordered2.step(function() {
test_dynamicUnordered2.done();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_parsedOrdered.step(function() {
assert_execCount(0, 2, "External deferred (#1) script element should have fired second");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_parsedOrdered.step(function() {
assert_execCount(0, 4, "External deferred (#2) script element should have fired fourth");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_parsedUnordered1.step(function() {
test_parsedUnordered1.done();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_parsedUnordered2.step(function() {
test_parsedUnordered2.done();
});

0 comments on commit e6fdc7d

Please sign in to comment.