Commit 16c46cd1 authored by Alexander Cooper's avatar Alexander Cooper Committed by Commit Bot

Remove WebXr Consent Flow Tests

The WebXr Permissions API has shipped with M83, as such the legacy
consent flow may also be removed. This change removes all tests that
were specific to the consent flow in preparation for removing the code
for the consent flow.

Bug: 1064384
Change-Id: I263a6f6acbac0abbd29436c4d1cfdf4502509628
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2219351
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773317}
parent cd3578ba
...@@ -1198,10 +1198,10 @@ if (enable_vr || enable_arcore) { ...@@ -1198,10 +1198,10 @@ if (enable_vr || enable_arcore) {
"javatests/src/org/chromium/chrome/browser/vr/VrDaydreamReadyModuleInstallTest.java", "javatests/src/org/chromium/chrome/browser/vr/VrDaydreamReadyModuleInstallTest.java",
"javatests/src/org/chromium/chrome/browser/vr/VrFeedbackInfoBarTest.java", "javatests/src/org/chromium/chrome/browser/vr/VrFeedbackInfoBarTest.java",
"javatests/src/org/chromium/chrome/browser/vr/VrInstallUpdateInfoBarTest.java", "javatests/src/org/chromium/chrome/browser/vr/VrInstallUpdateInfoBarTest.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrConsentTest.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrConsentTestFramework.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrDeviceTest.java", "javatests/src/org/chromium/chrome/browser/vr/WebXrVrDeviceTest.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrInputTest.java", "javatests/src/org/chromium/chrome/browser/vr/WebXrVrInputTest.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrPermissionTest.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrPermissionTestFramework.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrTabTest.java", "javatests/src/org/chromium/chrome/browser/vr/WebXrVrTabTest.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrTestFramework.java", "javatests/src/org/chromium/chrome/browser/vr/WebXrVrTestFramework.java",
"javatests/src/org/chromium/chrome/browser/vr/WebXrVrTransitionTest.java", "javatests/src/org/chromium/chrome/browser/vr/WebXrVrTransitionTest.java",
......
...@@ -25,12 +25,8 @@ import org.chromium.base.test.util.MinAndroidSdkLevel; ...@@ -25,12 +25,8 @@ import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.vr.rules.XrActivityRestriction; import org.chromium.chrome.browser.vr.rules.XrActivityRestriction;
import org.chromium.chrome.browser.vr.util.ArTestRuleUtils; import org.chromium.chrome.browser.vr.util.ArTestRuleUtils;
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;
...@@ -78,52 +74,13 @@ public class WebXrArSessionTest { ...@@ -78,52 +74,13 @@ public class WebXrArSessionTest {
} }
/** /**
* Tests that declining AR consent causes future attempts to still display the consent dialog. * Tests that consenting causes future attempts to skip the permission prompt as long as no
* Consent-flow specific * navigation occurs.
*/ */
@Test @Test
@MediumTest @MediumTest
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
@DisableFeatures(ContentFeatureList.WEBXR_PERMISSIONS_API)
public void testConsentShowsAfterDecline() {
mWebXrArTestFramework.loadFileAndAwaitInitialization(
"test_ar_request_session_succeeds", PAGE_LOAD_TIMEOUT_S);
WebContents contents = mWebXrArTestFramework.getCurrentWebContents();
// Start session, decline consent prompt.
mWebXrArTestFramework.enterSessionWithUserGestureAndDeclineConsentOrFail(contents);
mWebXrArTestFramework.assertNoJavaScriptErrors();
PermissionUtils.waitForConsentPromptDismissal(mTestRule.getActivity());
// Start new session, accept consent prompt this time.
mWebXrArTestFramework.enterSessionWithUserGestureOrFail(contents);
mWebXrArTestFramework.endSession();
mWebXrArTestFramework.assertNoJavaScriptErrors();
mWebXrArTestFramework.pollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.AR].currentSession == null", POLL_TIMEOUT_SHORT_MS);
}
@Test
@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() { 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( 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();
...@@ -136,7 +93,7 @@ public class WebXrArSessionTest { ...@@ -136,7 +93,7 @@ public class WebXrArSessionTest {
"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 // 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. // the permission prompt 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);
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package org.chromium.chrome.browser.vr; package org.chromium.chrome.browser.vr;
import org.junit.Assert;
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.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -23,8 +21,8 @@ public class WebXrArTestFramework extends WebXrTestFramework { ...@@ -23,8 +21,8 @@ public class WebXrArTestFramework extends WebXrTestFramework {
} }
/** /**
* Requests an AR session, automatically giving consent when prompted. * Requests an AR session, automatically granting permission when prompted.
* Causes a test failure if it is unable to do so, or if the consent prompt is missing. * Causes a test failure if it is unable to do so, or if the permission prompt is missing.
* *
* @param webContents The Webcontents to start the AR session in. * @param webContents The Webcontents to start the AR session in.
*/ */
...@@ -35,43 +33,17 @@ public class WebXrArTestFramework extends WebXrTestFramework { ...@@ -35,43 +33,17 @@ public class WebXrArTestFramework extends WebXrTestFramework {
enterSessionWithUserGesture(webContents); enterSessionWithUserGesture(webContents);
// We expect a session consent prompt (in this case the AR-specific one), but should not // We expect a session permissiom prompt (in this case the AR-specific one), but should not
// get prompted for page camera permission. // get prompted for page camera permission.
if (shouldExpectConsentDialog()) { if (shouldExpectPermissionPrompt()) {
PermissionUtils.waitForConsentPrompt(getRule().getActivity()); PermissionUtils.waitForPermissionPrompt();
PermissionUtils.acceptConsentPrompt(getRule().getActivity()); PermissionUtils.acceptPermissionPrompt();
} }
pollJavaScriptBooleanOrFail("sessionInfos[sessionTypes.AR].currentSession != null", pollJavaScriptBooleanOrFail("sessionInfos[sessionTypes.AR].currentSession != null",
POLL_TIMEOUT_LONG_MS, webContents); POLL_TIMEOUT_LONG_MS, webContents);
} }
/**
* Requests an AR session, then declines consent when prompted.
* Causes a test failure if there was no prompt, or if the session started without consent.
*
* @param webContents The Webcontents to start the AR session in.
*/
public void enterSessionWithUserGestureAndDeclineConsentOrFail(WebContents webContents) {
if (!shouldExpectConsentDialog()) {
Assert.fail("Attempted to decline the consent dialog when it would not appear.");
}
runJavaScriptOrFail(
"sessionTypeToRequest = sessionTypes.AR", POLL_TIMEOUT_LONG_MS, webContents);
enterSessionWithUserGesture(webContents);
// We expect the AR-specific AR session consent prompt but should not get
// prompted for page camera permission.
PermissionUtils.waitForConsentPrompt(getRule().getActivity());
PermissionUtils.declineConsentPrompt(getRule().getActivity());
pollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.AR].error != null", POLL_TIMEOUT_LONG_MS, webContents);
pollJavaScriptBooleanOrFail("sessionInfos[sessionTypes.AR].currentSession == null",
POLL_TIMEOUT_LONG_MS, webContents);
}
/** /**
* Exits a WebXR AR session. * Exits a WebXR AR session.
* *
...@@ -90,14 +62,15 @@ public class WebXrArTestFramework extends WebXrTestFramework { ...@@ -90,14 +62,15 @@ public class WebXrArTestFramework extends WebXrTestFramework {
} }
/** /**
* Checks whether an immersive AR session would trigger the consent dialog. * Checks whether an immersive AR session would trigger the permission prompt.
* *
* @param webContents The WebContents to check in. * @param webContents The WebContents to check in.
* @return True if an immersive AR session request would trigger the consent dialog, otherwise * @return True if an immersive AR session request would trigger the permission prompt,
* otherwise
* false. * false.
*/ */
@Override @Override
public boolean shouldExpectConsentDialog(WebContents webContents) { public boolean shouldExpectPermissionPrompt(WebContents webContents) {
return shouldExpectConsentDialog("sessionTypes.AR", webContents); return shouldExpectPermissionPrompt("sessionTypes.AR", webContents);
} }
} }
...@@ -177,22 +177,22 @@ public abstract class WebXrTestFramework extends XrTestFramework { ...@@ -177,22 +177,22 @@ public abstract class WebXrTestFramework extends XrTestFramework {
} }
/** /**
* Helper function to run shouldExpectConsentDialog with the correct session type for the * Helper function to run shouldExpectPermissionPrompt with the correct session type for the
* framework. * framework.
* *
* @param webContents The WebContents to check the consent dialog in. * @param webContents The WebContents to check the permission prompt in.
* @return True if the a request for the session type would trigger the consent dialog to be * @return True if the a request for the session type would trigger the permission prompt to be
* shown, otherwise false. * shown, otherwise false.
*/ */
public abstract boolean shouldExpectConsentDialog(WebContents webContents); public abstract boolean shouldExpectPermissionPrompt(WebContents webContents);
/** /**
* Helper function to run shouldExpectConsentDialog with the current tab's WebContents. * Helper function to run shouldExpectPermissionPrompt with the current tab's WebContents.
* @return True if the a request for the session type would trigger the consent dialog to be * @return True if the a request for the session type would trigger the permission prompt to be
* shown, otherwise false. * shown, otherwise false.
*/ */
public boolean shouldExpectConsentDialog() { public boolean shouldExpectPermissionPrompt() {
return shouldExpectConsentDialog(getCurrentWebContents()); return shouldExpectPermissionPrompt(getCurrentWebContents());
} }
/** /**
...@@ -202,10 +202,11 @@ public abstract class WebXrTestFramework extends XrTestFramework { ...@@ -202,10 +202,11 @@ public abstract class WebXrTestFramework extends XrTestFramework {
* @param sessionType The session type to pass to JavaScript defined in webxr_boilerplate.js, * @param sessionType The session type to pass to JavaScript defined in webxr_boilerplate.js,
* e.g. sessionTypes.AR * e.g. sessionTypes.AR
* @param webContents The WebContents to check in. * @param webContents The WebContents to check in.
* @return True if the given session type is expected to trigger the consent dialog, otherwise * @return True if the given session type is expected to trigger the permission prompt,
* otherwise
* false. * false.
*/ */
protected boolean shouldExpectConsentDialog(String sessionType, WebContents webContents) { protected boolean shouldExpectPermissionPrompt(String sessionType, WebContents webContents) {
return runJavaScriptOrFail("sessionTypeWouldTriggerConsent(" + sessionType + ")", return runJavaScriptOrFail("sessionTypeWouldTriggerConsent(" + sessionType + ")",
POLL_TIMEOUT_SHORT_MS, webContents) POLL_TIMEOUT_SHORT_MS, webContents)
.equals("true"); .equals("true");
......
...@@ -9,31 +9,31 @@ import org.chromium.content_public.browser.WebContents; ...@@ -9,31 +9,31 @@ import org.chromium.content_public.browser.WebContents;
/** /**
* Extension class of WebXrVrTestFramework that allows explicitly specifying whether or not the * Extension class of WebXrVrTestFramework that allows explicitly specifying whether or not the
* consent dialog is expected. * permission prompt is expected.
*/ */
public class WebXrVrConsentTestFramework extends WebXrVrTestFramework { public class WebXrVrPermissionTestFramework extends WebXrVrTestFramework {
private boolean mConsentDialogExpected = true; private boolean mPermissionPromptExpected = true;
public WebXrVrConsentTestFramework(ChromeActivityTestRule testRule) { public WebXrVrPermissionTestFramework(ChromeActivityTestRule testRule) {
super(testRule); super(testRule);
} }
/** /**
* Sets whether or not the consent dialog is expected to be shown. * Sets whether or not the permission prompt is expected to be shown.
* *
* @param consentDialogExpected whether or not to expect the consent dialog * @param permissionPromptExpected whether or not to expect the permission prompt
*/ */
public void setConsentDialogExpected(boolean consentDialogExpected) { public void setPermissionPromptExpected(boolean permissionPromptExpected) {
mConsentDialogExpected = consentDialogExpected; mPermissionPromptExpected = permissionPromptExpected;
} }
/** /**
* Determines whether or not the consent dialog is expected to be shown. * Determines whether or not the permission prompt is expected to be shown.
* *
* @param webContents The webContents of the tab to check if it expects the consent dialog. * @param webContents The webContents of the tab to check if it expects the permission prompt.
*/ */
@Override @Override
public boolean shouldExpectConsentDialog(WebContents webContents) { public boolean shouldExpectPermissionPrompt(WebContents webContents) {
return mConsentDialogExpected; return mPermissionPromptExpected;
} }
} }
...@@ -22,16 +22,16 @@ import java.lang.annotation.RetentionPolicy; ...@@ -22,16 +22,16 @@ import java.lang.annotation.RetentionPolicy;
*/ */
public class WebXrVrTestFramework extends WebXrTestFramework { public class WebXrVrTestFramework extends WebXrTestFramework {
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({CONSENT_DIALOG_ACTION_DO_NOTHING, CONSENT_DIALOG_ACTION_ALLOW, @IntDef({PERMISSION_PROMPT_ACTION_DO_NOTHING, PERMISSION_PROMPT_ACTION_ALLOW,
CONSENT_DIALOG_ACTION_DENY}) PERMISSION_PROMPT_ACTION_DENY})
public @interface ConsentDialogAction {} public @interface PermissionPromptAction {}
public static final int CONSENT_DIALOG_ACTION_DO_NOTHING = 0; public static final int PERMISSION_PROMPT_ACTION_DO_NOTHING = 0;
public static final int CONSENT_DIALOG_ACTION_ALLOW = 1; public static final int PERMISSION_PROMPT_ACTION_ALLOW = 1;
public static final int CONSENT_DIALOG_ACTION_DENY = 2; public static final int PERMISSION_PROMPT_ACTION_DENY = 2;
@ConsentDialogAction @PermissionPromptAction
protected int mConsentDialogAction = CONSENT_DIALOG_ACTION_ALLOW; protected int mPermissionPromptAction = PERMISSION_PROMPT_ACTION_ALLOW;
public WebXrVrTestFramework(ChromeActivityTestRule rule) { public WebXrVrTestFramework(ChromeActivityTestRule rule) {
super(rule); super(rule);
...@@ -41,12 +41,12 @@ public class WebXrVrTestFramework extends WebXrTestFramework { ...@@ -41,12 +41,12 @@ public class WebXrVrTestFramework extends WebXrTestFramework {
} }
/** /**
* Set the default action to be taken when the consent dialog is displayed. * Set the default action to be taken when the permission prompt is displayed.
* *
* @param action The action to take on a consent dialog. * @param action The action to take on a permission prompt.
*/ */
public void setConsentDialogAction(@ConsentDialogAction int action) { public void setPermissionPromptAction(@PermissionPromptAction int action) {
mConsentDialogAction = action; mPermissionPromptAction = action;
} }
/** /**
...@@ -66,12 +66,12 @@ public class WebXrVrTestFramework extends WebXrTestFramework { ...@@ -66,12 +66,12 @@ public class WebXrVrTestFramework extends WebXrTestFramework {
} }
super.enterSessionWithUserGesture(webContents); super.enterSessionWithUserGesture(webContents);
if (!shouldExpectConsentDialog()) return; if (!shouldExpectPermissionPrompt()) return;
PermissionUtils.waitForConsentPrompt(getRule().getActivity()); PermissionUtils.waitForPermissionPrompt();
if (mConsentDialogAction == CONSENT_DIALOG_ACTION_ALLOW) { if (mPermissionPromptAction == PERMISSION_PROMPT_ACTION_ALLOW) {
PermissionUtils.acceptConsentPrompt(getRule().getActivity()); PermissionUtils.acceptPermissionPrompt();
} else if (mConsentDialogAction == CONSENT_DIALOG_ACTION_DENY) { } else if (mPermissionPromptAction == PERMISSION_PROMPT_ACTION_DENY) {
PermissionUtils.declineConsentPrompt(getRule().getActivity()); PermissionUtils.denyPermissionPrompt();
} }
} }
...@@ -123,14 +123,15 @@ public class WebXrVrTestFramework extends WebXrTestFramework { ...@@ -123,14 +123,15 @@ public class WebXrVrTestFramework extends WebXrTestFramework {
} }
/** /**
* Checks whether an immersive VR session would trigger the consent dialog. * Checks whether an immersive VR session would trigger the permission prompt.
* *
* @param webContents The WebContents to check in. * @param webContents The WebContents to check in.
* @return True if an immersive VR session request would trigger the consent dialog, otherwise * @return True if an immersive VR session request would trigger the permission prompt,
* otherwise
* false. * false.
*/ */
@Override @Override
public boolean shouldExpectConsentDialog(WebContents webContents) { public boolean shouldExpectPermissionPrompt(WebContents webContents) {
return shouldExpectConsentDialog("sessionTypeToRequest", webContents); return shouldExpectPermissionPrompt("sessionTypeToRequest", webContents);
} }
} }
...@@ -347,7 +347,7 @@ public class WebXrVrTransitionTest { ...@@ -347,7 +347,7 @@ public class WebXrVrTransitionTest {
} }
/** /**
* Tests that a consent dialog dismisses by itself when the page navigates away from * Tests that a permission prompt dismisses by itself when the page navigates away from
* the current page. * the current page.
*/ */
@Test @Test
...@@ -355,14 +355,13 @@ public class WebXrVrTransitionTest { ...@@ -355,14 +355,13 @@ public class WebXrVrTransitionTest {
@CommandLineFlags.Add({"enable-features=WebXR"}) @CommandLineFlags.Add({"enable-features=WebXR"})
@XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL}) @XrActivityRestriction({XrActivityRestriction.SupportedActivity.ALL})
public void testConsentDialogIsDismissedWhenPageNavigatesAwayInMainFrame() { public void testConsentDialogIsDismissedWhenPageNavigatesAwayInMainFrame() {
mWebXrVrTestFramework.setConsentDialogAction( mWebXrVrTestFramework.setPermissionPromptAction(
WebXrVrTestFramework.CONSENT_DIALOG_ACTION_DO_NOTHING); WebXrVrTestFramework.PERMISSION_PROMPT_ACTION_DO_NOTHING);
mWebXrVrTestFramework.loadFileAndAwaitInitialization( mWebXrVrTestFramework.loadFileAndAwaitInitialization(
"generic_webxr_page", PAGE_LOAD_TIMEOUT_S); "generic_webxr_page", PAGE_LOAD_TIMEOUT_S);
mWebXrVrTestFramework.enterSessionWithUserGesture(); mWebXrVrTestFramework.enterSessionWithUserGesture();
mWebXrVrTestFramework.runJavaScriptOrFail( mWebXrVrTestFramework.runJavaScriptOrFail(
"window.location.href = 'https://google.com'", POLL_TIMEOUT_SHORT_MS); "window.location.href = 'https://google.com'", POLL_TIMEOUT_SHORT_MS);
PermissionUtils.waitForConsentPromptDismissal( PermissionUtils.waitForPermissionPromptDismissal();
mWebXrVrTestFramework.getRule().getActivity());
} }
} }
...@@ -4,18 +4,10 @@ ...@@ -4,18 +4,10 @@
package org.chromium.chrome.browser.vr.util; package org.chromium.chrome.browser.vr.util;
import android.os.SystemClock;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.vr.ArConsentDialog;
import org.chromium.chrome.browser.vr.VrConsentDialog;
import org.chromium.components.permissions.PermissionDialogController; import org.chromium.components.permissions.PermissionDialogController;
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.ModalDialogProperties; import org.chromium.ui.modaldialog.ModalDialogProperties;
import org.chromium.ui.modelutil.PropertyModel;
/** /**
* Utility class for interacting with permission prompts outside of the VR Browser. For interaction * Utility class for interacting with permission prompts outside of the VR Browser. For interaction
...@@ -64,93 +56,4 @@ public class PermissionUtils { ...@@ -64,93 +56,4 @@ public class PermissionUtils {
ModalDialogProperties.ButtonType.NEGATIVE); ModalDialogProperties.ButtonType.NEGATIVE);
}); });
} }
/**
* Blocks until the session consent prompt appears.
*/
public static void waitForConsentPrompt(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
waitForPermissionPrompt();
return;
}
CriteriaHelper.pollUiThread(()
-> { return isConsentDialogShown(activity); },
"Consent prompt did not appear in allotted time",
CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL, DIALOG_POLLING_INTERVAL_MS);
}
/**
* Blocks until the consent prompt is dismissed.
*/
public static void waitForConsentPromptDismissal(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
waitForPermissionPromptDismissal();
return;
}
CriteriaHelper.pollUiThread(()
-> { return !isConsentDialogShown(activity); },
"Consent prompt did not get dismissed in allotted time",
CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL, DIALOG_POLLING_INTERVAL_MS);
// For some reason, the prompt can be dismissed, but we won't be able to show a new one for
// a short period of time (animations?), so wait a little longer to avoid that.
SystemClock.sleep(500);
}
/**
* Accepts the currently displayed session consent prompt.
*/
public static void acceptConsentPrompt(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
acceptPermissionPrompt();
return;
}
TestThreadUtils.runOnUiThreadBlocking(() -> {
clickConsentDialogButton(activity, ModalDialogProperties.ButtonType.POSITIVE);
});
}
/**
* Declines the currently displayed session consent prompt.
*/
public static void declineConsentPrompt(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
denyPermissionPrompt();
return;
}
TestThreadUtils.runOnUiThreadBlocking(() -> {
clickConsentDialogButton(activity, ModalDialogProperties.ButtonType.NEGATIVE);
});
}
/**
* Helper function to check if the consent dialog is being shown.
*/
public static boolean isConsentDialogShown(ChromeActivity activity) {
if (ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API)) {
return PermissionDialogController.getInstance().isDialogShownForTest();
}
ModalDialogManager manager = activity.getModalDialogManager();
PropertyModel model = manager.getCurrentDialogForTest();
if (model == null) return false;
ModalDialogProperties.Controller controller = model.get(ModalDialogProperties.CONTROLLER);
return controller instanceof ArConsentDialog || controller instanceof VrConsentDialog;
}
/**
* Helper function to click a button in the consent dialog.
*/
private static void clickConsentDialogButton(ChromeActivity activity, int buttonType) {
assert (!ContentFeatureList.isEnabled(ContentFeatureList.WEBXR_PERMISSIONS_API));
ModalDialogManager manager = activity.getModalDialogManager();
PropertyModel model = manager.getCurrentDialogForTest();
ModalDialogProperties.Controller dialog =
(ModalDialogProperties.Controller) (model.get(ModalDialogProperties.CONTROLLER));
dialog.onClick(model, buttonType);
}
} }
...@@ -649,12 +649,8 @@ if (!is_android) { ...@@ -649,12 +649,8 @@ if (!is_android) {
# Infrastructure # Infrastructure
sources = [ sources = [
"test/fake_xr_session_request_consent_manager.cc",
"test/fake_xr_session_request_consent_manager.h",
"test/mock_xr_device_hook_base.cc", "test/mock_xr_device_hook_base.cc",
"test/mock_xr_device_hook_base.h", "test/mock_xr_device_hook_base.h",
"test/mock_xr_session_request_consent_manager.cc",
"test/mock_xr_session_request_consent_manager.h",
"test/multi_class_browser_test.h", "test/multi_class_browser_test.h",
] ]
...@@ -683,12 +679,12 @@ if (!is_android) { ...@@ -683,12 +679,12 @@ if (!is_android) {
# Tests. # Tests.
sources += [ sources += [
"webxr_vr_consent_dialog_browser_test.cc",
"webxr_vr_frame_loop_browser_test.cc", "webxr_vr_frame_loop_browser_test.cc",
"webxr_vr_frame_pose_browser_test.cc", "webxr_vr_frame_pose_browser_test.cc",
"webxr_vr_indicators_browser_test.cc", "webxr_vr_indicators_browser_test.cc",
"webxr_vr_input_browser_test.cc", "webxr_vr_input_browser_test.cc",
"webxr_vr_isolated_device_service_test.cc", "webxr_vr_isolated_device_service_test.cc",
"webxr_vr_permission_browser_test.cc",
"webxr_vr_permission_request_browser_test.cc", "webxr_vr_permission_request_browser_test.cc",
"webxr_vr_pixel_browser_test.cc", "webxr_vr_pixel_browser_test.cc",
"webxr_vr_tab_browser_test.cc", "webxr_vr_tab_browser_test.cc",
......
// Copyright 2019 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.
#include "chrome/browser/vr/test/fake_xr_session_request_consent_manager.h"
#include <utility>
#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
#include "content/public/test/test_utils.h"
namespace vr {
namespace {
static constexpr base::TimeDelta kConsentDialogDisplayingTime =
base::TimeDelta::FromMilliseconds(250);
} // namespace
FakeXRSessionRequestConsentManager::FakeXRSessionRequestConsentManager(
XRSessionRequestConsentManager* consent_manager,
UserResponse user_response)
: consent_manager_(consent_manager), user_response_(user_response) {}
FakeXRSessionRequestConsentManager::~FakeXRSessionRequestConsentManager() =
default;
TabModalConfirmDialog*
FakeXRSessionRequestConsentManager::ShowDialogAndGetConsent(
content::WebContents* web_contents,
content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback) {
shown_count_++;
auto* confirm_dialog = consent_manager_->ShowDialogAndGetConsent(
web_contents, consent_level, std::move(response_callback));
// Allow the dialog to show at least for a little while before simulating
// the action.
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, run_loop.QuitWhenIdleClosure(), kConsentDialogDisplayingTime);
run_loop.Run();
switch (user_response_) {
case UserResponse::kClickAllowButton:
confirm_dialog->AcceptTabModalDialog();
break;
case UserResponse::kClickCancelButton:
confirm_dialog->CancelTabModalDialog();
break;
case UserResponse::kCloseDialog:
confirm_dialog->CloseDialog();
break;
}
// Allow the dialog to close cleanly.
base::RunLoop dialog_clean_close_loop(
base::RunLoop::Type::kNestableTasksAllowed);
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, dialog_clean_close_loop.QuitWhenIdleClosure(),
kConsentDialogDisplayingTime);
dialog_clean_close_loop.Run();
return confirm_dialog;
}
} // namespace vr
// Copyright 2019 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.
#ifndef CHROME_BROWSER_VR_TEST_FAKE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
#define CHROME_BROWSER_VR_TEST_FAKE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
#include "base/macros.h"
#include "chrome/browser/vr/consent/xr_session_request_consent_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace vr {
class FakeXRSessionRequestConsentManager
: public XRSessionRequestConsentManager {
public:
enum class UserResponse {
kClickAllowButton,
kClickCancelButton,
kCloseDialog,
};
FakeXRSessionRequestConsentManager(
XRSessionRequestConsentManager* consent_manager,
UserResponse user_response);
~FakeXRSessionRequestConsentManager() override;
TabModalConfirmDialog* ShowDialogAndGetConsent(
content::WebContents* web_contents,
content::XrConsentPromptLevel conesent_level,
base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback) override;
uint32_t ShownCount() { return shown_count_; }
private:
XRSessionRequestConsentManager* consent_manager_;
UserResponse user_response_;
uint32_t shown_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(FakeXRSessionRequestConsentManager);
};
} // namespace vr
#endif // CHROME_BROWSER_VR_TEST_FAKE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
// Copyright 2019 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.
#include "chrome/browser/vr/test/mock_xr_session_request_consent_manager.h"
namespace vr {
MockXRSessionRequestConsentManager::MockXRSessionRequestConsentManager() =
default;
MockXRSessionRequestConsentManager::~MockXRSessionRequestConsentManager() =
default;
} // namespace vr
// Copyright 2019 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.
#ifndef CHROME_BROWSER_VR_TEST_MOCK_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
#define CHROME_BROWSER_VR_TEST_MOCK_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
#include "base/macros.h"
#include "chrome/browser/vr/consent/xr_session_request_consent_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace vr {
class MockXRSessionRequestConsentManager
: public XRSessionRequestConsentManager {
public:
MockXRSessionRequestConsentManager();
~MockXRSessionRequestConsentManager() override;
MOCK_METHOD3(ShowDialogAndGetConsent,
TabModalConfirmDialog*(
content::WebContents* web_contents,
content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
response_callback));
private:
DISALLOW_COPY_AND_ASSIGN(MockXRSessionRequestConsentManager);
};
} // namespace vr
#endif // CHROME_BROWSER_VR_TEST_MOCK_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
...@@ -22,22 +22,6 @@ WebXrVrBrowserTestBase::~WebXrVrBrowserTestBase() = default; ...@@ -22,22 +22,6 @@ WebXrVrBrowserTestBase::~WebXrVrBrowserTestBase() = default;
void WebXrVrBrowserTestBase::EnterSessionWithUserGesture( void WebXrVrBrowserTestBase::EnterSessionWithUserGesture(
content::WebContents* web_contents) { content::WebContents* web_contents) {
// Consent dialogs don't appear on platforms with enable_vr = false.
#if BUILDFLAG(ENABLE_VR)
if (!fake_consent_manager_) {
XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_);
ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _))
.WillByDefault(Invoke(
[](content::WebContents*,
content::XrConsentPromptLevel consent_level,
base::OnceCallback<void(content::XrConsentPromptLevel, bool)>
callback) {
std::move(callback).Run(consent_level, true);
return nullptr;
}));
}
#endif // BUILDFLAG(ENABLE_VR)
// Before requesting the session, set the requested auto-response so that the // Before requesting the session, set the requested auto-response so that the
// session is appropriately granted or rejected (or the request ignored). // session is appropriately granted or rejected (or the request ignored).
GetPermissionRequestManager()->set_auto_response_for_test( GetPermissionRequestManager()->set_auto_response_for_test(
...@@ -67,12 +51,6 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGestureOrFail( ...@@ -67,12 +51,6 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGestureOrFail(
} }
void WebXrVrBrowserTestBase::EndSession(content::WebContents* web_contents) { void WebXrVrBrowserTestBase::EndSession(content::WebContents* web_contents) {
// Consent dialogs don't appear on platforms with enable_vr = false.
#if BUILDFLAG(ENABLE_VR)
if (!fake_consent_manager_)
XRSessionRequestConsentManager::SetInstanceForTesting(nullptr);
#endif // BUILDFLAG(ENABLE_VR)
RunJavaScriptOrFail( RunJavaScriptOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].currentSession.end()", "sessionInfos[sessionTypes.IMMERSIVE].currentSession.end()",
web_contents); web_contents);
...@@ -101,35 +79,6 @@ WebXrVrBrowserTestBase::GetPermissionRequestManager( ...@@ -101,35 +79,6 @@ WebXrVrBrowserTestBase::GetPermissionRequestManager(
return permissions::PermissionRequestManager::FromWebContents(web_contents); return permissions::PermissionRequestManager::FromWebContents(web_contents);
} }
// Consent dialogs don't appear on platforms with enable_vr = false.
#if BUILDFLAG(ENABLE_VR)
void WebXrVrBrowserTestBase::SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse user_response) {
fake_consent_manager_.reset(new FakeXRSessionRequestConsentManager(
XRSessionRequestConsentManager::Instance(), user_response));
XRSessionRequestConsentManager::SetInstanceForTesting(
fake_consent_manager_.get());
// To ensure that consent flow tests can still use the same logic, we also set
// the auto-response behavior to the expected value here so that permissions
// will behave the same way as the consent flow would have.
switch (user_response) {
case FakeXRSessionRequestConsentManager::UserResponse::kClickAllowButton:
permission_auto_response_ =
permissions::PermissionRequestManager::AutoResponseType::ACCEPT_ALL;
break;
case FakeXRSessionRequestConsentManager::UserResponse::kClickCancelButton:
permission_auto_response_ =
permissions::PermissionRequestManager::AutoResponseType::DENY_ALL;
break;
case FakeXRSessionRequestConsentManager::UserResponse::kCloseDialog:
permission_auto_response_ =
permissions::PermissionRequestManager::AutoResponseType::DISMISS;
break;
}
}
#endif // BUILDFLAG(ENABLE_VR)
WebXrVrRuntimelessBrowserTest::WebXrVrRuntimelessBrowserTest() { WebXrVrRuntimelessBrowserTest::WebXrVrRuntimelessBrowserTest() {
#if BUILDFLAG(ENABLE_WINDOWS_MR) #if BUILDFLAG(ENABLE_WINDOWS_MR)
disable_features_.push_back(device::features::kWindowsMixedReality); disable_features_.push_back(device::features::kWindowsMixedReality);
......
...@@ -21,11 +21,6 @@ ...@@ -21,11 +21,6 @@
#include "services/service_manager/sandbox/features.h" #include "services/service_manager/sandbox/features.h"
#endif #endif
#if BUILDFLAG(ENABLE_VR)
#include "chrome/browser/vr/test/fake_xr_session_request_consent_manager.h"
#include "chrome/browser/vr/test/mock_xr_session_request_consent_manager.h"
#endif // BUILDFLAG(ENABLE_VR)
namespace vr { namespace vr {
// WebXR for VR-specific test base class without any particular runtime. // WebXR for VR-specific test base class without any particular runtime.
...@@ -56,21 +51,6 @@ class WebXrVrBrowserTestBase : public WebXrBrowserTestBase { ...@@ -56,21 +51,6 @@ class WebXrVrBrowserTestBase : public WebXrBrowserTestBase {
permissions::PermissionRequestManager::AutoResponseType permissions::PermissionRequestManager::AutoResponseType
permission_auto_response_ = permission_auto_response_ =
permissions::PermissionRequestManager::ACCEPT_ALL; permissions::PermissionRequestManager::ACCEPT_ALL;
// Methods/objects for managing consent. If SetupFakeConsentManager is never
// called, the test will default to mocking out the consent prompt and always
// provide consent. Once SetupFakeConsentManager is called, the test will show
// the Consent Dialog, and then rely on it's configuration for whether to
// accept or reject the dialog programmatically. While this is a more thorough
// end-to-end test, the extra overhead should be avoided unless that is the
// feature under test.
// Consent dialogs don't appear on platforms with enable_vr = false.
#if BUILDFLAG(ENABLE_VR)
void SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse user_response);
::testing::NiceMock<MockXRSessionRequestConsentManager> consent_manager_;
std::unique_ptr<FakeXRSessionRequestConsentManager> fake_consent_manager_;
#endif // BUILDFLAG(ENABLE_VR)
}; };
// Test class with OpenVR disabled. // Test class with OpenVR disabled.
......
// Copyright 2019 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.
#include "build/build_config.h"
#include "chrome/browser/vr/test/multi_class_browser_test.h"
#include "chrome/browser/vr/test/webxr_vr_browser_test.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
namespace vr {
// Helper macro to wrap consent flow tests that should be run with the custom
// consent flow as well as the standard permissions prompt.
#define CONSENT_FLOW_TEST_F(test_name) \
IN_PROC_MULTI_CLASS_BROWSER_TEST_F2( \
WebXrVrConsentBrowserTest, WebXrVrPermissionsBrowserTest, \
WebXrVrConsentBrowserTestBase, test_name)
// The consent flow isn't specific to any particular runtime; so it's okay to
// keep it specific to one runtime, especially while the additional setup steps
// are needed. Once we've consolidated this down to a single flow and don't need
// additional setup, ShownCount and SetupObservers could move to a higher level
// and tests could be run on all supported runtimes if desired.
class WebXrVrConsentBrowserTestBase : public WebXrVrWmrBrowserTestBase {
public:
WebXrVrConsentBrowserTestBase() {}
~WebXrVrConsentBrowserTestBase() override = default;
virtual uint32_t ShownCount() = 0;
virtual void SetupObservers() {}
};
class WebXrVrConsentBrowserTest : public WebXrVrConsentBrowserTestBase {
public:
WebXrVrConsentBrowserTest() {
disable_features_.push_back(features::kWebXrPermissionsApi);
}
~WebXrVrConsentBrowserTest() override = default;
uint32_t ShownCount() override { return fake_consent_manager_->ShownCount(); }
};
class WebXrVrPermissionsBrowserTest
: public WebXrVrConsentBrowserTestBase,
public permissions::PermissionRequestManager::Observer {
public:
WebXrVrPermissionsBrowserTest() {
enable_features_.push_back(features::kWebXrPermissionsApi);
}
~WebXrVrPermissionsBrowserTest() override = default;
uint32_t ShownCount() override { return shown_count_; }
private:
void OnBubbleAdded() override { shown_count_++; }
void SetupObservers() override {
GetPermissionRequestManager()->AddObserver(this);
}
uint32_t shown_count_ = 0u;
};
// Tests that WebXR sessions can be created when the "Allow" button is pressed.
CONSENT_FLOW_TEST_F(TestConsentAllowCreatesSession) {
t->SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickAllowButton);
t->LoadFileAndAwaitInitialization("generic_webxr_page");
t->SetupObservers();
t->EnterSessionWithUserGestureOrFail();
ASSERT_EQ(t->ShownCount(), 1u)
<< "Consent Dialog should have been shown once";
}
// Tests that a session is not created if the user explicitly clicks the
// cancel button.
CONSENT_FLOW_TEST_F(TestConsentCancelFailsSessionCreation) {
t->SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickCancelButton);
t->LoadFileAndAwaitInitialization("test_webxr_consent");
t->SetupObservers();
t->EnterSessionWithUserGesture();
t->PollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].error != null",
WebXrVrBrowserTestBase::kPollTimeoutMedium);
t->RunJavaScriptOrFail("verifySessionConsentError(sessionTypes.IMMERSIVE)");
t->AssertNoJavaScriptErrors();
ASSERT_EQ(t->ShownCount(), 1u)
<< "Consent Dialog should have been shown once";
}
// Tests that a session is not created if the user explicitly closes the
// dialog.
CONSENT_FLOW_TEST_F(TestConsentCloseFailsSessionCreation) {
t->SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kCloseDialog);
t->LoadFileAndAwaitInitialization("test_webxr_consent");
t->SetupObservers();
t->EnterSessionWithUserGesture();
t->PollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].error != null",
WebXrVrBrowserTestBase::kPollTimeoutMedium);
t->RunJavaScriptOrFail("verifySessionConsentError(sessionTypes.IMMERSIVE)");
t->AssertNoJavaScriptErrors();
ASSERT_EQ(t->ShownCount(), 1u)
<< "Consent Dialog should have been shown once";
}
// Tests that requesting a session with the same required level of consent
// without a page reload, only prompts once.
CONSENT_FLOW_TEST_F(TestConsentPersistsSameLevel) {
t->SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickAllowButton);
t->LoadFileAndAwaitInitialization("generic_webxr_page");
t->SetupObservers();
t->EnterSessionWithUserGestureOrFail();
t->EndSessionOrFail();
// Since the consent from the earlier prompt should be persisted, requesting
// an XR session a second time should not prompt the user, but should create
// a valid session.
t->EnterSessionWithUserGestureOrFail();
// Validate that the consent prompt has only been shown once since the start
// of this test.
ASSERT_EQ(t->ShownCount(), 1u)
<< "Consent Dialog should have only been shown once";
}
// Verify that inline with no session parameters doesn't prompt for consent.
CONSENT_FLOW_TEST_F(TestConsentNotNeededForInline) {
// This ensures that we have a fresh consent manager with a new count.
t->SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickAllowButton);
t->LoadFileAndAwaitInitialization("test_webxr_consent");
t->SetupObservers();
t->RunJavaScriptOrFail("requestMagicWindowSession()");
t->PollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.MAGIC_WINDOW].currentSession != null",
WebXrVrBrowserTestBase::kPollTimeoutLong);
// Validate that the consent prompt has not been shown since this test began.
ASSERT_EQ(t->ShownCount(), 0u) << "Consent Dialog should not have been shown";
}
// Verify that if a higher level of consent is granted (e.g. bounded), that the
// lower level does not re-prompt for consent.
IN_PROC_BROWSER_TEST_F(WebXrVrConsentBrowserTest,
TestConsentPersistsLowerLevel) {
// This ensures that we have a fresh consent manager with a new count.
SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickAllowButton);
LoadFileAndAwaitInitialization("test_webxr_consent");
SetupObservers();
// Setup to ensure that we request a session that requires a high level of
// consent.
RunJavaScriptOrFail("setupImmersiveSessionToRequestBounded()");
EnterSessionWithUserGestureOrFail();
EndSessionOrFail();
// Since the (higher) consent from the earlier prompt should be persisted,
// requesting an XR session a second time, with a lower level of permissions
// expected should not prompt the user, but should create a valid session.
RunJavaScriptOrFail("setupImmersiveSessionToRequestHeight()");
EnterSessionWithUserGestureOrFail();
// Validate that the consent prompt has only been shown once since the start
// of this test.
ASSERT_EQ(ShownCount(), 1u)
<< "Consent Dialog should have only been shown once";
}
// Tests that if a higher level of consent than was previously granted is needed
// that the user is re-prompted.
IN_PROC_BROWSER_TEST_F(WebXrVrConsentBrowserTest,
TestConsentRepromptsHigherLevel) {
// This ensures that we have a fresh consent manager with a new count.
SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickAllowButton);
LoadFileAndAwaitInitialization("test_webxr_consent");
SetupObservers();
// First request an immersive session with a medium level of consent.
RunJavaScriptOrFail("setupImmersiveSessionToRequestHeight()");
EnterSessionWithUserGestureOrFail();
EndSessionOrFail();
// Now set up to request a session with a higher level of consent than
// previously granted. This should cause the prompt to appear again, and then
// a new session be created.
RunJavaScriptOrFail("setupImmersiveSessionToRequestBounded()");
EnterSessionWithUserGestureOrFail();
// Validate that both request sessions showed a consent prompt.
ASSERT_EQ(ShownCount(), 2u) << "Consent Dialog should have been shown twice";
}
IN_PROC_BROWSER_TEST_F(WebXrVrConsentBrowserTest,
TestConsentRepromptsAfterReload) {
SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickAllowButton);
LoadFileAndAwaitInitialization("generic_webxr_page");
SetupObservers();
EnterSessionWithUserGestureOrFail();
EndSessionOrFail();
LoadFileAndAwaitInitialization("generic_webxr_page");
SetupObservers();
EnterSessionWithUserGestureOrFail();
// Validate that both request sessions showed a consent prompt.
ASSERT_EQ(ShownCount(), 2u) << "Consent Dialog should have been shown twice";
}
} // namespace vr
// Copyright 2019 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.
#include "build/build_config.h"
#include "chrome/browser/vr/test/multi_class_browser_test.h"
#include "chrome/browser/vr/test/webxr_vr_browser_test.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
namespace vr {
// The permission flow isn't specific to any particular runtime; so it's okay to
// keep it specific to one runtime; however, ShownCount and SetupObservers could
// move to a higher level and tests could be run on all supported runtimes if
// desired.
class WebXrVrPermissionsBrowserTest
: public WebXrVrWmrBrowserTestBase,
public permissions::PermissionRequestManager::Observer {
public:
WebXrVrPermissionsBrowserTest() = default;
~WebXrVrPermissionsBrowserTest() override = default;
void SetupObservers() { GetPermissionRequestManager()->AddObserver(this); }
uint32_t ShownCount() { return shown_count_; }
private:
void OnBubbleAdded() override { shown_count_++; }
uint32_t shown_count_ = 0u;
};
// Tests that WebXR sessions can be created when permission is granted.
IN_PROC_BROWSER_TEST_F(WebXrVrPermissionsBrowserTest,
TestGrantingPermissionCreatesSession) {
permission_auto_response_ =
permissions::PermissionRequestManager::AutoResponseType::ACCEPT_ALL;
LoadFileAndAwaitInitialization("generic_webxr_page");
SetupObservers();
EnterSessionWithUserGestureOrFail();
ASSERT_EQ(ShownCount(), 1u) << "Permission prompt should've been shown once";
}
// Tests that a session is not created if the user explicitly denies permission.
IN_PROC_BROWSER_TEST_F(WebXrVrPermissionsBrowserTest,
TestDenyingPermissionFailsSessionCreation) {
permission_auto_response_ =
permissions::PermissionRequestManager::AutoResponseType::DENY_ALL;
LoadFileAndAwaitInitialization("test_webxr_permission");
SetupObservers();
EnterSessionWithUserGesture();
PollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].error != null",
WebXrVrBrowserTestBase::kPollTimeoutMedium);
RunJavaScriptOrFail("verifyPermissionDeniedError(sessionTypes.IMMERSIVE)");
AssertNoJavaScriptErrors();
ASSERT_EQ(ShownCount(), 1u) << "Permission prompt should've been shown once";
}
// Tests that a session is not created if the user explicitly closes the
// dialog.
IN_PROC_BROWSER_TEST_F(WebXrVrPermissionsBrowserTest,
TestDismissingPromptCloseFailsSessionCreation) {
permission_auto_response_ =
permissions::PermissionRequestManager::AutoResponseType::DISMISS;
LoadFileAndAwaitInitialization("test_webxr_permission");
SetupObservers();
EnterSessionWithUserGesture();
PollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].error != null",
WebXrVrBrowserTestBase::kPollTimeoutMedium);
RunJavaScriptOrFail("verifyPermissionDeniedError(sessionTypes.IMMERSIVE)");
AssertNoJavaScriptErrors();
ASSERT_EQ(ShownCount(), 1u) << "Permission prompt should've been shown once";
}
// Tests that requesting the same type of session only prompts once.
IN_PROC_BROWSER_TEST_F(WebXrVrPermissionsBrowserTest, TestPermissionPersists) {
permission_auto_response_ =
permissions::PermissionRequestManager::AutoResponseType::ACCEPT_ALL;
LoadFileAndAwaitInitialization("generic_webxr_page");
SetupObservers();
EnterSessionWithUserGestureOrFail();
EndSessionOrFail();
// Since the permission from the earlier prompt should be persisted,
// requesting an XR session a second time should not prompt the user, but
// should create a valid session.
EnterSessionWithUserGestureOrFail();
// Validate that the permission prompt has only been shown once since the
// start of this test.
ASSERT_EQ(ShownCount(), 1u)
<< "Permission prompt should've only been shown once";
}
// Verify that inline with no session parameters doesn't prompt for permission.
IN_PROC_BROWSER_TEST_F(WebXrVrPermissionsBrowserTest,
TestPermissionNotNeededForInline) {
permission_auto_response_ =
permissions::PermissionRequestManager::AutoResponseType::ACCEPT_ALL;
LoadFileAndAwaitInitialization("test_webxr_permission");
SetupObservers();
RunJavaScriptOrFail("requestMagicWindowSession()");
PollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.MAGIC_WINDOW].currentSession != null",
WebXrVrBrowserTestBase::kPollTimeoutLong);
// Validate that the permission prompt has not been shown since this test
// began.
ASSERT_EQ(ShownCount(), 0u) << "Permission prompt should not have been shown";
}
} // namespace vr
...@@ -29,7 +29,7 @@ WebXR page without any code specific to one test ...@@ -29,7 +29,7 @@ WebXR page without any code specific to one test
immersiveSessionInit = {}; immersiveSessionInit = {};
} }
function verifySessionConsentError(sessionType) { function verifyPermissionDeniedError(sessionType) {
assert_not_equals(sessionInfos[sessionType].error, null); assert_not_equals(sessionInfos[sessionType].error, null);
let err = sessionInfos[sessionType].error; let err = sessionInfos[sessionType].error;
assert_true(err instanceof DOMException, "Session should be rejected with a DOMException"); assert_true(err instanceof DOMException, "Session should be rejected with a DOMException");
......
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