Commit b3cc34d8 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Add VR UiInputManagerForTesting

Adds a test-only UiInputManager that gets swapped with the real one
anytime we're using the InputDelegateForTesting. Currently, the only
difference is that the testing version always reports that the
controller is not in the viewport.

This is so that pixel diff tests are not flaky based on the initial
orientation of the device - without this, the controller tooltips
would remain visible if the device started pointed slightly down
even though we lock the head pose forward.

Bug: 904012
Change-Id: Ia34944bd9d678c43480ef218b2d740928732f5ae
Reviewed-on: https://chromium-review.googlesource.com/c/1334941
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608545}
parent faaa9346
......@@ -176,6 +176,11 @@ component("vr_ui") {
"vr_ui_export.h",
]
sources += [
"ui_input_manager_for_testing.cc",
"ui_input_manager_for_testing.h",
]
deps = [
":vr_base",
"//base",
......@@ -230,13 +235,9 @@ component("vr_common") {
"gesture_detector.h",
"graphics_delegate.h",
"input_delegate.h",
"input_delegate_for_testing.cc",
"input_delegate_for_testing.h",
"location_bar_helper.cc",
"location_bar_helper.h",
"platform_controller.h",
"platform_controller_for_testing.cc",
"platform_controller_for_testing.h",
"sample_queue.cc",
"sample_queue.h",
"scheduler_browser_renderer_interface.h",
......@@ -259,6 +260,13 @@ component("vr_common") {
"vr_web_contents_observer.h",
]
sources += [
"input_delegate_for_testing.cc",
"input_delegate_for_testing.h",
"platform_controller_for_testing.cc",
"platform_controller_for_testing.h",
]
public_deps = [
":vr_base",
]
......@@ -337,8 +345,6 @@ source_set("vr_base") {
"input_event.cc",
"input_event.h",
"keyboard_delegate.h",
"keyboard_delegate_for_testing.cc",
"keyboard_delegate_for_testing.h",
"keyboard_ui_interface.h",
"macros.h",
"metrics/metrics_helper.cc",
......@@ -391,6 +397,11 @@ source_set("vr_base") {
"vr_gl_util.h",
]
sources += [
"keyboard_delegate_for_testing.cc",
"keyboard_delegate_for_testing.h",
]
defines = [
"VR_IMPLEMENTATION",
"VR_UI_IMPLEMENTATION",
......
......@@ -335,6 +335,7 @@ void BrowserRenderer::PerformControllerActionForTesting(
"queued";
using_input_delegate_for_testing_ = false;
input_delegate_for_testing_.swap(input_delegate_);
ui_->SetUiInputManagerForTesting(false);
}
return;
}
......@@ -344,6 +345,7 @@ void BrowserRenderer::PerformControllerActionForTesting(
input_delegate_for_testing_ =
std::make_unique<InputDelegateForTesting>(ui_.get());
input_delegate_for_testing_.swap(input_delegate_);
ui_->SetUiInputManagerForTesting(true);
}
if (controller_input.action != VrControllerTestAction::kEnableMockedInput) {
static_cast<InputDelegateForTesting*>(input_delegate_.get())
......
......@@ -45,6 +45,7 @@ class MockUi : public UiInterface {
gfx::Point3F(UserFriendlyElementName,
const gfx::PointF& position));
MOCK_METHOD1(GetElementVisibilityForTesting, bool(UserFriendlyElementName));
MOCK_METHOD1(SetUiInputManagerForTesting, void(bool));
MOCK_METHOD0(IsContentVisibleAndOpaque, bool());
MOCK_METHOD1(SetContentUsesQuadLayer, void(bool));
gfx::Transform GetContentWorldSpaceTransform() override { return {}; }
......
......@@ -33,6 +33,7 @@
#include "chrome/browser/vr/ui_browser_interface.h"
#include "chrome/browser/vr/ui_element_renderer.h"
#include "chrome/browser/vr/ui_input_manager.h"
#include "chrome/browser/vr/ui_input_manager_for_testing.h"
#include "chrome/browser/vr/ui_renderer.h"
#include "chrome/browser/vr/ui_scene.h"
#include "chrome/browser/vr/ui_scene_constants.h"
......@@ -444,7 +445,7 @@ void Ui::OnControllerUpdated(const ControllerModel& controller_model,
model_->controller = controller_model;
model_->reticle = reticle_model;
model_->controller.resting_in_viewport =
input_manager_->controller_resting_in_viewport();
input_manager_->ControllerRestingInViewport();
}
void Ui::OnProjMatrixChanged(const gfx::Transform& proj_matrix) {
......@@ -556,6 +557,21 @@ bool Ui::GetElementVisibilityForTesting(UserFriendlyElementName element_name) {
return target_element->IsVisible();
}
void Ui::SetUiInputManagerForTesting(bool enabled) {
if (enabled) {
DCHECK(input_manager_for_testing_ == nullptr)
<< "Attempted to set test UiInputManager while already using it";
input_manager_for_testing_ =
std::make_unique<UiInputManagerForTesting>(scene_.get());
input_manager_for_testing_.swap(input_manager_);
} else {
DCHECK(input_manager_for_testing_ != nullptr)
<< "Attempted to unset test UiInputManager while not using it";
input_manager_for_testing_.swap(input_manager_);
input_manager_for_testing_.reset();
}
}
void Ui::InitializeModel(const UiInitialState& ui_initial_state) {
model_->speech.has_or_can_request_audio_permission =
ui_initial_state.has_or_can_request_audio_permission;
......
......@@ -75,6 +75,7 @@ class VR_UI_EXPORT Ui : public UiInterface,
}
bool GetElementVisibilityForTesting(
UserFriendlyElementName element_name) override;
void SetUiInputManagerForTesting(bool enabled) override;
void Dump(bool include_bindings);
// TODO(crbug.com/767957): Refactor to hide these behind the UI interface.
......@@ -214,6 +215,7 @@ class VR_UI_EXPORT Ui : public UiInterface,
std::unique_ptr<ContentInputDelegate> content_input_delegate_;
std::unique_ptr<UiElementRenderer> ui_element_renderer_;
std::unique_ptr<UiInputManager> input_manager_;
std::unique_ptr<UiInputManager> input_manager_for_testing_;
std::unique_ptr<UiRenderer> ui_renderer_;
std::unique_ptr<SkiaSurfaceProvider> provider_;
......
......@@ -419,6 +419,10 @@ void UiInputManager::OnKeyboardHidden() {
UnfocusFocusedElement();
}
bool UiInputManager::ControllerRestingInViewport() const {
return controller_resting_in_viewport_;
}
gfx::PointF UiInputManager::GetCapturedElementHitPoint(
const gfx::Point3F& target_point) const {
UiElement* captured_element =
......
......@@ -41,7 +41,7 @@ class VR_UI_EXPORT UiInputManager {
};
explicit UiInputManager(UiScene* scene);
~UiInputManager();
virtual ~UiInputManager();
void HandleInput(base::TimeTicks current_time,
const RenderInfo& render_info,
const ControllerModel& controller_model,
......@@ -57,9 +57,7 @@ class VR_UI_EXPORT UiInputManager {
void OnInputCommitted(const EditedText& info);
void OnKeyboardHidden();
bool controller_resting_in_viewport() const {
return controller_resting_in_viewport_;
}
virtual bool ControllerRestingInViewport() const;
void set_hit_test_strategy(HitTestStrategy strategy) {
hit_test_strategy_ = strategy;
......
// Copyright 2018 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/ui_input_manager_for_testing.h"
namespace vr {
UiInputManagerForTesting::UiInputManagerForTesting(UiScene* scene)
: UiInputManager(scene) {}
bool UiInputManagerForTesting::ControllerRestingInViewport() const {
return false;
}
} // namespace vr
// Copyright 2018 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_UI_INPUT_MANAGER_FOR_TESTING_H_
#define CHROME_BROWSER_VR_UI_INPUT_MANAGER_FOR_TESTING_H_
#include "chrome/browser/vr/ui_input_manager.h"
namespace vr {
class UiInputManagerForTesting : public UiInputManager {
public:
explicit UiInputManagerForTesting(UiScene* scene);
bool ControllerRestingInViewport() const override;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_UI_INPUT_MANAGER_FOR_TESTING_H_
......@@ -599,7 +599,7 @@ TEST_F(UiInputManagerContentTest, ControllerRestingInViewport) {
RenderInfo render_info = CreateRenderInfo();
// The controller is initially not in the viewport.
EXPECT_FALSE(input_manager_->controller_resting_in_viewport());
EXPECT_FALSE(input_manager_->ControllerRestingInViewport());
input_manager_->HandleInput(MsToTicks(1), render_info, controller_model,
&reticle_model, &input_event_list);
......@@ -608,7 +608,7 @@ TEST_F(UiInputManagerContentTest, ControllerRestingInViewport) {
// Although we are currently looking at the controller, it is not focused yet.
// It must remain in the viewport for the requisite amount of time.
EXPECT_FALSE(input_manager_->controller_resting_in_viewport());
EXPECT_FALSE(input_manager_->ControllerRestingInViewport());
input_manager_->HandleInput(MsToTicks(50000), render_info, controller_model,
&reticle_model, &input_event_list);
......@@ -617,7 +617,7 @@ TEST_F(UiInputManagerContentTest, ControllerRestingInViewport) {
// Since the controller has been in the viewport for a long time (50s), it
// must report that it is focused.
EXPECT_TRUE(input_manager_->controller_resting_in_viewport());
EXPECT_TRUE(input_manager_->ControllerRestingInViewport());
ui_->OnControllerUpdated(controller_model, reticle_model);
scene_->OnBeginFrame(base::TimeTicks(), head_pose_);
......
......@@ -72,6 +72,7 @@ class UiInterface {
const gfx::PointF& position) = 0;
virtual bool GetElementVisibilityForTesting(
UserFriendlyElementName element_name) = 0;
virtual void SetUiInputManagerForTesting(bool enabled) = 0;
virtual bool IsContentVisibleAndOpaque() = 0;
virtual void SetContentUsesQuadLayer(bool uses_quad_buffers) = 0;
virtual gfx::Transform GetContentWorldSpaceTransform() = 0;
......
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