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

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..e695f3051ebbef251f42e500d440e341781a25b0
--- /dev/null
+++ b/chrome/browser/ui/views/touch_events_interactive_uitest_win.cc
@@ -0,0 +1,119 @@
+// 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_touches_(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_touches() const { return num_touches_; }
+
+ private:
+ // ui::EventHandler:
+ void OnTouchEvent(ui::TouchEvent* event) override {
+ switch (event->type()) {
+ case ui::ET_TOUCH_PRESSED:
+ num_touch_presses_++;
+ num_touches_++;
+ break;
+ case ui::ET_TOUCH_RELEASED:
+ 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.
+ if (!quit_closure_.is_null() && num_touches_ == 0)
+ quit_closure_.Run();
+ break;
+ default:
+ break;
+ }
+ }
+
+ int num_touch_presses_;
+ int num_touches_;
+ base::Closure quit_closure_;
+ DISALLOW_COPY_AND_ASSIGN(TouchEventHandler);
+};
+
+// A view that always processes all touch events.
+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.
+ public:
+ TouchView() : View() {}
+ ~TouchView() override {}
+
+ DISALLOW_COPY_AND_ASSIGN(TouchView);
+};
+
+} // namespace
+
+class TouchEventsViewTest : public ViewEventTestBase {
+ public:
+ TouchEventsViewTest() {}
+
+ // ViewEventTestBase:
+ void SetUp() override {
+ touch_view_ = new TouchView();
+ touch_view_->SetBounds(0, 0, 600, 600);
+ ViewEventTestBase::SetUp();
+ }
+
+ void TearDown() override { ViewEventTestBase::TearDown(); }
+
+ views::View* CreateContentsView() override { return touch_view_; }
+
+ gfx::Size GetPreferredSizeForContents() const override {
+ 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.
+ }
+
+ void DoTestOnMessageLoop() override {
+ 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);
+ ui_controls::SendTouchEventsNotifyWhenDone(
sky 2017/06/24 00:01:14 EXPECT_TRUE.
lanwei 2017/06/26 22:59:28 Done.
+ ui_controls::PRESS, 3, in_content.x(), in_content.y(),
+ CreateEventTask(this, &TouchEventsViewTest::Step2));
+ }
+
+ private:
+ void Step2() {
+ 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.
+ Done();
+ return;
+ }
+
+ touch_event_handler_.WaitForEvents();
+ 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.
+ ASSERT_EQ(0, touch_event_handler_.num_touches());
+ GetWidget()->GetNativeWindow()->GetHost()->window()->RemovePreTargetHandler(
+ &touch_event_handler_);
+ Done();
+ }
+ 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.
+ TouchView* touch_view_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(TouchEventsViewTest);
+};
+
+VIEW_TEST(TouchEventsViewTest, CheckWindowsNativeMessageForTouchEvents)

Powered by Google App Engine
This is Rietveld 408576698