Bug 795367 - Establish makefiles/directories for gUM/webrtc test automation and add a simple gUM error test. r=jesup
authorJason Smith <jsmith@mozilla.com>
Sat, 13 Oct 2012 13:33:22 -0700
changeset 118153 796eea064cd4dd0d71b80880ca095d5f563c5a2e
parent 118152 ffc0fb337aa0b8b8943226cfa01e33b69b5754d8
child 118154 eaa7aff9f43c4d065c47f99dacbe30d8a0accdc4
push id1997
push userakeybl@mozilla.com
push dateMon, 07 Jan 2013 21:25:26 +0000
treeherdermozilla-beta@4baf45cdcf21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs795367
milestone19.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 795367 - Establish makefiles/directories for gUM/webrtc test automation and add a simple gUM error test. r=jesup
dom/tests/mochitest/Makefile.in
dom/tests/mochitest/media/Makefile.in
dom/tests/mochitest/media/head.js
dom/tests/mochitest/media/test_getUserMedia_exceptions.html
--- a/dom/tests/mochitest/Makefile.in
+++ b/dom/tests/mochitest/Makefile.in
@@ -17,16 +17,17 @@ DIRS	+= \
 	dom-level2-html \
 	ajax \
 	bugs \
 	chrome \
 	general \
 	whatwg \
 	geolocation \
 	localstorage \
+	media \
 	orientation \
 	sessionstorage \
 	storageevent \
 	pointerlock \
 	webapps \
 	$(NULL)
 
 #needs IPC support, also tests do not run successfully in Firefox for now
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/media/Makefile.in
@@ -0,0 +1,18 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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/.
+
+DEPTH = @DEPTH@
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+relativesrcdir = @relativesrcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+MOCHITEST_FILES	= \
+  test_getUserMedia_exceptions.html \
+  head.js \
+  $(NULL)
+
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/media/head.js
@@ -0,0 +1,22 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+var Cc = SpecialPowers.Cc;
+var Ci = SpecialPowers.Ci;
+var Cr = SpecialPowers.Cr;
+
+/**
+ * Setup any Mochitest for WebRTC by enabling the preference for
+ * peer connections. As by bug 797979 it will also enable mozGetUserMedia().
+ * Additionally, we disable the permissions prompt for these mochitests.
+ *
+ * @param {Function} aCallback Test method to execute after initialization
+ */
+function runTest(aCallback) {
+  SimpleTest.waitForExplicitFinish();
+
+  SpecialPowers.pushPrefEnv({'set': [['media.peerconnection.enabled', true],
+                            ['media.navigator.permission.disabled', true]]},
+                            aCallback);
+}
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/media/test_getUserMedia_exceptions.html
@@ -0,0 +1,86 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=795367
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test mozGetUserMedia Exceptions</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>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795367">Test mozGetUserMedia Exceptions</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/**
+  These tests verify that the appropriate exception is thrown when incorrect
+  values are provided to the immediate mozGetUserMedia call.
+*/
+var exceptionTests = [
+  // Each test here verifies that a caller is required to have all
+  // three arguments in order to call mozGetUserMedia
+  { params: undefined,
+    error: Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS,
+    message: "no arguments specified" },
+  { params: [{video: true, fake: true}],
+    error: Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS,
+    message: "one argument specified" },
+  { params: [{video: true, fake: true}, unexpectedCall],
+    error: Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS,
+    message: "two arguments specified" },
+
+  // Each test here verifies that providing an incorret object
+  // type to any mozGetUserMedia parameter should throw
+  // the correct exception specified
+  { params: [1, unexpectedCall, unexpectedCall],
+    error: Cr.NS_ERROR_XPC_BAD_CONVERT_JS,
+    message: "wrong object type as first parameter" },
+  { params: [{video: true, fake: true}, 1, unexpectedCall],
+    error: Cr.NS_ERROR_XPC_BAD_CONVERT_JS,
+    message: "wrong object type as second parameter" },
+  { params: [{video: true, fake: true}, unexpectedCall, 1],
+    error: Cr.NS_ERROR_XPC_BAD_CONVERT_JS,
+    message: "wrong object type as third parameter" }
+];
+
+/**
+ * A callback function that is only called if a particular
+ * exception was not thrown, resulting in the test failing.
+ *
+ * @param  {MediaStream} argument ignored
+ */
+function unexpectedCall(obj) {
+  ok(false, "Callback should not have been called");
+}
+
+/**
+ * Starts the test run by running through each exception
+ * test by verifying that the correct exception type specified
+ * is thrown on the mozGetUserMedia call with the parameters
+ * specified.
+ */
+runTest(function () {
+  exceptionTests.forEach(function (test) {
+    var exception = false;
+    try {
+      navigator.mozGetUserMedia.apply(navigator, test.params);
+    } catch (e) {
+      exception = (e.result === test.error);
+    }
+    ok(exception, "Exception for " + test.message);
+  });
+
+  SimpleTest.finish();
+});
+
+</script>
+</pre>
+</body>
+</html>