Commit ac18515d authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

[vr] Apply content move suppression in UiInputManager

The change in https://chromium-review.googlesource.com/567384 did not
have exactly the same behaviour as the change in
https://codereview.chromium.org/2944453002. This CL moves the content
move suppression as per the previous CL and introduces a testing
framework for the UiInputManager.

Bug: 741020, 743014
Change-Id: Idd8fb0a1c6fb3f74c24dc555b1a72e0c7c3bc611
Reviewed-on: https://chromium-review.googlesource.com/573100
Commit-Queue: Ian Vollick <vollick@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487104}
parent 7f893823
...@@ -548,7 +548,7 @@ void VrShellGl::HandleControllerInput(const gfx::Vector3dF& head_direction) { ...@@ -548,7 +548,7 @@ void VrShellGl::HandleControllerInput(const gfx::Vector3dF& head_direction) {
controller_info_.opacity = controller_->GetOpacity(); controller_info_.opacity = controller_->GetOpacity();
input_manager_->HandleInput( input_manager_->HandleInput(
controller_direction, controller_info_.laser_origin, controller_direction, controller_info_.laser_origin,
controller_info_.touchpad_button_state, gesture_list, controller_info_.touchpad_button_state, &gesture_list,
&controller_info_.target_point, &controller_info_.reticle_render_target); &controller_info_.target_point, &controller_info_.reticle_render_target);
} }
...@@ -626,12 +626,6 @@ void VrShellGl::OnContentLeave() { ...@@ -626,12 +626,6 @@ void VrShellGl::OnContentLeave() {
} }
void VrShellGl::OnContentMove(const gfx::PointF& normalized_hit_point) { void VrShellGl::OnContentMove(const gfx::PointF& normalized_hit_point) {
// TODO(mthiesse, vollick): Content is currently way too sensitive to mouse
// moves for how noisy the controller is. It's almost impossible to click a
// link without unintentionally starting a drag event. For this reason we
// disable mouse moves, only delivering a down and up event.
if (controller_->ButtonState(gvr::kControllerButtonClick))
return;
SendGestureToContent( SendGestureToContent(
MakeMouseEvent(blink::WebInputEvent::kMouseMove, normalized_hit_point)); MakeMouseEvent(blink::WebInputEvent::kMouseMove, normalized_hit_point));
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_
#define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_ #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_GL_H_
#include <chrome/browser/vr/ui_input_manager.h>
#include <memory> #include <memory>
#include <queue> #include <queue>
#include <utility> #include <utility>
...@@ -17,6 +16,7 @@ ...@@ -17,6 +16,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "chrome/browser/android/vr_shell/vr_controller.h" #include "chrome/browser/android/vr_shell/vr_controller.h"
#include "chrome/browser/vr/ui_input_manager.h"
#include "chrome/browser/vr/ui_renderer.h" #include "chrome/browser/vr/ui_renderer.h"
#include "chrome/browser/vr/vr_controller_model.h" #include "chrome/browser/vr/vr_controller_model.h"
#include "device/vr/vr_service.mojom.h" #include "device/vr/vr_service.mojom.h"
......
...@@ -136,8 +136,13 @@ test("vr_common_unittests") { ...@@ -136,8 +136,13 @@ test("vr_common_unittests") {
"run_all_unittests.cc", "run_all_unittests.cc",
"test/animation_utils.cc", "test/animation_utils.cc",
"test/animation_utils.h", "test/animation_utils.h",
"test/mock_browser_interface.cc",
"test/mock_browser_interface.h",
"test/paths.cc", "test/paths.cc",
"test/paths.h", "test/paths.h",
"test/ui_scene_manager_test.cc",
"test/ui_scene_manager_test.h",
"ui_input_manager_unittest.cc",
"ui_scene_manager_unittest.cc", "ui_scene_manager_unittest.cc",
"ui_scene_unittest.cc", "ui_scene_unittest.cc",
] ]
......
// Copyright 2017 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/mock_browser_interface.h"
namespace vr {
MockBrowserInterface::MockBrowserInterface() {}
MockBrowserInterface::~MockBrowserInterface() {}
} // namespace vr
// Copyright 2017 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_MOCK_BROWSER_INTERFACE_H_
#define CHROME_BROWSER_VR_TEST_MOCK_BROWSER_INTERFACE_H_
#include "base/macros.h"
#include "chrome/browser/vr/ui_browser_interface.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace vr {
class MockBrowserInterface : public UiBrowserInterface {
public:
MockBrowserInterface();
~MockBrowserInterface() override;
MOCK_METHOD0(ExitPresent, void());
MOCK_METHOD0(ExitFullscreen, void());
MOCK_METHOD0(NavigateBack, void());
MOCK_METHOD0(ExitCct, void());
MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode mode));
private:
DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface);
};
} // namespace vr
#endif // CHROME_BROWSER_VR_TEST_MOCK_BROWSER_INTERFACE_H_
// Copyright 2017 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/ui_scene_manager_test.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/vr/ui_scene.h"
#include "chrome/browser/vr/ui_scene_manager.h"
namespace vr {
UiSceneManagerTest::UiSceneManagerTest() {}
UiSceneManagerTest::~UiSceneManagerTest() {}
void UiSceneManagerTest::SetUp() {
browser_ = base::MakeUnique<MockBrowserInterface>();
}
void UiSceneManagerTest::MakeManager(InCct in_cct, InWebVr in_web_vr) {
scene_ = base::MakeUnique<UiScene>();
manager_ = base::MakeUnique<UiSceneManager>(
browser_.get(), scene_.get(), in_cct, in_web_vr, kNotAutopresented);
}
void UiSceneManagerTest::MakeAutoPresentedManager() {
scene_ = base::MakeUnique<UiScene>();
manager_ = base::MakeUnique<UiSceneManager>(
browser_.get(), scene_.get(), kNotInCct, kNotInWebVr, kAutopresented);
}
bool UiSceneManagerTest::IsVisible(UiElementDebugId debug_id) {
UiElement* element = scene_->GetUiElementByDebugId(debug_id);
return element ? element->visible() : false;
}
void UiSceneManagerTest::VerifyElementsVisible(
const std::string& debug_name,
const std::set<UiElementDebugId>& debug_ids) {
SCOPED_TRACE(debug_name);
for (const auto& element : scene_->GetUiElements()) {
SCOPED_TRACE(element->debug_id());
bool should_be_visible =
debug_ids.find(element->debug_id()) != debug_ids.end();
EXPECT_EQ(should_be_visible, element->visible());
}
}
bool UiSceneManagerTest::VerifyVisibility(
const std::set<UiElementDebugId>& debug_ids,
bool visible) {
for (const auto& element : scene_->GetUiElements()) {
if (debug_ids.find(element->debug_id()) != debug_ids.end() &&
element->visible() != visible) {
return false;
}
}
return true;
}
} // namespace vr
// Copyright 2017 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_UI_SCENE_MANAGER_TEST_H_
#define CHROME_BROWSER_VR_TEST_UI_SCENE_MANAGER_TEST_H_
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "chrome/browser/vr/elements/ui_element_debug_id.h"
#include "chrome/browser/vr/test/mock_browser_interface.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace vr {
class UiScene;
class UiSceneManager;
class UiSceneManagerTest : public testing::Test {
public:
UiSceneManagerTest();
~UiSceneManagerTest() override;
void SetUp() override;
protected:
enum InCct : bool {
kNotInCct = false,
kInCct = true,
};
enum InWebVr : bool {
kNotInWebVr = false,
kInWebVr = true,
};
enum WebVrAutopresented : bool {
kNotAutopresented = false,
kAutopresented = true,
};
void MakeManager(InCct in_cct, InWebVr in_web_vr);
void MakeAutoPresentedManager();
bool IsVisible(UiElementDebugId debug_id);
// Verify that only the elements in the set are visible.
void VerifyElementsVisible(const std::string& debug_name,
const std::set<UiElementDebugId>& debug_ids);
// Return false if not all elements in the set match the specified visibility
// state. Other elements are ignored.
bool VerifyVisibility(const std::set<UiElementDebugId>& debug_ids,
bool visible);
base::MessageLoop message_loop_;
std::unique_ptr<MockBrowserInterface> browser_;
std::unique_ptr<UiScene> scene_;
std::unique_ptr<UiSceneManager> manager_;
};
} // namespace vr
#endif // CHROME_BROWSER_VR_TEST_UI_SCENE_MANAGER_TEST_H_
...@@ -38,7 +38,7 @@ UiInputManager::~UiInputManager() {} ...@@ -38,7 +38,7 @@ UiInputManager::~UiInputManager() {}
void UiInputManager::HandleInput(const gfx::Vector3dF& laser_direction, void UiInputManager::HandleInput(const gfx::Vector3dF& laser_direction,
const gfx::Point3F& laser_origin, const gfx::Point3F& laser_origin,
ButtonState button_state, ButtonState button_state,
GestureList& gesture_list, GestureList* gesture_list,
gfx::Point3F* out_target_point, gfx::Point3F* out_target_point,
UiElement** out_reticle_render_target) { UiElement** out_reticle_render_target) {
gfx::PointF target_local_point(kInvalidTargetPoint); gfx::PointF target_local_point(kInvalidTargetPoint);
...@@ -88,24 +88,25 @@ void UiInputManager::HandleInput(const gfx::Vector3dF& laser_direction, ...@@ -88,24 +88,25 @@ void UiInputManager::HandleInput(const gfx::Vector3dF& laser_direction,
(button_state == ButtonState::CLICKED) ? ButtonState::UP : button_state; (button_state == ButtonState::CLICKED) ? ButtonState::UP : button_state;
} }
void UiInputManager::SendFlingCancel(GestureList& gesture_list, void UiInputManager::SendFlingCancel(GestureList* gesture_list,
const gfx::PointF& target_point) { const gfx::PointF& target_point) {
if (!fling_target_) { if (!fling_target_) {
return; return;
} }
if (gesture_list.empty() || (gesture_list.front()->GetType() != if (gesture_list->empty() || (gesture_list->front()->GetType() !=
blink::WebInputEvent::kGestureFlingCancel)) { blink::WebInputEvent::kGestureFlingCancel)) {
return; return;
} }
// Scrolling currently only supported on content window. // Scrolling currently only supported on content window.
DCHECK_EQ(fling_target_->fill(), Fill::CONTENT); DCHECK_EQ(fling_target_->fill(), Fill::CONTENT);
delegate_->OnContentFlingCancel(std::move(gesture_list.front()), delegate_->OnContentFlingCancel(std::move(gesture_list->front()),
target_point); target_point);
gesture_list.erase(gesture_list.begin()); gesture_list->erase(gesture_list->begin());
fling_target_ = nullptr; fling_target_ = nullptr;
} }
void UiInputManager::SendScrollEnd(GestureList& gesture_list, void UiInputManager::SendScrollEnd(GestureList* gesture_list,
const gfx::PointF& target_point, const gfx::PointF& target_point,
ButtonState button_state) { ButtonState button_state) {
if (!in_scroll_) { if (!in_scroll_) {
...@@ -116,33 +117,33 @@ void UiInputManager::SendScrollEnd(GestureList& gesture_list, ...@@ -116,33 +117,33 @@ void UiInputManager::SendScrollEnd(GestureList& gesture_list,
if (previous_button_state_ != button_state && if (previous_button_state_ != button_state &&
(button_state == ButtonState::DOWN || (button_state == ButtonState::DOWN ||
button_state == ButtonState::CLICKED)) { button_state == ButtonState::CLICKED)) {
DCHECK_GT(gesture_list.size(), 0LU); DCHECK_GT(gesture_list->size(), 0LU);
DCHECK_EQ(gesture_list.front()->GetType(), DCHECK_EQ(gesture_list->front()->GetType(),
blink::WebInputEvent::kGestureScrollEnd); blink::WebInputEvent::kGestureScrollEnd);
} }
// Scrolling currently only supported on content window. // Scrolling currently only supported on content window.
DCHECK_EQ(input_locked_element_->fill(), Fill::CONTENT); DCHECK_EQ(input_locked_element_->fill(), Fill::CONTENT);
if (gesture_list.empty() || (gesture_list.front()->GetType() != if (gesture_list->empty() || (gesture_list->front()->GetType() !=
blink::WebInputEvent::kGestureScrollEnd)) { blink::WebInputEvent::kGestureScrollEnd)) {
return; return;
} }
DCHECK_LE(gesture_list.size(), 2LU); DCHECK_LE(gesture_list->size(), 2LU);
delegate_->OnContentScrollEnd(std::move(gesture_list.front()), target_point); delegate_->OnContentScrollEnd(std::move(gesture_list->front()), target_point);
gesture_list.erase(gesture_list.begin()); gesture_list->erase(gesture_list->begin());
if (!gesture_list.empty()) { if (!gesture_list->empty()) {
DCHECK_EQ(gesture_list.front()->GetType(), DCHECK_EQ(gesture_list->front()->GetType(),
blink::WebInputEvent::kGestureFlingStart); blink::WebInputEvent::kGestureFlingStart);
delegate_->OnContentFlingBegin(std::move(gesture_list.front()), delegate_->OnContentFlingBegin(std::move(gesture_list->front()),
target_point); target_point);
fling_target_ = input_locked_element_; fling_target_ = input_locked_element_;
gesture_list.erase(gesture_list.begin()); gesture_list->erase(gesture_list->begin());
} }
input_locked_element_ = nullptr; input_locked_element_ = nullptr;
in_scroll_ = false; in_scroll_ = false;
} }
bool UiInputManager::SendScrollBegin(UiElement* target, bool UiInputManager::SendScrollBegin(UiElement* target,
GestureList& gesture_list, GestureList* gesture_list,
const gfx::PointF& target_point) { const gfx::PointF& target_point) {
if (in_scroll_ || !target) { if (in_scroll_ || !target) {
return false; return false;
...@@ -151,34 +152,34 @@ bool UiInputManager::SendScrollBegin(UiElement* target, ...@@ -151,34 +152,34 @@ bool UiInputManager::SendScrollBegin(UiElement* target,
if (target->fill() != Fill::CONTENT) { if (target->fill() != Fill::CONTENT) {
return false; return false;
} }
if (gesture_list.empty() || (gesture_list.front()->GetType() != if (gesture_list->empty() || (gesture_list->front()->GetType() !=
blink::WebInputEvent::kGestureScrollBegin)) { blink::WebInputEvent::kGestureScrollBegin)) {
return false; return false;
} }
input_locked_element_ = target; input_locked_element_ = target;
in_scroll_ = true; in_scroll_ = true;
delegate_->OnContentScrollBegin(std::move(gesture_list.front()), delegate_->OnContentScrollBegin(std::move(gesture_list->front()),
target_point); target_point);
gesture_list.erase(gesture_list.begin()); gesture_list->erase(gesture_list->begin());
return true; return true;
} }
void UiInputManager::SendScrollUpdate(GestureList& gesture_list, void UiInputManager::SendScrollUpdate(GestureList* gesture_list,
const gfx::PointF& target_point) { const gfx::PointF& target_point) {
if (!in_scroll_) { if (!in_scroll_) {
return; return;
} }
DCHECK(input_locked_element_); DCHECK(input_locked_element_);
if (gesture_list.empty() || (gesture_list.front()->GetType() != if (gesture_list->empty() || (gesture_list->front()->GetType() !=
blink::WebInputEvent::kGestureScrollUpdate)) { blink::WebInputEvent::kGestureScrollUpdate)) {
return; return;
} }
// Scrolling currently only supported on content window. // Scrolling currently only supported on content window.
DCHECK_EQ(input_locked_element_->fill(), Fill::CONTENT); DCHECK_EQ(input_locked_element_->fill(), Fill::CONTENT);
delegate_->OnContentScrollUpdate(std::move(gesture_list.front()), delegate_->OnContentScrollUpdate(std::move(gesture_list->front()),
target_point); target_point);
gesture_list.erase(gesture_list.begin()); gesture_list->erase(gesture_list->begin());
} }
void UiInputManager::SendHoverLeave(UiElement* target) { void UiInputManager::SendHoverLeave(UiElement* target) {
...@@ -212,6 +213,13 @@ void UiInputManager::SendHoverMove(const gfx::PointF& target_point) { ...@@ -212,6 +213,13 @@ void UiInputManager::SendHoverMove(const gfx::PointF& target_point) {
return; return;
} }
if (hover_target_->fill() == Fill::CONTENT) { if (hover_target_->fill() == Fill::CONTENT) {
// TODO(mthiesse, vollick): Content is currently way too sensitive to mouse
// moves for how noisy the controller is. It's almost impossible to click a
// link without unintentionally starting a drag event. For this reason we
// disable mouse moves, only delivering a down and up event.
if (in_click_) {
return;
}
delegate_->OnContentMove(target_point); delegate_->OnContentMove(target_point);
} else { } else {
hover_target_->OnMove(target_point); hover_target_->OnMove(target_point);
......
...@@ -66,20 +66,20 @@ class UiInputManager { ...@@ -66,20 +66,20 @@ class UiInputManager {
void HandleInput(const gfx::Vector3dF& laser_direction, void HandleInput(const gfx::Vector3dF& laser_direction,
const gfx::Point3F& laser_origin, const gfx::Point3F& laser_origin,
ButtonState button_state, ButtonState button_state,
GestureList& gesture_list, GestureList* gesture_list,
gfx::Point3F* out_target_point, gfx::Point3F* out_target_point,
UiElement** out_reticle_render_target); UiElement** out_reticle_render_target);
private: private:
void SendFlingCancel(GestureList& gesture_list, void SendFlingCancel(GestureList* gesture_list,
const gfx::PointF& target_point); const gfx::PointF& target_point);
void SendScrollEnd(GestureList& gesture_list, void SendScrollEnd(GestureList* gesture_list,
const gfx::PointF& target_point, const gfx::PointF& target_point,
ButtonState button_state); ButtonState button_state);
bool SendScrollBegin(UiElement* target, bool SendScrollBegin(UiElement* target,
GestureList& gesture_list, GestureList* gesture_list,
const gfx::PointF& target_point); const gfx::PointF& target_point);
void SendScrollUpdate(GestureList& gesture_list, void SendScrollUpdate(GestureList* gesture_list,
const gfx::PointF& target_point); const gfx::PointF& target_point);
void SendHoverLeave(UiElement* target); void SendHoverLeave(UiElement* target);
bool SendHoverEnter(UiElement* target, const gfx::PointF& target_point); bool SendHoverEnter(UiElement* target, const gfx::PointF& target_point);
......
// Copyright 2017 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.h"
#include <memory>
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "chrome/browser/vr/elements/ui_element.h"
#include "chrome/browser/vr/test/animation_utils.h"
#include "chrome/browser/vr/test/ui_scene_manager_test.h"
#include "chrome/browser/vr/ui_scene.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/WebKit/public/platform/WebGestureEvent.h"
namespace vr {
class MockUiInputManagerDelegate : public UiInputManagerDelegate {
public:
MOCK_METHOD1(OnContentEnter, void(const gfx::PointF& normalized_hit_point));
MOCK_METHOD0(OnContentLeave, void());
MOCK_METHOD1(OnContentMove, void(const gfx::PointF& normalized_hit_point));
MOCK_METHOD1(OnContentDown, void(const gfx::PointF& normalized_hit_point));
MOCK_METHOD1(OnContentUp, void(const gfx::PointF& normalized_hit_point));
// As move-only parameters aren't supported by mock methods, we will override
// the functions explicitly and fwd the calls to the mocked functions.
MOCK_METHOD2(FwdContentFlingBegin,
void(std::unique_ptr<blink::WebGestureEvent>& gesture,
const gfx::PointF& normalized_hit_point));
MOCK_METHOD2(FwdContentFlingCancel,
void(std::unique_ptr<blink::WebGestureEvent>& gesture,
const gfx::PointF& normalized_hit_point));
MOCK_METHOD2(FwdContentScrollBegin,
void(std::unique_ptr<blink::WebGestureEvent>& gesture,
const gfx::PointF& normalized_hit_point));
MOCK_METHOD2(FwdContentScrollUpdate,
void(std::unique_ptr<blink::WebGestureEvent>& gesture,
const gfx::PointF& normalized_hit_point));
MOCK_METHOD2(FwdContentScrollEnd,
void(std::unique_ptr<blink::WebGestureEvent>& gesture,
const gfx::PointF& normalized_hit_point));
void OnContentFlingBegin(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& normalized_hit_point) override {
FwdContentFlingBegin(gesture, normalized_hit_point);
}
void OnContentFlingCancel(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& normalized_hit_point) override {
FwdContentFlingCancel(gesture, normalized_hit_point);
}
void OnContentScrollBegin(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& normalized_hit_point) override {
FwdContentScrollBegin(gesture, normalized_hit_point);
}
void OnContentScrollUpdate(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& normalized_hit_point) override {
FwdContentScrollUpdate(gesture, normalized_hit_point);
}
void OnContentScrollEnd(std::unique_ptr<blink::WebGestureEvent> gesture,
const gfx::PointF& normalized_hit_point) override {
FwdContentScrollEnd(gesture, normalized_hit_point);
}
};
class UiInputManagerTest : public UiSceneManagerTest {
public:
void SetUp() override {
UiSceneManagerTest::SetUp();
MakeManager(kNotInCct, kNotInWebVr);
input_manager_ = base::MakeUnique<UiInputManager>(scene_.get(), &delegate_);
scene_->OnBeginFrame(UsToTicks(1));
}
protected:
std::unique_ptr<UiInputManager> input_manager_;
MockUiInputManagerDelegate delegate_;
};
TEST_F(UiInputManagerTest, NoMouseMovesDuringClick) {
// It would be nice if the controller weren't platform specific and we could
// mock out the underlying sensor data. For now, we will hallucinate
// parameters to HandleInput.
UiElement* content_quad =
scene_->GetUiElementByDebugId(UiElementDebugId::kContentQuad);
gfx::Point3F content_quad_center;
content_quad->screen_space_transform().TransformPoint(&content_quad_center);
gfx::Point3F origin;
GestureList gesture_list;
gfx::Point3F out_target_point;
UiElement* out_reticle_render_target;
input_manager_->HandleInput(content_quad_center - origin, origin,
UiInputManager::ButtonState::DOWN, &gesture_list,
&out_target_point, &out_reticle_render_target);
// We should have hit the content quad if our math was correct.
EXPECT_EQ(UiElementDebugId::kContentQuad,
out_reticle_render_target->debug_id());
// Unless we suppress content move events during clicks, this will cause us to
// call OnContentMove on the delegate. We should do this suppression, so we
// set the expected number of calls to zero.
EXPECT_CALL(delegate_, OnContentMove(testing::_)).Times(0);
input_manager_->HandleInput(content_quad_center - origin, origin,
UiInputManager::ButtonState::DOWN, &gesture_list,
&out_target_point, &out_reticle_render_target);
}
} // namespace vr
...@@ -21,7 +21,10 @@ static constexpr gfx::Point3F kOrigin = {0.0f, 0.0f, 0.0f}; ...@@ -21,7 +21,10 @@ static constexpr gfx::Point3F kOrigin = {0.0f, 0.0f, 0.0f};
// rounding errors drawing the reticle behind the object. // rounding errors drawing the reticle behind the object.
// TODO(mthiesse): Find a better approach for drawing the reticle on an object. // TODO(mthiesse): Find a better approach for drawing the reticle on an object.
// Right now we have to wedge it very precisely between the content window and // Right now we have to wedge it very precisely between the content window and
// backplane to avoid rendering artifacts. // backplane to avoid rendering artifacts. We should stop using the depth buffer
// since the back-to-front order of our elements is well defined. This would,
// among other things, prevent z-fighting when we draw content in the same
// plane.
static constexpr float kReticleOffset = 0.999f; static constexpr float kReticleOffset = 0.999f;
static constexpr float kLaserWidth = 0.01f; static constexpr float kLaserWidth = 0.01f;
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
#include "chrome/browser/vr/ui_scene_manager.h" #include "chrome/browser/vr/ui_scene_manager.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/test/scoped_mock_time_message_loop_task_runner.h" #include "base/test/scoped_mock_time_message_loop_task_runner.h"
#include "chrome/browser/vr/elements/ui_element.h" #include "chrome/browser/vr/elements/ui_element.h"
#include "chrome/browser/vr/elements/ui_element_debug_id.h" #include "chrome/browser/vr/elements/ui_element_debug_id.h"
#include "chrome/browser/vr/ui_browser_interface.h" #include "chrome/browser/vr/test/mock_browser_interface.h"
#include "chrome/browser/vr/test/ui_scene_manager_test.h"
#include "chrome/browser/vr/ui_scene.h" #include "chrome/browser/vr/ui_scene.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -18,96 +18,12 @@ ...@@ -18,96 +18,12 @@
namespace vr { namespace vr {
namespace { namespace {
class MockBrowserInterface : public UiBrowserInterface {
public:
MockBrowserInterface() {}
~MockBrowserInterface() override {}
MOCK_METHOD0(ExitPresent, void());
MOCK_METHOD0(ExitFullscreen, void());
MOCK_METHOD0(NavigateBack, void());
MOCK_METHOD0(ExitCct, void());
MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode mode));
private:
DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface);
};
std::set<UiElementDebugId> kElementsVisibleInBrowsing = { std::set<UiElementDebugId> kElementsVisibleInBrowsing = {
kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar}; kContentQuad, kBackplane, kCeiling, kFloor, kUrlBar};
std::set<UiElementDebugId> kElementsVisibleWithExitPrompt = { std::set<UiElementDebugId> kElementsVisibleWithExitPrompt = {
kExitPrompt, kExitPromptBackplane, kCeiling, kFloor}; kExitPrompt, kExitPromptBackplane, kCeiling, kFloor};
} // namespace } // namespace
class UiSceneManagerTest : public testing::Test {
public:
void SetUp() override { browser_ = base::MakeUnique<MockBrowserInterface>(); }
protected:
enum InCct : bool {
kNotInCct = false,
kInCct = true,
};
enum InWebVr : bool {
kNotInWebVr = false,
kInWebVr = true,
};
enum WebVrAutopresented : bool {
kNotAutopresented = false,
kAutopresented = true,
};
void MakeManager(InCct in_cct, InWebVr in_web_vr) {
scene_ = base::MakeUnique<UiScene>();
manager_ = base::MakeUnique<UiSceneManager>(
browser_.get(), scene_.get(), in_cct, in_web_vr, kNotAutopresented);
}
void MakeAutoPresentedManager() {
scene_ = base::MakeUnique<UiScene>();
manager_ = base::MakeUnique<UiSceneManager>(
browser_.get(), scene_.get(), kNotInCct, kNotInWebVr, kAutopresented);
}
bool IsVisible(UiElementDebugId debug_id) {
UiElement* element = scene_->GetUiElementByDebugId(debug_id);
return element ? element->visible() : false;
}
// Verify that only the elements in the set are visible.
void VerifyElementsVisible(const std::string& debug_name,
const std::set<UiElementDebugId>& debug_ids) {
SCOPED_TRACE(debug_name);
for (const auto& element : scene_->GetUiElements()) {
SCOPED_TRACE(element->debug_id());
bool should_be_visible =
debug_ids.find(element->debug_id()) != debug_ids.end();
EXPECT_EQ(should_be_visible, element->visible());
}
}
// Return false if not all elements in the set match the specified visibility
// state. Other elements are ignored.
bool VerifyVisibility(const std::set<UiElementDebugId>& debug_ids,
bool visible) {
for (const auto& element : scene_->GetUiElements()) {
if (debug_ids.find(element->debug_id()) != debug_ids.end() &&
element->visible() != visible) {
return false;
}
}
return true;
}
base::MessageLoop message_loop_;
std::unique_ptr<MockBrowserInterface> browser_;
std::unique_ptr<UiScene> scene_;
std::unique_ptr<UiSceneManager> manager_;
};
TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) { TEST_F(UiSceneManagerTest, ExitPresentAndFullscreenOnAppButtonClick) {
MakeManager(kNotInCct, kInWebVr); MakeManager(kNotInCct, kInWebVr);
......
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