Bug 1531833 - Fix PermissionDelegateTest to not require audio input on an emulator, where it's not available. r=snorp
authorPaul Adenot <paul@paul.cx>
Tue, 16 Apr 2019 15:44:45 +0000
changeset 469696 a1e8c5a64ceb
parent 469695 c749a1823112
child 469697 bf3af9a319ee
push id35879
push usernerli@mozilla.com
push dateTue, 16 Apr 2019 22:01:48 +0000
treeherdermozilla-central@12a60898fdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1531833
milestone68.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 1531833 - Fix PermissionDelegateTest to not require audio input on an emulator, where it's not available. r=snorp Differential Revision: https://phabricator.services.mozilla.com/D27573
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/PermissionDelegateTest.kt
@@ -29,16 +29,20 @@ class PermissionDelegateTest : BaseSessi
     private fun hasPermission(permission: String): Boolean {
         if (Build.VERSION.SDK_INT < 23) {
             return true
         }
         return PackageManager.PERMISSION_GRANTED ==
                 InstrumentationRegistry.getTargetContext().checkSelfPermission(permission)
     }
 
+    private fun isEmulator(): Boolean {
+        return "generic".equals(Build.DEVICE) || Build.DEVICE.startsWith("generic_")
+    }
+
     @WithDevToolsAPI
     @Test fun media() {
         assertInAutomationThat("Should have camera permission",
                                hasPermission(Manifest.permission.CAMERA), equalTo(true))
 
         assertInAutomationThat("Should have microphone permission",
                                hasPermission(Manifest.permission.RECORD_AUDIO),
                                equalTo(true))
@@ -63,27 +67,39 @@ class PermissionDelegateTest : BaseSessi
             @AssertCalled(count = 1)
             override fun onMediaPermissionRequest(
                     session: GeckoSession, uri: String,
                     video: Array<out GeckoSession.PermissionDelegate.MediaSource>?,
                     audio: Array<out GeckoSession.PermissionDelegate.MediaSource>?,
                     callback: GeckoSession.PermissionDelegate.MediaCallback) {
                 assertThat("URI should match", uri, endsWith(HELLO_HTML_PATH))
                 assertThat("Video source should be valid", video, not(emptyArray()))
-                assertThat("Audio source should be valid", audio, not(emptyArray()))
-                callback.grant(video!![0], audio!![0])
+
+                if (isEmulator()) {
+                  callback.grant(video!![0], null)
+                } else {
+                  assertThat("Audio source should be valid", audio, not(emptyArray()))
+                  callback.grant(video!![0], audio!![0])
+                }
             }
         })
 
-        // Start a video/audio stream.
-        val stream = mainSession.waitForJS(
-                """window.navigator.mediaDevices.getUserMedia({
+        // Start a video stream, with audio if on a real device.
+        var code: String?
+        if (isEmulator()) {
+          code = """window.navigator.mediaDevices.getUserMedia({
                        video: { width: 320, height: 240, frameRate: 10 },
-                       audio: true,
-                   })""")
+                   })"""
+        } else {
+          code = """window.navigator.mediaDevices.getUserMedia({
+                       video: { width: 320, height: 240, frameRate: 10 },
+                       audio: true
+                   })"""
+        }
+        val stream = mainSession.waitForJS(code)
 
         assertThat("Stream should be active", stream.asJSMap(),
                    hasEntry("active", true))
         assertThat("Stream should have ID", stream.asJSMap(),
                    hasEntry(equalTo("id"), not(isEmptyString())))
 
         // Stop the stream.
         mainSession.waitForJS(
@@ -98,18 +114,23 @@ class PermissionDelegateTest : BaseSessi
                     video: Array<out GeckoSession.PermissionDelegate.MediaSource>?,
                     audio: Array<out GeckoSession.PermissionDelegate.MediaSource>?,
                     callback: GeckoSession.PermissionDelegate.MediaCallback) {
                 callback.reject()
             }
         })
 
         try {
-            mainSession.waitForJS("""
-                    window.navigator.mediaDevices.getUserMedia({ audio: true, video: true })""")
+            if (isEmulator()) {
+                mainSession.waitForJS("""
+                        window.navigator.mediaDevices.getUserMedia({ video: true })""")
+            } else {
+                mainSession.waitForJS("""
+                        window.navigator.mediaDevices.getUserMedia({ audio: true: video: true })""")
+            }
             fail("Request should have failed")
         } catch (e: RejectedPromiseException) {
             assertThat("Error should be correct",
                        e.reason.asJSMap(), hasEntry("name", "NotAllowedError"))
         }
     }
 
     @WithDevToolsAPI