Bug 1348174 - Test that deviceIds are stable for same origin and differ across origins. r=jesup, a=test-only
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 20 Mar 2017 18:28:52 +0100
changeset 377207 3abcaea76fa30d9b568cf8b664d7ecf8f55f4abd
parent 377206 fc330c62b897264f113013ea16def5ec4d32cd93
child 377208 9e3e0759726b21e37afe2e55acf53f13a94f3918
push id7168
push userryanvm@gmail.com
push dateThu, 06 Apr 2017 21:11:01 +0000
treeherdermozilla-beta@65eb65fb5933 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, test-only
bugs1348174
milestone53.0
Bug 1348174 - Test that deviceIds are stable for same origin and differ across origins. r=jesup, a=test-only MozReview-Commit-ID: LEkHzgUZwqd
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_enumerateDevices.html
dom/media/tests/mochitest/test_enumerateDevices_iframe.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -34,16 +34,18 @@ skip-if = android_version == '18' # andr
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_basicDataOnly.html]
 [test_dataChannel_basicVideo.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_bug1013809.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_noOffer.html]
 [test_enumerateDevices.html]
+[test_enumerateDevices_iframe.html]
+skip-if = true # needed by test_enumerateDevices.html on builders
 [test_ondevicechange.html]
 skip-if = os == 'android'
 [test_getUserMedia_active_autoplay.html]
 [test_getUserMedia_audioCapture.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_addTrackRemoveTrack.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_addtrack_removetrack_events.html]
--- a/dom/media/tests/mochitest/test_enumerateDevices.html
+++ b/dom/media/tests/mochitest/test_enumerateDevices.html
@@ -76,16 +76,56 @@ runTest(async () => {
   await mustSucceed("unknown plain deviceId on audio",
                     () => gUM({ audio: { deviceId: unknownId } }));
   await mustFailWith("unknown exact deviceId on video",
                      "OverconstrainedError", "deviceId",
                      () => gUM({ video: { deviceId: { exact: unknownId } } }));
   await mustFailWith("unknown exact deviceId on audio",
                      "OverconstrainedError", "deviceId",
                      () => gUM({ audio: { deviceId: { exact: unknownId } } }));
+
+  // Check that deviceIds are stable for same origin and differ across origins.
+
+  const path = "/tests/dom/media/tests/mochitest/test_enumerateDevices_iframe.html";
+  const origins = ["http://mochi.test:8888", "http://test1.mochi.test:8888"];
+  info(window.location);
+
+  let haveDevicesMap = new Promise(resolve => {
+    let map = new Map();
+    window.addEventListener("message", ({origin, data}) => {
+      ok(origins.includes(origin), "Got message from expected origin");
+      map.set(origin, JSON.parse(data));
+      if (map.size < origins.length) return;
+      resolve(map);
+    });
+  });
+
+  await Promise.all(origins.map(origin => {
+    let iframe = document.createElement("iframe");
+    iframe.src = origin + path;
+    info(iframe.src);
+    document.documentElement.appendChild(iframe);
+    return new Promise(resolve => iframe.onload = resolve);
+  }));
+  let devicesMap = await haveDevicesMap;
+  let [sameOriginDevices, differentOriginDevices] = origins.map(o => devicesMap.get(o));
+
+  is(sameOriginDevices.length, devices.length);
+  is(differentOriginDevices.length, devices.length);
+  [...sameOriginDevices, ...differentOriginDevices].forEach(d => validateDevice(d));
+
+  for (let device of sameOriginDevices) {
+    ok(devices.find(d => d.deviceId == device.deviceId),
+       "Same origin deviceId for " + device.label + " must match");
+  }
+  for (let device of differentOriginDevices) {
+    ok(!devices.find(d => d.deviceId == device.deviceId),
+         "Different origin deviceId for " + device.label + " must be different");
+  }
+
   // Check the special case of no devices found.
   await pushPrefs(["media.navigator.streams.fake", false],
                   ["media.audio_loopback_dev", "none"],
                   ["media.video_loopback_dev", "none"]);
   devices = await navigator.mediaDevices.enumerateDevices();
   ok(devices.length === 0, "No devices found");
 });
 </script>
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_enumerateDevices_iframe.html
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+<pre id="test">
+<script type="application/javascript">
+/**
+  Runs inside iframe in test_enumerateDevices.html.
+*/
+
+var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
+var gUM = c => navigator.mediaDevices.getUserMedia(c);
+
+(async () => {
+  await pushPrefs(["media.navigator.streams.fake", true]);
+
+  let devices = await navigator.mediaDevices.enumerateDevices();
+  parent.postMessage(JSON.stringify(devices), "http://mochi.test:8888");
+
+})().catch(e => setTimeout(() => { throw e; }));
+</script>
+</pre>
+</body>
+</html>