Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/permissions/MediaTest.java

Issue 2456243002: Consolidate Android permissions prompt testing. (Closed)
Patch Set: Improve commenting of PermissionTestCaseBase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/permissions/MediaTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/permissions/MediaTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/permissions/MediaTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..5f452a7c17b73eab442998a1ae237ed13604d10b
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/permissions/MediaTest.java
@@ -0,0 +1,150 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.permissions;
+
+import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.Smoke;
+
+import org.chromium.base.test.util.CommandLineFlags;
+import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.ChromeSwitches;
+import org.chromium.chrome.browser.tab.Tab;
+
+/**
+ * Test suite for media permissions requests.
+ */
+public class MediaTest extends PermissionTestCaseBase {
+ private static final String FAKE_DEVICE = ChromeSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM;
+ private static final String TEST_FILE = "/content/test/data/android/media_permissions.html";
+
+ public MediaTest() {}
+
+ private void testMediaPermissionsPlumbing(String prefix, String script, int numUpdates,
+ boolean withGesture, boolean isDialog, boolean hasSwitch, boolean toggleSwitch)
+ throws Exception {
+ Tab tab = getActivity().getActivityTab();
+ PermissionUpdateWaiter updateWaiter = new PermissionUpdateWaiter(prefix);
+ tab.addObserver(updateWaiter);
+ runAllowTest(updateWaiter, TEST_FILE, script, numUpdates, withGesture, isDialog, hasSwitch,
+ toggleSwitch);
+ tab.removeObserver(updateWaiter);
+ }
+
+ /**
+ * Verify asking for microphone creates an InfoBar and works when the permission is granted.
+ * @throws Exception
+ */
+ @Smoke
+ @MediumTest
+ @Feature({"MediaPermissions", "Main"})
+ @CommandLineFlags.Add(FAKE_DEVICE)
+ public void testMicrophonePermissionsPlumbing() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Mic count:", "initiate_getMicrophone()", 1, false, false, false, false);
+ }
+
+ /**
+ * Verify asking for camera creates an InfoBar and works when the permission is granted.
+ * @throws Exception
+ */
+ @MediumTest
+ @Feature({"MediaPermissions", "Main"})
+ @CommandLineFlags.Add(FAKE_DEVICE)
+ public void testCameraPermissionsPlumbing() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Camera count:", "initiate_getCamera()", 1, false, false, false, false);
+ }
+
+ /**
+ * Verify asking for both mic and camera creates a combined InfoBar and works when the
+ * permissions are granted.
+ * @throws Exception
+ */
+ @MediumTest
+ @Feature({"MediaPermissions", "Main"})
+ @CommandLineFlags.Add(FAKE_DEVICE)
+ public void testCombinedPermissionsPlumbing() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Combined count:", "initiate_getCombined()", 1, false, false, false, false);
+ }
+
+ /**
+ * Verify microphone prompts with a persistence toggle if that feature is enabled. Check the
+ * switch appears and that permission is granted with it toggled on.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add({FAKE_DEVICE, "enable-features=" + TOGGLE_FLAG})
+ @Feature({"MediaPermissions"})
+ public void testMicrophonePersistenceOn() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Mic count:", "initiate_getMicrophone()", 1, false, false, true, false);
+ }
+
+ /**
+ * Verify microphone prompts with a persistence toggle if that feature is enabled. Check the
+ * switch appears and that permission is granted with it toggled off.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add({FAKE_DEVICE, "enable-features=" + TOGGLE_FLAG})
+ @Feature({"MediaPermissions"})
+ public void testMicrophonePersistenceOff() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Mic count:", "initiate_getMicrophone()", 1, false, false, true, true);
+ }
+
+ /**
+ * Verify camera prompts with a persistence toggle if that feature is enabled. Check the
+ * switch appears and that permission is granted with it toggled on.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add({FAKE_DEVICE, "enable-features=" + TOGGLE_FLAG})
+ @Feature({"MediaPermissions"})
+ public void testCameraPersistenceOn() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Camera count:", "initiate_getCamera()", 1, false, false, true, false);
+ }
+
+ /**
+ * Verify camera prompts with a persistence toggle if that feature is enabled. Check the
+ * switch appears and that permission is granted with it toggled off.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add({FAKE_DEVICE, "enable-features=" + TOGGLE_FLAG})
+ @Feature({"MediaPermissions"})
+ public void testCameraPersistenceOff() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Camera count:", "initiate_getCamera()", 1, false, false, true, true);
+ }
+
+ /**
+ * Verify combined prompts show a persistence toggle if that feature is enabled. Check the
+ * switch appears and that permission is granted with it toggled on.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add({FAKE_DEVICE, "enable-features=" + TOGGLE_FLAG})
+ @Feature({"MediaPermissions"})
+ public void testCombinedPersistenceOn() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Combined count:", "initiate_getCombined()", 1, false, false, true, false);
+ }
+
+ /**
+ * Verify combined prompts show a persistence toggle if that feature is enabled. Check the
+ * switch appears and that permission is granted with it toggled of.
+ * @throws Exception
+ */
+ @MediumTest
+ @CommandLineFlags.Add({FAKE_DEVICE, "enable-features=" + TOGGLE_FLAG})
+ @Feature({"MediaPermissions"})
+ public void testCombinedPersistenceOff() throws Exception {
+ testMediaPermissionsPlumbing(
+ "Combined count:", "initiate_getCombined()", 1, false, false, true, true);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698