tor-browser

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

browser_timeout_throttling_with_audio_playback.js (2399B)


      1 // The tab closing code leaves an uncaught rejection. This test has been
      2 // whitelisted until the issue is fixed.
      3 if (!gMultiProcessBrowser) {
      4  const { PromiseTestUtils } = ChromeUtils.importESModule(
      5    "resource://testing-common/PromiseTestUtils.sys.mjs"
      6  );
      7  PromiseTestUtils.expectUncaughtRejection(/is no longer, usable/);
      8 }
      9 
     10 const kBaseURI = "http://mochi.test:8888/browser/dom/base/test/empty.html";
     11 var testURLs = [
     12  "http://mochi.test:8888/browser/dom/base/test/file_audioLoop.html",
     13  "http://mochi.test:8888/browser/dom/base/test/file_audioLoopInIframe.html",
     14  "http://mochi.test:8888/browser/dom/base/test/file_webaudio_startstop.html",
     15 ];
     16 
     17 // We want to ensure that while audio is being played back, a background tab is
     18 // treated the same as a foreground tab as far as timeout throttling is concerned.
     19 // So we use a 100,000 second minimum timeout value for background tabs.  This
     20 // means that in case the test fails, it will time out in practice, but just for
     21 // sanity the test condition ensures that the observed timeout delay falls in
     22 // this range.
     23 const kMinTimeoutBackground = 100 * 1000 * 1000;
     24 
     25 const kDelay = 10;
     26 
     27 async function runTest(url) {
     28  let currentTab = gBrowser.selectedTab;
     29  let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kBaseURI);
     30  let newBrowser = gBrowser.getBrowserForTab(newTab);
     31 
     32  // Wait for the UI to indicate that audio is being played back.
     33  let promise = BrowserTestUtils.waitForAttribute("soundplaying", newTab);
     34  BrowserTestUtils.startLoadingURIString(newBrowser, url);
     35  await promise;
     36 
     37  // Put the tab in the background.
     38  await BrowserTestUtils.switchTab(gBrowser, currentTab);
     39 
     40  let timeout = await SpecialPowers.spawn(
     41    newBrowser,
     42    [kDelay],
     43    function (delay) {
     44      return new Promise(resolve => {
     45        let before = new Date();
     46        content.window.setTimeout(function () {
     47          let after = new Date();
     48          resolve(after - before);
     49        }, delay);
     50      });
     51    }
     52  );
     53  Assert.lessOrEqual(
     54    timeout,
     55    kMinTimeoutBackground,
     56    `Got the correct timeout (${timeout})`
     57  );
     58 
     59  // All done.
     60  BrowserTestUtils.removeTab(newTab);
     61 }
     62 
     63 add_setup(async function () {
     64  await SpecialPowers.pushPrefEnv({
     65    set: [["dom.min_background_timeout_value", kMinTimeoutBackground]],
     66  });
     67 });
     68 
     69 add_task(async function test() {
     70  for (var url of testURLs) {
     71    await runTest(url);
     72  }
     73 });