Bug 934425 - Add mochitest for setSinkId. r?jib draft
authorAlex Chronopoulos <achronop@gmail.com>
Thu, 09 Aug 2018 17:14:28 +0300
changeset 827857 da535568f290872945a3f39882cd5471394569a6
parent 827856 855b9882bf68ffdbf01a9a49396b14d0dfd9c0a1
push id118601
push userachronop@gmail.com
push dateThu, 09 Aug 2018 14:17:09 +0000
reviewersjib
bugs934425
milestone63.0a1
Bug 934425 - Add mochitest for setSinkId. r?jib MozReview-Commit-ID: JhjQtxj3146
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
@@ -345,8 +345,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,59 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+
+<audio id='a1'></audio>
+
+<script>
+  createHTML({
+    title: "SetSinkId in HTMLMediaElement",
+    bug: "934425",
+  });
+  SpecialPowers.setBoolPref("media.setsinkid.enabled", true);
+
+  /**
+   * Run a test to verify set sink id in audio element.
+   */
+  scriptsReady.then(() => runTestWhenReady(async () => {
+    let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev", "");
+    if (!audioDevice) {
+      todo(false, "No loopback device set by framework. Try --use-test-media-devices");
+      return Promise.resolve();
+    }
+
+    let allDevices = await navigator.mediaDevices.enumerateDevices()
+    let audioDevices = allDevices.filter(device => device.kind === 'audiooutput');
+    info("Found " + audioDevices.length + " output devices");
+    ok(audioDevices.length > 0, "More than one output device found");
+
+    try {
+      await a1.setSinkId(audioDevices[0].deviceId)
+      ok(true, "Sink device is set, id: " + a1.sinkId);
+    } catch(error) {
+      ok(false, "Set sink id rejected: " + error);
+    }
+
+    try {
+      await a1.setSinkId(audioDevices[0].deviceId)
+      ok(true, "Sink device is set for 2nd time, id: " + a1.sinkId);
+    } catch(error) {
+      ok(false, "Set sink id rejected: " + error);
+    }
+
+    try {
+      await a1.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");
+    }
+  }))
+  .then(() => finish())
+</script>
+</pre>
+</body>
+</html>