Bug 1334825 - part 3: test case. r?bkelly draft
authorJohn Lin <jolin@mozilla.com>
Fri, 10 Feb 2017 16:38:35 +0800
changeset 481645 a9e69e8269851726a9967d0cd89efd4de6eadade
parent 481644 2c747e94f9530fc508e598484d99067c006f055c
child 481657 55baa5ec01af16d12233d5b7cc0919ce058341d6
push id44891
push userbmo:jolin@mozilla.com
push dateFri, 10 Feb 2017 08:51:17 +0000
reviewersbkelly
bugs1334825
milestone54.0a1
Bug 1334825 - part 3: test case. r?bkelly MozReview-Commit-ID: GIqlShOhbNT
dom/base/test/browser.ini
dom/base/test/browser_bug1334825.js
--- a/dom/base/test/browser.ini
+++ b/dom/base/test/browser.ini
@@ -1,11 +1,13 @@
 [DEFAULT]
 support-files =
+  audio.ogg
   empty.html
+  file_audioLoop.html
   file_bug1011748_redirect.sjs
   file_bug1011748_OK.sjs
   file_messagemanager_unload.html
   file_use_counter_outer.html
   file_use_counter_svg_getElementById.svg
   file_use_counter_svg_currentScale.svg
   file_use_counter_svg_fill_pattern_definition.svg
   file_use_counter_svg_fill_pattern.svg
@@ -22,8 +24,9 @@ skip-if = e10s # Bug 1315042
 [browser_messagemanager_targetframeloader.js]
 [browser_messagemanager_unload.js]
 [browser_pagehide_on_tab_close.js]
 skip-if = e10s # this tests non-e10s behavior. it's not expected to work in e10s.
 [browser_state_notifications.js]
 skip-if = true # Bug 1271028
 [browser_use_counters.js]
 [browser_bug1307747.js]
+[browser_bug1334825.js]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/browser_bug1334825.js
@@ -0,0 +1,66 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* Test for bug 1334825.
+   Load a tab with audio playing and send it to background.
+   setTimeout() throttling should be relaxed when audio is playing.
+   Then pause the audio. Throttling should work as expected.
+ */
+
+"use strict";
+
+const BASE_URI = "http://mochi.test:8888/browser/dom/base/test/file_audioLoop.html";
+
+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));
+
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, BASE_URI);
+  let browser = gBrowser.selectedBrowser;
+
+  // Wait for timeupdate event to make sure audio is playing.
+  yield ContentTask.spawn(browser, null, function () {
+    let audio = content.document.getElementsByTagName('audio')[0];
+    return ContentTaskUtils.waitForEvent(audio, 'timeupdate');
+  });
+
+  yield BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+  let time = yield ContentTask.spawn(browser, null, function () {
+    return new Promise(resolve => {
+      let start = content.performance.now();
+      let id = content.window.setTimeout(() => {
+        let end = content.performance.now();
+        content.window.clearTimeout(id);
+        resolve(end - start);
+      }, 0);
+    });
+  });
+  ok(time < 1000, "SetTimeout is not throttled with audio playing (" + time + " ms)");
+
+  // Pause the audio.
+  yield ContentTask.spawn(browser, null, function () {
+    let audio = content.document.getElementsByTagName('audio')[0];
+    let pause = ContentTaskUtils.waitForEvent(audio, 'pause');
+    audio.pause();
+    return pause;
+  });
+
+  time = yield ContentTask.spawn(browser, null, () => {
+    return new Promise(resolve => {
+      let start = content.performance.now();
+      let id = content.window.setTimeout(() => {
+        let end = content.performance.now();
+        content.window.clearInterval(id);
+        resolve(end - start);
+      }, 0);
+    });
+  });
+  ok(time > 2000, "SetTimeout is throttled with audio stopped (" + time + " ms)");
+
+  while (gBrowser.tabs.length > 1)
+    gBrowser.removeCurrentTab();
+});
\ No newline at end of file