Bug 1216168 - Add reftest support for mach web-platform-tests-create, r=Ms2ger
authorJames Graham <james@hoppipolla.co.uk>
Mon, 19 Oct 2015 15:44:19 +0100
changeset 268394 89d1402a45f44d3286e88ac3b326e93f2cbba972
parent 268393 eddce960bab66cda1f940b39cbb1d006863bcb17
child 268395 147668fd913fce223fd287df6f08bece7cf02f01
push id29551
push usercbook@mozilla.com
push dateTue, 20 Oct 2015 10:01:15 +0000
treeherdermozilla-central@f7b746b4e913 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs1216168
milestone44.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 1216168 - Add reftest support for mach web-platform-tests-create, r=Ms2ger
testing/web-platform/mach_commands.py
--- a/testing/web-platform/mach_commands.py
+++ b/testing/web-platform/mach_commands.py
@@ -113,49 +113,100 @@ class WebPlatformTestsReduce(WebPlatform
         if not tests:
             logger.warning("Test was not unstable")
 
         for item in tests:
             logger.info(item.id)
 
 class WebPlatformTestsCreator(MozbuildObject):
     template_prefix = """<!doctype html>
-<meta charset=utf-8>
+%(documentElement)s<meta charset=utf-8>
 """
     template_long_timeout = "<meta name=timeout content=long>\n"
 
-    template_body = """<title></title>
+    template_body_th = """<title></title>
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
 <script>
 
 </script>
 """
 
+    template_body_reftest = """<title></title>
+<link rel=%(match)s href=%(ref)s>
+"""
+
+    template_body_reftest_wait = """<script src="/common/reftest-wait.js"></script>
+"""
+
+    def rel_path(self, path):
+        if path is None:
+            return
+
+        abs_path = os.path.normpath(os.path.abspath(path))
+        return os.path.relpath(abs_path, self.topsrcdir)
+
+    def rel_url(self, rel_path):
+        upstream_path = os.path.join("testing", "web-platform", "tests")
+        local_path = os.path.join("testing", "web-platform", "mozilla", "tests")
+
+        if rel_path.startswith(upstream_path):
+            return rel_path[len(upstream_path):].replace(os.path.sep, "/")
+        elif rel_path.startswith(local_path):
+            return "/_mozilla" + rel_path[len(local_path):].replace(os.path.sep, "/")
+        else:
+            return None
+
     def run_create(self, context, **kwargs):
         import subprocess
 
-        path = os.path.normpath(os.path.abspath(kwargs["path"]))
+        path = self.rel_path(kwargs["path"])
+        ref_path = self.rel_path(kwargs["ref"])
+
+        if kwargs["ref"]:
+            kwargs["reftest"] = True
 
-        rel_path = os.path.relpath(path, self.topsrcdir)
-        if not (rel_path.startswith("testing/web-platform/tests") or
-                rel_path.startswith("testing/web-platform/mozilla/tests")):
-            print("""Test path is not in wpt directories:
+        if self.rel_url(path) is None:
+            print("""Test path %s is not in wpt directories:
 testing/web-platform/tests for tests that may be shared
-testing/web-platform/mozilla/tests for Gecko only tests""")
+testing/web-platform/mozilla/tests for Gecko-only tests""" % path)
             return 1
 
+        if ref_path and self.rel_url(ref_path) is None:
+            print("""Reference path %s is not in wpt directories:
+testing/web-platform/tests for tests that may be shared
+            testing/web-platform/mozilla/tests for Gecko-only tests""" % ref_path)
+            return 1
+
+
         if os.path.exists(path) and not kwargs["overwrite"]:
             print("Test path already exists, pass --overwrite to replace")
             return 1
 
-        template = self.template_prefix
+        if kwargs["mismatch"] and not kwargs["reftest"]:
+            print("--mismatch only makes sense for a reftest")
+            return 1
+
+        if kwargs["wait"] and not kwargs["reftest"]:
+            print("--wait only makes sense for a reftest")
+            return 1
+
+        args = {"documentElement": "<html class=reftest-wait>\n" if kwargs["wait"] else ""}
+        template = self.template_prefix % args
         if kwargs["long_timeout"]:
             template += self.template_long_timeout
-        template += self.template_body
+
+        if kwargs["reftest"]:
+            args = {"match": "match" if not kwargs["mismatch"] else "mismatch",
+                    "ref": self.rel_url(ref_path) if kwargs["ref"] else '""'}
+            template += self.template_body_reftest % args
+            if kwargs["wait"]:
+                template += self.template_body_reftest_wait
+        else:
+            template += self.template_body_th
         with open(path, "w") as f:
             f.write(template)
 
         if kwargs["no_editor"]:
             editor = None
         elif kwargs["editor"]:
             editor = kwargs["editor"]
         elif "VISUAL" in os.environ:
@@ -194,16 +245,23 @@ def create_parser_create():
                    help="Don't try to open the test in an editor")
     p.add_argument("-e", "--editor", action="store", help="Editor to use")
     p.add_argument("--no-run", action="store_true",
                    help="Don't try to update the wpt manifest or open the test in a browser")
     p.add_argument("--long-timeout", action="store_true",
                    help="Test should be given a long timeout (typically 60s rather than 10s, but varies depending on environment)")
     p.add_argument("--overwrite", action="store_true",
                    help="Allow overwriting an existing test file")
+    p.add_argument("-r", "--reftest", action="store_true",
+                   help="Create a reftest rather than a testharness (js) test"),
+    p.add_argument("-ref", "--reference", dest="ref", help="Path to the reference file")
+    p.add_argument("--mismatch", action="store_true",
+                   help="Create a mismatch reftest")
+    p.add_argument("--wait", action="store_true",
+                   help="Create a reftest that waits until takeScreenshot() is called")
     p.add_argument("path", action="store", help="Path to the test file")
     return p
 
 
 @CommandProvider
 class MachCommands(MachCommandBase):
     @Command("web-platform-tests",
              category="testing",