11cb0ef41Sopenharmony_ci/* global add_completion_callback */
21cb0ef41Sopenharmony_ci/* global setup */
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci/*
51cb0ef41Sopenharmony_ci * This file is intended for vendors to implement code needed to integrate
61cb0ef41Sopenharmony_ci * testharness.js tests with their own test systems.
71cb0ef41Sopenharmony_ci *
81cb0ef41Sopenharmony_ci * Typically test system integration will attach callbacks when each test has
91cb0ef41Sopenharmony_ci * run, using add_result_callback(callback(test)), or when the whole test file
101cb0ef41Sopenharmony_ci * has completed, using
111cb0ef41Sopenharmony_ci * add_completion_callback(callback(tests, harness_status)).
121cb0ef41Sopenharmony_ci *
131cb0ef41Sopenharmony_ci * For more documentation about the callback functions and the
141cb0ef41Sopenharmony_ci * parameters they are called with see testharness.js
151cb0ef41Sopenharmony_ci */
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cifunction dump_test_results(tests, status) {
181cb0ef41Sopenharmony_ci    var results_element = document.createElement("script");
191cb0ef41Sopenharmony_ci    results_element.type = "text/json";
201cb0ef41Sopenharmony_ci    results_element.id = "__testharness__results__";
211cb0ef41Sopenharmony_ci    var test_results = tests.map(function(x) {
221cb0ef41Sopenharmony_ci        return {name:x.name, status:x.status, message:x.message, stack:x.stack}
231cb0ef41Sopenharmony_ci    });
241cb0ef41Sopenharmony_ci    var data = {test:window.location.href,
251cb0ef41Sopenharmony_ci                tests:test_results,
261cb0ef41Sopenharmony_ci                status: status.status,
271cb0ef41Sopenharmony_ci                message: status.message,
281cb0ef41Sopenharmony_ci                stack: status.stack};
291cb0ef41Sopenharmony_ci    results_element.textContent = JSON.stringify(data);
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    // To avoid a HierarchyRequestError with XML documents, ensure that 'results_element'
321cb0ef41Sopenharmony_ci    // is inserted at a location that results in a valid document.
331cb0ef41Sopenharmony_ci    var parent = document.body
341cb0ef41Sopenharmony_ci        ? document.body                 // <body> is required in XHTML documents
351cb0ef41Sopenharmony_ci        : document.documentElement;     // fallback for optional <body> in HTML5, SVG, etc.
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci    parent.appendChild(results_element);
381cb0ef41Sopenharmony_ci}
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ciadd_completion_callback(dump_test_results);
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci/* If the parent window has a testharness_properties object,
431cb0ef41Sopenharmony_ci * we use this to provide the test settings. This is used by the
441cb0ef41Sopenharmony_ci * default in-browser runner to configure the timeout and the
451cb0ef41Sopenharmony_ci * rendering of results
461cb0ef41Sopenharmony_ci */
471cb0ef41Sopenharmony_citry {
481cb0ef41Sopenharmony_ci    if (window.opener && "testharness_properties" in window.opener) {
491cb0ef41Sopenharmony_ci        /* If we pass the testharness_properties object as-is here without
501cb0ef41Sopenharmony_ci         * JSON stringifying and reparsing it, IE fails & emits the message
511cb0ef41Sopenharmony_ci         * "Could not complete the operation due to error 80700019".
521cb0ef41Sopenharmony_ci         */
531cb0ef41Sopenharmony_ci        setup(JSON.parse(JSON.stringify(window.opener.testharness_properties)));
541cb0ef41Sopenharmony_ci    }
551cb0ef41Sopenharmony_ci} catch (e) {
561cb0ef41Sopenharmony_ci}
571cb0ef41Sopenharmony_ci// vim: set expandtab shiftwidth=4 tabstop=4:
58