Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 0032bc0
Author: Simon Pieters <[email protected]>
Date:   Sun Jun 10 12:28:37 2018 +0200

    Add functional selftests, set status to ERROR when mixing single_test and test

commit c3c3625
Author: Simon Pieters <[email protected]>
Date:   Sun Jun 10 09:56:40 2018 +0200

    Docs

commit bff2d71
Author: Simon Pieters <[email protected]>
Date:   Sun Jun 10 09:44:46 2018 +0200

    Rename single() to single_test() and allow passing test name

commit 0bc6450
Author: Simon Pieters <[email protected]>
Date:   Tue Jun 5 16:59:23 2018 +0200

    [testharness.js] Implement `single()` opt-in to single page test

    Fixes #10853. Closes #11024.
  • Loading branch information
foolip committed Sep 22, 2019
1 parent d89d13d commit c01e1b7
Show file tree
Hide file tree
Showing 68 changed files with 190 additions and 25 deletions.
1 change: 1 addition & 0 deletions FileAPI/url/multi-global-origin-serialization.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<script>
"use strict";
single_test();
document.domain = "{{host}}";

window.onload = () => {
Expand Down
14 changes: 7 additions & 7 deletions docs/writing-tests/testharness-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,9 @@ wrapping everything in functions for isolation becomes
burdensome. For these cases `testharness.js` support "single page
tests".

In order for a test to be interpreted as a single page test, then
it must simply not call `test()` or `async_test()` anywhere on the page, and
must call the `done()` function to indicate that the test is complete. All
the `assert_*` functions are available as normal, but are called without
the normal step function wrapper. For example:
To write a single page test, call `single_test()`. Call the `done()` function to
indicate that the test is complete. All the `assert_*` functions are available
as normal, but are called without the normal step function wrapper. For example:

```html
<!doctype html>
Expand All @@ -274,12 +272,14 @@ the normal step function wrapper. For example:
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
single_test();
assert_equals(document.body, document.getElementsByTagName("body")[0])
done()
</script>
</script>
```

The test title for single page tests is always taken from `document.title`.
The test title for single page tests is taken from `document.title` or from the
argument to `single_test()`.

## Making assertions ##

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script src=/resources/testharnessreport.js></script>
<iframe src="Element-getElementsByTagName-change-document-HTMLNess-iframe.xml"></iframe>
<script>
single_test();
onload = function() {
var parent = document.createElement("div");
var child1 = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
Expand Down
1 change: 1 addition & 0 deletions fetch/content-length/content-length.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
single_test();
onload = function() {
assert_equals(document.body.textContent, "PASS");
done();
Expand Down
2 changes: 1 addition & 1 deletion fetch/content-length/content-length.html.headers
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Content-Length: 373
Content-Length: 383
1 change: 1 addition & 0 deletions fetch/corb/script-js-mislabeled-as-html-nosniff.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div id=log></div>

<script>
single_test();
window.has_executed_script = false;
</script>

Expand Down
1 change: 1 addition & 0 deletions fetch/corb/script-js-mislabeled-as-html.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<div id=log></div>

<script>
single_test();
window.has_executed_script = false;
</script>

Expand Down
1 change: 1 addition & 0 deletions fetch/corb/style-css-mislabeled-as-html-nosniff.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ <h1 id="header">Header example</h1>
</body>

<script>
single_test();
// Verify that CSS is not applied (because of nosniff + non-text/css headers).
let style = getComputedStyle(document.getElementById('header'));
const external_color = 'rgb(255, 0, 0)'; // red
Expand Down
1 change: 1 addition & 0 deletions fetch/corb/style-css-mislabeled-as-html.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h1 id="header">Header example</h1>
</body>

<script>
single_test();
// Verify that CSS is not applied (because of strict content-type enforcement
// for cross-origin stylesheets).
let style = getComputedStyle(document.getElementById('header'));
Expand Down
1 change: 1 addition & 0 deletions fetch/corb/style-css-with-json-parser-breaker.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ <h1 id="header">Header example</h1>
</body>

<script>
single_test();
// Verify that CSS got applied / did not get blocked by CORB.
let style = getComputedStyle(document.getElementById('header'));
const external_color = 'rgb(255, 0, 0)'; // red
Expand Down
1 change: 1 addition & 0 deletions fetch/corb/style-html-correctly-labeled.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h1 id="header">Header example</h1>
</body>

<script>
single_test();
// Verify that CSS is not applied (because of mismatched Content-Type header).
var style = getComputedStyle(document.getElementById('header'));
const default_color = 'rgb(0, 128, 0)'; // green
Expand Down
1 change: 1 addition & 0 deletions gamepad/events-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="/resources/testharnessreport.js"></script>
<script>
setup({explicit_timeout: true});
single_test();

function set_instructions(text) {
document.getElementById("instructions").textContent = text;
Expand Down
1 change: 1 addition & 0 deletions gamepad/timestamp-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<script src="/resources/testharnessreport.js"></script>
<script>
setup({explicit_timeout: true});
single_test();

function set_instructions(text) {
document.getElementById("instructions").textContent = text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div id=log></div>
<iframe></iframe>
<script>
single_test();
onload = function() {
var fr = document.querySelector("iframe")
fr.contentWindow.location = "support/dummy.html"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<div id=log></div>
<iframe></iframe>
<script>
single_test();
onload = function() {
var fr = document.querySelector("iframe")
fr.src = "about:blank"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</style>
<dialog open id=dialog></dialog>
<script>
single_test();
assert_equals(getComputedStyle(document.getElementById('dialog')).display, 'block');
done();
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<table vspace=25 hspace=25><tr><td>x</table>
<div>x</div>
<script>
single_test();
var style = getComputedStyle(document.querySelector('table'));
['marginTop', 'marginRight', 'marginBottom', 'marginLeft'].forEach(function(m) {
assert_equals(style[m], '0px', m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<table vspace=25 hspace=25><tr><td>x</table>
<div>x</div> <!-- prevent margin collapsing quirks -->
<script>
single_test();
var style = getComputedStyle(document.querySelector('table'));
['marginTop', 'marginRight', 'marginBottom', 'marginLeft'].forEach(function(m) {
assert_equals(style[m], '0px', m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<script src="/resources/testharnessreport.js"></script>
<iframe src="/common/blank.html" marginwidth=0 marginheight=0></iframe>
<script>
single_test();
onload = () => {
assert_equals(window[0].document.body.attributes.length, 0, "Number of attributes on the child document's body");
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<script>
"use strict";
single_test();

const sourceIFrame = document.createElement("iframe");
sourceIFrame.setAttribute("sandbox", "allow-same-origin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<script>
"use strict";
single_test();

const sourceIFrame = document.createElement("iframe");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<script>
"use strict";
single_test();

const iframe = document.createElement("iframe");
let loadCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div id="log"></div>
<script>
"use strict";
single_test();

const iframe = document.createElement("iframe");
iframe.src = "support/ufoo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<script>
"use strict";
single_test();

const sourceIFrame = document.createElement("iframe");
let sourceLoadCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//
// So if the text tracks are not yet ready, we can't autoplay.

single_test();
var started = 0;
var numOfTests = 5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<iframe src="about:blank"></iframe>
<div id="target"></div>
<script>
single_test();
onload = function() {
var ifr = document.getElementsByTagName('iframe')[0];
ifr.contentDocument.body.appendChild(ifr.contentDocument.createElement('p')).textContent = 'Modified document';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<iframe src="about:blank"></iframe>
<div id="target"></div>
<script>
single_test();
onload = function() {
var ifr = document.getElementsByTagName('iframe')[0];
ifr.contentDocument.open();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<iframe src="support/blank.htm"></iframe>
<div id="target"></div>
<script>
single_test();
onload = function() {
var ifr = document.getElementsByTagName('iframe')[0];
ifr.contentDocument.body.appendChild(ifr.contentDocument.createElement('p')).textContent = 'Modified document';
Expand All @@ -17,4 +18,4 @@
document.getElementById('target').appendChild(ifr);
}, 100);
}
</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<iframe src="support/blank.htm"></iframe>
<div id="target"></div>
<script>
single_test();
onload = function(){
var ifr = document.getElementsByTagName('iframe')[0];
ifr.contentDocument.open();
Expand All @@ -19,4 +20,4 @@
document.getElementById('target').appendChild(ifr);
}, 100);
}
</script>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
single_test();
var c = document.createElement("canvas"),
con = c.getContext("2d"),
img = document.createElement("img")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script src="/resources/testharnessreport.js"></script>
<p id="display"><img src="image.png"></p>
<script>
single_test();
function check() {
var img = document.querySelector("img");
assert_true(img.complete, "By onload, image should have loaded");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<script>
"use strict";
single_test();

promise_test(async () => {
const input1 = document.querySelector("input");
Expand Down
1 change: 1 addition & 0 deletions html/semantics/forms/autofocus/first-when-later.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<script>
"use strict";
single_test();

promise_test(async () => {
const input1 = document.querySelector("input");
Expand Down
1 change: 1 addition & 0 deletions html/semantics/forms/autofocus/first.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<script>
"use strict";
single_test();

promise_test(async () => {
const [input1, input2] = document.querySelectorAll("input");
Expand Down
1 change: 1 addition & 0 deletions html/semantics/forms/autofocus/not-on-first-task.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<script>
"use strict";
single_test();

const input = document.querySelector("input");

Expand Down
1 change: 1 addition & 0 deletions html/webappapis/timers/negative-setinterval.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
single_test();
var i = 0;
var interval;
function next() {
Expand Down
1 change: 1 addition & 0 deletions html/webappapis/timers/negative-settimeout.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
single_test();
setTimeout(done, -100);
setTimeout(assert_unreached, 10);
</script>
1 change: 1 addition & 0 deletions html/webappapis/timers/type-long-setinterval.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
single_test();
var interval;
function next() {
clearInterval(interval);
Expand Down
1 change: 1 addition & 0 deletions html/webappapis/timers/type-long-settimeout.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
single_test();
setTimeout(done, Math.pow(2, 32));
setTimeout(assert_unreached, 100);
</script>
1 change: 1 addition & 0 deletions infrastructure/browsers/firefox/prefs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
single_test();
assert_equals(getComputedStyle(document.documentElement).color, "rgb(0, 255, 0)")
done();
</script>
Expand Down
1 change: 1 addition & 0 deletions navigation-timing/nav2_test_navigate_within_document.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h1>Description</h1>
<p>This test validates that all of the window.performance.getEntriesByType("navigation") attributes remain unchanged after an in document navigation (URL fragment change).</p>

<script>
single_test();
var navTiming2Attributes = [
'connectEnd',
'connectStart',
Expand Down
1 change: 1 addition & 0 deletions preload/single-download-late-used-preload.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script src="/preload/resources/preload_helper.js"></script>
<link rel=preload href="resources/square.png?pipe=trickle(d1)" as=image>
<script>
single_test();
var link = document.getElementsByTagName("link")[0]
assert_equals(link.as, "image");
link.addEventListener("load", () => {
Expand Down
26 changes: 26 additions & 0 deletions resources/test/tests/functional/single-page-test-and-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<title>Example with single_test() and test()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
single_test();
test();
done();
</script>
<script type="text/json" id="expected">
{
"summarized_status": {
"status_string": "ERROR",
"message": "Tried to create a test after calling single_test()"
},
"summarized_tests": [
{
"status_string": "FAIL",
"name": "Example with single_test() and test()",
"properties": {},
"message": "Tried to create a test after calling single_test()"
}
],
"type": "complete"
}
</script>
Loading

0 comments on commit c01e1b7

Please sign in to comment.