Commit b60c592b authored by Suman Kancherla's avatar Suman Kancherla Committed by Commit Bot

Added consent dialog XR browser tests

Bug: 962744
Change-Id: I99b6a2574e3adb42bf8967cd181c490bc4f5107a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1611846
Commit-Queue: Suman Kancherla <sumankancherla@chromium.org>
Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660068}
parent 1e56f971
...@@ -669,6 +669,8 @@ if (!is_android) { ...@@ -669,6 +669,8 @@ if (!is_android) {
sources = [ sources = [
"test/conditional_skipping.cc", "test/conditional_skipping.cc",
"test/conditional_skipping.h", "test/conditional_skipping.h",
"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.cc",
...@@ -728,6 +730,7 @@ if (!is_android) { ...@@ -728,6 +730,7 @@ if (!is_android) {
# Tests. # Tests.
sources += [ sources += [
"webxr_vr_consent_dialog_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",
......
...@@ -12,6 +12,8 @@ namespace content { ...@@ -12,6 +12,8 @@ namespace content {
class WebContents; class WebContents;
} }
class TabModalConfirmDialog;
namespace vr { namespace vr {
// Abstract class to break a dependency loop between the "vr_common" component // Abstract class to break a dependency loop between the "vr_common" component
...@@ -42,7 +44,7 @@ class VR_EXPORT XRSessionRequestConsentManager { ...@@ -42,7 +44,7 @@ class VR_EXPORT XRSessionRequestConsentManager {
// |response_callback| is guaranteed to be called with 'true' as arg if // |response_callback| is guaranteed to be called with 'true' as arg if
// the user presses the 'accept' button, or with 'false' if the user // the user presses the 'accept' button, or with 'false' if the user
// either closes the dialog by any means or clicks on 'cancel' button. // either closes the dialog by any means or clicks on 'cancel' button.
virtual void ShowDialogAndGetConsent( virtual TabModalConfirmDialog* ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
base::OnceCallback<void(bool)> response_callback) = 0; base::OnceCallback<void(bool)> response_callback) = 0;
}; };
......
...@@ -18,12 +18,14 @@ XRSessionRequestConsentManagerImpl::XRSessionRequestConsentManagerImpl() = ...@@ -18,12 +18,14 @@ XRSessionRequestConsentManagerImpl::XRSessionRequestConsentManagerImpl() =
XRSessionRequestConsentManagerImpl::~XRSessionRequestConsentManagerImpl() = XRSessionRequestConsentManagerImpl::~XRSessionRequestConsentManagerImpl() =
default; default;
void XRSessionRequestConsentManagerImpl::ShowDialogAndGetConsent( TabModalConfirmDialog*
XRSessionRequestConsentManagerImpl::ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
base::OnceCallback<void(bool)> response_callback) { base::OnceCallback<void(bool)> response_callback) {
TabModalConfirmDialog::Create(new XrSessionRequestConsentDialogDelegate( return TabModalConfirmDialog::Create(
web_contents, std::move(response_callback)), new XrSessionRequestConsentDialogDelegate(web_contents,
web_contents); std::move(response_callback)),
web_contents);
} }
} // namespace vr } // namespace vr
...@@ -19,7 +19,7 @@ class XRSessionRequestConsentManagerImpl ...@@ -19,7 +19,7 @@ class XRSessionRequestConsentManagerImpl
~XRSessionRequestConsentManagerImpl() override; ~XRSessionRequestConsentManagerImpl() override;
// XRSessionRequestConsentManager: // XRSessionRequestConsentManager:
void ShowDialogAndGetConsent( TabModalConfirmDialog* ShowDialogAndGetConsent(
content::WebContents* web_contents, content::WebContents* web_contents,
base::OnceCallback<void(bool)> response_callback) override; base::OnceCallback<void(bool)> response_callback) override;
......
// 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,
base::OnceCallback<void(bool)> response_callback) {
auto* confirm_dialog = consent_manager_->ShowDialogAndGetConsent(
web_contents, 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;
}
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/service/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,
base::OnceCallback<void(bool)> response_callback) override;
private:
XRSessionRequestConsentManager* consent_manager_;
UserResponse user_response_;
DISALLOW_COPY_AND_ASSIGN(FakeXRSessionRequestConsentManager);
};
} // namespace vr
#endif // CHROME_BROWSER_VR_TEST_FAKE_XR_SESSION_REQUEST_CONSENT_MANAGER_H_
...@@ -17,9 +17,10 @@ class MockXRSessionRequestConsentManager ...@@ -17,9 +17,10 @@ class MockXRSessionRequestConsentManager
MockXRSessionRequestConsentManager(); MockXRSessionRequestConsentManager();
~MockXRSessionRequestConsentManager() override; ~MockXRSessionRequestConsentManager() override;
MOCK_METHOD2(ShowDialogAndGetConsent, MOCK_METHOD2(
void(content::WebContents* web_contents, ShowDialogAndGetConsent,
base::OnceCallback<void(bool)> response_callback)); TabModalConfirmDialog*(content::WebContents* web_contents,
base::OnceCallback<void(bool)> response_callback));
private: private:
DISALLOW_COPY_AND_ASSIGN(MockXRSessionRequestConsentManager); DISALLOW_COPY_AND_ASSIGN(MockXRSessionRequestConsentManager);
......
...@@ -26,6 +26,7 @@ void WebVrBrowserTestBase::EnterSessionWithUserGesture( ...@@ -26,6 +26,7 @@ void WebVrBrowserTestBase::EnterSessionWithUserGesture(
.WillByDefault(Invoke( .WillByDefault(Invoke(
[](content::WebContents*, base::OnceCallback<void(bool)> callback) { [](content::WebContents*, base::OnceCallback<void(bool)> callback) {
std::move(callback).Run(true); std::move(callback).Run(true);
return nullptr;
})); }));
#endif #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
......
...@@ -22,6 +22,7 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGesture( ...@@ -22,6 +22,7 @@ void WebXrVrBrowserTestBase::EnterSessionWithUserGesture(
.WillByDefault(Invoke( .WillByDefault(Invoke(
[](content::WebContents*, base::OnceCallback<void(bool)> callback) { [](content::WebContents*, base::OnceCallback<void(bool)> callback) {
std::move(callback).Run(true); std::move(callback).Run(true);
return nullptr;
})); }));
#endif #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
......
// 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/fake_xr_session_request_consent_manager.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 {
#if defined(OS_WIN)
// Browser test class exclusively to test the consent dialog that's shown when
// attempting to enter VR.
class WebXrVrConsentDialogBrowserTest : public WebXrVrBrowserTestBase {
public:
WebXrVrConsentDialogBrowserTest();
// Must be called first thing in the test. This cannot be part of SetUp()
// because the XRSessionRequestConsentManager::SetInstance() is not called
// in ChromeBrowserMain code by that time.
void SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse user_response);
private:
std::unique_ptr<FakeXRSessionRequestConsentManager> fake_consent_manager_;
};
WebXrVrConsentDialogBrowserTest::WebXrVrConsentDialogBrowserTest() {
enable_features_.push_back(features::kOpenVR);
enable_features_.push_back(features::kWebXr);
}
void WebXrVrConsentDialogBrowserTest::SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse user_response) {
fake_consent_manager_.reset(new FakeXRSessionRequestConsentManager(
XRSessionRequestConsentManager::Instance(), user_response));
XRSessionRequestConsentManager::SetInstanceForTesting(
fake_consent_manager_.get());
}
IN_PROC_BROWSER_TEST_F(
WebXrVrConsentDialogBrowserTest,
TestWebXrVrSucceedsWhenUserClicksConsentDialogAllowButton) {
SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickAllowButton);
LoadUrlAndAwaitInitialization(
GetFileUrlForHtmlTestFile("generic_webxr_page"));
// These two functions below are exactly the same as
// WebXrVrBrowserTestBase::EnterSessionWithUserGesture, except that the base
// class' implementation replaces the FakeXRSessionRequestConsentManager
// set in the SetupFakeConsentManager call above, which should be avoided.
RunJavaScriptOrFail("onRequestSession()", GetCurrentWebContents());
PollJavaScriptBooleanOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].currentSession != null",
kPollTimeoutLong, GetCurrentWebContents());
RunJavaScriptOrFail(
"sessionInfos[sessionTypes.IMMERSIVE].currentSession.end()",
GetCurrentWebContents());
}
IN_PROC_BROWSER_TEST_F(
WebXrVrConsentDialogBrowserTest,
TestWebXrVrFailsWhenUserClicksConsentDialogCancelButton) {
SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kClickCancelButton);
LoadUrlAndAwaitInitialization(GetFileUrlForHtmlTestFile(
"webxr_test_presentation_promise_rejected_if_don_canceled"));
ExecuteStepAndWait("onImmersiveRequestWithDon()");
EndTest();
}
IN_PROC_BROWSER_TEST_F(WebXrVrConsentDialogBrowserTest,
TestWebXrVrFailsWhenUserClosesConsentDialog) {
SetupFakeConsentManager(
FakeXRSessionRequestConsentManager::UserResponse::kCloseDialog);
LoadUrlAndAwaitInitialization(GetFileUrlForHtmlTestFile(
"webxr_test_presentation_promise_rejected_if_don_canceled"));
ExecuteStepAndWait("onImmersiveRequestWithDon()");
EndTest();
}
#endif
} // namespace vr
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