Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: chrome/browser/ui/views/touch_events_interactive_uitest_win.cc

Issue 2904113002: Replacing WM_TOUCH with WM_POINTER for touch events on Wins 8+ (Closed)
Patch Set: wm touch Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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/win/windows_version.h"
6 #include "chrome/test/base/testing_profile.h"
7 #include "chrome/test/base/view_event_test_base.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_tree_host.h"
10 #include "ui/base/models/simple_menu_model.h"
11 #include "ui/base/test/ui_controls.h"
12 #include "ui/views/controls/menu/menu_runner.h"
13
14 namespace {
15
16 class TouchEventHandler : public ui::EventHandler {
17 public:
18 TouchEventHandler() : num_touch_presses_(0), num_pointers_down_(0) {}
19
20 ~TouchEventHandler() override {}
21
22 void WaitForEvents() {
23 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
24 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
25 base::RunLoop run_loop;
26 quit_closure_ = run_loop.QuitClosure();
27 run_loop.Run();
28 }
29
30 int num_touch_presses() const { return num_touch_presses_; }
31
32 int num_pointers_down() const { return num_pointers_down_; }
33
34 private:
35 // ui::EventHandler:
36 void OnTouchEvent(ui::TouchEvent* event) override {
37 switch (event->type()) {
38 case ui::ET_TOUCH_PRESSED:
39 num_touch_presses_++;
40 num_pointers_down_++;
41 break;
42 case ui::ET_TOUCH_RELEASED:
43 num_pointers_down_--;
44 if (!quit_closure_.is_null() && num_pointers_down_ == 0)
45 quit_closure_.Run();
46 break;
47 default:
48 break;
49 }
50 }
51
52 int num_touch_presses_;
53 int num_pointers_down_;
54 base::Closure quit_closure_;
55 DISALLOW_COPY_AND_ASSIGN(TouchEventHandler);
56 };
57
58 } // namespace
59
60 class TouchEventsViewTest : public ViewEventTestBase {
61 public:
62 TouchEventsViewTest() : ViewEventTestBase(), touch_view_(nullptr) {}
63
64 // ViewEventTestBase:
65 void SetUp() override {
66 touch_view_ = new views::View();
67 ViewEventTestBase::SetUp();
68 }
69
70 void TearDown() override {
71 touch_view_ = nullptr;
72 ViewEventTestBase::TearDown();
73 }
74
75 views::View* CreateContentsView() override { return touch_view_; }
76
77 gfx::Size GetPreferredSizeForContents() const override {
78 return gfx::Size(600, 600);
79 }
80
81 void DoTestOnMessageLoop() override {
82 // ui_controls::SendTouchEvents which uses InjectTouchInput API only works
83 // on Windows 8 and up.
84 if (base::win::GetVersion() <= base::win::VERSION_WIN7) {
85 Done();
86 return;
87 }
88
89 const int touch_pointer_count = 3;
90 TouchEventHandler touch_event_handler;
91 GetWidget()->GetNativeWindow()->GetHost()->window()->AddPreTargetHandler(
92 &touch_event_handler);
93 gfx::Point in_content(touch_view_->width() / 2, touch_view_->height() / 2);
94 views::View::ConvertPointToScreen(touch_view_, &in_content);
95
96 ASSERT_TRUE(ui_controls::SendTouchEvents(ui_controls::PRESS,
97 touch_pointer_count,
98 in_content.x(), in_content.y()));
99 touch_event_handler.WaitForEvents();
100 EXPECT_EQ(touch_pointer_count, touch_event_handler.num_touch_presses());
101 EXPECT_EQ(0, touch_event_handler.num_pointers_down());
102
103 GetWidget()->GetNativeWindow()->GetHost()->window()->RemovePreTargetHandler(
104 &touch_event_handler);
105 Done();
106 }
107
108 private:
109 views::View* touch_view_ = nullptr;
110
111 DISALLOW_COPY_AND_ASSIGN(TouchEventsViewTest);
112 };
113
114 VIEW_TEST(TouchEventsViewTest, CheckWindowsNativeMessageForTouchEvents)
OLDNEW
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698