| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 | |
| 6 #include "base/sys_info.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 #include "ui/aura/test/aura_test_base.h" | |
| 9 #include "ui/aura/window.h" | |
| 10 #include "ui/aura/window_event_dispatcher.h" | |
| 11 #include "ui/aura/window_tree_host_x11.h" | |
| 12 #include "ui/events/event_processor.h" | |
| 13 #include "ui/events/event_target.h" | |
| 14 #include "ui/events/event_target_iterator.h" | |
| 15 #include "ui/events/test/events_test_utils_x11.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 class RootWindowEventHandler : public ui::EventHandler { | |
| 20 public: | |
| 21 RootWindowEventHandler() : last_touch_type_(ui::ET_UNKNOWN), | |
| 22 last_touch_id_(-1), | |
| 23 last_touch_location_(0, 0) { | |
| 24 } | |
| 25 virtual ~RootWindowEventHandler () {} | |
| 26 | |
| 27 // ui::EventHandler: | |
| 28 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { | |
| 29 last_touch_id_ = event->touch_id(); | |
| 30 last_touch_type_ = event->type(); | |
| 31 last_touch_location_ = event->location(); | |
| 32 } | |
| 33 | |
| 34 ui::EventType last_touch_type() { | |
| 35 return last_touch_type_; | |
| 36 } | |
| 37 | |
| 38 int last_touch_id() { | |
| 39 return last_touch_id_; | |
| 40 } | |
| 41 | |
| 42 gfx::Point last_touch_location() { | |
| 43 return last_touch_location_; | |
| 44 } | |
| 45 | |
| 46 private: | |
| 47 ui::EventType last_touch_type_; | |
| 48 int last_touch_id_; | |
| 49 gfx::Point last_touch_location_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(RootWindowEventHandler); | |
| 52 }; | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 namespace aura { | |
| 57 | |
| 58 typedef test::AuraTestBase WindowTreeHostX11Test; | |
| 59 | |
| 60 // Send X touch events to one WindowTreeHost. The WindowTreeHost's | |
| 61 // delegate will get corresponding ui::TouchEvent if the touch events | |
| 62 // are winthin the bound of the WindowTreeHost. | |
| 63 TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) { | |
| 64 #if defined(OS_CHROMEOS) | |
| 65 // Fake a ChromeOS running env. | |
| 66 const char* kLsbRelease = "CHROMEOS_RELEASE_NAME=Chromium OS\n"; | |
| 67 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | |
| 68 #endif // defined(OS_CHROMEOS) | |
| 69 | |
| 70 scoped_ptr<WindowTreeHostX11> window_tree_host( | |
| 71 new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); | |
| 72 window_tree_host->InitHost(); | |
| 73 scoped_ptr<RootWindowEventHandler> handler(new RootWindowEventHandler()); | |
| 74 window_tree_host->window()->AddPreTargetHandler(handler.get()); | |
| 75 | |
| 76 std::vector<unsigned int> devices; | |
| 77 devices.push_back(0); | |
| 78 ui::SetUpTouchDevicesForTest(devices); | |
| 79 std::vector<ui::Valuator> valuators; | |
| 80 | |
| 81 EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type()); | |
| 82 EXPECT_EQ(-1, handler->last_touch_id()); | |
| 83 | |
| 84 ui::ScopedXI2Event scoped_xevent; | |
| 85 #if defined(OS_CHROMEOS) | |
| 86 // This touch is out of bounds. | |
| 87 scoped_xevent.InitTouchEvent( | |
| 88 0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators); | |
| 89 window_tree_host->DispatchEvent(scoped_xevent); | |
| 90 EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type()); | |
| 91 EXPECT_EQ(-1, handler->last_touch_id()); | |
| 92 EXPECT_EQ(gfx::Point(0, 0), handler->last_touch_location()); | |
| 93 #endif // defined(OS_CHROMEOS) | |
| 94 | |
| 95 // Following touchs are within bounds and are passed to delegate. | |
| 96 scoped_xevent.InitTouchEvent( | |
| 97 0, XI_TouchBegin, 5, gfx::Point(1500, 1500), valuators); | |
| 98 window_tree_host->DispatchEvent(scoped_xevent); | |
| 99 EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler->last_touch_type()); | |
| 100 EXPECT_EQ(0, handler->last_touch_id()); | |
| 101 EXPECT_EQ(gfx::Point(1500, 1500), handler->last_touch_location()); | |
| 102 | |
| 103 scoped_xevent.InitTouchEvent( | |
| 104 0, XI_TouchUpdate, 5, gfx::Point(1500, 1600), valuators); | |
| 105 window_tree_host->DispatchEvent(scoped_xevent); | |
| 106 EXPECT_EQ(ui::ET_TOUCH_MOVED, handler->last_touch_type()); | |
| 107 EXPECT_EQ(0, handler->last_touch_id()); | |
| 108 EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location()); | |
| 109 | |
| 110 scoped_xevent.InitTouchEvent( | |
| 111 0, XI_TouchEnd, 5, gfx::Point(1500, 1600), valuators); | |
| 112 window_tree_host->DispatchEvent(scoped_xevent); | |
| 113 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler->last_touch_type()); | |
| 114 EXPECT_EQ(0, handler->last_touch_id()); | |
| 115 EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location()); | |
| 116 | |
| 117 // Revert the CrOS testing env otherwise the following non-CrOS aura | |
| 118 // tests will fail. | |
| 119 #if defined(OS_CHROMEOS) | |
| 120 // Fake a ChromeOS running env. | |
| 121 kLsbRelease = ""; | |
| 122 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | |
| 123 #endif // defined(OS_CHROMEOS) | |
| 124 } | |
| 125 | |
| 126 // Send X touch events to two WindowTreeHost. The WindowTreeHost which is | |
| 127 // the event target of the X touch events should generate the corresponding | |
| 128 // ui::TouchEvent for its delegate. | |
| 129 #if defined(OS_CHROMEOS) | |
| 130 TEST_F(WindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) { | |
| 131 // Fake a ChromeOS running env. | |
| 132 const char* kLsbRelease = "CHROMEOS_RELEASE_NAME=Chromium OS\n"; | |
| 133 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | |
| 134 | |
| 135 scoped_ptr<WindowTreeHostX11> window_tree_host1( | |
| 136 new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); | |
| 137 window_tree_host1->InitHost(); | |
| 138 scoped_ptr<RootWindowEventHandler> handler1(new RootWindowEventHandler()); | |
| 139 window_tree_host1->window()->AddPreTargetHandler(handler1.get()); | |
| 140 | |
| 141 int host2_y_offset = 1700; | |
| 142 scoped_ptr<WindowTreeHostX11> window_tree_host2( | |
| 143 new WindowTreeHostX11(gfx::Rect(0, host2_y_offset, 1920, 1080))); | |
| 144 window_tree_host2->InitHost(); | |
| 145 scoped_ptr<RootWindowEventHandler> handler2(new RootWindowEventHandler()); | |
| 146 window_tree_host2->window()->AddPreTargetHandler(handler2.get()); | |
| 147 | |
| 148 std::vector<unsigned int> devices; | |
| 149 devices.push_back(0); | |
| 150 ui::SetUpTouchDevicesForTest(devices); | |
| 151 std::vector<ui::Valuator> valuators; | |
| 152 | |
| 153 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); | |
| 154 EXPECT_EQ(-1, handler1->last_touch_id()); | |
| 155 EXPECT_EQ(ui::ET_UNKNOWN, handler2->last_touch_type()); | |
| 156 EXPECT_EQ(-1, handler2->last_touch_id()); | |
| 157 | |
| 158 // 2 Touch events are targeted at the second WindowTreeHost. | |
| 159 ui::ScopedXI2Event scoped_xevent; | |
| 160 scoped_xevent.InitTouchEvent( | |
| 161 0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators); | |
| 162 window_tree_host1->DispatchEvent(scoped_xevent); | |
| 163 window_tree_host2->DispatchEvent(scoped_xevent); | |
| 164 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); | |
| 165 EXPECT_EQ(-1, handler1->last_touch_id()); | |
| 166 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); | |
| 167 EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler2->last_touch_type()); | |
| 168 EXPECT_EQ(0, handler2->last_touch_id()); | |
| 169 EXPECT_EQ(gfx::Point(1500, 2500 - host2_y_offset), | |
| 170 handler2->last_touch_location()); | |
| 171 | |
| 172 scoped_xevent.InitTouchEvent( | |
| 173 0, XI_TouchBegin, 6, gfx::Point(1600, 2600), valuators); | |
| 174 window_tree_host1->DispatchEvent(scoped_xevent); | |
| 175 window_tree_host2->DispatchEvent(scoped_xevent); | |
| 176 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); | |
| 177 EXPECT_EQ(-1, handler1->last_touch_id()); | |
| 178 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); | |
| 179 EXPECT_EQ(ui::ET_TOUCH_PRESSED, handler2->last_touch_type()); | |
| 180 EXPECT_EQ(1, handler2->last_touch_id()); | |
| 181 EXPECT_EQ(gfx::Point(1600, 2600 - host2_y_offset), | |
| 182 handler2->last_touch_location()); | |
| 183 | |
| 184 scoped_xevent.InitTouchEvent( | |
| 185 0, XI_TouchUpdate, 5, gfx::Point(1500, 2550), valuators); | |
| 186 window_tree_host1->DispatchEvent(scoped_xevent); | |
| 187 window_tree_host2->DispatchEvent(scoped_xevent); | |
| 188 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); | |
| 189 EXPECT_EQ(-1, handler1->last_touch_id()); | |
| 190 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); | |
| 191 EXPECT_EQ(ui::ET_TOUCH_MOVED, handler2->last_touch_type()); | |
| 192 EXPECT_EQ(0, handler2->last_touch_id()); | |
| 193 EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset), | |
| 194 handler2->last_touch_location()); | |
| 195 | |
| 196 scoped_xevent.InitTouchEvent( | |
| 197 0, XI_TouchUpdate, 6, gfx::Point(1600, 2650), valuators); | |
| 198 window_tree_host1->DispatchEvent(scoped_xevent); | |
| 199 window_tree_host2->DispatchEvent(scoped_xevent); | |
| 200 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); | |
| 201 EXPECT_EQ(-1, handler1->last_touch_id()); | |
| 202 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); | |
| 203 EXPECT_EQ(ui::ET_TOUCH_MOVED, handler2->last_touch_type()); | |
| 204 EXPECT_EQ(1, handler2->last_touch_id()); | |
| 205 EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset), | |
| 206 handler2->last_touch_location()); | |
| 207 | |
| 208 scoped_xevent.InitTouchEvent( | |
| 209 0, XI_TouchEnd, 5, gfx::Point(1500, 2550), valuators); | |
| 210 window_tree_host1->DispatchEvent(scoped_xevent); | |
| 211 window_tree_host2->DispatchEvent(scoped_xevent); | |
| 212 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); | |
| 213 EXPECT_EQ(-1, handler1->last_touch_id()); | |
| 214 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); | |
| 215 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type()); | |
| 216 EXPECT_EQ(0, handler2->last_touch_id()); | |
| 217 EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset), | |
| 218 handler2->last_touch_location()); | |
| 219 | |
| 220 scoped_xevent.InitTouchEvent( | |
| 221 0, XI_TouchEnd, 6, gfx::Point(1600, 2650), valuators); | |
| 222 window_tree_host1->DispatchEvent(scoped_xevent); | |
| 223 window_tree_host2->DispatchEvent(scoped_xevent); | |
| 224 EXPECT_EQ(ui::ET_UNKNOWN, handler1->last_touch_type()); | |
| 225 EXPECT_EQ(-1, handler1->last_touch_id()); | |
| 226 EXPECT_EQ(gfx::Point(0, 0), handler1->last_touch_location()); | |
| 227 EXPECT_EQ(ui::ET_TOUCH_RELEASED, handler2->last_touch_type()); | |
| 228 EXPECT_EQ(1, handler2->last_touch_id()); | |
| 229 EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset), | |
| 230 handler2->last_touch_location()); | |
| 231 | |
| 232 // Revert the CrOS testing env otherwise the following non-CrOS aura | |
| 233 // tests will fail. | |
| 234 // Fake a ChromeOS running env. | |
| 235 kLsbRelease = ""; | |
| 236 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); | |
| 237 } | |
| 238 #endif // defined(OS_CHROMEOS) | |
| 239 | |
| 240 } // namespace aura | |
| OLD | NEW |