Bug 934425 - Add mochitest for setSinkId. r=jib
authorAlex Chronopoulos <achronop@gmail.com>
Fri, 12 Oct 2018 08:45:17 +0000
changeset 499292 94caf76cf9a3d32fc46780f6144b027fd4b11536
parent 499291 55c832b1f2fecec90fb4afef27669ab971fc2fab
child 499293 341a3c4a36fda88db31ec95d3d6ad254019b36b3
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs934425
milestone64.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 934425 - Add mochitest for setSinkId. r=jib Differential Revision: https://phabricator.services.mozilla.com/D5875
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_setSinkId.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -353,8 +353,11 @@ skip-if = (android_version == '18') # an
 skip-if = (android_version == '18') # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_peerConnection_verifyDescriptions.html]
 skip-if = (android_version == '18')
 [test_fingerprinting_resistance.html]
 [test_getUserMedia_nonDefaultRate.html]
 [test_peerConnection_nonDefaultRate.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_forceSampleRate.html]
+
+[test_setSinkId.html]
+skip-if = os != 'linux' # the only platform with real devices
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_setSinkId.html
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+
+<audio id="audio"></audio>
+
+<script>
+  createHTML({
+    title: "SetSinkId in HTMLMediaElement",
+    bug: "934425",
+  });
+
+  /**
+   * Run a test to verify set sink id in audio element.
+   */
+  runTest(async () => {
+    await pushPrefs(["media.setsinkid.enabled", true]);
+
+    if (!SpecialPowers.getCharPref("media.audio_loopback_dev", "")) {
+      ok(false, "No loopback device set by framework. Try --use-test-media-devices");
+      return;
+    }
+
+    const allDevices = await navigator.mediaDevices.enumerateDevices();
+    const audioDevices = allDevices.filter(({kind}) => kind == 'audiooutput');
+    info(`Found  ${audioDevices.length} output devices`);
+    ok(audioDevices.length > 0, "More than one output device found");
+
+    is(audio.sinkId, "", "Initial value is empty string");
+
+    const p = audio.setSinkId(audioDevices[0].deviceId);
+    is(audio.sinkId, "", "Value is unchanged upon function return");
+    is(await p, undefined, "promise resolves with undefined");
+    is(audio.sinkId, audioDevices[0].deviceId, `Sink device is set, id: ${audio.sinkId}`);
+
+    await audio.setSinkId(audioDevices[0].deviceId);
+    ok(true, `Sink device is set for 2nd time for the same id: ${audio.sinkId}`);
+
+    try {
+      await audio.setSinkId("dummy sink id");
+      ok(false, "Never enter here, this must fail");
+    } catch (error) {
+      ok(true, `Set sink id expected to fail: ${error}`);
+      is(error.name, "NotFoundError", "Verify correct error");
+    }
+  });
+
+</script>
+</pre>
+</body>
+</html>