tor-browser

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

browser_bug1309630.js (2293B)


      1 "use strict";
      2 
      3 const BASE = "https://example.com/browser/dom/xslt/tests/browser";
      4 const SERVER_SCRIPT = `${BASE}/bug1309630.sjs`;
      5 
      6 function resetCounter() {
      7  return fetch(`${SERVER_SCRIPT}?reset_counter`);
      8 }
      9 function recordCounter() {
     10  return fetch(`${SERVER_SCRIPT}?record_counter`);
     11 }
     12 // Returns a promise that resolves to true if the counter in
     13 // bug1309630.sjs changed by more than 'value' since last calling
     14 // recordCounter(), or false if it doesn't and we time out.
     15 function waitForCounterChangeAbove(value) {
     16  return TestUtils.waitForCondition(() =>
     17    fetch(`${SERVER_SCRIPT}?get_counter_change`).then(response =>
     18      response.ok
     19        ? response.text().then(str => Number(str) > value)
     20        : Promise.reject()
     21    )
     22  ).then(
     23    () => true,
     24    () => false
     25  );
     26 }
     27 
     28 add_task(async function test_eternal_xslt() {
     29  await resetCounter();
     30  await BrowserTestUtils.withNewTab(
     31    { gBrowser, url: SERVER_SCRIPT, waitForLoad: false },
     32    async function (browser) {
     33      info("Waiting for XSLT to keep loading");
     34 
     35      ok(
     36        await waitForCounterChangeAbove(1),
     37        "We should receive at least a request from the document function call."
     38      );
     39 
     40      info("Navigating to about:blank");
     41      BrowserTestUtils.startLoadingURIString(browser, "about:blank");
     42      await BrowserTestUtils.browserLoaded(browser);
     43 
     44      info("Check to see if XSLT stops loading");
     45      await recordCounter();
     46      ok(
     47        !(await waitForCounterChangeAbove(0)),
     48        "We shouldn't receive more requests to the XSLT file within the timeout period."
     49      );
     50    }
     51  );
     52 
     53  await resetCounter();
     54  await BrowserTestUtils.withNewTab(
     55    { gBrowser, url: `${BASE}/file_bug1309630.html` },
     56    async function (browser) {
     57      ok(
     58        await waitForCounterChangeAbove(1),
     59        "We should receive at least a request from the document function call."
     60      );
     61 
     62      info("Navigating to about:blank");
     63      BrowserTestUtils.startLoadingURIString(browser, "about:blank");
     64      await BrowserTestUtils.browserLoaded(browser);
     65 
     66      info("Check to see if XSLT stops loading");
     67      await recordCounter();
     68      ok(
     69        !(await waitForCounterChangeAbove(0)),
     70        "We shouldn't receive more requests to the XSLT file within the timeout period."
     71      );
     72    }
     73  );
     74 });