Bug 1482160 [wpt PR 12381] - Fix service worker tests generated from non-https .any.js, a=testonly
authormoz-wptsync-bot <wptsync@mozilla.com>
Wed, 15 Aug 2018 09:53:32 +0000
changeset 431727 ace355575739ab115e98a4485dfbd9451608e6f4
parent 431726 c03828e252cf356f7a1c6c12f2358bbd90a96741
child 431728 a4f967c85a74272d895bc5b25997994d25bfa658
push id34451
push userebalazs@mozilla.com
push dateThu, 16 Aug 2018 09:25:15 +0000
treeherdermozilla-central@161817e6d127 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1482160, 12381
milestone63.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 1482160 [wpt PR 12381] - Fix service worker tests generated from non-https .any.js, a=testonly Automatic update from web-platform-testsFix service worker tests generated from non-https .any.js Note: this contains a change to the expected behaviour of test runners. Previously .any.js tests specifying a serviceworker variant generated a url like foo.https.any.serviceworker.html. But that causes a problem because that looks exctly like a url generated from a file named foo.https.js. This ambiguity, together with the fact that wptrunner wasn't actually looking at the https flag in the test id, but only in the filename, meant that service worker tests weren't being run properly. This change stops adding .https. to serviceworker tests generated from .any.js files and instead makes .serviceworker. in the test id directly mean that the test should be loaded over https. -- wpt-commits: bfec5399443c15c7a201a3d2b5505967433f570c wpt-pr: 12381
testing/web-platform/tests/infrastructure/server/context.any.js
testing/web-platform/tests/infrastructure/server/secure-context.https.any.js
testing/web-platform/tests/tools/manifest/item.py
testing/web-platform/tests/tools/manifest/sourcefile.py
testing/web-platform/tests/tools/manifest/tests/test_item.py
testing/web-platform/tests/tools/manifest/tests/test_sourcefile.py
testing/web-platform/tests/tools/serve/serve.py
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/infrastructure/server/context.any.js
@@ -0,0 +1,13 @@
+// META: global=window,dedicatedworker,sharedworker,serviceworker
+test(t => {
+  // Test for object that's only exposed in serviceworker
+  if (self.clients) {
+      assert_true(self.isSecureContext);
+      assert_equals(location.protocol, "https:");
+  } else {
+      assert_false(self.isSecureContext);
+      assert_equals(location.protocol, "http:");
+  }
+});
+
+done();
--- a/testing/web-platform/tests/infrastructure/server/secure-context.https.any.js
+++ b/testing/web-platform/tests/infrastructure/server/secure-context.https.any.js
@@ -1,8 +1,9 @@
+// META: global=window,dedicatedworker,sharedworker,serviceworker
 test(() => {
   assert_true(self.isSecureContext);
 }, "Use of .https file name flag implies secure context");
 
 test(() => {
   assert_equals(location.protocol, "https:");
 }, "Use of .https file name flag implies HTTPS scheme");
 
--- a/testing/web-platform/tests/tools/manifest/item.py
+++ b/testing/web-platform/tests/tools/manifest/item.py
@@ -1,10 +1,9 @@
-import os
-from six.moves.urllib.parse import urljoin
+from six.moves.urllib.parse import urljoin, urlparse
 from abc import ABCMeta, abstractproperty
 
 
 def get_source_file(source_files, tests_root, manifest, path):
     def make_new():
         from .sourcefile import SourceFile
 
         return SourceFile(tests_root, path, manifest.url_base)
@@ -43,23 +42,28 @@ class ManifestItem(object):
         self.source_file = source_file
 
     @abstractproperty
     def id(self):
         """The test's id (usually its url)"""
         pass
 
     @property
+    def meta_flags(self):
+        return set(self.source_file.meta_flags)
+
+    @property
     def path(self):
         """The test path relative to the test_root"""
         return self.source_file.rel_path
 
     @property
     def https(self):
-        return "https" in self.source_file.meta_flags
+        flags = self.meta_flags
+        return ("https" in flags or "serviceworker" in flags)
 
     def key(self):
         """A unique identifier for the test"""
         return (self.item_type, self.id)
 
     def meta_key(self):
         """Extra metadata that doesn't form part of the test identity, but for
         which changes mean regenerating the manifest (e.g. the test timeout."""
@@ -92,16 +96,20 @@ class URLManifestItem(ManifestItem):
         self._url = url
         self.url_base = url_base
 
     @property
     def id(self):
         return self.url
 
     @property
