Bug 853356 - Test: Check mediastream track according to request type. r=jsmith
authorAlfredo Yang <ayang@mozilla.com>
Sat, 26 Oct 2013 21:20:31 -0400
changeset 167144 c7ea3c8c837587a82510b7b5812ddb75ee583f7d
parent 167143 987b3ec24f6837525d6c5f39a60c5eb2feb8e55e
child 167145 bd9d47feac878aa9f46e3ff180cb6a3eca820a3d
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsmith
bugs853356
milestone27.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 853356 - Test: Check mediastream track according to request type. r=jsmith
dom/media/tests/mochitest/Makefile.in
dom/media/tests/mochitest/test_getUserMedia_permission.html
--- a/dom/media/tests/mochitest/Makefile.in
+++ b/dom/media/tests/mochitest/Makefile.in
@@ -2,8 +2,14 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # The following tests are leaking and cannot be run by default yet
 ifdef MOZ_WEBRTC_LEAKING_TESTS
 MOCHITEST_FILES += \
   $(NULL)
 endif
+
+ifdef MOZ_B2G_CAMERA
+MOCHITEST_FILES += \
+  test_getUserMedia_permission.html \
+  $(NULL)
+endif
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_permission.html
@@ -0,0 +1,77 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=853356
+-->
+<head>
+  <meta charset="utf-8">
+  <title>mozGetUserMedia Permission Test</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=853356">Display camera/microphone permission acquisition prompt</a>
+<script type="application/javascript">
+var MockPermissionPrompt = SpecialPowers.MockPermissionPrompt;
+MockPermissionPrompt.init();
+
+var gCount = 0;
+var gTests = [
+  {
+    constraints: {video: true, audio: false}
+  }
+  ,
+  {
+    constraints: {video: false, audio: true}
+  }
+  ,
+  {
+    constraints: {video: true, audio: true},
+  }
+  ];
+
+function gUM(data) {
+  var gum_success = function (stream) {
+    SimpleTest.info("TEST-INFO | Got succss callback for " + JSON.stringify(data.constraints));
+
+    var hasAudioTrack = stream.getAudioTracks().length > 0;
+    var hasVideoTrack = stream.getVideoTracks().length > 0;
+
+    is(data.constraints.audio, hasAudioTrack, "Request audio track:" +
+                  data.constraints.audio + " contain audio track:" + hasAudioTrack);
+    is(data.constraints.video, hasVideoTrack, "Request video track:" +
+                  data.constraints.video + " contain audio track:" + hasVideoTrack);
+    gCount++;
+    if (gCount < gTests.length) {
+      gUM(gTests[gCount]);
+    } else {
+      SimpleTest.finish();
+    }
+  }
+
+  var gum_fail = function () {
+    ok(false, "permission not granted for " + JSON.stringify(data.constraints));
+
+    SimpleTest.finish();
+  }
+
+  SimpleTest.info("TEST-INFO | Call getUserMedia for " + JSON.stringify(data.constraints));
+  navigator.mozGetUserMedia(data.constraints, gum_success, gum_fail);
+}
+
+SpecialPowers.pushPrefEnv({"set": [["media.navigator.permission.disabled", false]]},
+  function () {
+    SpecialPowers.addPermission('video-capture',
+                                Ci.nsIPermissionManager.ALLOW_ACTION, document);
+    SpecialPowers.addPermission('audio-capture',
+                                Ci.nsIPermissionManager.ALLOW_ACTION, document);
+
+    gUM(gTests[gCount]);
+  });
+SimpleTest.waitForExplicitFinish();
+</script>
+</pre>
+</body>
+</html>