summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/browser_bug1181073.js
blob: 6ee48144c4a9615621d4edd80319b44bd067238c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
add_task(function*() {
  // Make the min_background_timeout_value very high to avoid problems on slow machines
  yield new Promise(resolve => SpecialPowers.pushPrefEnv({
    'set': [['dom.min_background_timeout_value', 3000]]
  }, resolve));

  // Make a new tab, and put it in the background
  yield BrowserTestUtils.withNewTab("about:blank", function*(browser) {
    yield BrowserTestUtils.withNewTab("about:blank", function*() {
      let time = yield ContentTask.spawn(browser, null, function () {
        return new Promise(resolve => {
          let start = content.performance.now();
          let id = content.window.setInterval(function() {
            let end = content.performance.now();
            content.window.clearInterval(id);
            resolve(end - start);
          }, 0);
        });
      });

      ok(time > 2000, "Interval is throttled with no webaudio (" + time + " ms)");

      time = yield ContentTask.spawn(browser, null, function () {
        return new Promise(resolve => {
          // Create an audio context, and save it on the window so it doesn't get GCed
          content.window._audioCtx = new content.window.AudioContext();

          let start = content.performance.now();
          let id = content.window.setInterval(function() {
            let end = content.performance.now();
            content.window.clearInterval(id);
            resolve(end - start);
          }, 0);
        });
      });

      ok(time < 1000, "Interval is not throttled with an audio context present (" + time + " ms)");
    });
  });
});