Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wptrunner] Support testdriver.js in {ref,print-ref,crash}tests #48486

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/writing-tests/testdriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ written purely using web platform APIs. Outside of automation
contexts, it allows human operators to provide expected input
manually (for operations which may be described in simple terms).

It is currently supported only for [testharness.js](testharness)
tests.

## Markup ##

The `testdriver.js` and `testdriver-vendor.js` must both be included
Expand Down
13 changes: 13 additions & 0 deletions infrastructure/crashtests/testdriver.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html class="test-wait">
<title>crashtests support testdriver.js</title>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<button>Complete the test</button>
<script>
const button = document.querySelector("button");
button.addEventListener("click", () => {
document.documentElement.classList.remove("reftest-wait");
});
test_driver.click(button);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[testdriver-in-ref.html]
disabled:
# https://github.com/web-platform-tests/wpt/issues/13183
if product == "firefox" or product == "firefox_android":
"marionette executor doesn't implement testdriver for reftests"
19 changes: 19 additions & 0 deletions infrastructure/reftest/testdriver-child.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<style>
:root {
background-color: red;
}
</style>
<button>Turn green</button>
<script>
test_driver.set_test_context(parent);
const button = document.querySelector("button");
button.addEventListener("click", () => {
button.remove();
document.documentElement.style.backgroundColor = "green";
test_driver.message_test("ready");
});
test_driver.click(button);
</script>
29 changes: 29 additions & 0 deletions infrastructure/reftest/testdriver-iframe.sub.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html class="reftest-wait">
<title>reftests support testdriver.js in iframes</title>
<link rel="match" href="green.html">
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<style>
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
iframe {
position: absolute;
border: none;
width: inherit;
height: inherit;
}
</style>
<script>
// Attach the handler that completes the test before loading the calling iframe.
window.addEventListener("message", (evt) => {
if (evt.data === "ready") {
document.documentElement.classList.remove("reftest-wait");
}
});
</script>
<iframe src="https://{{host}}:{{ports[https][1]}}/infrastructure/reftest/testdriver-child.html"></iframe>
6 changes: 6 additions & 0 deletions infrastructure/reftest/testdriver-in-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<title>references support testdriver.js</title>
<link rel="match" href="testdriver.html">
<style>
:root {background-color:green}
</style>
23 changes: 23 additions & 0 deletions infrastructure/reftest/testdriver-print.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html class="reftest-wait">
<title>print-reftests support testdriver.js</title>
<link rel="match" href="reftest_match-print-ref.html">
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<style>
* { margin: 0; padding: 0; }
div { page-break-after: always; }
</style>
<button>Add a page</button>
<div>page 1</div>
<script>
const button = document.querySelector("button");
button.addEventListener("click", () => {
button.remove();
const page2 = document.createElement("div");
page2.innerText = "page 2";
document.body.appendChild(page2);
document.documentElement.classList.remove("reftest-wait");
});
test_driver.click(button);
</script>
21 changes: 21 additions & 0 deletions infrastructure/reftest/testdriver.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html class="reftest-wait">
<title>reftests support testdriver.js</title>
<link rel="match" href="green.html">
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<style>
:root {
background-color: red;
}
</style>
<button>Turn green</button>
<script>
const button = document.querySelector("button");
button.addEventListener("click", () => {
button.remove();
document.documentElement.style.backgroundColor = "green";
document.documentElement.classList.remove("reftest-wait");
});
test_driver.click(button);
</script>
6 changes: 6 additions & 0 deletions lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,12 @@ HTML INVALID SYNTAX: quirks/percentage-height-calculation.html
HTML INVALID SYNTAX: trusted-types/TrustedTypePolicyFactory-getAttributeType-namespace.html

# Tests which include testdriver.js but aren't testharness.js tests
# TODO(web-platform-tests/wpt#13183): Dismantle this rule once support is added.
TESTDRIVER-IN-UNSUPPORTED-TYPE: infrastructure/crashtests/testdriver.html
TESTDRIVER-IN-UNSUPPORTED-TYPE: infrastructure/reftest/testdriver.html
TESTDRIVER-IN-UNSUPPORTED-TYPE: infrastructure/reftest/testdriver-child.html
TESTDRIVER-IN-UNSUPPORTED-TYPE: infrastructure/reftest/testdriver-iframe.sub.html
TESTDRIVER-IN-UNSUPPORTED-TYPE: infrastructure/reftest/testdriver-print.html
TESTDRIVER-IN-UNSUPPORTED-TYPE: css/css-grid/grid-model/grid-layout-stale-001.html
TESTDRIVER-IN-UNSUPPORTED-TYPE: css/css-grid/grid-model/grid-layout-stale-002.html
TESTDRIVER-IN-UNSUPPORTED-TYPE: css/css-scroll-anchoring/fullscreen-crash.html
Expand Down
18 changes: 17 additions & 1 deletion tools/manifest/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def pac(self) -> Optional[Text]:
return self._extras.get("pac")

@property
def testdriver(self) -> Optional[Text]:
def testdriver(self) -> Optional[bool]:
return self._extras.get("testdriver")

@property
Expand Down Expand Up @@ -240,6 +240,10 @@ def fuzzy(self) -> Fuzzy:
rv[key] = v
return rv

@property
def testdriver(self) -> Optional[bool]:
return self._extras.get("testdriver")

