Bug 928870 - Add test for Android gUM doorhanger. r=gbrown
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Tue, 22 Oct 2013 11:10:17 +0200
changeset 165460 ececa191d8b5c87f8862d23916b5dc7cb24335e5
parent 165459 0dc6eccf8c776a4905ca9ffcb6bf1282f2b1b633
child 165461 03f9c4191bf0b6b0a52bd4cbd8c1a837ff40f0dc
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs928870
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 928870 - Add test for Android gUM doorhanger. r=gbrown
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/robocop_getusermedia.html
mobile/android/base/tests/testGetUserMedia.java.in
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -41,14 +41,15 @@
 [testFindInPage]
 [testInputUrlBar]
 [testAddSearchEngine]
 [testImportFromAndroid]
 [testMasterPassword]
 [testDeviceSearchEngine]
 [testPrivateBrowsing]
 [testReaderMode]
+[testGetUserMedia]
 
 # Used for Talos, please don't use in mochitest
 #[testPan]
 #[testCheck]
 #[testCheck2]
 #[testBrowserProviderPerf]
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/robocop_getusermedia.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html><head>
+  <title>gUM Test Page</title>
+  <meta http-equiv="content-type" content="text/html; charset=UTF-8" charset="utf-8">
+</head>
+<body>
+  <script type="application/javascript">
+  var video_status = false;
+  var video = document.createElement("video");
+  video.setAttribute("width", 640);
+  video.setAttribute("height", 480);
+
+  var audio_status = false;
+  var audio = document.createElement("audio");
+  audio.setAttribute("controls", true);
+
+  startAudioVideo();
+
+  function startAudioVideo() {
+    video_status = true;
+    audio_status = true;
+    startMedia({video:true, audio:true});
+  }
+
+  function stopMedia() {
+    if (video_status) {
+      video.mozSrcObject.stop();
+      video.mozSrcObject = null;
+      content.removeChild(video);
+      capturing = false;
+      video_status = false;
+    }
+    if (audio_status) {
+      audio.mozSrcObject.stop();
+      audio.mozSrcObject = null;
+      content.removeChild(audio);
+      audio_status = false;
+    }
+  }
+
+  function startMedia(param) {
+    try {
+      window.navigator.mozGetUserMedia(param, function(stream) {
+        message.innerHTML = "<p>Success!</p>";
+        if (video_status) {
+          content.appendChild(video);
+          video.mozSrcObject = stream;
+          video.play();
+        }
+        if (audio_status) {
+          content.appendChild(audio);
+          audio.mozSrcObject = stream;
+          audio.play();
+        }
+      }, function(err) {
+        stopMedia();
+      });
+    } catch(e) {
+      stopMedia();
+    }
+  }
+</script>
+</body></html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testGetUserMedia.java.in
@@ -0,0 +1,40 @@
+#filter substitution
+package @ANDROID_PACKAGE_NAME@.tests;
+
+import @ANDROID_PACKAGE_NAME@.*;
+
+import android.app.Activity;
+import android.hardware.Camera;
+import android.os.Build;
+import java.lang.reflect.Method;
+
+public class testGetUserMedia extends BaseTest {
+    @Override
+    protected int getTestType() {
+        return TEST_MOCHITEST;
+    }
+
+    public void testGetUserMedia() {
+        String GUM_URL = getAbsoluteUrl("/robocop/robocop_getusermedia.html");
+
+        String GUM_MESSAGE = "Would you like to share your camera and microphone with";
+        String GUM_ALLOW = "Share";
+        String GUM_DENY = "Don't share";
+
+        blockForGeckoReady();
+
+        // Only try GUM test if the device has a camera. If there's a working Camera,
+        // we'll assume there is a working audio device as well.
+        // getNumberOfCameras is Gingerbread/9+
+        // We could avoid that requirement by trying to open a Camera but we
+        // already know our 2.2/Tegra test devices don't have them.
+        if (Build.VERSION.SDK_INT >= 9) {
+            if (Camera.getNumberOfCameras() > 0) {
+                // Test GUM notification
+                inputAndLoadUrl(GUM_URL);
+                waitForText(GUM_MESSAGE);
+                mAsserter.is(mSolo.searchText(GUM_MESSAGE), true, "GetUserMedia doorhanger has been displayed");
+            }
+        }
+    }
+}