Commit 44ca1064 authored by Sarthak Shah's avatar Sarthak Shah Committed by Commit Bot

Fix FlingController unittest failure

Currently, if experimental fling animation feature is turned on,
FlingControllerTest fails with an exception as
ScreenWin::GetPixelsPerInch() returns zero. As there is no display
instantiated while running FlingController unittest,
GetScreenWinDisplayNearestDIPPoint returns default ScreenWin object which
has zero value for pixels per inch.

This CL fixes the issue by return default value if the value of pixels
per inch from ScreenWinDisplay is zero.

Change-Id: I9cd7aa2ccfd62fa1896981f09a2dd4a336e49469
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1974620Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarDaniel Libby <dlibby@microsoft.com>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734692}
parent 019a8580
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/events/blink/fling_booster.h" #include "ui/events/blink/fling_booster.h"
#if defined(OS_WIN)
#include "ui/display/win/test/scoped_screen_win.h"
#endif
using blink::WebGestureEvent; using blink::WebGestureEvent;
using blink::WebInputEvent; using blink::WebInputEvent;
using blink::WebMouseWheelEvent; using blink::WebMouseWheelEvent;
...@@ -172,6 +176,9 @@ class FlingControllerTest : public FlingControllerEventSenderClient, ...@@ -172,6 +176,9 @@ class FlingControllerTest : public FlingControllerEventSenderClient,
bool notified_client_after_fling_stop_ = false; bool notified_client_after_fling_stop_ = false;
bool first_wheel_event_sent_ = false; bool first_wheel_event_sent_ = false;
int sent_scroll_gesture_count_ = 0; int sent_scroll_gesture_count_ = 0;
#if defined(OS_WIN)
display::win::test::ScopedScreenWin scoped_screen_win_;
#endif
private: private:
base::SimpleTestTickClock mock_clock_; base::SimpleTestTickClock mock_clock_;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/input/fling_scheduler.h" #include "content/browser/renderer_host/input/fling_scheduler.h"
#include "build/build_config.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h" #include "content/public/test/test_browser_context.h"
...@@ -12,6 +13,10 @@ ...@@ -12,6 +13,10 @@
#include "content/test/test_render_widget_host.h" #include "content/test/test_render_widget_host.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_WIN)
#include "ui/display/win/test/scoped_screen_win.h"
#endif
namespace content { namespace content {
class FakeFlingScheduler : public FlingScheduler { class FakeFlingScheduler : public FlingScheduler {
...@@ -119,6 +124,9 @@ class FlingSchedulerTest : public testing::Test, ...@@ -119,6 +124,9 @@ class FlingSchedulerTest : public testing::Test,
MockRenderProcessHost* process_host_; MockRenderProcessHost* process_host_;
TestRenderWidgetHostView* view_; TestRenderWidgetHostView* view_;
std::unique_ptr<MockRenderWidgetHostDelegate> delegate_; std::unique_ptr<MockRenderWidgetHostDelegate> delegate_;
#if defined(OS_WIN)
display::win::test::ScopedScreenWin scoped_screen_win_;
#endif
DISALLOW_COPY_AND_ASSIGN(FlingSchedulerTest); DISALLOW_COPY_AND_ASSIGN(FlingSchedulerTest);
}; };
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h"
#include "content/browser/renderer_host/input/input_router_config_helper.h" #include "content/browser/renderer_host/input/input_router_config_helper.h"
#include "content/browser/renderer_host/input/touchpad_tap_suppression_controller.h" #include "content/browser/renderer_host/input/touchpad_tap_suppression_controller.h"
#include "content/common/input/synthetic_web_input_event_builders.h" #include "content/common/input/synthetic_web_input_event_builders.h"
...@@ -26,6 +27,10 @@ ...@@ -26,6 +27,10 @@
#include "third_party/blink/public/common/input/web_input_event.h" #include "third_party/blink/public/common/input/web_input_event.h"
#include "ui/events/blink/blink_features.h" #include "ui/events/blink/blink_features.h"
#if defined(OS_WIN)
#include "ui/display/win/test/scoped_screen_win.h"
#endif
using base::TimeDelta; using base::TimeDelta;
using blink::WebGestureDevice; using blink::WebGestureDevice;
using blink::WebGestureEvent; using blink::WebGestureEvent;
...@@ -232,6 +237,9 @@ class GestureEventQueueTest : public testing::Test, ...@@ -232,6 +237,9 @@ class GestureEventQueueTest : public testing::Test,
std::unique_ptr<InputEventAckState> sync_ack_result_; std::unique_ptr<InputEventAckState> sync_ack_result_;
std::unique_ptr<WebGestureEvent> sync_followup_event_; std::unique_ptr<WebGestureEvent> sync_followup_event_;
base::test::ScopedFeatureList feature_list_; base::test::ScopedFeatureList feature_list_;
#if defined(OS_WIN)
display::win::test::ScopedScreenWin scoped_screen_win_;
#endif
}; };
// This is for tests that are to be run for all source devices. // This is for tests that are to be run for all source devices.
......
...@@ -47,6 +47,10 @@ ...@@ -47,6 +47,10 @@
#include "ui/events/event.h" #include "ui/events/event.h"
#endif #endif
#if defined(OS_WIN)
#include "ui/display/win/test/scoped_screen_win.h"
#endif
using blink::WebGestureDevice; using blink::WebGestureDevice;
using blink::WebGestureEvent; using blink::WebGestureEvent;
using blink::WebKeyboardEvent; using blink::WebKeyboardEvent;
...@@ -983,6 +987,10 @@ TEST_P(InputRouterImplTest, TouchTypesIgnoringAck) { ...@@ -983,6 +987,10 @@ TEST_P(InputRouterImplTest, TouchTypesIgnoringAck) {
#endif #endif
TEST_P(InputRouterImplTest, MAYBE_GestureTypesIgnoringAck) { TEST_P(InputRouterImplTest, MAYBE_GestureTypesIgnoringAck) {
// We test every gesture type, ensuring that the stream of gestures is valid. // We test every gesture type, ensuring that the stream of gestures is valid.
#if defined(OS_WIN)
display::win::test::ScopedScreenWin scoped_screen_win_;
#endif
const WebInputEvent::Type eventTypes[] = { const WebInputEvent::Type eventTypes[] = {
WebInputEvent::kGestureTapDown, WebInputEvent::kGestureShowPress, WebInputEvent::kGestureTapDown, WebInputEvent::kGestureShowPress,
WebInputEvent::kGestureTapCancel, WebInputEvent::kGestureScrollBegin, WebInputEvent::kGestureTapCancel, WebInputEvent::kGestureScrollBegin,
......
...@@ -122,6 +122,10 @@ ...@@ -122,6 +122,10 @@
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#endif #endif
#if defined(OS_WIN)
#include "ui/display/win/test/scoped_screen_win.h"
#endif
using testing::_; using testing::_;
using blink::WebGestureEvent; using blink::WebGestureEvent;
...@@ -3668,6 +3672,11 @@ TEST_F(RenderWidgetHostViewAuraOverscrollTest, ...@@ -3668,6 +3672,11 @@ TEST_F(RenderWidgetHostViewAuraOverscrollTest,
ScrollEventsOverscrollWithFling) { ScrollEventsOverscrollWithFling) {
SetUpOverscrollEnvironment(); SetUpOverscrollEnvironment();
#if defined(OS_WIN)
// Create a ScopedScreenWin.
display::win::test::ScopedScreenWin scoped_screen_win;
#endif
// Send a wheel event. ACK the event as not processed. This should not // Send a wheel event. ACK the event as not processed. This should not
// initiate an overscroll gesture since it doesn't cross the threshold yet. // initiate an overscroll gesture since it doesn't cross the threshold yet.
SimulateWheelEvent(10, 0, 0, true, WebMouseWheelEvent::kPhaseBegan); SimulateWheelEvent(10, 0, 0, true, WebMouseWheelEvent::kPhaseBegan);
...@@ -3743,6 +3752,11 @@ TEST_F(RenderWidgetHostViewAuraOverscrollTest, ...@@ -3743,6 +3752,11 @@ TEST_F(RenderWidgetHostViewAuraOverscrollTest,
ScrollEventsOverscrollWithZeroFling) { ScrollEventsOverscrollWithZeroFling) {
SetUpOverscrollEnvironment(); SetUpOverscrollEnvironment();
#if defined(OS_WIN)
// Create a ScopedScreenWin.
display::win::test::ScopedScreenWin scoped_screen_win;
#endif
// Send a wheel event. ACK the event as not processed. This should not // Send a wheel event. ACK the event as not processed. This should not
// initiate an overscroll gesture since it doesn't cross the threshold yet. // initiate an overscroll gesture since it doesn't cross the threshold yet.
SimulateWheelEvent(10, 0, 0, true, WebMouseWheelEvent::kPhaseBegan); SimulateWheelEvent(10, 0, 0, true, WebMouseWheelEvent::kPhaseBegan);
...@@ -3820,6 +3834,11 @@ TEST_F(RenderWidgetHostViewAuraOverscrollTest, ...@@ -3820,6 +3834,11 @@ TEST_F(RenderWidgetHostViewAuraOverscrollTest,
MAYBE_ReverseFlingCancelsOverscroll) { MAYBE_ReverseFlingCancelsOverscroll) {
SetUpOverscrollEnvironment(); SetUpOverscrollEnvironment();
#if defined(OS_WIN)
// Create a ScopedScreenWin.
display::win::test::ScopedScreenWin scoped_screen_win;
#endif
{ {
PressAndSetTouchActionAuto(); PressAndSetTouchActionAuto();
// Start and end a gesture in the same direction without processing the // Start and end a gesture in the same direction without processing the
...@@ -4672,6 +4691,11 @@ TEST_F(RenderWidgetHostViewAuraOverscrollTest, ...@@ -4672,6 +4691,11 @@ TEST_F(RenderWidgetHostViewAuraOverscrollTest,
OverscrollStateResetsAfterScroll) { OverscrollStateResetsAfterScroll) {
SetUpOverscrollEnvironment(); SetUpOverscrollEnvironment();
#if defined(OS_WIN)
// Create a ScopedScreenWin.
display::win::test::ScopedScreenWin scoped_screen_win;
#endif
SimulateWheelEvent(0, 5, 0, true, SimulateWheelEvent(0, 5, 0, true,
WebMouseWheelEvent::kPhaseBegan); // sent directly WebMouseWheelEvent::kPhaseBegan); // sent directly
SimulateWheelEvent(0, 30, 0, true, SimulateWheelEvent(0, 30, 0, true,
...@@ -5051,6 +5075,11 @@ TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { ...@@ -5051,6 +5075,11 @@ TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) {
TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) { TEST_F(RenderWidgetHostViewAuraOverscrollTest, ScrollDeltasResetOnEnd) {
SetUpOverscrollEnvironment(); SetUpOverscrollEnvironment();
#if defined(OS_WIN)
// Create a ScopedScreenWin.
display::win::test::ScopedScreenWin scoped_screen_win;
#endif
PressAndSetTouchActionAuto(); PressAndSetTouchActionAuto();
// Wheel event scroll ending with mouse move. // Wheel event scroll ending with mouse move.
SimulateWheelEvent(-30, -10, 0, true, SimulateWheelEvent(-30, -10, 0, true,
......
...@@ -145,6 +145,8 @@ jumbo_static_library("test_support") { ...@@ -145,6 +145,8 @@ jumbo_static_library("test_support") {
if (is_win) { if (is_win) {
sources += [ sources += [
"win/test/scoped_screen_win.cc",
"win/test/scoped_screen_win.h",
"win/test/screen_util_win.cc", "win/test/screen_util_win.cc",
"win/test/screen_util_win.h", "win/test/screen_util_win.h",
] ]
......
// Copyright 2020 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 "ui/display/win/test/scoped_screen_win.h"
#include "ui/display/win/display_info.h"
#include "ui/display/win/test/screen_util_win.h"
namespace display {
namespace win {
namespace test {
ScopedScreenWin::ScopedScreenWin() : ScreenWin(false) {
const gfx::Rect pixel_bounds = gfx::Rect(0, 0, 1920, 1200);
const gfx::Rect pixel_work = gfx::Rect(0, 0, 1920, 1100);
MONITORINFOEX monitor_info =
CreateMonitorInfo(pixel_bounds, pixel_work, L"primary");
std::vector<DisplayInfo> display_infos;
display_infos.push_back(
DisplayInfo(monitor_info, 1.0f /* device_scale_factor*/, 1.0f,
Display::ROTATE_0, 60, gfx::Vector2dF(96.0, 96.0)));
UpdateFromDisplayInfos(display_infos);
previous_screen_ = Screen::GetScreen();
Screen::SetScreenInstance(this);
}
ScopedScreenWin::~ScopedScreenWin() {
Screen::SetScreenInstance(previous_screen_);
}
} // namespace test
} // namespace win
} // namespace display
// Copyright 2020 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 UI_DISPLAY_WIN_TEST_SCOPED_SCREEN_WIN_H_
#define UI_DISPLAY_WIN_TEST_SCOPED_SCREEN_WIN_H_
#include "base/macros.h"
#include "ui/display/win/screen_win.h"
namespace display {
namespace win {
namespace test {
// ScopedScreenWin construct a instance of ScreenWinDisplay with bounds
// (1920,1080). This will allow unittests to query the details about ScreenWin
// using static methods. ScopedScreenWin needs to be initialized before running
// the code that queries ScreenWin.
class ScopedScreenWin : public ScreenWin {
public:
ScopedScreenWin();
~ScopedScreenWin() override;
private:
Screen* previous_screen_;
DISALLOW_COPY_AND_ASSIGN(ScopedScreenWin);
};
} // namespace test
} // namespace win
} // namespace display
#endif // UI_DISPLAY_WIN_TEST_SCOPED_SCREEN_WIN_H_
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