Commit 7b61c208 authored by Andy Paicu's avatar Andy Paicu Committed by Commit Bot

Implement section 1.3 of the manual permissions tests suite

https://testtracker.googleplex.com/testplans/details/33023?revision=10
The link above describes the currently existing manual tests related
to the permission prompts. As part of the review process, I've
implemented the tests from section 1.3.

Bug: 1063164
Change-Id: I30b1268fe010ee450afe440ac610cdc6fa3b9fef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218169
Commit-Queue: Andy Paicu <andypaicu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#776228}
parent 1b57b4e4
......@@ -413,6 +413,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/payments/PaymentRequestUseStatsTest.java",
"javatests/src/org/chromium/chrome/browser/payments/SkipToGPayHelperTest.java",
"javatests/src/org/chromium/chrome/browser/payments/WebPaymentIntentHelperTest.java",
"javatests/src/org/chromium/chrome/browser/permissions/AutomaticEmbargoTest.java",
"javatests/src/org/chromium/chrome/browser/permissions/GeolocationTest.java",
"javatests/src/org/chromium/chrome/browser/permissions/MIDITest.java",
"javatests/src/org/chromium/chrome/browser/permissions/MediaTest.java",
......
// Copyright 2020 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.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.permissions.PermissionTestRule.PermissionUpdateWaiter;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.common.ContentSwitches;
import org.chromium.ui.modaldialog.DialogDismissalCause;
/**
* Test suite for permissions automatic embargo logic.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
public class AutomaticEmbargoTest {
@Rule
public PermissionTestRule mPermissionRule = new PermissionTestRule(true /* useHttpsServer */);
private static final String GEOLOCATION_TEST_FILE =
"/chrome/test/data/geolocation/geolocation_on_load.html";
private static final String NOTIFICATIONS_TEST_FILE =
"/chrome/test/data/notifications/notification_tester.html";
private static final String MIDI_TEST_FILE = "/content/test/data/android/midi_permissions.html";
private static final String MEDIA_TEST_FILE =
"/content/test/data/android/media_permissions.html";
private static final int NUMBER_OF_DISMISSALS = 3;
@Before
public void setUp() throws Exception {
mPermissionRule.setUpActivity();
}
private void runTest(final String testFile, final String javascript, final String updaterPrefix,
final int nUpdates) throws Exception {
Tab tab = mPermissionRule.getActivity().getActivityTab();
PermissionUpdateWaiter updateWaiter =
new PermissionUpdateWaiter(updaterPrefix, mPermissionRule.getActivity());
tab.addObserver(updateWaiter);
for (int i = 0; i < NUMBER_OF_DISMISSALS; ++i) {
mPermissionRule.setUpUrl(testFile);
mPermissionRule.runJavaScriptCodeInCurrentTab(javascript);
PermissionTestRule.waitForDialog(mPermissionRule.getActivity());
TestThreadUtils.runOnUiThreadBlocking(() -> {
mPermissionRule.getActivity()
.getModalDialogManager()
.getCurrentPresenterForTest()
.dismissCurrentDialog(DialogDismissalCause.NAVIGATE_BACK_OR_TOUCH_OUTSIDE);
});
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
mPermissionRule.runNoPromptTest(updateWaiter, testFile, javascript, nUpdates, false, true);
tab.removeObserver(updateWaiter);
}
@Test
@LargeTest
@Feature({"Location"})
public void testGeolocationEmbargo() throws Exception {
runTest(GEOLOCATION_TEST_FILE, "", "Denied", 0);
}
@Test
@LargeTest
@Feature({"Notifications"})
public void testNotificationsEmbargo() throws Exception {
runTest(NOTIFICATIONS_TEST_FILE, "requestPermission()", "request-callback-denied", 0);
}
@Test
@LargeTest
@Feature({"MIDI"})
public void testMIDIEmbargo() throws Exception {
runTest(MIDI_TEST_FILE, "", "fail", 0);
}
@Test
@LargeTest
@Feature({"MediaPermissions"})
@CommandLineFlags.Add({ContentSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM})
public void testCameraEmbargo() throws Exception {
runTest(MEDIA_TEST_FILE, "initiate_getMicrophone()", "deny", 0);
}
@Test
@LargeTest
@Feature({"MediaPermissions"})
@CommandLineFlags.Add({ContentSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM})
public void testMicrophoneEmbargo() throws Exception {
runTest(MEDIA_TEST_FILE, "initiate_getCamera()", "deny", 0);
}
@Test
@LargeTest
@Feature({"MediaPermissions"})
@CommandLineFlags.Add({ContentSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM})
public void testMicrophoneAndCameraEmbargo() throws Exception {
runTest(MEDIA_TEST_FILE, "initiate_getCombined()", "deny", 0);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment