Bug 1519430 - part3 : add test. r=padenot
☠☠ backed out by eff7fd1e573c ☠ ☠
authorAlastor Wu <alwu@mozilla.com>
Thu, 17 Jan 2019 02:58:05 +0000
changeset 514224 b7bc38b0f9c5614fb4fd5edf7e4686c9b3b0d179
parent 514223 987aa2594ba62b25ca9a36ae51e8c4d7afb0939e
child 514225 263e45bdcd59a06a69caa935a5e8ab8d2dd2a1d1
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1519430
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1519430 - part3 : add test. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D16614
dom/media/test/mochitest.ini
dom/media/test/test_autoplay_policy_web_audio_notResumePageInvokedSuspendedAudioContext.html
--- a/dom/media/test/mochitest.ini
+++ b/dom/media/test/mochitest.ini
@@ -719,16 +719,18 @@ skip-if = android_version >= '23' # bug 
 [test_autoplay_policy_key_blacklist.html]
 skip-if = android_version >= '23' || (verify && debug && (os == 'win')) # bug 1424903
 [test_autoplay_policy_unmute_pauses.html]
 skip-if = android_version >= '23' # bug 1424903
 [test_autoplay_policy_play_before_loadedmetadata.html]
 skip-if = android_version >= '23' # bug 1424903
 [test_autoplay_policy_permission.html]
 skip-if = android_version >= '23' # bug 1424903
+[test_autoplay_policy_web_audio_notResumePageInvokedSuspendedAudioContext.html]
+skip-if = android_version >= '23' # bug 1424903
 [test_autoplay_policy_web_audio_mediaElementAudioSourceNode.html]
 skip-if = android_version >= '23' # bug 1424903
 [test_buffered.html]
 skip-if = android_version == '22' # bug 1308388, android(bug 1232305)
 [test_bug448534.html]
 [test_bug463162.xhtml]
 [test_bug465498.html]
 skip-if = toolkit == 'android' # android(bug 1232305)
new file mode 100644
--- /dev/null
+++ b/dom/media/test/test_autoplay_policy_web_audio_notResumePageInvokedSuspendedAudioContext.html
@@ -0,0 +1,95 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Autoplay policy test : do not resume AudioContext which is suspended by page</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script type="text/javascript" src="manifest.js"></script>
+</head>
+<body>
+<script>
+
+/**
+ * This test is used to ensure we won't resume AudioContext which is suspended
+ * by page (it means calling suspend() explicitly) when calling
+ * `AudioScheduledSourceNode.start()`.
+ */
+
+SimpleTest.waitForExplicitFinish();
+
+(async function testNotResumeUserInvokedSuspendedAudioContext() {
+  await setupTestPreferences();
+
+  const nodeTypes = ["AudioBufferSourceNode", "ConstantSourceNode", "OscillatorNode"];
+  for (let nodeType of nodeTypes) {
+    info(`- create an audio context which should not be allowed to start, it's allowed to be created, but it's forbidden to start -`);
+    await createAudioContext();
+
+    info(`- explicitly suspend the AudioContext in the page -`);
+    suspendAudioContext();
+
+    info(`- start an 'AudioScheduledSourceNode', and check that the AudioContext does not start, because it has been explicitly suspended -`);
+    await createAndStartAudioScheduledSourceNode(nodeType);
+  }
+
+  SimpleTest.finish();
+})();
+
+/**
+ * Test utility functions
+ */
+
+function setupTestPreferences() {
+  return SpecialPowers.pushPrefEnv({"set": [
+    ["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
+    ["media.autoplay.enabled.user-gestures-needed", true],
+    ["media.autoplay.block-webaudio", true],
+    ["media.autoplay.block-event.enabled", true],
+  ]});
+}
+
+async function createAudioContext() {
+  window.ac = new AudioContext();
+  await once(ac, "blocked");
+  is(ac.state, "suspended", `AudioContext is blocked.`);
+}
+
+function suspendAudioContext() {
+  try {
+    ac.suspend();
+  } catch(e) {
+    ok(false, `AudioContext suspend failed!`);
+  }
+}
+
+async function createAndStartAudioScheduledSourceNode(nodeType) {
+  let node;
+  info(`- create ${nodeType} -`);
+  switch (nodeType) {
+    case "AudioBufferSourceNode":
+      node = ac.createBufferSource();
+      break;
+    case "ConstantSourceNode":
+      node = ac.createConstantSource();
+      break;
+    case "OscillatorNode":
+      node = ac.createOscillator();
+      break;
+    default:
+      ok(false, "undefined AudioScheduledSourceNode type");
+      return;
+  }
+  node.connect(ac.destination);
+
+  // activate the document in order to allow autoplay.
+  SpecialPowers.wrap(document).notifyUserGestureActivation();
+  node.start();
+
+  await once(ac, "blocked");
+  is(ac.state, "suspended", `AudioContext should not be resumed.`);
+
+  // reset the activation flag of the document in order not to interfere next test.
+  SpecialPowers.wrap(document).clearUserGestureActivation();
+}
+
+</script>