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

Add Tests for WebXR Tailored Consent

Adds four new tests around tailored consent/level scenarios:
* TestConsentNotNeededForInline
* TestConsentPersistsLowerLevel
* TestConsentRepromptsHigherLevel
* TestConsentRepromptsAfterReload

Refactored WebXrVrConsentDialogBrowserTest methods into the base class
and re-works how base class methods work.  The mock (which always
accepts consent requests, but does not call out to display the dialog)
is now used unless the fake consent manager has previously been set up.

This allowed changing the consent tests to run on all runtimes rather
than just the OpenVr Runtime.

Renamed existing tests so that all test names fit a similar pattern.

Bug: 987029,996454
Change-Id: I9a4224fb169ee7df764a061fdb65038e42c05a8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767085
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690024}
parent 4d50311b
...@@ -29,8 +29,7 @@ FakeXRSessionRequestConsentManager::ShowDialogAndGetConsent( ...@@ -29,8 +29,7 @@ FakeXRSessionRequestConsentManager::ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
XrConsentPromptLevel consent_level, XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) { base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) {
DCHECK(UserResponse::kUnexpected != user_response_); shown_count_++;
auto* confirm_dialog = consent_manager_->ShowDialogAndGetConsent( auto* confirm_dialog = consent_manager_->ShowDialogAndGetConsent(
web_contents, consent_level, std::move(response_callback)); web_contents, consent_level, std::move(response_callback));
...@@ -49,7 +48,6 @@ FakeXRSessionRequestConsentManager::ShowDialogAndGetConsent( ...@@ -49,7 +48,6 @@ FakeXRSessionRequestConsentManager::ShowDialogAndGetConsent(
confirm_dialog->CancelTabModalDialog(); confirm_dialog->CancelTabModalDialog();
break; break;
case UserResponse::kCloseDialog: case UserResponse::kCloseDialog:
case UserResponse::kUnexpected:
confirm_dialog->CloseDialog(); confirm_dialog->CloseDialog();
break; break;
} }
......
...@@ -18,7 +18,6 @@ class FakeXRSessionRequestConsentManager ...@@ -18,7 +18,6 @@ class FakeXRSessionRequestConsentManager
kClickAllowButton, kClickAllowButton,
kClickCancelButton, kClickCancelButton,
kCloseDialog, kCloseDialog,
kUnexpected,
}; };
FakeXRSessionRequestConsentManager( FakeXRSessionRequestConsentManager(
...@@ -32,9 +31,12 @@ class FakeXRSessionRequestConsentManager ...@@ -32,9 +31,12 @@ class FakeXRSessionRequestConsentManager
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback)
override; override;
uint32_t ShownCount() { return shown_count_; }
private: private:
XRSessionRequestConsentManager* consent_manager_; XRSessionRequestConsentManager* consent_manager_;
UserResponse user_response_; UserResponse user_response_;
uint32_t shown_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(FakeXRSessionRequestConsentManager); DISALLOW_COPY_AND_ASSIGN(FakeXRSessionRequestConsentManager);
}; };
......
...@@ -20,16 +20,9 @@ bool WebVrBrowserTestBase::XrDeviceFound(content::WebContents* web_contents) { ...@@ -20,16 +20,9 @@ bool WebVrBrowserTestBase::XrDeviceFound(content::WebContents* web_contents) {
void WebVrBrowserTestBase::EnterSessionWithUserGesture( void WebVrBrowserTestBase::EnterSessionWithUserGesture(
content::WebContents* web_contents) { content::WebContents* web_contents) {
#if defined(OS_WIN)
XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_); XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_);
ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _)) EXPECT_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _)).Times(0);
.WillByDefault(Invoke(
[](content::WebContents*, XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> callback) {
std::move(callback).Run(consent_level, true);
return nullptr;
}));
#endif
// ExecuteScript runs with a user gesture, so we can just directly call // ExecuteScript runs with a user gesture, so we can just directly call
// requestPresent instead of having to do the hacky workaround the // requestPresent instead of having to do the hacky workaround the
// instrumentation tests use of actually sending a click event to the canvas. // instrumentation tests use of actually sending a click event to the canvas.
...@@ -44,9 +37,7 @@ void WebVrBrowserTestBase::EnterSessionWithUserGestureOrFail( ...@@ -44,9 +37,7 @@ void WebVrBrowserTestBase::EnterSessionWithUserGestureOrFail(
} }
void WebVrBrowserTestBase::EndSession(content::WebContents* web_contents) { void WebVrBrowserTestBase::EndSession(content::WebContents* web_contents) {
#if defined(OS_WIN)
XRSessionRequestConsentManager::SetInstanceForTesting(nullptr); XRSessionRequestConsentManager::SetInstanceForTesting(nullptr);
#endif
RunJavaScriptOrFail("vrDisplay.exitPresent()", web_contents); RunJavaScriptOrFail("vrDisplay.exitPresent()", web_contents);
} }
......
...@@ -18,18 +18,21 @@ WebXrVrBrowserTestBase::WebXrVrBrowserTestBase() { ...@@ -18,18 +18,21 @@ WebXrVrBrowserTestBase::WebXrVrBrowserTestBase() {
enable_features_.push_back(features::kWebXr); enable_features_.push_back(features::kWebXr);
} }
WebXrVrBrowserTestBase::~WebXrVrBrowserTestBase() = default;
void WebXrVrBrowserTestBase::EnterSessionWithUserGesture( void WebXrVrBrowserTestBase::EnterSessionWithUserGesture(
content::WebContents* web_contents) { content::WebContents* web_contents) {
#if defined(OS_WIN) if (!fake_consent_manager_) {
XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_); XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_);
ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _)) ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _))
.WillByDefault(Invoke( .WillByDefault(Invoke(
[](content::WebContents*, XrConsentPromptLevel consent_level, [](content::WebContents*, XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> callback) { base::OnceCallback<void(XrConsentPromptLevel, bool)> callback) {
std::move(callback).Run(consent_level, true); std::move(callback).Run(consent_level, true);
return nullptr; return nullptr;
})); }));
#endif }
// ExecuteScript runs with a user gesture, so we can just directly call // ExecuteScript runs with a user gesture, so we can just directly call
// requestSession instead of having to do the hacky workaround the // requestSession instead of having to do the hacky workaround the
// instrumentation tests use of actually sending a click event to the canvas. // instrumentation tests use of actually sending a click event to the canvas.
...@@ -54,9 +57,9 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGestureOrFail( ...@@ -54,9 +57,9 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGestureOrFail(
} }
void WebXrVrBrowserTestBase::EndSession(content::WebContents* web_contents) { void WebXrVrBrowserTestBase::EndSession(content::WebContents* web_contents) {
#if defined(OS_WIN) if (!fake_consent_manager_)
XRSessionRequestConsentManager::SetInstanceForTesting(nullptr); XRSessionRequestConsentManager::SetInstanceForTesting(nullptr);
#endif
RunJavaScriptOrFail( RunJavaScriptOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].currentSession.end()", "sessionInfos[sessionTypes.IMMERSIVE].currentSession.end()",
web_contents); web_contents);
...@@ -74,6 +77,14 @@ gfx::Vector3dF WebXrVrBrowserTestBase::GetControllerOffset() const { ...@@ -74,6 +77,14 @@ gfx::Vector3dF WebXrVrBrowserTestBase::GetControllerOffset() const {
return gfx::Vector3dF(); return gfx::Vector3dF();
} }
void WebXrVrBrowserTestBase::SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse user_response) {
fake_consent_manager_.reset(new FakeXRSessionRequestConsentManager(
XRSessionRequestConsentManager::Instance(), user_response));
XRSessionRequestConsentManager::SetInstanceForTesting(
fake_consent_manager_.get());
}
WebXrVrRuntimelessBrowserTest::WebXrVrRuntimelessBrowserTest() { WebXrVrRuntimelessBrowserTest::WebXrVrRuntimelessBrowserTest() {
#if BUILDFLAG(ENABLE_WINDOWS_MR) #if BUILDFLAG(ENABLE_WINDOWS_MR)
disable_features_.push_back(features::kWindowsMixedReality); disable_features_.push_back(features::kWindowsMixedReality);
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/vr/test/conditional_skipping.h" #include "chrome/browser/vr/test/conditional_skipping.h"
#include "chrome/browser/vr/test/fake_xr_session_request_consent_manager.h"
#include "chrome/browser/vr/test/mock_xr_device_hook_base.h" #include "chrome/browser/vr/test/mock_xr_device_hook_base.h"
#include "chrome/browser/vr/test/mock_xr_session_request_consent_manager.h"
#include "chrome/browser/vr/test/webxr_browser_test.h" #include "chrome/browser/vr/test/webxr_browser_test.h"
#include "chrome/browser/vr/test/xr_browser_test.h" #include "chrome/browser/vr/test/xr_browser_test.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
...@@ -18,7 +20,6 @@ ...@@ -18,7 +20,6 @@
#include "ui/gfx/geometry/vector3d_f.h" #include "ui/gfx/geometry/vector3d_f.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/browser/vr/test/mock_xr_session_request_consent_manager.h"
#include "services/service_manager/sandbox/features.h" #include "services/service_manager/sandbox/features.h"
#endif #endif
...@@ -28,6 +29,7 @@ namespace vr { ...@@ -28,6 +29,7 @@ namespace vr {
class WebXrVrBrowserTestBase : public WebXrBrowserTestBase { class WebXrVrBrowserTestBase : public WebXrBrowserTestBase {
public: public:
WebXrVrBrowserTestBase(); WebXrVrBrowserTestBase();
virtual ~WebXrVrBrowserTestBase();
void EnterSessionWithUserGesture(content::WebContents* web_contents) override; void EnterSessionWithUserGesture(content::WebContents* web_contents) override;
void EnterSessionWithUserGestureOrFail( void EnterSessionWithUserGestureOrFail(
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
...@@ -44,9 +46,17 @@ class WebXrVrBrowserTestBase : public WebXrBrowserTestBase { ...@@ -44,9 +46,17 @@ class WebXrVrBrowserTestBase : public WebXrBrowserTestBase {
using WebXrBrowserTestBase::EndSession; using WebXrBrowserTestBase::EndSession;
using WebXrBrowserTestBase::EndSessionOrFail; using WebXrBrowserTestBase::EndSessionOrFail;
#if defined(OS_WIN) // Methods/objects for managing consent. If SetupFakeConsentManager is never
MockXRSessionRequestConsentManager consent_manager_; // called, the test will default to mocking out the consent prompt and always
#endif // 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.
void SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse user_response);
::testing::NiceMock<MockXRSessionRequestConsentManager> consent_manager_;
std::unique_ptr<FakeXRSessionRequestConsentManager> fake_consent_manager_;
}; };
// Test class with OpenVR disabled. // Test class with OpenVR disabled.
......
<!doctype html>
<!--
WebXR page without any code specific to one test
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../resources/webxr_e2e.css">
</head>
<body>
<canvas id="webgl-canvas"></canvas>
<script src="../../../../../../third_party/blink/web_tests/resources/testharness.js"></script>
<script src="../resources/webxr_e2e.js"></script>
<script>var shouldAutoCreateNonImmersiveSession = false;</script>
<script src="../resources/webxr_boilerplate.js"></script>
<script>
function setupImmersiveSessionToRequestHeight() {
immersiveSessionInit = {
requiredFeatures: ['local-floor']
}
}
function setupImmersiveSessionToRequestBounded() {
immersiveSessionInit = {
requiredFeatures: ['bounded-floor']
}
}
</script>
</body>
</html>
...@@ -73,6 +73,8 @@ sessionInfos[sessionTypes.IMMERSIVE] = new SessionInfo(); ...@@ -73,6 +73,8 @@ sessionInfos[sessionTypes.IMMERSIVE] = new SessionInfo();
sessionInfos[sessionTypes.AR] = new SessionInfo(); sessionInfos[sessionTypes.AR] = new SessionInfo();
sessionInfos[sessionTypes.MAGIC_WINDOW] = new SessionInfo(); sessionInfos[sessionTypes.MAGIC_WINDOW] = new SessionInfo();
var immersiveSessionInit = {};
function getSessionType(session) { function getSessionType(session) {
if (session.mode == 'immersive-vr') { if (session.mode == 'immersive-vr') {
return sessionTypes.IMMERSIVE; return sessionTypes.IMMERSIVE;
...@@ -94,7 +96,8 @@ function onRequestSession() { ...@@ -94,7 +96,8 @@ function onRequestSession() {
switch (sessionTypeToRequest) { switch (sessionTypeToRequest) {
case sessionTypes.IMMERSIVE: case sessionTypes.IMMERSIVE:
console.info('Requesting immersive VR session'); console.info('Requesting immersive VR session');
navigator.xr.requestSession('immersive-vr').then( (session) => { navigator.xr.requestSession('immersive-vr', immersiveSessionInit)
.then( (session) => {
session.mode = 'immersive-vr'; session.mode = 'immersive-vr';
console.info('Immersive VR session request succeeded'); console.info('Immersive VR session request succeeded');
sessionInfos[sessionTypes.IMMERSIVE].currentSession = session; sessionInfos[sessionTypes.IMMERSIVE].currentSession = session;
...@@ -106,7 +109,8 @@ function onRequestSession() { ...@@ -106,7 +109,8 @@ function onRequestSession() {
break; break;
case sessionTypes.AR: case sessionTypes.AR:
console.info('Requesting Immersive AR session'); console.info('Requesting Immersive AR session');
navigator.xr.requestSession('immersive-ar').then((session) => { navigator.xr.requestSession('immersive-ar', immersiveSessionInit)
.then((session) => {
session.mode = 'immersive-ar'; session.mode = 'immersive-ar';
console.info('Immersive AR session request succeeded'); console.info('Immersive AR session request succeeded');
sessionInfos[sessionTypes.AR].currentSession = session; sessionInfos[sessionTypes.AR].currentSession = session;
......
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