Commit a16fcedb authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Update WebXr tests for permissions prompt

Updates the Android WebXr test infrastructure to allow accepting or
rejecting permissions prompts in addition to the consent dialog, based
on whether or not the feature is enabled. This ensures that tests will
keep running when the permissions prompt is enabled by default, and can
be cleaned up as time permits.

Additionally, consent prompt tests that still make sense to run when
the permissions prompt is enabled were pulled into an impl method and
a variation of the test was created which explicitly sets the feature
to the desired state. The old tests can thus be more easily removed when
the feature flag is removed. This ensures both some coverage of the
permissions prompt flow now, and continued coverage of the consent flow
after it is disabled, until such time as it can be removed.

Some tests were determined to be testing logic specific only to the
current consent flow, and as such those tests forcibly ensure that the
permissions prompt is disabled.

Bug: 1043241
Change-Id: Ib61d81a3f3aa90b1869d13ad53112ecd5606b627
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051367
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742234}
parent 16c153e6
...@@ -28,6 +28,9 @@ import org.chromium.chrome.browser.vr.util.ArTestRuleUtils; ...@@ -28,6 +28,9 @@ import org.chromium.chrome.browser.vr.util.ArTestRuleUtils;
import org.chromium.chrome.browser.vr.util.PermissionUtils; import org.chromium.chrome.browser.vr.util.PermissionUtils;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate; import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.content_public.browser.ContentFeatureList;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import java.util.List; import java.util.List;
...@@ -75,14 +78,14 @@ public class WebXrArSessionTest { ...@@ -75,14 +78,14 @@ public class WebXrArSessionTest {
} }
/** /**
* Tests that declining AR consent causes future attempts to still display the consent dialog, * Tests that declining AR consent causes future attempts to still display the consent dialog.
* but consenting causes future attempts to skip the consent dialog as long as no navigation * Consent-flow specific
* occurs.
*/ */
@Test @Test
@MediumTest @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
public void testConsentPersistanceOnSamePage() { @DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testConsentShowsAfterDecline() {
mWebXrArTestFramework.loadFileAndAwaitInitialization( mWebXrArTestFramework.loadFileAndAwaitInitialization(
"test_ar_request_session_succeeds", PAGE_LOAD_TIMEOUT_S); "test_ar_request_session_succeeds", PAGE_LOAD_TIMEOUT_S);
WebContents contents = mWebXrArTestFramework.getCurrentWebContents(); WebContents contents = mWebXrArTestFramework.getCurrentWebContents();
...@@ -90,17 +93,50 @@ public class WebXrArSessionTest { ...@@ -90,17 +93,50 @@ public class WebXrArSessionTest {
// Start session, decline consent prompt. // Start session, decline consent prompt.
mWebXrArTestFramework.enterSessionWithUserGestureAndDeclineConsentOrFail(contents); mWebXrArTestFramework.enterSessionWithUserGestureAndDeclineConsentOrFail(contents);
mWebXrArTestFramework.assertNoJavaScriptErrors(); mWebXrArTestFramework.assertNoJavaScriptErrors();
PermissionUtils.waitForConsentPromptDismissal(mTestRule.getActivity());
// Start new session, accept consent prompt this time. // Start new session, accept consent prompt this time.
PermissionUtils.waitForConsentPromptDismissal(mTestRule.getActivity());
mWebXrArTestFramework.enterSessionWithUserGestureOrFail(contents); mWebXrArTestFramework.enterSessionWithUserGestureOrFail(contents);
mWebXrArTestFramework.endSession(); mWebXrArTestFramework.endSession();
mWebXrArTestFramework.assertNoJavaScriptErrors(); mWebXrArTestFramework.assertNoJavaScriptErrors();
mWebXrArTestFramework.pollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.AR].currentSession == null", POLL_TIMEOUT_SHORT_MS);
}
// Start yet another session, but go through a path that doesn't automatically handle @Test
// the consent dialog to ensure that it doesn't actually appear. @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testConsentPersistanceOnSamePage() {
testConsentPersistanceOnSamePageImpl();
}
@Test
@MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@EnableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testArPermissionPersistance() {
testConsentPersistanceOnSamePageImpl();
}
/**
* Tests that consenting causes future attempts to skip the consent dialog as long as no
* navigation occurs.
*/
private void testConsentPersistanceOnSamePageImpl() {
mWebXrArTestFramework.loadFileAndAwaitInitialization(
"test_ar_request_session_succeeds", PAGE_LOAD_TIMEOUT_S);
WebContents contents = mWebXrArTestFramework.getCurrentWebContents();
// Start new session, accepting the consent prompt
mWebXrArTestFramework.enterSessionWithUserGestureOrFail(contents);
mWebXrArTestFramework.endSession();
mWebXrArTestFramework.assertNoJavaScriptErrors();
mWebXrArTestFramework.pollJavaScriptBooleanOrFail( mWebXrArTestFramework.pollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.AR].currentSession == null", POLL_TIMEOUT_SHORT_MS); "sessionInfos[sessionTypes.AR].currentSession == null", POLL_TIMEOUT_SHORT_MS);
// Start yet another session, but go through a path that doesn't automatically handle
// the consent dialog to ensure that it doesn't actually appear.
mWebXrArTestFramework.enterSessionWithUserGesture(); mWebXrArTestFramework.enterSessionWithUserGesture();
mWebXrArTestFramework.pollJavaScriptBooleanOrFail( mWebXrArTestFramework.pollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.AR].currentSession != null", POLL_TIMEOUT_SHORT_MS); "sessionInfos[sessionTypes.AR].currentSession != null", POLL_TIMEOUT_SHORT_MS);
......
...@@ -28,6 +28,9 @@ import org.chromium.chrome.browser.vr.rules.XrActivityRestriction; ...@@ -28,6 +28,9 @@ import org.chromium.chrome.browser.vr.rules.XrActivityRestriction;
import org.chromium.chrome.browser.vr.util.VrTestRuleUtils; import org.chromium.chrome.browser.vr.util.VrTestRuleUtils;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate; import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.util.browser.Features.DisableFeatures;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.content_public.browser.ContentFeatureList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
...@@ -60,13 +63,26 @@ public class WebXrVrConsentTest { ...@@ -60,13 +63,26 @@ public class WebXrVrConsentTest {
mWebXrVrConsentTestFramework = new WebXrVrConsentTestFramework(mTestRule); mWebXrVrConsentTestFramework = new WebXrVrConsentTestFramework(mTestRule);
} }
/**
* Tests that denying consent blocks the session from being created.
*/
@Test @Test
@MediumTest @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testConsentCancelFailsSessionCreation() { public void testConsentCancelFailsSessionCreation() {
testConsentCancelFailsSessionCreationImpl();
}
@Test
@MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@EnableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testPermissionDenyFailsSessionCreation() {
testConsentCancelFailsSessionCreationImpl();
}
/**
* Tests that denying consent blocks the session from being created.
*/
private void testConsentCancelFailsSessionCreationImpl() {
mWebXrVrConsentTestFramework.setConsentDialogAction( mWebXrVrConsentTestFramework.setConsentDialogAction(
WebXrVrTestFramework.CONSENT_DIALOG_ACTION_DENY); WebXrVrTestFramework.CONSENT_DIALOG_ACTION_DENY);
mWebXrVrConsentTestFramework.setConsentDialogExpected(true); mWebXrVrConsentTestFramework.setConsentDialogExpected(true);
...@@ -82,14 +98,27 @@ public class WebXrVrConsentTest { ...@@ -82,14 +98,27 @@ public class WebXrVrConsentTest {
mWebXrVrConsentTestFramework.assertNoJavaScriptErrors(); mWebXrVrConsentTestFramework.assertNoJavaScriptErrors();
} }
/**
* Tests that attempting to enter a session that requires the same permission level does not
* reprompt.
*/
@Test @Test
@MediumTest @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testConsentPersistsSameLevel() { public void testConsentPersistsSameLevel() {
testConsentPersistsImpl();
}
@Test
@MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@EnableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testVrPermissionPersistance() {
testConsentPersistsImpl();
}
/**
* Tests that attempting to enter a session that requires the same permission level/type does
* not reprompt.
*/
private void testConsentPersistsImpl() {
mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization( mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization(
"generic_webxr_page", PAGE_LOAD_TIMEOUT_S); "generic_webxr_page", PAGE_LOAD_TIMEOUT_S);
mWebXrVrConsentTestFramework.enterSessionWithUserGestureOrFail(); mWebXrVrConsentTestFramework.enterSessionWithUserGestureOrFail();
...@@ -100,14 +129,27 @@ public class WebXrVrConsentTest { ...@@ -100,14 +129,27 @@ public class WebXrVrConsentTest {
mWebXrVrConsentTestFramework.enterSessionWithUserGestureOrFail(); mWebXrVrConsentTestFramework.enterSessionWithUserGestureOrFail();
} }
/**
* Tests that attempting to enter an inline session with no special features does not require
* consent.
*/
@Test @Test
@MediumTest @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testConsentNotNeededForInline() { public void testConsentNotNeededForInline() {
testConsentNotNeededForInlineImpl();
}
@Test
@MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@EnableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testPermissionNotNeededForInline() {
testConsentNotNeededForInlineImpl();
}
/**
* Tests that attempting to enter an inline session with no special features does not require
* consent.
*/
private void testConsentNotNeededForInlineImpl() {
mWebXrVrConsentTestFramework.setConsentDialogExpected(false); mWebXrVrConsentTestFramework.setConsentDialogExpected(false);
mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization( mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization(
...@@ -122,10 +164,12 @@ public class WebXrVrConsentTest { ...@@ -122,10 +164,12 @@ public class WebXrVrConsentTest {
/** /**
* Tests that if consent is granted for a higher level, the lower level does not need consent. * Tests that if consent is granted for a higher level, the lower level does not need consent.
* Consent-prompt flow specific.
*/ */
@Test @Test
@MediumTest @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testConsentPersistsLowerLevel() { public void testConsentPersistsLowerLevel() {
mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization( mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization(
"test_webxr_consent", PAGE_LOAD_TIMEOUT_S); "test_webxr_consent", PAGE_LOAD_TIMEOUT_S);
...@@ -146,10 +190,13 @@ public class WebXrVrConsentTest { ...@@ -146,10 +190,13 @@ public class WebXrVrConsentTest {
/** /**
* Tests that if consent is granted for a lower level, the higher level still needs consent. * Tests that if consent is granted for a lower level, the higher level still needs consent.
* Consent-prompt flow specific.
*/ */
@Test @Test
@MediumTest @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
// Need to force consent prompt visible
public void testConsentRepromptsHigherLevel() { public void testConsentRepromptsHigherLevel() {
mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization( mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization(
"test_webxr_consent", PAGE_LOAD_TIMEOUT_S); "test_webxr_consent", PAGE_LOAD_TIMEOUT_S);
...@@ -167,13 +214,28 @@ public class WebXrVrConsentTest { ...@@ -167,13 +214,28 @@ public class WebXrVrConsentTest {
mWebXrVrConsentTestFramework.enterSessionWithUserGestureOrFail(); mWebXrVrConsentTestFramework.enterSessionWithUserGestureOrFail();
} }
/**
* Tests that granted consent does not persist after a page reload.
*/
@Test @Test
@MediumTest @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testConsentRepromptsAfterReload() { public void testConsentRepromptsAfterReload() {
// Verfies that consent is prompted for again after reload.
testConsentAfterReload(true);
}
@Test
@MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@EnableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testPermissionPersistsAfterReload() {
// Verifies that permission is persisted after reload.
testConsentAfterReload(false);
}
/**
* Tests that granted consent does not persist after a page reload.
*/
private void testConsentAfterReload(boolean expectedAfterReload) {
mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization( mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization(
"generic_webxr_page", PAGE_LOAD_TIMEOUT_S); "generic_webxr_page", PAGE_LOAD_TIMEOUT_S);
...@@ -182,6 +244,9 @@ public class WebXrVrConsentTest { ...@@ -182,6 +244,9 @@ public class WebXrVrConsentTest {
mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization( mWebXrVrConsentTestFramework.loadFileAndAwaitInitialization(
"generic_webxr_page", PAGE_LOAD_TIMEOUT_S); "generic_webxr_page", PAGE_LOAD_TIMEOUT_S);
mWebXrVrConsentTestFramework.setConsentDialogExpected(expectedAfterReload);
mWebXrVrConsentTestFramework.enterSessionWithUserGestureOrFail(); mWebXrVrConsentTestFramework.enterSessionWithUserGestureOrFail();
} }
} }
...@@ -10,6 +10,7 @@ import org.chromium.chrome.browser.ChromeActivity; ...@@ -10,6 +10,7 @@ import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.permissions.PermissionDialogController; import org.chromium.chrome.browser.permissions.PermissionDialogController;
import org.chromium.chrome.browser.vr.ArConsentDialog; import org.chromium.chrome.browser.vr.ArConsentDialog;
import org.chromium.chrome.browser.vr.VrConsentDialog; import org.chromium.chrome.browser.vr.VrConsentDialog;
import org.chromium.content_public.browser.ContentFeatureList;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
...@@ -31,6 +32,19 @@ public class PermissionUtils { ...@@ -31,6 +32,19 @@ public class PermissionUtils {
}, "Permission prompt did not appear in allotted time"); }, "Permission prompt did not appear in allotted time");
} }
/**
* Blocks until the consent prompt is dismissed.
*/
public static void waitForPermissionPromptDismissal() {
CriteriaHelper.pollUiThread(
()
-> {
return !PermissionDialogController.getInstance().isDialogShownForTest();
},
"Consent prompt did not get dismissed in allotted time",
CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL, DIALOG_POLLING_INTERVAL_MS);
}
/** /**
* Accepts the currently displayed permission prompt. * Accepts the currently displayed permission prompt.
*/ */
...@@ -55,6 +69,11 @@ public class PermissionUtils { ...@@ -55,6 +69,11 @@ public class PermissionUtils {
* Blocks until the session consent prompt appears. * Blocks until the session consent prompt appears.
*/ */
public static void waitForConsentPrompt(ChromeActivity activity) { public static void waitForConsentPrompt(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
waitForPermissionPrompt();
return;
}
CriteriaHelper.pollUiThread(() CriteriaHelper.pollUiThread(()
-> { return isConsentDialogShown(activity); }, -> { return isConsentDialogShown(activity); },
"Consent prompt did not appear in allotted time", "Consent prompt did not appear in allotted time",
...@@ -65,6 +84,11 @@ public class PermissionUtils { ...@@ -65,6 +84,11 @@ public class PermissionUtils {
* Blocks until the consent prompt is dismissed. * Blocks until the consent prompt is dismissed.
*/ */
public static void waitForConsentPromptDismissal(ChromeActivity activity) { public static void waitForConsentPromptDismissal(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
waitForPermissionPromptDismissal();
return;
}
CriteriaHelper.pollUiThread(() CriteriaHelper.pollUiThread(()
-> { return !isConsentDialogShown(activity); }, -> { return !isConsentDialogShown(activity); },
"Consent prompt did not get dismissed in allotted time", "Consent prompt did not get dismissed in allotted time",
...@@ -78,6 +102,11 @@ public class PermissionUtils { ...@@ -78,6 +102,11 @@ public class PermissionUtils {
* Accepts the currently displayed session consent prompt. * Accepts the currently displayed session consent prompt.
*/ */
public static void acceptConsentPrompt(ChromeActivity activity) { public static void acceptConsentPrompt(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
acceptPermissionPrompt();
return;
}
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
clickConsentDialogButton(activity, ModalDialogProperties.ButtonType.POSITIVE); clickConsentDialogButton(activity, ModalDialogProperties.ButtonType.POSITIVE);
}); });
...@@ -87,6 +116,11 @@ public class PermissionUtils { ...@@ -87,6 +116,11 @@ public class PermissionUtils {
* Declines the currently displayed session consent prompt. * Declines the currently displayed session consent prompt.
*/ */
public static void declineConsentPrompt(ChromeActivity activity) { public static void declineConsentPrompt(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
denyPermissionPrompt();
return;
}
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
clickConsentDialogButton(activity, ModalDialogProperties.ButtonType.NEGATIVE); clickConsentDialogButton(activity, ModalDialogProperties.ButtonType.NEGATIVE);
}); });
...@@ -96,6 +130,10 @@ public class PermissionUtils { ...@@ -96,6 +130,10 @@ public class PermissionUtils {
* Helper function to check if the consent dialog is being shown. * Helper function to check if the consent dialog is being shown.
*/ */
public static boolean isConsentDialogShown(ChromeActivity activity) { public static boolean isConsentDialogShown(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
return PermissionDialogController.getInstance().isDialogShownForTest();
}
ModalDialogManager manager = activity.getModalDialogManager(); ModalDialogManager manager = activity.getModalDialogManager();
PropertyModel model = manager.getCurrentDialogForTest(); PropertyModel model = manager.getCurrentDialogForTest();
if (model == null) return false; if (model == null) return false;
...@@ -106,7 +144,9 @@ public class PermissionUtils { ...@@ -106,7 +144,9 @@ public class PermissionUtils {
/** /**
* Helper function to click a button in the consent dialog. * Helper function to click a button in the consent dialog.
*/ */
public static void clickConsentDialogButton(ChromeActivity activity, int buttonType) { private static void clickConsentDialogButton(ChromeActivity activity, int buttonType) {
assert (!ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API));
ModalDialogManager manager = activity.getModalDialogManager(); ModalDialogManager manager = activity.getModalDialogManager();
PropertyModel model = manager.getCurrentDialogForTest(); PropertyModel model = manager.getCurrentDialogForTest();
ModalDialogProperties.Controller dialog = ModalDialogProperties.Controller dialog =
......
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