Bug 1348174 - Test that deviceIds are stable for same origin and differ across origins.
MozReview-Commit-ID: LEkHzgUZwqd
--- 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,57 @@ 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) {
+ // TODO: s/todo/ok/ once bug 1340163 is fixed.
+ todo(!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>