Commit 338045a8 authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Update xr_browser_tests for permissions prompt

Updates xr_browser_test infrastructure to appropriately grant (or deny)
permissions, as well as providing tests with a way to override that.
This ensures that tests will keep running when the permissions prompt is
enabled by default and can be cleaned up as time permits.

Additionally, refactors consent flow tests to a base class and two sub-
classes. These sub classes can be used to explicitly test the custom
consent flow or permissions prompt behavior. A (local) helper macro was
created to indicate which of these tests should be run for both versions
versus which tests were specific only to one or the other. To simplify
this change (and because the permissions flow is runtime agnostic),
consent flow tests are now run against only one runtime.

Bug: 1043241
Change-Id: Ifb9040c46993f8b0375383426a4cafa7e342f6da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055304
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741172}
parent bd91ebc3
......@@ -36,6 +36,11 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGesture(
}
#endif // BUILDFLAG(ENABLE_VR)
// Before requesting the session, set the requested auto-response so that the
// session is appropriately granted or rejected (or the request ignored).
GetPermissionRequestManager()->set_auto_response_for_test(
permission_auto_response_);
// ExecuteScript runs with a user gesture, so we can just directly call
// requestSession instead of having to do the hacky workaround the
// instrumentation tests use of actually sending a click event to the canvas.
......@@ -83,6 +88,16 @@ gfx::Vector3dF WebXrVrBrowserTestBase::GetControllerOffset() const {
return gfx::Vector3dF();
}
PermissionRequestManager*
WebXrVrBrowserTestBase::GetPermissionRequestManager() {
return GetPermissionRequestManager(GetCurrentWebContents());
}
PermissionRequestManager* WebXrVrBrowserTestBase::GetPermissionRequestManager(
content::WebContents* web_contents) {
return PermissionRequestManager::FromWebContents(web_contents);
}
// Consent dialogs don't appear on platforms with enable_vr = false.
#if BUILDFLAG(ENABLE_VR)
void WebXrVrBrowserTestBase::SetupFakeConsentManager(
......@@ -91,6 +106,24 @@ void WebXrVrBrowserTestBase::SetupFakeConsentManager(
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_ =
PermissionRequestManager::AutoResponseType::ACCEPT_ALL;
break;
case FakeXRSessionRequestConsentManager::UserResponse::kClickCancelButton:
permission_auto_response_ =
PermissionRequestManager::AutoResponseType::DENY_ALL;
break;
case FakeXRSessionRequestConsentManager::UserResponse::kCloseDialog:
permission_auto_response_ =
PermissionRequestManager::AutoResponseType::DISMISS;
break;
}
}
#endif // BUILDFLAG(ENABLE_VR)
......
......@@ -6,6 +6,7 @@
#define CHROME_BROWSER_VR_TEST_WEBXR_VR_BROWSER_TEST_H_
#include "build/build_config.h"
#include "chrome/browser/permissions/permission_request_manager.h"
#include "chrome/browser/vr/test/conditional_skipping.h"
#include "chrome/browser/vr/test/mock_xr_device_hook_base.h"
#include "chrome/browser/vr/test/webxr_browser_test.h"
......@@ -39,6 +40,10 @@ class WebXrVrBrowserTestBase : public WebXrBrowserTestBase {
void EndSession(content::WebContents* web_contents) override;
void EndSessionOrFail(content::WebContents* web_contents) override;
PermissionRequestManager* GetPermissionRequestManager();
PermissionRequestManager* GetPermissionRequestManager(
content::WebContents* web_contents);
virtual gfx::Vector3dF GetControllerOffset() const;
// Necessary to use the WebContents-less versions of functions.
......@@ -49,6 +54,9 @@ class WebXrVrBrowserTestBase : public WebXrBrowserTestBase {
using WebXrBrowserTestBase::EndSession;
using WebXrBrowserTestBase::EndSessionOrFail;
PermissionRequestManager::AutoResponseType permission_auto_response_ =
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
......
......@@ -27,6 +27,13 @@ WEBXR_VR_ALL_RUNTIMES_BROWSER_TEST_F(
// if a suitable device is not connected.
// TODO(bsheedy): Find a way to support more permission types (maybe use
// MockPermissionPromptFactory?).
// AutoResponseForTest is overridden when requesting a session. We don't want
// to change that as we want anything necessary to request a session to get
// granted. However, we want no action to be taken now so that the prompt for
// location comes up and does not get dismissed.
t->GetPermissionRequestManager()->set_auto_response_for_test(
PermissionRequestManager::NONE);
t->RunJavaScriptOrFail(
"navigator.geolocation.getCurrentPosition( ()=>{}, ()=>{} )");
base::RunLoop().RunUntilIdle();
......
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