OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/win/windows_version.h" | 6 #include "base/win/windows_version.h" |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 9 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
10 #include "ui/display/display.h" | 10 #include "ui/display/display.h" |
11 #include "ui/display/display_switches.h" | 11 #include "ui/display/display_switches.h" |
12 #include "ui/events/blink/web_input_event_builders_win.h" | 12 #include "ui/events/blink/web_input_event_builders_win.h" |
13 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
14 | 14 |
15 using blink::WebMouseEvent; | 15 using blink::WebMouseEvent; |
16 using blink::WebMouseWheelEvent; | 16 using blink::WebMouseWheelEvent; |
17 | 17 |
18 namespace ui { | 18 namespace ui { |
19 | 19 |
20 // This test validates that Pixel to DIP conversion occurs as needed in the | 20 // This test validates that Pixel to DIP conversion occurs as needed in the |
21 // WebMouseEventBuilder::Build function. | 21 // WebMouseEventBuilder::Build function. |
22 TEST(WebInputEventBuilderTest, TestMouseEventScale) { | 22 TEST(WebInputEventBuilderTest, TestMouseEventScale) { |
23 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
24 return; | |
25 | |
26 display::Display::ResetForceDeviceScaleFactorForTesting(); | 23 display::Display::ResetForceDeviceScaleFactorForTesting(); |
27 | 24 |
28 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 25 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
29 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "2"); | 26 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "2"); |
30 | 27 |
31 // Synthesize a mouse move with x = 300 and y = 200. | 28 // Synthesize a mouse move with x = 300 and y = 200. |
32 WebMouseEvent mouse_move = ui::WebMouseEventBuilder::Build( | 29 WebMouseEvent mouse_move = ui::WebMouseEventBuilder::Build( |
33 ::GetDesktopWindow(), WM_MOUSEMOVE, 0, MAKELPARAM(300, 200), 100, | 30 ::GetDesktopWindow(), WM_MOUSEMOVE, 0, MAKELPARAM(300, 200), 100, |
34 blink::WebPointerProperties::PointerType::kMouse); | 31 blink::WebPointerProperties::PointerType::kMouse); |
35 | 32 |
36 // The WebMouseEvent.position field should be in pixels on return and hence | 33 // The WebMouseEvent.position field should be in pixels on return and hence |
37 // should be the same value as the x and y coordinates passed in to the | 34 // should be the same value as the x and y coordinates passed in to the |
38 // WebMouseEventBuilder::Build function. | 35 // WebMouseEventBuilder::Build function. |
39 EXPECT_EQ(300, mouse_move.PositionInWidget().x); | 36 EXPECT_EQ(300, mouse_move.PositionInWidget().x); |
40 EXPECT_EQ(200, mouse_move.PositionInWidget().y); | 37 EXPECT_EQ(200, mouse_move.PositionInWidget().y); |
41 | 38 |
42 // WebMouseEvent.positionInScreen is calculated in DIPs. | 39 // WebMouseEvent.positionInScreen is calculated in DIPs. |
43 EXPECT_EQ(150, mouse_move.PositionInScreen().x); | 40 EXPECT_EQ(150, mouse_move.PositionInScreen().x); |
44 EXPECT_EQ(100, mouse_move.PositionInScreen().y); | 41 EXPECT_EQ(100, mouse_move.PositionInScreen().y); |
45 | 42 |
46 EXPECT_EQ(blink::WebPointerProperties::PointerType::kMouse, | 43 EXPECT_EQ(blink::WebPointerProperties::PointerType::kMouse, |
47 mouse_move.pointer_type); | 44 mouse_move.pointer_type); |
48 | 45 |
49 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "1"); | 46 command_line->AppendSwitchASCII(switches::kForceDeviceScaleFactor, "1"); |
50 display::Display::ResetForceDeviceScaleFactorForTesting(); | 47 display::Display::ResetForceDeviceScaleFactorForTesting(); |
51 } | 48 } |
52 | 49 |
53 } // namespace ui | 50 } // namespace ui |
OLD | NEW |