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

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, 6 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
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_touches_(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_touches() const { return num_touches_; }
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_touches_++;
41 break;
42 case ui::ET_TOUCH_RELEASED:
43 num_touches_--;
sky 2017/06/24 00:01:14 num_touches_ is really the number of pointers curr
lanwei 2017/06/26 22:59:28 Done.
44 if (!quit_closure_.is_null() && num_touches_ == 0)
45 quit_closure_.Run();
46 break;
47 default:
48 break;
49 }
50 }
51
52 int num_touch_presses_;
53 int num_touches_;
54 base::Closure quit_closure_;
55 DISALLOW_COPY_AND_ASSIGN(TouchEventHandler);
56 };
57
58 // A view that always processes all touch events.
59 class TouchView : public views::View {
sky 2017/06/24 00:01:14 You don't need a View subclass here, create View()
lanwei 2017/06/26 22:59:28 Done.
60 public:
61 TouchView() : View() {}
62 ~TouchView() override {}
63
64 DISALLOW_COPY_AND_ASSIGN(TouchView);
65 };
66
67 } // namespace
68
69 class TouchEventsViewTest : public ViewEventTestBase {
70 public:
71 TouchEventsViewTest() {}
72
73 // ViewEventTestBase:
74 void SetUp() override {
75 touch_view_ = new TouchView();
76 touch_view_->SetBounds(0, 0, 600, 600);
77 ViewEventTestBase::SetUp();
78 }
79
80 void TearDown() override { ViewEventTestBase::TearDown(); }
81
82 views::View* CreateContentsView() override { return touch_view_; }
83
84 gfx::Size GetPreferredSizeForContents() const override {
85 return touch_view_->GetPreferredSize();
sky 2017/06/24 00:01:14 This returns 0. I think you want to return gfx::Si
lanwei 2017/06/26 22:59:29 Acknowledged.
86 }
87
88 void DoTestOnMessageLoop() override {
89 GetWidget()->GetNativeWindow()->GetHost()->window()->AddPreTargetHandler(
90 &touch_event_handler_);
91
92 gfx::Point in_content(touch_view_->width() / 2, touch_view_->height() / 2);
93 views::View::ConvertPointToScreen(touch_view_, &in_content);
94 ui_controls::SendTouchEventsNotifyWhenDone(
sky 2017/06/24 00:01:14 EXPECT_TRUE.
lanwei 2017/06/26 22:59:28 Done.
95 ui_controls::PRESS, 3, in_content.x(), in_content.y(),
96 CreateEventTask(this, &TouchEventsViewTest::Step2));
97 }
98
99 private:
100 void Step2() {
101 if (base::win::GetVersion() <= base::win::VERSION_WIN7) {
sky 2017/06/24 00:01:14 This test should be done first in DoTestOnMessageL
lanwei 2017/06/26 22:59:29 Done.
102 Done();
103 return;
104 }
105
106 touch_event_handler_.WaitForEvents();
107 ASSERT_EQ(3, touch_event_handler_.num_touch_presses());
sky 2017/06/24 00:01:14 This is the same as the 3 on 95, right? Use a cons
lanwei 2017/06/26 22:59:28 Done.
108 ASSERT_EQ(0, touch_event_handler_.num_touches());
109 GetWidget()->GetNativeWindow()->GetHost()->window()->RemovePreTargetHandler(
110 &touch_event_handler_);
111 Done();
112 }
113 TouchEventHandler touch_event_handler_;
sky 2017/06/24 00:01:14 When you end up with a single function, make this
lanwei 2017/06/26 22:59:28 Done.
114 TouchView* touch_view_ = nullptr;
115
116 DISALLOW_COPY_AND_ASSIGN(TouchEventsViewTest);
117 };
118
119 VIEW_TEST(TouchEventsViewTest, CheckWindowsNativeMessageForTouchEvents)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698