Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Apr 24, 2018
1 parent 79aa1a0 commit ecffddb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
3 changes: 2 additions & 1 deletion docs/_writing-tests/file-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ themselves precede any test type flag, but are otherwise unordered.

`.any`
: (js files only) Indicates that the file generates tests in which it
is run in Window and dedicated worker environments.
is [run in multiple scopes][multi-global-tests].

`.tentative`
: Indicates that a test makes assertions not yet required by any specification,
Expand All @@ -63,3 +63,4 @@ themselves precede any test type flag, but are otherwise unordered.


[server-side substitution]: https://wptserve.readthedocs.io/en/latest/pipes.html#sub
[multi-global-tests]: {{ site.baseurl }}{% link _writing-tests/testharness.md %}#multi-global-tests
34 changes: 28 additions & 6 deletions docs/_writing-tests/testharness.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ This test could then be run from `FileAPI/FileReaderSync.worker.html`.

### Multi-global tests

Tests for features that exist in multiple global scopes can be written
in a way that they are automatically run in a window scope and a
worker scope.
Tests for features that exist in multiple global scopes can be written in a way
that they are automatically run in several scopes. In this case, the test is a
JavaScript file with extension `.any.js`, which can use all the usual APIs.

In this case, the test is a JavaScript file with extension `.any.js`.
The test can then use all the usual APIs, and can be run from the path to the
JavaScript file with the `.js` replaced by `.worker.html` or `.html`.
By default, the test runs in a window scope and a dedicated worker scope.

For example, one could write a test for the `Blob` constructor by
creating a `FileAPI/Blob-constructor.any.js` as follows:
Expand All @@ -80,6 +78,30 @@ creating a `FileAPI/Blob-constructor.any.js` as follows:
This test could then be run from `FileAPI/Blob-constructor.any.worker.html` as well
as `FileAPI/Blob-constructor.any.html`.

It is possible to customize the set of scopes with a metadata comment, such as

// META: global=sharedworker
// ==> would run in the default window and dedicated worker scopes,
// as well as the shared worker scope
// META: global=!default,serviceworker
// ==> would only run in the service worker scope
// META: global=!window
// ==> would run in the default dedicated worker scope, but not the
// window scope
// META: global=worker
// ==> would run in the default window scope, as well as in the
// dedicated, shared and service worker scopes

For a test file <code><var>x</var>.any.js</code>, the available scope keywords
are:

* `window` (default): to be run at <code><var>x</var>.html</code>
* `dedicatedworker` (default): to be run at <code><var>x</var>.worker.html</code>
* `serviceworker`: to be run at <code><var>x</var>.https.any.serviceworker.html</code>
* `sharedworker`: to be run at <code><var>x</var>.any.sharedworker.html</code>
* `default`: shorthand for the default scopes
* `worker`: shorthand for the dedicated, shared and service worker scopes

To check if your test is run from a window or worker you can use the following two methods that will
be made available by the framework:

Expand Down
7 changes: 6 additions & 1 deletion tools/lint/tests/test_file_lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ def test_script_metadata(filename, input, error):


@pytest.mark.parametrize("globals,error", [
(b"", None),
(b"default", None),
(b"!default", None),
(b"window", None),
(b"!window", None),
(b"!dedicatedworker", None),
Expand All @@ -568,7 +571,9 @@ def test_script_metadata(filename, input, error):
(b"serviceworker, !serviceworker", "BROKEN-GLOBAL-METADATA"),
(b"worker, !dedicatedworker", None),
(b"worker, !serviceworker", None),
(b"!worker", "BROKEN-GLOBAL-METADATA"),
(b"!worker", None),
(b"foo", "UNKNOWN-GLOBAL-METADATA"),
(b"!foo", "UNKNOWN-GLOBAL-METADATA"),
])
def test_script_globals_metadata(globals, error):
filename = "foo.any.js"
Expand Down
10 changes: 5 additions & 5 deletions tools/manifest/sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ def parse_variants(value):
"""
assert isinstance(value, binary_type), value

included = set()
excluded = set()
globals = get_default_any_variants()

for item in value.split(b","):
item = item.strip()
if item.startswith(b"!"):
excluded |= get_any_variants(item[1:])
globals -= get_any_variants(item[1:])
else:
included |= get_any_variants(item)
globals |= get_any_variants(item)

return (get_default_any_variants() | included) - excluded
return globals


def global_suffixes(value):
Expand Down
15 changes: 9 additions & 6 deletions tools/manifest/tests/test_sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,24 @@ def test_multi_global_long_timeout():

@pytest.mark.parametrize("input,expected", [
(b"", {"dedicatedworker", "window"}),
(b"default", {"dedicatedworker", "window"}),
(b"!default", {}),
(b"!default,window", {"window"}),
(b"window,!default", {"window"}),
(b"window,!default", {}),
(b"!default,dedicatedworker", {"dedicatedworker"}),
(b"dedicatedworker,!default", {"dedicatedworker"}),
(b"!default,worker", {"dedicatedworker"}),
(b"worker,!default", {"dedicatedworker"}),
(b"dedicatedworker,!default", {}),
(b"!default,worker", {"dedicatedworker", "serviceworker", "sharedworker"}),
(b"worker,!default", {"serviceworker", "sharedworker"}),
(b"!dedicatedworker", {"window"}),
(b"!worker", {"window"}),
(b"!window", {"dedicatedworker"}),
(b"!window,worker", {"dedicatedworker", "serviceworker", "sharedworker"}),
(b"worker,!dedicatedworker", {"serviceworker", "sharedworker", "window"}),
(b"!dedicatedworker,worker", {"serviceworker", "sharedworker", "window"}),
(b"!dedicatedworker,worker", {"dedicatedworker", "serviceworker", "sharedworker", "window"}),
(b"worker,!sharedworker", {"dedicatedworker", "serviceworker", "window"}),
(b"!sharedworker,worker", {"dedicatedworker", "serviceworker", "window"}),
(b"!sharedworker,worker", {"dedicatedworker", "serviceworker", "sharedworker", "window"}),
(b"sharedworker", {"dedicatedworker", "sharedworker", "window"}),
(b"sharedworker,serviceworker", {"dedicatedworker", "serviceworker", "sharedworker", "window"}),
])
def test_multi_global_with_custom_globals(input, expected):
contents = b"""// META: global=%s
Expand Down

0 comments on commit ecffddb

Please sign in to comment.