Skip to content

Commit

Permalink
Merge pull request #1511 from Ms2ger/auto-workers3
Browse files Browse the repository at this point in the history
Add support for standalone workers tests.
  • Loading branch information
jgraham committed Jan 9, 2015
2 parents 10fd732 + 0c803a4 commit 63286a5
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 29 deletions.
22 changes: 22 additions & 0 deletions docs/test-format-guidelines.md
Expand Up @@ -185,6 +185,28 @@ generation. This is supported through the
[wptserve](http://github.com/w3c/wptserve) server. Several scenarios
in particular are common:

### Standalone workers tests

Tests that only require assertions in a dedicated worker scope can use
standalone workers tests. In this case, the test is a JavaScript file
with extension `.worker.js` that imports `testharness.js`. The test can
then use all the usual APIs, and can be run from the path to the
JavaScript file with the `.js` removed.

For example, one could write a test for the `Blob` constructor by
creating a `FileAPI/Blob-constructor.worker.js` as follows:

importScripts("/resources/testharness.js");
test(function () {
var blob = new Blob();
assert_equals(blob.size, 0);
assert_equals(blob.type, "");
assert_false(blob.isClosed);
}, "The Blob constructor.");
done();

This test could then be run from `FileAPI/Blob-constructor.worker`.

### Tests Involving Multiple Origins

In the test environment, five subdomains are available; `www`, `www1`,
Expand Down
17 changes: 17 additions & 0 deletions serve.py
Expand Up @@ -24,6 +24,22 @@
sys.path.insert(1, os.path.join(repo_root, "tools"))
import sslutils


@handlers.handler
def workers_handler(request, response):
worker_path = request.url_parts.path.replace(".worker", ".worker.js")
return """
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
fetch_tests_from_worker(new Worker("%s"));
</script>
""" % (worker_path,)


routes = [("GET", "/tools/runner/*", handlers.file_handler),
("POST", "/tools/runner/update_manifest.py", handlers.python_script_handler),
(any_method, "/_certs/*", handlers.ErrorHandler(404)),
Expand All @@ -32,6 +48,7 @@
(any_method, "/serve.py", handlers.ErrorHandler(404)),
(any_method, "*.py", handlers.python_script_handler),
("GET", "*.asis", handlers.as_is_handler),
("GET", "*.worker", workers_handler),
("GET", "*", handlers.file_handler),
]

Expand Down
3 changes: 3 additions & 0 deletions tools/scripts/manifest.py
Expand Up @@ -532,6 +532,9 @@ def get_manifest_items(tests_root, rel_path, url_base, use_committed=False):
if name.lower().endswith("-manual"):
return [ManualTest(url)]

if filename.endswith(".worker.js"):
return [TestharnessTest(url[:-3])]

ref_list = []

for suffix in ref_suffixes:
Expand Down
29 changes: 0 additions & 29 deletions workers/semantics/interface-objects/001.html

This file was deleted.

48 changes: 48 additions & 0 deletions workers/semantics/interface-objects/001.worker.js
@@ -0,0 +1,48 @@
importScripts("/resources/testharness.js");
var expected = [
"WorkerGlobalScope",
"EventTarget",
"DedicatedWorkerGlobalScope",
"ErrorEvent",
"Event",
"Worker",
"DOMException",
"SharedWorker",
"MessagePort",
"MessageEvent",
"WorkerNavigator",
"MessageChannel",
"WorkerLocation",
"ImageData",
"File",
"Blob",
"FileList",
"XMLHttpRequest",
"ProgressEvent",
"FormData",
"ArrayBuffer",
"Int8Array",
"Uint8Array",
"Uint8ClampedArray",
"Int16Array",
"Uint16Array",
"Int32Array",
"Uint32Array",
"Float32Array",
"Float64Array",
"DataView",
"CanvasProxy",
"ImageBitmap",
"CanvasRenderingContext2D",
"DrawingStyle",
"CanvasGradient",
"CanvasPattern",
"Path",
"TextMetrics"
];
for (var i = 0; i < expected.length; ++i) {
test(function () {
assert_own_property(self, expected[i]);
}, "The " + expected[i] + " interface object should be exposed.");
}
done();

0 comments on commit 63286a5

Please sign in to comment.