1/* global add_completion_callback */
2/* global setup */
3
4/*
5 * This file is intended for vendors to implement code needed to integrate
6 * testharness.js tests with their own test systems.
7 *
8 * Typically test system integration will attach callbacks when each test has
9 * run, using add_result_callback(callback(test)), or when the whole test file
10 * has completed, using
11 * add_completion_callback(callback(tests, harness_status)).
12 *
13 * For more documentation about the callback functions and the
14 * parameters they are called with see testharness.js
15 */
16
17function dump_test_results(tests, status) {
18    var results_element = document.createElement("script");
19    results_element.type = "text/json";
20    results_element.id = "__testharness__results__";
21    var test_results = tests.map(function(x) {
22        return {name:x.name, status:x.status, message:x.message, stack:x.stack}
23    });
24    var data = {test:window.location.href,
25                tests:test_results,
26                status: status.status,
27                message: status.message,
28                stack: status.stack};
29    results_element.textContent = JSON.stringify(data);
30
31    // To avoid a HierarchyRequestError with XML documents, ensure that 'results_element'
32    // is inserted at a location that results in a valid document.
33    var parent = document.body
34        ? document.body                 // <body> is required in XHTML documents
35        : document.documentElement;     // fallback for optional <body> in HTML5, SVG, etc.
36
37    parent.appendChild(results_element);
38}
39
40add_completion_callback(dump_test_results);
41
42/* If the parent window has a testharness_properties object,
43 * we use this to provide the test settings. This is used by the
44 * default in-browser runner to configure the timeout and the
45 * rendering of results
46 */
47try {
48    if (window.opener && "testharness_properties" in window.opener) {
49        /* If we pass the testharness_properties object as-is here without
50         * JSON stringifying and reparsing it, IE fails & emits the message
51         * "Could not complete the operation due to error 80700019".
52         */
53        setup(JSON.parse(JSON.stringify(window.opener.testharness_properties)));
54    }
55} catch (e) {
56}
57// vim: set expandtab shiftwidth=4 tabstop=4:
58