From 4b4d610c725916bc277ca680057078de55ade74a Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 11 Nov 2016 17:28:26 +0000 Subject: [PATCH] Bug 1317236 - Fix handling of .any.* tests, r=Ms2ger MozReview-Commit-ID: HEpEOgvYigU --- .../web-platform/tests/tools/serve/serve.py | 94 +++++++++++-------- 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/testing/web-platform/tests/tools/serve/serve.py b/testing/web-platform/tests/tools/serve/serve.py index 1e83392a15ca..4d35af2c0c26 100644 --- a/testing/web-platform/tests/tools/serve/serve.py +++ b/testing/web-platform/tests/tools/serve/serve.py @@ -34,7 +34,12 @@ def replace_end(s, old, new): return s[:-len(old)] + new -class WorkersHandler(object): +class BaseWorkerHandler(object): + source_suffix = None + url_suffix = None + path_suffix = None + response_template = None + def __init__(self, base_path=None, url_base="/"): self.base_path = base_path self.url_base = url_base @@ -44,22 +49,13 @@ class WorkersHandler(object): return self.handler(request, response) def handle_request(self, request, response): - worker_path = replace_end(request.url_parts.path, ".worker.html", ".worker.js") + url_path = replace_end(request.url_parts.path, self.source_suffix, self.url_suffix) meta = self._get_meta(request) - return """ - -%(meta)s - - -
- -""" % {"meta": meta, "worker_path": worker_path} + return self.response_template % {"meta": meta, "url_path": url_path} def _get_meta(self, request): path = filesystem_path(self.base_path, request, self.url_base) - path = path.replace(".worker.html", ".worker.js") + path = replace_end(path, self.source_suffix, self.path_suffix) meta_values = [] with open(path) as f: for line in f: @@ -72,19 +68,37 @@ fetch_tests_from_worker(new Worker("%(worker_path)s")); return "\n".join('' % item for item in meta_values) +class WorkerHandler(BaseWorkerHandler): + source_suffix = ".worker.html" + url_suffix = ".worker.js" + path_suffix = ".worker.js" -class AnyHtmlHandler(object): - def __init__(self): - self.handler = handlers.handler(self.handle_request) - - def __call__(self, request, response): - return self.handler(request, response) - - def handle_request(self, request, response): - test_path = replace_end(request.url_parts.path, ".any.html", ".any.js") - return """\ - + response_template = """ +%(meta)s + + +
+ +""" + + +class AnyWorkerHandler(WorkerHandler): + source_suffix = ".any.worker.html" + url_suffix = ".any.worker.js" + path_suffix = ".any.js" + + +class AnyHtmlHandler(BaseWorkerHandler): + source_suffix = ".any.html" + url_suffix = ".any.js" + path_suffix = ".any.js" + + response_template = """ + +%(meta)s
- -""" % (test_path,) + +""" -class AnyWorkerHandler(object): - def __init__(self): - self.handler = handlers.handler(self.handle_request) +class AnyWorkerScriptHandler(BaseWorkerHandler): + source_suffix = ".any.worker.js" + url_suffix = ".any.js" + path_suffix = None - def __call__(self, request, response): - return self.handler(request, response) - - def handle_request(self, request, response): - test_path = replace_end(request.url_parts.path, ".any.worker.js", ".any.js") - return """\ + response_template = """\ self.GLOBAL = { isWindow: function() { return false; }, isWorker: function() { return true; }, }; importScripts("/resources/testharness.js"); -importScripts("%s"); +importScripts("%(url_path)s"); done(); -""" % (test_path,) +""" + + def _get_meta(self, path): + return None rewrites = [("GET", "/resources/WebIDLParser.js", "/resources/webidl2/lib/webidl2.js")] + subdomains = [u"www", u"www1", u"www2", u"天気の良い日", u"élève"] + class RoutesBuilder(object): def __init__(self): self.forbidden_override = [("GET", "/tools/runner/*", handlers.file_handler), @@ -138,9 +153,10 @@ class RoutesBuilder(object): ("*", "/serve.py", handlers.ErrorHandler(404))] self.static = [ - ("GET", "*.worker.html", WorkersHandler()), ("GET", "*.any.html", AnyHtmlHandler()), - ("GET", "*.any.worker.js", AnyWorkerHandler()), + ("GET", "*.any.worker.html", AnyWorkerHandler()), + ("GET", "*.any.worker.js", AnyWorkerScriptHandler()), + ("GET", "*.worker.html", WorkerHandler()), ] self.mountpoint_routes = OrderedDict()