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(
content::WebContents* web_contents,
XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> response_callback) {
DCHECK(UserResponse::kUnexpected != user_response_);
shown_count_++;
auto* confirm_dialog = consent_manager_->ShowDialogAndGetConsent(
web_contents, consent_level, std::move(response_callback));
......@@ -49,7 +48,6 @@ FakeXRSessionRequestConsentManager::ShowDialogAndGetConsent(
confirm_dialog->CancelTabModalDialog();
break;
case UserResponse::kCloseDialog:
case UserResponse::kUnexpected:
confirm_dialog->CloseDialog();
break;
}
......
......@@ -18,7 +18,6 @@ class FakeXRSessionRequestConsentManager
kClickAllowButton,
kClickCancelButton,
kCloseDialog,
kUnexpected,
};
FakeXRSessionRequestConsentManager(
......@@ -32,9 +31,12 @@ class FakeXRSessionRequestConsentManager
base::OnceCallback<void(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);
};
......
......@@ -20,16 +20,9 @@ bool WebVrBrowserTestBase::XrDeviceFound(content::WebContents* web_contents) {
void WebVrBrowserTestBase::EnterSessionWithUserGesture(
content::WebContents* web_contents) {
#if defined(OS_WIN)
XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_);
ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _))
.WillByDefault(Invoke(
[](content::WebContents*, XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> callback) {
std::move(callback).Run(consent_level, true);
return nullptr;
}));
#endif
EXPECT_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _)).Times(0);
// ExecuteScript runs with a user gesture, so we can just directly call
// requestPresent instead of having to do the hacky workaround the
// instrumentation tests use of actually sending a click event to the canvas.
......@@ -44,9 +37,7 @@ void WebVrBrowserTestBase::EnterSessionWithUserGestureOrFail(
}
void WebVrBrowserTestBase::EndSession(content::WebContents* web_contents) {
#if defined(OS_WIN)
XRSessionRequestConsentManager::SetInstanceForTesting(nullptr);
#endif
RunJavaScriptOrFail("vrDisplay.exitPresent()", web_contents);
}
......
......@@ -18,18 +18,21 @@ WebXrVrBrowserTestBase::WebXrVrBrowserTestBase() {
enable_features_.push_back(features::kWebXr);
}
WebXrVrBrowserTestBase::~WebXrVrBrowserTestBase() = default;
void WebXrVrBrowserTestBase::EnterSessionWithUserGesture(
content::WebContents* web_contents) {
#if defined(OS_WIN)
XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_);
ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _))
.WillByDefault(Invoke(
[](content::WebContents*, XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> callback) {
std::move(callback).Run(consent_level, true);
return nullptr;
}));
#endif
if (!fake_consent_manager_) {
XRSessionRequestConsentManager::SetInstanceForTesting(&consent_manager_);
ON_CALL(consent_manager_, ShowDialogAndGetConsent(_, _, _))
.WillByDefault(Invoke(
[](content::WebContents*, XrConsentPromptLevel consent_level,
base::OnceCallback<void(XrConsentPromptLevel, bool)> callback) {
std::move(callback).Run(consent_level, true);
return nullptr;
}));
}
// 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.
......@@ -54,9 +57,9 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGestureOrFail(
}
void WebXrVrBrowserTestBase::EndSession(content::WebContents* web_contents) {
#if defined(OS_WIN)
XRSessionRequestConsentManager::SetInstanceForTesting(nullptr);
#endif
if (!fake_consent_manager_)
XRSessionRequestConsentManager::SetInstanceForTesting(nullptr);
RunJavaScriptOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].currentSession.end()",
web_contents);
......@@ -74,6 +77,14 @@ gfx::Vector3dF WebXrVrBrowserTestBase::GetControllerOffset() const {
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() {
#if BUILDFLAG(ENABLE_WINDOWS_MR)
disable_features_.push_back(features::kWindowsMixedReality);
......
......@@ -7,7 +7,9 @@
#include "build/build_config.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_session_request_consent_manager.h"
#include "chrome/browser/vr/test/webxr_browser_test.h"
#include "chrome/browser/vr/test/xr_browser_test.h"
#include "chrome/common/chrome_features.h"
......@@ -18,7 +20,6 @@
#include "ui/gfx/geometry/vector3d_f.h"
#if defined(OS_WIN)
#include "chrome/browser/vr/test/mock_xr_session_request_consent_manager.h"
#include "services/service_manager/sandbox/features.h"
#endif
......@@ -28,6 +29,7 @@ namespace vr {
class WebXrVrBrowserTestBase : public WebXrBrowserTestBase {
public:
WebXrVrBrowserTestBase();
virtual ~WebXrVrBrowserTestBase();
void EnterSessionWithUserGesture(content::WebContents* web_contents) override;
void EnterSessionWithUserGestureOrFail(
content::WebContents* web_contents) override;
......@@ -44,9 +46,17 @@ class WebXrVrBrowserTestBase : public WebXrBrowserTestBase {
using WebXrBrowserTestBase::EndSession;
using WebXrBrowserTestBase::EndSessionOrFail;
#if defined(OS_WIN)
MockXRSessionRequestConsentManager consent_manager_;
#endif
// 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.
void SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse user_response);
::testing::NiceMock<MockXRSessionRequestConsentManager> consent_manager_;
std::unique_ptr<FakeXRSessionRequestConsentManager> fake_consent_manager_;
};
// 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();
sessionInfos[sessionTypes.AR] = new SessionInfo();
sessionInfos[sessionTypes.MAGIC_WINDOW] = new SessionInfo();
var immersiveSessionInit = {};
function getSessionType(session) {
if (session.mode == 'immersive-vr') {
return sessionTypes.IMMERSIVE;
......@@ -94,7 +96,8 @@ function onRequestSession() {
switch (sessionTypeToRequest) {
case sessionTypes.IMMERSIVE:
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';
console.info('Immersive VR session request succeeded');
sessionInfos[sessionTypes.IMMERSIVE].currentSession = session;
......@@ -106,7 +109,8 @@ function onRequestSession() {
break;
case sessionTypes.AR:
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';
console.info('Immersive AR session request succeeded');
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