Bug 1286429 - MediaDevices ondevicechange mochitest; r=jib
authorMunro Mengjue Chiang <mchiang@mozilla.com>
Fri, 12 Aug 2016 10:40:52 +0800
changeset 309760 5ff0ce53fccfeb3ef9ff14454045d02d66db6b21
parent 309759 5022a33fd3e950aafb09ac6dc64219ce71063857
child 309761 236306f262993214f3c9f3485f0fd05273c44b51
push id31455
push userryanvm@gmail.com
push dateWed, 17 Aug 2016 19:55:02 +0000
treeherderautoland@5ff0ce53fccf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1286429
milestone51.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 1286429 - MediaDevices ondevicechange mochitest; r=jib MozReview-Commit-ID: 9Mk1jDzRAEQ
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_ondevicechange.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -35,16 +35,18 @@ skip-if = toolkit == 'gonk' || buildapp 
 [test_dataChannel_basicDataOnly.html]
 [test_dataChannel_basicVideo.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version == '18' # b2g(Bug 960442, video support for WebRTC is disabled on b2g), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_bug1013809.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' # b2g emulator seems to be too slow (Bug 1016498 and 1008080)
 [test_dataChannel_noOffer.html]
 [test_enumerateDevices.html]
 skip-if = buildapp == 'mulet'
+[test_ondevicechange.html]
+skip-if = toolkit == 'gonk' || buildapp == 'mulet' || os == 'linux' || os == 'win' || os == 'android'
 [test_getUserMedia_audioCapture.html]
 skip-if = toolkit == 'gonk' || buildapp == 'mulet' || android_version == '18' # b2g emulator seems to be too slow (Bug 1016498 and 1008080), android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_addTrackRemoveTrack.html]
 skip-if = (toolkit == 'gonk' || buildapp == 'mulet' && debug) # debug-only failure
 [test_getUserMedia_addtrack_removetrack_events.html]
 [test_getUserMedia_basicAudio.html]
 skip-if = (toolkit == 'gonk' || buildapp == 'mulet' && debug) # debug-only failure
 [test_getUserMedia_basicVideo.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_ondevicechange.html
@@ -0,0 +1,80 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1041393
+-->
+<head>
+  <meta charset="utf-8">
+  <title>onndevicechange tests</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1152383">ondevicechange tests</a>
+<script type="application/javascript">
+
+const RESPONSE_WAIT_TIME_MS = 10000;
+
+function wait(time, message) {
+  return new Promise(r => setTimeout(() => r(message), time));
+}
+
+function OnDeviceChangeEvent() {
+  return new Promise(resolve => navigator.mediaDevices.ondevicechange = resolve);
+}
+
+function OnDeviceChangeEventReceived() {
+  return Promise.race([
+    OnDeviceChangeEvent(),
+    wait(RESPONSE_WAIT_TIME_MS).then(() => Promise.reject("Timed out while waiting for devicechange event"))
+  ]);
+}
+
+function OnDeviceChangeEventNotReceived() {
+  return Promise.race([
+    OnDeviceChangeEvent().then(() => Promise.reject("ondevicechange event is fired unexpectedly.")),
+    wait(RESPONSE_WAIT_TIME_MS)
+  ]);
+}
+
+var pushPrefs = (...p) => new Promise(r => SpecialPowers.pushPrefEnv({set: p}, r));
+
+var videoTracks;
+
+SimpleTest.requestCompleteLog();
+SimpleTest.waitForExplicitFinish();
+SimpleTest.requestFlakyTimeout("Fake devicechange event is fired periodically, \
+so we need to wait a while to make sure the event is fired or not as we expect.");
+
+var videoTracks;
+
+function wait(time, message) {
+  return new Promise(r => setTimeout(() => r(message), time));
+}
+
+pushPrefs(["media.ondevicechange.fakeDeviceChangeEvent.enabled", true])
+.then(() => pushPrefs(["media.navigator.permission.disabled", false]))
+.then(() => pushPrefs(["media.ondevicechange.enabled", true]))
+.then(() => info("assure devicechange event is NOT fired when gUM is NOT in use and permanent permission is NOT granted"))
+.then(() => OnDeviceChangeEventNotReceived())
+.then(() => ok(true, "devicechange event is NOT fired when gUM is NOT in use and permanent permission is NOT granted"))
+.then(() => pushPrefs(['media.navigator.permission.disabled', true]))
+.then(() => info("assure devicechange event is fired when gUM is NOT in use and permanent permission is granted"))
+.then(() => OnDeviceChangeEventReceived())
+.then(() => ok(true, "devicechange event is fired when gUM is NOT in use and permanent permission is granted"))
+.then(() => navigator.mediaDevices.getUserMedia({video: true, fake: true}))
+.then(st => {videoTracks = st.getVideoTracks();})
+.then(() => info("assure devicechange event is fired when gUM is in use"))
+.then(() => OnDeviceChangeEventReceived())
+.then(() => ok(true, "devicechange event is fired when gUM is in use"))
+.catch(e => ok(false, "Error: " + e))
+.then(() => {
+  if(videoTracks)
+    videoTracks.forEach(track => track.stop());
+})
+.then(() => SimpleTest.finish());
+
+</script>
+</pre>
+</body>
+</html>