def to_json(self) -> Tuple[Optional[Text], List[Tuple[Text, Text]], Dict[Text, Any]]: # type: ignore
rel_url = None if self._url == self.path else self._url
rv: Tuple[Optional[Text], List[Tuple[Text, Text]], Dict[Text, Any]] = (rel_url, self.references, {})
Expand All @@ -252,6 +256,8 @@ def to_json(self) -> Tuple[Optional[Text], List[Tuple[Text, Text]], Dict[Text, A
extras["dpi"] = self.dpi
if self.fuzzy:
extras["fuzzy"] = list(self.fuzzy.items())
if self.testdriver:
extras["testdriver"] = self.testdriver
return rv

@classmethod
Expand Down Expand Up @@ -315,6 +321,16 @@ class CrashTest(URLManifestItem):
def timeout(self) -> Optional[Text]:
return None

@property
def testdriver(self) -> Optional[bool]:
return self._extras.get("testdriver")

def to_json(self): # type: ignore
rel_url, extras = super().to_json()
if self.testdriver:
extras["testdriver"] = self.testdriver
return rel_url, extras


class WebDriverSpecTest(URLManifestItem):
__slots__ = ()
Expand Down
7 changes: 5 additions & 2 deletions tools/manifest/sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ def manifest_items(self) -> Tuple[Text, List[ManifestItem]]:
self.tests_root,
self.rel_path,
self.url_base,
self.rel_url
self.rel_url,
testdriver=self.has_testdriver,
)]

elif self.name_is_print_reftest:
Expand All @@ -946,6 +947,7 @@ def manifest_items(self) -> Tuple[Text, List[ManifestItem]]:
viewport_size=self.viewport_size,
fuzzy=self.fuzzy,
page_ranges=self.page_ranges,
testdriver=self.has_testdriver,
)]

elif self.name_is_multi_global:
Expand Down Expand Up @@ -1046,7 +1048,8 @@ def manifest_items(self) -> Tuple[Text, List[ManifestItem]]:
timeout=self.timeout,
viewport_size=self.viewport_size,
dpi=self.dpi,
fuzzy=self.fuzzy
fuzzy=self.fuzzy,
testdriver=self.has_testdriver,
))

elif self.content_is_css_visual and not self.name_is_reference:
Expand Down
26 changes: 26 additions & 0 deletions tools/manifest/tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,29 @@ def test_manifest_spec_to_json():
]}},
}
}


@pytest.mark.parametrize("testdriver,expected_extra", [
(True, {"testdriver": True}),
# Don't bloat the manifest with the `testdriver=False` default.
(False, {}),
])
def test_dump_testdriver(testdriver, expected_extra):
m = manifest.Manifest("")
source_file = SourceFileWithTest("a" + os.path.sep + "b", "0"*40, item.RefTest,
testdriver=testdriver)

tree, sourcefile_mock = tree_and_sourcefile_mocks([(source_file, None, True)])
with mock.patch("tools.manifest.manifest.SourceFile", side_effect=sourcefile_mock):
assert m.update(tree) is True

assert m.to_json() == {
'version': 8,
'url_base': '/',
'items': {
'reftest': {'a': {'b': [
'0000000000000000000000000000000000000000',
(mock.ANY, [], expected_extra)
]}},
}
}
38 changes: 9 additions & 29 deletions tools/wptrunner/wptrunner/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
sys.path.insert(0, repo_root)
from tools import localpaths # noqa: F401

from wptserve.handlers import StringHandler

serve = None


Expand Down Expand Up @@ -232,22 +230,25 @@ def get_routes(self):
"text/javascript", "/_pdf_js/pdf.js"),
(os.path.join(here, "..", "..", "third_party", "pdf_js", "pdf.worker.js"), None,
"text/javascript", "/_pdf_js/pdf.worker.js"),
(self.options.get("testharnessreport", "testharnessreport.js"),
(self.options.get("testharnessreport", [os.path.join("executors", "message-queue.js"),
"testharnessreport.js"]),
{"output": self.pause_after_test,
"timeout_multiplier": self.testharness_timeout_multipler,
"explicit_timeout": "true" if self.debug_info is not None else "false",
"debug": "true" if self.debug_test else "false"},
"text/javascript;charset=utf8",
"/resources/testharnessreport.js")]:
path = os.path.normpath(os.path.join(here, path))
"/resources/testharnessreport.js"),
([os.path.join(repo_root, "resources", "testdriver.js"),
os.path.join("executors", "message-queue.js"),
"testdriver-extra.js"], {}, "text/javascript", "/resources/testdriver.js")]:
paths = [path] if isinstance(path, str) else path
abs_paths = [os.path.normpath(os.path.join(here, path)) for path in paths]
# Note that .headers. files don't apply to static routes, so we need to
# readd any static headers here.
headers = {"Cache-Control": "max-age=3600"}
route_builder.add_static(path, format_args, content_type, route,
route_builder.add_static(abs_paths, format_args, content_type, route,
headers=headers)

route_builder.add_handler("GET", "/resources/testdriver.js", TestdriverLoader())

for url_base, test_root in self.test_paths.items():
if url_base == "/":
continue
Expand Down Expand Up @@ -315,27 +316,6 @@ def test_servers(self):
return failed, pending


class TestdriverLoader:
"""A special static handler for serving `/resources/testdriver.js`.

This handler lazily reads `testdriver{,-extra}.js` so that wptrunner doesn't
need to pass the entire file contents to child `wptserve` processes, which
can slow `wptserve` startup by several seconds (crbug.com/1479850).
"""
def __init__(self):
self._handler = None

def __call__(self, request, response):
if not self._handler:
data = b""
with open(os.path.join(repo_root, "resources", "testdriver.js"), "rb") as fp:
data += fp.read()
with open(os.path.join(here, "testdriver-extra.js"), "rb") as fp:
data += fp.read()
self._handler = StringHandler(data, "text/javascript")
return self._handler(request, response)


def wait_for_service(logger: StructuredLogger,
host: str,
port: int,
Expand Down
Loading
Loading