/* global add_completion_callback */
/* global setup */

/*
 * This file is intended for vendors to implement code needed to integrate
 * testharness.js tests with their own test systems.
 *
 * Typically test system integration will attach callbacks when each test has
 * run, using add_result_callback(callback(test)), or when the whole test file
 * has completed, using
 * add_completion_callback(callback(tests, harness_status)).
 *
 * For more documentation about the callback functions and the
 * parameters they are called with see testharness.js
 */

/* If the parent window has a testharness_properties object,
 * we use this to provide the test settings. This is used by the
 * default in-browser runner to configure the timeout and the
 * rendering of results
 */
try {
    if (window.opener && "testharness_properties" in window.opener) {
        /* If we pass the testharness_properties object as-is here without
         * JSON stringifying and reparsing it, IE fails & emits the message
         * "Could not complete the operation due to error 80700019".
         */
        setup(JSON.parse(JSON.stringify(window.opener.testharness_properties)));
    }
} catch (e) {
}

add_completion_callback(function(tests, harness_status) {
    if (window.internals) {
        // NOTE: If we're running inside the test harness,
        //       filter out stuff we don't want to see, like local filesystem paths.
        for (const details of document.querySelectorAll("pre, details")) {
            details.style.display = 'none';
        }
        window.internals.signalTextTestIsDone(document.getElementById("log").innerText);
    }
});


// vim: set expandtab shiftwidth=4 tabstop=4:
