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