Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Implement support for multi-global tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Jul 23, 2016
1 parent 2f34984 commit 4c32741
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
12 changes: 12 additions & 0 deletions manifest/sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def name_is_manual(self):
be a manual test file"""
return self.type_flag == "manual"

@property
def name_is_multi_global(self):
"""Check if the file name matches the conditions for the file to
be a multi-global js test file"""
return "any" in self.meta_flags and self.ext == ".js"

@property
def name_is_worker(self):
"""Check if the file name matches the conditions for the file to
Expand Down Expand Up @@ -296,6 +302,12 @@ def manifest_items(self):
elif self.name_is_manual:
rv = [ManualTest(self, self.url)]

elif self.name_is_multi_global:
rv = [
TestharnessTest(self, self.url.replace(".any.js", ".any.html")),
TestharnessTest(self, self.url.replace(".any.js", ".any.worker")),
]

elif self.name_is_worker:
rv = [TestharnessTest(self, self.url[:-3])]

Expand Down
7 changes: 7 additions & 0 deletions manifest/tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ def test_manifest_to_json():
assert list(loaded) == list(m)

assert loaded.to_json() == json_str

def test_multi_global():
s = sourcefile.SourceFile("/", "test.any.js", "/")
assert s.name_is_multi_global
assert not s.name_is_manual
assert not s.name_is_reference
assert not s.name_is_worker
52 changes: 51 additions & 1 deletion serve/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,52 @@ def handle_request(self, request, response):
</script>
""" % (worker_path,)


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 = request.url_parts.path.replace(".any.html", ".any.js")
return """\
<!doctype html>
<meta charset=utf-8>
<script>
self.GLOBAL = {
isWindow: function() { return true; },
isWorker: function() { return false; },
};
</script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script src="%s"></script>
""" % (test_path,)


class AnyWorkerHandler(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 = request.url_parts.path.replace(".any.worker.js", ".any.js")
return """\
self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return true; },
};
importScripts("/resources/testharness.js");
importScripts("%s");
done();
""" % (test_path,)


rewrites = [("GET", "/resources/WebIDLParser.js", "/resources/webidl2/lib/webidl2.js")]

subdomains = [u"www",
Expand All @@ -61,7 +107,11 @@ def __init__(self):
("*", "{spec}/tools/*", handlers.ErrorHandler(404)),
("*", "/serve.py", handlers.ErrorHandler(404))]

self.static = [("GET", "*.worker", WorkersHandler())]
self.static = [
("GET", "*.worker", WorkersHandler()),
("GET", "*.any.html", AnyHtmlHandler()),
("GET", "*.any.worker.js", AnyWorkerHandler()),
]

self.mountpoint_routes = OrderedDict()

Expand Down

0 comments on commit 4c32741

Please sign in to comment.