Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Commit a5802df

Browse files
sfuquajgraham
authored andcommitted
Add doc and sample for fetch_tests_from_window.
1 parent 39051c9 commit a5802df

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

docs/api.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,19 @@ object. These objects are structured as follows:
522522
* result - `{ type: "result", test: Test }`
523523
* complete - `{ type: "complete", tests: [Test, ...], status: TestsStatus }`
524524
525+
## Consolidating tests from other documents ##
526+
527+
If it is desirable to coalesce multiple test suites running in separate
528+
documents into one primary test document, that is possible through
529+
`fetch_tests_from_window`. The argument to `fetch_tests_from_window` is any [`Window`](https://html.spec.whatwg.org/multipage/browsers.html#the-window-object)
530+
capable of accessing the browsing context as either an ancestor or opener.
531+
532+
This can be used, for example, to pull in tests from a child that was created
533+
with `window.open`, or in a frame, such that all tests are ultimately reported
534+
in the same document. The current test suite will not report completion until
535+
all fetched tests are complete, and errors in the child contexts will result in
536+
failures for the suite in the current context.
537+
525538
## Web Workers ##
526539
527540
The `testharness.js` script can be used from within [dedicated workers, shared

examples/apisample18.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
>
2+
<html>
3+
<head>
4+
<title>Example with iframe that consolidates tests via fetch_tests_from_windowtitle>
5+
<script src="../testharness.js">script>
6+
<script src="../testharnessreport.js">script>
7+
<script>
8+
var parent_test = async_test("Test executing in parent context");
9+
script>
10+
head>
11+
<body onload="parent_test.done()">
12+
<h1>Fetching Tests From a Child Contexth1>
13+
<p>This test demonstrates the use of <tt>fetch_tests_from_windowtt> to pull
14+
tests from an <tt>iframett> into the primary document.p>
15+
<p>The test suite is expected to fail due to an unhandled exception in the
16+
child context.p>
17+
<div id="log">div>
18+
19+
<iframe id="childContext" src="apisample4.htm" style="display:none">iframe>
20+
21+
22+
<script>
23+
var childContext = document.getElementById("childContext");
24+
fetch_tests_from_window(childContext.contentWindow);
25+
script>
26+
body>

testharness.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,10 @@ policies and contribution forms [3].
16141614
stack: error.stack
16151615
}
16161616
});
1617-
error.preventDefault();
1617+
1618+
if (error.preventDefault) {
1619+
error.preventDefault();
1620+
}
16181621
};
16191622

16201623
RemoteContext.prototype.test_state = function(data) {

0 commit comments

Comments
 (0)