tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

reftest-wait.js (1165B)


      1 /**
      2 * Remove the `reftest-wait` class on the document element.
      3 * The reftest runner will wait with taking a screenshot while
      4 * this class is present.
      5 *
      6 * See https://web-platform-tests.org/writing-tests/reftests.html#controlling-when-comparison-occurs
      7 */
      8 function takeScreenshot() {
      9    document.documentElement.classList.remove("reftest-wait");
     10 }
     11 
     12 /**
     13 * Call `takeScreenshot()` after a delay of at least |timeout| milliseconds.
     14 * @param {number} timeout - milliseconds
     15 */
     16 function takeScreenshotDelayed(timeout) {
     17    setTimeout(function() {
     18        takeScreenshot();
     19    }, timeout);
     20 }
     21 
     22 /**
     23 * Ensure that a precondition is met before waiting for a screenshot.
     24 * @param {bool} condition - Fail the test if this evaluates to false
     25 * @param {string} msg - Error message to write to the screenshot
     26 */
     27 function failIfNot(condition, msg) {
     28  const fail = () => {
     29    (document.body || document.documentElement).textContent = `Precondition Failed: ${msg}`;
     30    takeScreenshot();
     31  };
     32  if (!condition) {
     33    if (document.readyState == "interactive") {
     34      fail();
     35    } else {
     36      document.addEventListener("DOMContentLoaded", fail, false);
     37    }
     38  }
     39 }