Bug 1456464 [wpt PR 10599] - Add support for test variants in .any.js tests., a=testonly
authorMs2ger <Ms2ger@gmail.com>
Tue, 01 May 2018 14:15:26 +0000
changeset 472627 08144ec19cf20fdb3465d1dece89770b0edde8b8
parent 472626 b87d81ccc298171901d6e871326638aa0c60913e
child 472628 99ec68dd3a38eb548c453e0dd3888185890ff844
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1456464, 10599
milestone61.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 1456464 [wpt PR 10599] - Add support for test variants in .any.js tests., a=testonly Automatic update from web-platform-testsAdd support for test variants in .any.js tests. Fixes #7210. -- wpt-commits: f80c6be526fe94bf9c925afb77fd2d99ce52c9b6 wpt-pr: 10599
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/docs/_writing-tests/testharness.md
testing/web-platform/tests/tools/manifest/sourcefile.py
testing/web-platform/tests/tools/manifest/tests/test_sourcefile.py
testing/web-platform/tests/tools/serve/serve.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -512345,21 +512345,21 @@
    "a0b74d2e6bf24e9142904a925f95e969d206db20",
    "reftest"
   ],
   "css/css-scoping/host-slotted-001.html": [
    "918bd04b95a276c6035383f2fe4dcfe4274bceeb",
    "reftest"
   ],
   "css/css-scoping/keyframes-001.html": [
-   "f0cda2f0f3d4093c7a24d283416c4fead20e597f",
+   "1b72da32df7b17edbd42429d2dc8b791b9f49eff",
    "testharness"
   ],
   "css/css-scoping/keyframes-002.html": [
-   "748ba6ae7c4f34770652c3269b92ff004e71e542",
+   "87f06cf1de80a4cf001fff6d150ce7013e78d604",
    "testharness"
   ],
   "css/css-scoping/reference/green-box.html": [
    "a736f68dc602c0fccab56ec5cc6234cb3298c88d",
    "support"
   ],
   "css/css-scoping/shadow-assign-dynamic-001.html": [
    "c57e0fd5aa5be63e1cadf65a4e382798c5e05ec4",
@@ -550937,17 +550937,17 @@
    "2ffb3871fb13e6acd3171205bf80517dca06bcfe",
    "support"
   ],
   "docs/_writing-tests/testharness-api.md": [
    "5fa854f33ee9141f2226fa1e1b4e5aa44c3b75c7",
    "support"
   ],
   "docs/_writing-tests/testharness.md": [
-   "722513380b0d6f0b02fa1fb39dbb0cb12cc16788",
+   "0986587a94d0aa4ed52d95b0fc7f41fb7bb791be",
    "support"
   ],
   "docs/_writing-tests/visual.md": [
    "43ab66e46d0a59851c3ad9d11cc0e2d5dd3ca8c5",
    "support"
   ],
   "docs/assets/_reftest_graph_example.dot": [
    "bc8ebc09e30ff18994b32aa9e5ea43334c276ade",
--- a/testing/web-platform/tests/docs/_writing-tests/testharness.md
+++ b/testing/web-platform/tests/docs/_writing-tests/testharness.md
@@ -116,13 +116,20 @@ Use `// META: script=link/to/resource.js
     // META: script=resources/utils.js
 
 can be used to include both the global and a local `utils.js` in a test.
 
 ### Specifying a timeout of long in auto-generated boilerplate tests
 
 Use `// META: timeout=long` at the beginning of the resource.
 
+### Specifying test variants in auto-generated boilerplate tests
+
+Use `// META: variant=url-suffix` at the beginning of the resource. For example,
+
+    // META: variant=
+    // META: variant=?wss
+
 
 [general guidelines]: {{ site.baseurl }}{% link _writing-tests/general-guidelines.md %}
 [testharness-api]: {{ site.baseurl }}{% link _writing-tests/testharness-api.md %}
 [idlharness]: {{ site.baseurl }}{% link _writing-tests/idlharness.md %}
 [server features]: {{ site.baseurl }}{% link _writing-tests/server-features.md %}
--- a/testing/web-platform/tests/tools/manifest/sourcefile.py
+++ b/testing/web-platform/tests/tools/manifest/sourcefile.py
@@ -446,21 +446,28 @@ class SourceFile(object):
     def variant_nodes(self):
         """List of ElementTree Elements corresponding to nodes representing a
         test variant"""
         return self.root.findall(".//{http://www.w3.org/1999/xhtml}meta[@name='variant']")
 
     @cached_property
     def test_variants(self):
         rv = []
-        for element in self.variant_nodes:
-            if "content" in element.attrib:
-                variant = element.attrib["content"]
-                assert variant == "" or variant[0] in ["#", "?"]
-                rv.append(variant)
+        if self.ext == ".js":
+            for (key, value) in self.script_metadata:
+                if key == b"variant":
+                    rv.append(value.decode("utf-8"))
+        else:
+            for element in self.variant_nodes:
+                if "content" in element.attrib:
+                    variant = element.attrib["content"]
+                    rv.append(variant)
+
+        for variant in rv:
+            assert variant == "" or variant[0] in ["#", "?"], variant
 
         if not rv:
             rv = [""]
 
         return rv
 
     @cached_property
     def testdriver_nodes(self):
@@ -593,30 +600,37 @@ class SourceFile(object):
         elif self.name_is_multi_global:
             globals = b""
             for (key, value) in self.script_metadata:
                 if key == b"global":
                     globals = value
                     break
 
             tests = [
-                TestharnessTest(self, global_variant_url(self.url, suffix), timeout=self.timeout)
+                TestharnessTest(self, global_variant_url(self.url, suffix) + variant, timeout=self.timeout)
                 for suffix in sorted(global_suffixes(globals))
+                for variant in self.test_variants
             ]
             rv = TestharnessTest.item_type, tests
 
         elif self.name_is_worker:
-            rv = (TestharnessTest.item_type,
-                  [TestharnessTest(self, replace_end(self.url, ".worker.js", ".worker.html"),
-                                   timeout=self.timeout)])
+            test_url = replace_end(self.url, ".worker.js", ".worker.html")
+            tests = [
+                TestharnessTest(self, test_url + variant, timeout=self.timeout)
+                for variant in self.test_variants
+            ]
+            rv = TestharnessTest.item_type, tests
 
         elif self.name_is_window:
-            rv = (TestharnessTest.item_type,
-                  [TestharnessTest(self, replace_end(self.url, ".window.js", ".window.html"),
-                                   timeout=self.timeout)])
+            test_url = replace_end(self.url, ".window.js", ".window.html")
+            tests = [
+                TestharnessTest(self, test_url + variant, timeout=self.timeout)
+                for variant in self.test_variants
+            ]
+            rv = TestharnessTest.item_type, tests
 
         elif self.name_is_webdriver:
             rv = WebdriverSpecTest.item_type, [WebdriverSpecTest(self, self.url,
                                                                  timeout=self.timeout)]
 
         elif self.content_is_css_manual and not self.name_is_reference:
             rv = ManualTest.item_type, [ManualTest(self, self.url)]
 
--- a/testing/web-platform/tests/tools/manifest/tests/test_sourcefile.py
+++ b/testing/web-platform/tests/tools/manifest/tests/test_sourcefile.py
@@ -197,16 +197,76 @@ test()"""
 
     item_type, items = s.manifest_items()
     assert item_type == "testharness"
 
     for item in items:
         assert item.timeout == "long"
 
 
+def test_worker_with_variants():
+    contents = b"""// META: variant=
+// META: variant=?wss
+test()"""
+
+    s = create("html/test.worker.js", contents=contents)
+    assert not s.name_is_non_test
+    assert not s.name_is_manual
+    assert not s.name_is_visual
+    assert not s.name_is_multi_global
+    assert s.name_is_worker
+    assert not s.name_is_window
+    assert not s.name_is_reference
+
+    assert not s.content_is_testharness
+
+    item_type, items = s.manifest_items()
+    assert item_type == "testharness"
+
+    expected_urls = [
+        "/html/test.worker.html" + suffix
+        for suffix in ["", "?wss"]
+    ]
+    assert len(items) == len(expected_urls)
+
+    for item, url in zip(items, expected_urls):
+        assert item.url == url
+        assert item.timeout is None
+
+
+def test_window_with_variants():
+    contents = b"""// META: variant=
+// META: variant=?wss
+test()"""
+
+    s = create("html/test.window.js", contents=contents)
+    assert not s.name_is_non_test
+    assert not s.name_is_manual
+    assert not s.name_is_visual
+    assert not s.name_is_multi_global
+    assert not s.name_is_worker
+    assert s.name_is_window
+    assert not s.name_is_reference
+
+    assert not s.content_is_testharness
+
+    item_type, items = s.manifest_items()
+    assert item_type == "testharness"
+
+    expected_urls = [
+        "/html/test.window.html" + suffix
+        for suffix in ["", "?wss"]
+    ]
+    assert len(items) == len(expected_urls)
+
+    for item, url in zip(items, expected_urls):
+        assert item.url == url
+        assert item.timeout is None
+
+
 def test_python_long_timeout():
     contents = b"""# META: timeout=long
 
 """
 
     metadata = list(read_script_metadata(BytesIO(contents),
                                          python_meta_re))
     assert metadata == [(b"timeout", b"long")]
@@ -314,16 +374,54 @@ test()""" % input
     expected_urls = sorted(urls[ty] for ty in expected)
     assert len(items) == len(expected_urls)
 
     for item, url in zip(items, expected_urls):
         assert item.url == url
         assert item.timeout is None
 
 
+def test_multi_global_with_variants():
+    contents = b"""// META: global=window,worker
+// META: variant=
+// META: variant=?wss
+test()"""
+
+    s = create("html/test.any.js", contents=contents)
+    assert not s.name_is_non_test
+    assert not s.name_is_manual
+    assert not s.name_is_visual
+    assert s.name_is_multi_global
+    assert not s.name_is_worker
+    assert not s.name_is_reference
+
+    assert not s.content_is_testharness
+
+    item_type, items = s.manifest_items()
+    assert item_type == "testharness"
+
+    urls = {
+        "dedicatedworker": "/html/test.any.worker.html",
+        "serviceworker": "/html/test.https.any.serviceworker.html",
+        "sharedworker": "/html/test.any.sharedworker.html",
+        "window": "/html/test.any.html",
+    }
+
+    expected_urls = sorted(
+        urls[ty] + suffix
+        for ty in ["dedicatedworker", "serviceworker", "sharedworker", "window"]
+        for suffix in ["", "?wss"]
+    )
+    assert len(items) == len(expected_urls)
+
+    for item, url in zip(items, expected_urls):
+        assert item.url == url
+        assert item.timeout is None
+
+
 @pytest.mark.parametrize("input,expected", [
     (b"""//META: foo=bar\n""", [(b"foo", b"bar")]),
     (b"""// META: foo=bar\n""", [(b"foo", b"bar")]),
     (b"""//  META: foo=bar\n""", [(b"foo", b"bar")]),
     (b"""\n// META: foo=bar\n""", []),
     (b""" // META: foo=bar\n""", []),
     (b"""// META: foo=bar\n// META: baz=quux\n""", [(b"foo", b"bar"), (b"baz", b"quux")]),
     (b"""// META: foo=bar\n\n// META: baz=quux\n""", [(b"foo", b"bar")]),
--- a/testing/web-platform/tests/tools/serve/serve.py
+++ b/testing/web-platform/tests/tools/serve/serve.py
@@ -54,18 +54,21 @@ class WrapperHandler(object):
 
     def handle_request(self, request, response):
         for header_name, header_value in self.headers:
             response.headers.set(header_name, header_value)
 
         self.check_exposure(request)
 
         path = self._get_path(request.url_parts.path, True)
+        query = request.url_parts.query
+        if query:
+            query = "?" + query
         meta = "\n".join(self._get_meta(request))
-        response.content = self.wrapper % {"meta": meta, "path": path}
+        response.content = self.wrapper % {"meta": meta, "path": path, "query": query}
         wrap_pipeline(path, request, response)
 
     def _get_path(self, path, resource_path):
         """Convert the path from an incoming request into a path corresponding to an "unwrapped"
         resource e.g. the file on disk that will be loaded in the wrapper.
 
         :param path: Path from the HTTP request
         :param resource_path: Boolean used to control whether to get the path for the resource that
@@ -166,17 +169,17 @@ class WorkersHandler(HtmlWrapperHandler)
                     (".worker.html", ".worker.js")]
     wrapper = """<!doctype html>
 <meta charset=utf-8>
 %(meta)s
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <div id=log></div>
 <script>
-fetch_tests_from_worker(new Worker("%(path)s"));
+fetch_tests_from_worker(new Worker("%(path)s%(query)s"));
 </script>
 """
 
 
 class WindowHandler(HtmlWrapperHandler):
     path_replace = [(".window.html", ".window.js")]
     wrapper = """<!doctype html>
 <meta charset=utf-8>
@@ -212,17 +215,17 @@ class SharedWorkersHandler(HtmlWrapperHa
     path_replace = [(".any.sharedworker.html", ".any.js", ".any.worker.js")]
     wrapper = """<!doctype html>
 <meta charset=utf-8>
 %(meta)s
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <div id=log></div>
 <script>
-fetch_tests_from_worker(new SharedWorker("%(path)s"));
+fetch_tests_from_worker(new SharedWorker("%(path)s%(query)s"));
 </script>
 """
 
 
 class ServiceWorkersHandler(HtmlWrapperHandler):
     global_type = b"serviceworker"
     path_replace = [(".https.any.serviceworker.html", ".any.js", ".any.worker.js")]
     wrapper = """<!doctype html>
@@ -231,17 +234,17 @@ class ServiceWorkersHandler(HtmlWrapperH
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <div id=log></div>
 <script>
 (async function() {
   const scope = 'does/not/exist';
   let reg = await navigator.serviceWorker.getRegistration(scope);
   if (reg) await reg.unregister();
-  reg = await navigator.serviceWorker.register("%(path)s", {scope});
+  reg = await navigator.serviceWorker.register("%(path)s%(query)s", {scope});
   fetch_tests_from_worker(reg.installing);
 })();
 </script>
 """
 
 
 class AnyWorkerHandler(WrapperHandler):
     headers = [('Content-Type', 'text/javascript')]