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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/touch_events_interactive_uitest_win.cc
diff --git a/chrome/browser/ui/views/touch_events_interactive_uitest_win.cc b/chrome/browser/ui/views/touch_events_interactive_uitest_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..45b20a620d242774dd8f7b3ba49d96c8d366981d
--- /dev/null
+++ b/chrome/browser/ui/views/touch_events_interactive_uitest_win.cc
@@ -0,0 +1,112 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/win/windows_version.h"
+#include "chrome/test/base/testing_profile.h"
+#include "chrome/test/base/view_event_test_base.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_tree_host.h"
+#include "ui/base/models/simple_menu_model.h"
+#include "ui/base/test/ui_controls.h"
+#include "ui/views/controls/menu/menu_runner.h"
+
+namespace {
+
+class TouchEventHandler : public ui::EventHandler {
+ public:
+ TouchEventHandler() : num_touch_presses_(0), num_pointers_down_(0) {}
+
+ ~TouchEventHandler() override {}
+
+ void WaitForEvents() {
+ base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
+ base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
+ base::RunLoop run_loop;
+ quit_closure_ = run_loop.QuitClosure();
+ run_loop.Run();
+ }
+
+ int num_touch_presses() const { return num_touch_presses_; }
+
+ int num_pointers_down() const { return num_pointers_down_; }
+
+ private:
+ // ui::EventHandler:
+ void OnTouchEvent(ui::TouchEvent* event) override {
+ switch (event->type()) {
+ case ui::ET_TOUCH_PRESSED:
+ num_touch_presses_++;
+ num_pointers_down_++;
+ break;
+ case ui::ET_TOUCH_RELEASED:
+ num_pointers_down_--;
+ if (!quit_closure_.is_null() && num_pointers_down_ == 0)
+ quit_closure_.Run();
+ break;
+ default:
+ break;
+ }
+ }
+
+ int num_touch_presses_;
+ int num_pointers_down_;
+ base::Closure quit_closure_;
+ DISALLOW_COPY_AND_ASSIGN(TouchEventHandler);
+};
+
+} // namespace
+
+class TouchEventsViewTest : public ViewEventTestBase {
+ public:
+ TouchEventsViewTest() : ViewEventTestBase(), touch_view_(NULL) {}
sky 2017/06/27 02:19:47 NULL -> nullptr
lanwei 2017/06/27 18:55:42 Done.
+
+ // ViewEventTestBase:
+ void SetUp() override {
+ touch_view_ = new views::View();
+ ViewEventTestBase::SetUp();
+ }
+
+ void TearDown() override {
+ touch_view_ = NULL;
sky 2017/06/27 02:19:47 NULL -> nullptr
lanwei 2017/06/27 18:55:42 Done.
+ ViewEventTestBase::TearDown();
+ }
+
+ views::View* CreateContentsView() override { return touch_view_; }
+
+ gfx::Size GetPreferredSizeForContents() const override {
+ return gfx::Size(600, 600);
+ }
+
+ void DoTestOnMessageLoop() override {
+ if (base::win::GetVersion() <= base::win::VERSION_WIN7) {
sky 2017/06/27 02:19:47 Please add comment as to why this is only availabl
lanwei 2017/06/27 18:55:42 Done.
+ Done();
+ return;
+ }
+
+ TouchEventHandler touch_event_handler;
+ GetWidget()->GetNativeWindow()->GetHost()->window()->AddPreTargetHandler(
+ &touch_event_handler);
+ gfx::Point in_content(touch_view_->width() / 2, touch_view_->height() / 2);
+ views::View::ConvertPointToScreen(touch_view_, &in_content);
+
+ EXPECT_TRUE(ui_controls::SendTouchEvents(ui_controls::PRESS,
sky 2017/06/27 02:19:47 There is no point in continuing the test if this f
lanwei 2017/06/27 18:55:42 Done.
+ touch_pointer_count_,
+ in_content.x(), in_content.y()));
+ touch_event_handler.WaitForEvents();
+ ASSERT_EQ(touch_pointer_count_, touch_event_handler.num_touch_presses());
+ ASSERT_EQ(0, touch_event_handler.num_pointers_down());
+
+ GetWidget()->GetNativeWindow()->GetHost()->window()->RemovePreTargetHandler(
+ &touch_event_handler);
+ Done();
+ }
+
+ private:
+ views::View* touch_view_ = NULL;
+ const int touch_pointer_count_ = 3;
sky 2017/06/27 02:19:47 Make this a local in DodTestOnMessageLoop.
lanwei 2017/06/27 18:55:42 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(TouchEventsViewTest);
+};
+
+VIEW_TEST(TouchEventsViewTest, CheckWindowsNativeMessageForTouchEvents)

Powered by Google App Engine
This is Rietveld 408576698