+    def meta_flags(self):
+        return set(urlparse(self.url).path.rsplit("/", 1)[1].split(".")[1:-1])
+
+    @property
     def url(self):
         return urljoin(self.url_base, self._url)
 
     def to_json(self):
         rv = [self._url, {}]
         return rv
 
     @classmethod
--- a/testing/web-platform/tests/tools/manifest/sourcefile.py
+++ b/testing/web-platform/tests/tools/manifest/sourcefile.py
@@ -108,18 +108,16 @@ def global_suffixes(value):
     assert isinstance(value, binary_type), value
 
     rv = set()
 
     global_types = parse_variants(value)
     for global_type in global_types:
         variant = _any_variants[global_type]
         suffix = variant.get("suffix", ".any.%s.html" % global_type.decode("utf-8"))
-        if variant.get("force_https", False):
-            suffix = ".https" + suffix
         rv.add((suffix, global_type == b"jsshell"))
 
     return rv
 
 
 def global_variant_url(url, suffix):
     """
     Returns a url created from the given url and suffix (all strings).
@@ -618,17 +616,18 @@ 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) + variant, timeout=self.timeout, jsshell=jsshell)
+                TestharnessTest(self, global_variant_url(self.url, suffix) + variant, timeout=self.timeout,
+                                jsshell=jsshell)
                 for (suffix, jsshell) in sorted(global_suffixes(globals))
                 for variant in self.test_variants
             ]
             rv = TestharnessTest.item_type, tests
 
         elif self.name_is_worker:
             test_url = replace_end(self.url, ".worker.js", ".worker.html")
             tests = [
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/tools/manifest/tests/test_item.py
@@ -0,0 +1,23 @@
+from ..item import SupportFile, URLManifestItem
+from ..sourcefile import SourceFile
+
+
+def test_base_meta_flags():
+    s = SourceFile("/", "a.b.c.d", "/", contents="")
+    m = SupportFile(s)
+
+    assert m.meta_flags == {"b", "c"}
+
+
+def test_url_meta_flags():
+    s = SourceFile("/", "a.b.c", "/", contents="")
+    m = URLManifestItem(s, "/foo.bar/a.b.d.e")
+
+    assert m.meta_flags == {"b", "d"}
+
+
+def test_url_empty_meta_flags():
+    s = SourceFile("/", "a.b.c", "/", contents="")
+    m = URLManifestItem(s, "/foo.bar/abcde")
+
+    assert m.meta_flags == set()
--- a/testing/web-platform/tests/tools/manifest/tests/test_sourcefile.py
+++ b/testing/web-platform/tests/tools/manifest/tests/test_sourcefile.py
@@ -361,17 +361,17 @@ test()""" % input
 
     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",
+        "serviceworker": "/html/test.any.serviceworker.html",
         "sharedworker": "/html/test.any.sharedworker.html",
         "window": "/html/test.any.html",
     }
 
     expected_urls = sorted(urls[ty] for ty in expected)
     assert len(items) == len(expected_urls)
 
     for item, url in zip(items, expected_urls):
@@ -426,17 +426,17 @@ test()"""
 
     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",
+        "serviceworker": "/html/test.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"]
--- a/testing/web-platform/tests/tools/serve/serve.py
+++ b/testing/web-platform/tests/tools/serve/serve.py
@@ -244,17 +244,17 @@ class SharedWorkersHandler(HtmlWrapperHa
 <script>
 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")]
+    path_replace = [(".any.serviceworker.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>
 (async function() {
@@ -337,17 +337,17 @@ class RoutesBuilder(object):
 
         self.mountpoint_routes[url_base] = []
 
         routes = [
             ("GET", "*.worker.html", WorkersHandler),
             ("GET", "*.window.html", WindowHandler),
             ("GET", "*.any.html", AnyHtmlHandler),
             ("GET", "*.any.sharedworker.html", SharedWorkersHandler),
-            ("GET", "*.https.any.serviceworker.html", ServiceWorkersHandler),
+            ("GET", "*.any.serviceworker.html", ServiceWorkersHandler),
             ("GET", "*.any.worker.js", AnyWorkerHandler),
             ("GET", "*.asis", handlers.AsIsHandler),
             ("*", "*.py", handlers.PythonScriptHandler),
             ("GET", "*", handlers.FileHandler)
         ]
 
         for (method, suffix, handler_cls) in routes:
             self.mountpoint_routes[url_base].append(