Bug 934425 - Enable the pref for wpt https test for setSinkId and update it to expect NotAllowedError. r=jib
authorAlex Chronopoulos <achronop@gmail.com>
Fri, 12 Oct 2018 08:46:31 +0000
changeset 496582 8fae8b6f75729913a112744214059491dd6b375b
parent 496581 341a3c4a36fda88db31ec95d3d6ad254019b36b3
child 496583 00388a3697f10a44b6cc2a7fccd34e6726411555
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [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 - Enable the pref for wpt https test for setSinkId and update it to expect NotAllowedError. r=jib Differential Revision: https://phabricator.services.mozilla.com/D5877
testing/web-platform/meta/audio-output/setSinkId.https.html.ini
testing/web-platform/tests/audio-output/setSinkId.https.html
--- a/testing/web-platform/meta/audio-output/setSinkId.https.html.ini
+++ b/testing/web-platform/meta/audio-output/setSinkId.https.html.ini
@@ -1,10 +1,2 @@
 [setSinkId.https.html]
-  [setSinkId on default audio output should always work]
-    expected: FAIL
-
-  [setSinkId fails with NotFoundError on made up deviceid]
-    expected: FAIL
-
-  [List media devices]
-    expected: FAIL
-
+  prefs: [media.setsinkid.enabled:true]
--- a/testing/web-platform/tests/audio-output/setSinkId.https.html
+++ b/testing/web-platform/tests/audio-output/setSinkId.https.html
@@ -1,45 +1,46 @@
 <!doctype html>
-<html>
 <head>
 <title>Test setSinkId behavior </title>
 <link rel="author" title="Dominique Hazael-Massieux" href="mailto:dom@w3.org"/>
 <link rel="help" href="https://www.w3.org/TR/audio-output/#dom-htmlmediaelement-setsinkid">
 </head>
-<body>
-<h1 class="instructions">Description</h1>
-<p class="instructions">This test checks that <code>setSinkId</code> follows the algorithm (but does not consider actual rendering of the audio which needs to be manual).</p>
-<div id='log'></div>
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
 <script>
 "use strict";
 
-const is_output = d => d.kind === "audiooutput";
 const audio = new Audio();
 
 promise_test(t => audio.setSinkId(""), "setSinkId on default audio output should always work");
 
-promise_test(t => promise_rejects(t, "NotFoundError", audio.setSinkId("inexistent_device_id")), "setSinkId fails with NotFoundError on made up deviceid");
+promise_test(t => promise_rejects(t, "NotFoundError", audio.setSinkId("nonexistent_device_id")),
+  "setSinkId fails with NotFoundError on made up deviceid");
+
+promise_test(async t => {
+  const list = await navigator.mediaDevices.enumerateDevices();
+  const outputDevicesList = list.filter(({kind}) => kind == "audiooutput");
+  assert_not_equals(outputDevicesList.length, 0,
+    "media device list includes at least one audio output device");
 
-promise_test(t =>
-             navigator.mediaDevices.enumerateDevices().then(list => {
-                 assert_not_equals(list.find(is_output), undefined, "media device list includes at least one audio output device");
-                 // since we haven't gained any specific permission,
-                 // for all listed audio output devices, calling setSinkId with device id can
-                 // either create a security exception or work and thus reflect the deviceId
-                 let acceptedDevice = 0;
-                 list.filter(is_output).forEach((d,i) => promise_test(td => audio.setSinkId(d.deviceId).then(r => {
-                     assert_equals(r, undefined, "setSinkId resolves with undefined");
-                     assert_equals(audio.sinkId, d.deviceId, "when it resolves, setSinkId updates sinkId to the requested deviceId");
-                     assert_equals(acceptedDevice, 0, "only one output device can be set without permission");
-                     acceptedDevice++;
-                     promise_test(t => audio.setSinkId(d.deviceId), "resetting sinkid on same current value should always work");
-                     promise_test(t => audio.setSinkId(""), "resetting sinkid on default audio output should always work");
-                 }, e => {
-                     assert_equals(e.name, "SecurityError", "On known devices, the only possible failure of setSinkId is a securityerror"); // assuming AbortError can't happen in the test environment by default
-                 }), "Correctly reacts to setting known deviceid as sinkid "  + i));
-             }), "List media devices");
+  let acceptedDevices = 0;
+  for (const {deviceId} of outputDevicesList) {
+    const {deviceId} = outputDevicesList[0];
+    const p1 = audio.setSinkId(deviceId);
+    assert_equals(audio.sinkId, "", "before it resolves, setSinkId is unchanged");
+    try {
+      let r = await p1;
+      assert_equals(acceptedDevices, 0, "only the default sink device can be set");
+      acceptedDevices++;
+      assert_equals(r, undefined, "setSinkId resolves with undefined");
+      assert_equals(audio.sinkId, deviceId, "when it resolves, setSinkId updates sinkId to the requested deviceId");
+      r = await audio.setSinkId(deviceId);
+      assert_equals(r, undefined, "resetting sinkid on same current value should always work");
+      r = await audio.setSinkId("");
+      assert_equals(r, undefined, "resetting sinkid on default audio output should always work");
+    } catch (e) {
+      assert_equals(e.name, "NotAllowedError", "Non-default devices are failing with NotAllowed error");
+    }
+  }
+}, "List device, setSinkId should on the default, the rest of the devices will get a NotAlowedError");
 
 </script>
-</body>
-</html>