Blame dom/base/test/browser_timeout_throttling_with_audio_playback.js

Packit f0b94e
// The tab closing code leaves an uncaught rejection. This test has been
Packit f0b94e
// whitelisted until the issue is fixed.
Packit f0b94e
if (!gMultiProcessBrowser) {
Packit f0b94e
  ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", this);
Packit f0b94e
  PromiseTestUtils.expectUncaughtRejection(/is no longer, usable/);
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
const kBaseURI = "http://mochi.test:8888/browser/dom/base/test/empty.html";
Packit f0b94e
const kPluginJS = "chrome://mochitests/content/browser/dom/base/test/plugin.js";
Packit f0b94e
var testURLs = [
Packit f0b94e
  "http://mochi.test:8888/browser/dom/base/test/file_audioLoop.html",
Packit f0b94e
  "http://mochi.test:8888/browser/dom/base/test/file_audioLoopInIframe.html",
Packit f0b94e
  "http://mochi.test:8888/browser/dom/base/test/file_pluginAudio.html",
Packit f0b94e
  "http://mochi.test:8888/browser/dom/base/test/file_webaudio_startstop.html",
Packit f0b94e
];
Packit f0b94e
Packit f0b94e
// We want to ensure that while audio is being played back, a background tab is
Packit f0b94e
// treated the same as a foreground tab as far as timeout throttling is concerned.
Packit f0b94e
// So we use a 100,000 second minimum timeout value for background tabs.  This
Packit f0b94e
// means that in case the test fails, it will time out in practice, but just for
Packit f0b94e
// sanity the test condition ensures that the observed timeout delay falls in
Packit f0b94e
// this range.
Packit f0b94e
const kMinTimeoutBackground = 100 * 1000 * 1000;
Packit f0b94e
Packit f0b94e
const kDelay = 10;
Packit f0b94e
Packit f0b94e
Services.scriptloader.loadSubScript(kPluginJS, this);
Packit f0b94e
Packit f0b94e
async function runTest(url) {
Packit f0b94e
  let currentTab = gBrowser.selectedTab;
Packit f0b94e
  let newTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kBaseURI);
Packit f0b94e
  let newBrowser = gBrowser.getBrowserForTab(newTab);
Packit f0b94e
Packit f0b94e
  // Wait for the UI to indicate that audio is being played back.
Packit f0b94e
  let promise = BrowserTestUtils.waitForAttribute("soundplaying", newTab, "true");
Packit f0b94e
  newBrowser.loadURI(url);
Packit f0b94e
  await promise;
Packit f0b94e
Packit f0b94e
  // Put the tab in the background.
Packit f0b94e
  await BrowserTestUtils.switchTab(gBrowser, currentTab);
Packit f0b94e
Packit f0b94e
  let timeout = await ContentTask.spawn(newBrowser, kDelay, function(delay) {
Packit f0b94e
    return new Promise(resolve => {
Packit f0b94e
      let before = new Date();
Packit f0b94e
      content.window.setTimeout(function() {
Packit f0b94e
        let after = new Date();
Packit f0b94e
        resolve(after - before);
Packit f0b94e
      }, delay);
Packit f0b94e
    });
Packit f0b94e
  });
Packit f0b94e
  ok(timeout <= kMinTimeoutBackground, `Got the correct timeout (${timeout})`);
Packit f0b94e
Packit f0b94e
  // All done.
Packit f0b94e
  await BrowserTestUtils.removeTab(newTab);
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
add_task(async function setup() {
Packit f0b94e
  await SpecialPowers.pushPrefEnv({"set": [
Packit f0b94e
    ["dom.min_background_timeout_value", kMinTimeoutBackground],
Packit f0b94e
  ]});
Packit f0b94e
});
Packit f0b94e
Packit f0b94e
add_task(async function test() {
Packit f0b94e
  for (var url of testURLs) {
Packit f0b94e
    await runTest(url);
Packit f0b94e
  }
Packit f0b94e
});