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.
5 #include "base/command_line.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "third_party/WebKit/public/web/WebInputEvent.h"
8 #include "ui/events/event_constants.h"
9 #include "ui/gfx/display.h"
10 #include "ui/gfx/switches.h"
13 #include "base/win/windows_version.h"
14 #include "content/browser/renderer_host/input/web_input_event_builders_win.h"
17 using blink::WebMouseEvent
;
22 // This test validates that Pixel to DIP conversion occurs as needed in the
23 // WebMouseEventBuilder::Build function.
24 TEST(WebInputEventBuilderTest
, TestMouseEventScale
) {
25 if (base::win::GetVersion() < base::win::VERSION_WIN7
)
28 gfx::Display::ResetForceDeviceScaleFactorForTesting();
30 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
31 command_line
->AppendSwitchASCII(switches::kForceDeviceScaleFactor
, "2");
33 // Synthesize a mouse move with x = 300 and y = 200.
34 WebMouseEvent mouse_move
=
35 WebMouseEventBuilder::Build(::GetDesktopWindow(), WM_MOUSEMOVE
, 0,
36 MAKELPARAM(300, 200), 100);
38 // The WebMouseEvent.x, WebMouseEvent.y, WebMouseEvent.windowX and
39 // WebMouseEvent.windowY fields should be in pixels on return and hence
40 // should be the same value as the x and y coordinates passed in to the
41 // WebMouseEventBuilder::Build function.
42 EXPECT_EQ(300, mouse_move
.x
);
43 EXPECT_EQ(200, mouse_move
.y
);
45 EXPECT_EQ(300, mouse_move
.windowX
);
46 EXPECT_EQ(200, mouse_move
.windowY
);
48 // WebMouseEvent.globalX and WebMouseEvent.globalY are calculated in DIPs.
49 EXPECT_EQ(150, mouse_move
.globalX
);
50 EXPECT_EQ(100, mouse_move
.globalY
);
52 command_line
->AppendSwitchASCII(switches::kForceDeviceScaleFactor
, "1");
53 gfx::Display::ResetForceDeviceScaleFactorForTesting();
57 } // namespace content