Bug 1334825 - part 3: test case. r?bkelly
MozReview-Commit-ID: GIqlShOhbNT
--- 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