OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "services/ui/ws/event_dispatcher.h" | 5 #include "services/ui/ws/event_dispatcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <queue> | 10 #include <queue> |
11 | 11 |
| 12 #include "base/command_line.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/run_loop.h" |
| 17 #include "base/test/scoped_task_environment.h" |
15 #include "services/ui/common/accelerator_util.h" | 18 #include "services/ui/common/accelerator_util.h" |
16 #include "services/ui/ws/accelerator.h" | 19 #include "services/ui/ws/accelerator.h" |
17 #include "services/ui/ws/event_dispatcher_delegate.h" | 20 #include "services/ui/ws/event_dispatcher_delegate.h" |
18 #include "services/ui/ws/server_window.h" | 21 #include "services/ui/ws/server_window.h" |
19 #include "services/ui/ws/test_server_window_delegate.h" | 22 #include "services/ui/ws/test_server_window_delegate.h" |
20 #include "services/ui/ws/test_utils.h" | 23 #include "services/ui/ws/test_utils.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
23 | 26 |
24 namespace ui { | 27 namespace ui { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 const int64_t display_id, | 137 const int64_t display_id, |
135 const ui::Event& event, | 138 const ui::Event& event, |
136 Accelerator* accelerator) override { | 139 Accelerator* accelerator) override { |
137 std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails); | 140 std::unique_ptr<DispatchedEventDetails> details(new DispatchedEventDetails); |
138 details->window = target; | 141 details->window = target; |
139 details->client_id = client_id; | 142 details->client_id = client_id; |
140 details->event = ui::Event::Clone(event); | 143 details->event = ui::Event::Clone(event); |
141 details->accelerator = accelerator; | 144 details->accelerator = accelerator; |
142 dispatched_event_queue_.push(std::move(details)); | 145 dispatched_event_queue_.push(std::move(details)); |
143 } | 146 } |
| 147 void ProcessNextEventFromQueue() override {} |
144 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, | 148 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, |
145 bool in_nonclient_area) override { | 149 bool in_nonclient_area) override { |
146 return in_nonclient_area ? kNonclientAreaId : kClientAreaId; | 150 return in_nonclient_area ? kNonclientAreaId : kClientAreaId; |
147 } | 151 } |
148 ServerWindow* GetRootWindowContaining(gfx::Point* location_in_display, | 152 ServerWindow* GetRootWindowContaining(gfx::Point* location_in_display, |
149 int64_t* display_id) override { | 153 int64_t* display_id) override { |
150 return root_; | 154 return root_; |
151 } | 155 } |
152 void OnEventTargetNotFound(const ui::Event& event, | 156 void OnEventTargetNotFound(const ui::Event& event, |
153 const int64_t display_id) override { | 157 const int64_t display_id) override { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 195 } |
192 | 196 |
193 ASSERT_EQ(target, details->window); | 197 ASSERT_EQ(target, details->window); |
194 ASSERT_TRUE(details->event); | 198 ASSERT_TRUE(details->event); |
195 ASSERT_TRUE(details->event->IsLocatedEvent()); | 199 ASSERT_TRUE(details->event->IsLocatedEvent()); |
196 ASSERT_TRUE(details->IsClientArea()); | 200 ASSERT_TRUE(details->IsClientArea()); |
197 ASSERT_EQ(root_location, details->event->AsLocatedEvent()->root_location()); | 201 ASSERT_EQ(root_location, details->event->AsLocatedEvent()->root_location()); |
198 ASSERT_EQ(location, details->event->AsLocatedEvent()->location()); | 202 ASSERT_EQ(location, details->event->AsLocatedEvent()->location()); |
199 } | 203 } |
200 | 204 |
201 void RunMouseEventTests(EventDispatcher* dispatcher, | |
202 TestEventDispatcherDelegate* dispatcher_delegate, | |
203 MouseEventTest* tests, | |
204 size_t test_count) { | |
205 for (size_t i = 0; i < test_count; ++i) { | |
206 const MouseEventTest& test = tests[i]; | |
207 ASSERT_FALSE(dispatcher_delegate->has_queued_events()) | |
208 << " unexpected queued events before running " << i; | |
209 dispatcher->ProcessEvent(ui::PointerEvent(test.input_event), 0, | |
210 EventDispatcher::AcceleratorMatchPhase::ANY); | |
211 | |
212 std::unique_ptr<DispatchedEventDetails> details = | |
213 dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | |
214 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches( | |
215 details.get(), test.expected_target_window1, | |
216 test.expected_root_location1, test.expected_location1)) | |
217 << " details don't match " << i; | |
218 details = dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | |
219 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches( | |
220 details.get(), test.expected_target_window2, | |
221 test.expected_root_location2, test.expected_location2)) | |
222 << " details2 don't match " << i; | |
223 ASSERT_FALSE(dispatcher_delegate->has_queued_events()) | |
224 << " unexpected queued events after running " << i; | |
225 } | |
226 } | |
227 | |
228 } // namespace | 205 } // namespace |
229 | 206 |
230 // Test fixture for EventDispatcher with friend access to verify the internal | 207 // Test fixture for EventDispatcher with friend access to verify the internal |
231 // state. Setup creates a TestServerWindowDelegate, a visible root ServerWindow, | 208 // state. Setup creates a TestServerWindowDelegate, a visible root ServerWindow, |
232 // a TestEventDispatcher and the EventDispatcher for testing. | 209 // a TestEventDispatcher and the EventDispatcher for testing. |
233 class EventDispatcherTest : public testing::Test, | 210 class EventDispatcherTest : public testing::TestWithParam<bool>, |
234 public TestEventDispatcherDelegate::Delegate { | 211 public TestEventDispatcherDelegate::Delegate { |
235 public: | 212 public: |
236 EventDispatcherTest() {} | 213 EventDispatcherTest() {} |
237 ~EventDispatcherTest() override {} | 214 ~EventDispatcherTest() override {} |
238 | 215 |
239 ServerWindow* root_window() { return root_window_.get(); } | 216 ServerWindow* root_window() { return root_window_.get(); } |
240 TestEventDispatcherDelegate* test_event_dispatcher_delegate() { | 217 TestEventDispatcherDelegate* test_event_dispatcher_delegate() { |
241 return test_event_dispatcher_delegate_.get(); | 218 return test_event_dispatcher_delegate_.get(); |
242 } | 219 } |
243 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); } | 220 EventDispatcher* event_dispatcher() { return event_dispatcher_.get(); } |
244 | 221 |
| 222 void RunTasks(); |
| 223 void RunMouseEventTests(EventDispatcher* dispatcher, |
| 224 TestEventDispatcherDelegate* dispatcher_delegate, |
| 225 MouseEventTest* tests, |
| 226 size_t test_count); |
245 bool AreAnyPointersDown() const; | 227 bool AreAnyPointersDown() const; |
246 // Deletes everything created during SetUp() | 228 // Deletes everything created during SetUp() |
247 void ClearSetup(); | 229 void ClearSetup(); |
248 std::unique_ptr<ServerWindow> CreateChildWindowWithParent( | 230 std::unique_ptr<ServerWindow> CreateChildWindowWithParent( |
249 const WindowId& id, | 231 const WindowId& id, |
250 ServerWindow* parent); | 232 ServerWindow* parent); |
251 // Creates a window which is a child of |root_window_|. | 233 // Creates a window which is a child of |root_window_|. |
252 std::unique_ptr<ServerWindow> CreateChildWindow(const WindowId& id); | 234 std::unique_ptr<ServerWindow> CreateChildWindow(const WindowId& id); |
253 bool IsMouseButtonDown() const; | 235 bool IsMouseButtonDown() const; |
254 bool IsWindowPointerTarget(const ServerWindow* window) const; | 236 bool IsWindowPointerTarget(const ServerWindow* window) const; |
255 int NumberPointerTargetsForWindow(ServerWindow* window) const; | 237 int NumberPointerTargetsForWindow(ServerWindow* window) const; |
256 ServerWindow* GetActiveSystemModalWindow() const; | 238 ServerWindow* GetActiveSystemModalWindow() const; |
257 | 239 |
258 protected: | 240 protected: |
259 // testing::Test: | 241 // testing::TestWithParam<bool>: |
260 void SetUp() override; | 242 void SetUp() override; |
261 | 243 |
262 private: | 244 private: |
263 // TestEventDispatcherDelegate::Delegate: | 245 // TestEventDispatcherDelegate::Delegate: |
264 void ReleaseCapture() override { | 246 void ReleaseCapture() override { |
265 event_dispatcher_->SetCaptureWindow(nullptr, kInvalidClientId); | 247 event_dispatcher_->SetCaptureWindow(nullptr, kInvalidClientId); |
266 } | 248 } |
267 | 249 |
268 std::unique_ptr<TestServerWindowDelegate> window_delegate_; | 250 std::unique_ptr<TestServerWindowDelegate> window_delegate_; |
269 std::unique_ptr<ServerWindow> root_window_; | 251 std::unique_ptr<ServerWindow> root_window_; |
270 std::unique_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; | 252 std::unique_ptr<TestEventDispatcherDelegate> test_event_dispatcher_delegate_; |
271 std::unique_ptr<EventDispatcher> event_dispatcher_; | 253 std::unique_ptr<EventDispatcher> event_dispatcher_; |
272 | 254 |
| 255 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 256 |
273 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest); | 257 DISALLOW_COPY_AND_ASSIGN(EventDispatcherTest); |
274 }; | 258 }; |
275 | 259 |
| 260 void EventDispatcherTest::RunTasks() { |
| 261 bool enable_async_event_targeting = GetParam(); |
| 262 if (!enable_async_event_targeting) |
| 263 return; |
| 264 |
| 265 base::RunLoop runloop; |
| 266 runloop.RunUntilIdle(); |
| 267 } |
| 268 |
| 269 void EventDispatcherTest::RunMouseEventTests( |
| 270 EventDispatcher* dispatcher, |
| 271 TestEventDispatcherDelegate* dispatcher_delegate, |
| 272 MouseEventTest* tests, |
| 273 size_t test_count) { |
| 274 for (size_t i = 0; i < test_count; ++i) { |
| 275 const MouseEventTest& test = tests[i]; |
| 276 ASSERT_FALSE(dispatcher_delegate->has_queued_events()) |
| 277 << " unexpected queued events before running " << i; |
| 278 dispatcher->ProcessEvent(ui::PointerEvent(test.input_event), 0, |
| 279 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 280 RunTasks(); |
| 281 |
| 282 std::unique_ptr<DispatchedEventDetails> details = |
| 283 dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 284 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches( |
| 285 details.get(), test.expected_target_window1, |
| 286 test.expected_root_location1, test.expected_location1)) |
| 287 << " details don't match " << i; |
| 288 details = dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
| 289 ASSERT_NO_FATAL_FAILURE(ExpectDispatchedEventDetailsMatches( |
| 290 details.get(), test.expected_target_window2, |
| 291 test.expected_root_location2, test.expected_location2)) |
| 292 << " details2 don't match " << i; |
| 293 ASSERT_FALSE(dispatcher_delegate->has_queued_events()) |
| 294 << " unexpected queued events after running " << i; |
| 295 } |
| 296 } |
| 297 |
276 bool EventDispatcherTest::AreAnyPointersDown() const { | 298 bool EventDispatcherTest::AreAnyPointersDown() const { |
277 return EventDispatcherTestApi(event_dispatcher_.get()).AreAnyPointersDown(); | 299 return EventDispatcherTestApi(event_dispatcher_.get()).AreAnyPointersDown(); |
278 } | 300 } |
279 | 301 |
280 void EventDispatcherTest::ClearSetup() { | 302 void EventDispatcherTest::ClearSetup() { |
281 window_delegate_.reset(); | 303 window_delegate_.reset(); |
282 root_window_.reset(); | 304 root_window_.reset(); |
283 test_event_dispatcher_delegate_.reset(); | 305 test_event_dispatcher_delegate_.reset(); |
284 event_dispatcher_.reset(); | 306 event_dispatcher_.reset(); |
285 } | 307 } |
(...skipping 29 matching lines...) Expand all Loading... |
315 .NumberPointerTargetsForWindow(window); | 337 .NumberPointerTargetsForWindow(window); |
316 } | 338 } |
317 | 339 |
318 ServerWindow* EventDispatcherTest::GetActiveSystemModalWindow() const { | 340 ServerWindow* EventDispatcherTest::GetActiveSystemModalWindow() const { |
319 ModalWindowController* mwc = | 341 ModalWindowController* mwc = |
320 EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller(); | 342 EventDispatcherTestApi(event_dispatcher_.get()).modal_window_controller(); |
321 return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow(); | 343 return ModalWindowControllerTestApi(mwc).GetActiveSystemModalWindow(); |
322 } | 344 } |
323 | 345 |
324 void EventDispatcherTest::SetUp() { | 346 void EventDispatcherTest::SetUp() { |
325 testing::Test::SetUp(); | 347 bool enable_async_event_targeting = GetParam(); |
| 348 if (enable_async_event_targeting) { |
| 349 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 350 "enable-async-event-targeting"); |
| 351 } |
| 352 testing::TestWithParam<bool>::SetUp(); |
326 | 353 |
327 window_delegate_ = base::MakeUnique<TestServerWindowDelegate>(); | 354 window_delegate_ = base::MakeUnique<TestServerWindowDelegate>(); |
328 root_window_ = | 355 root_window_ = |
329 base::MakeUnique<ServerWindow>(window_delegate_.get(), WindowId(1, 2)); | 356 base::MakeUnique<ServerWindow>(window_delegate_.get(), WindowId(1, 2)); |
330 window_delegate_->set_root_window(root_window_.get()); | 357 window_delegate_->set_root_window(root_window_.get()); |
331 root_window_->SetVisible(true); | 358 root_window_->SetVisible(true); |
332 | 359 |
333 test_event_dispatcher_delegate_ = | 360 test_event_dispatcher_delegate_ = |
334 base::MakeUnique<TestEventDispatcherDelegate>(this); | 361 base::MakeUnique<TestEventDispatcherDelegate>(this); |
335 event_dispatcher_ = | 362 event_dispatcher_ = |
336 base::MakeUnique<EventDispatcher>(test_event_dispatcher_delegate_.get()); | 363 base::MakeUnique<EventDispatcher>(test_event_dispatcher_delegate_.get()); |
337 test_event_dispatcher_delegate_->set_root(root_window_.get()); | 364 test_event_dispatcher_delegate_->set_root(root_window_.get()); |
338 } | 365 } |
339 | 366 |
340 TEST_F(EventDispatcherTest, ProcessEvent) { | 367 TEST_P(EventDispatcherTest, ProcessEvent) { |
341 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 368 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
342 | 369 |
343 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 370 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
344 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 371 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
345 | 372 |
346 // Send event that is over child. | 373 // Send event that is over child. |
347 const ui::PointerEvent ui_event(ui::MouseEvent( | 374 const ui::PointerEvent ui_event(ui::MouseEvent( |
348 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), | 375 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), |
349 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 376 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
350 event_dispatcher()->ProcessEvent(ui_event, 0, | 377 event_dispatcher()->ProcessEvent(ui_event, 0, |
351 EventDispatcher::AcceleratorMatchPhase::ANY); | 378 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 379 RunTasks(); |
352 | 380 |
353 std::unique_ptr<DispatchedEventDetails> details = | 381 std::unique_ptr<DispatchedEventDetails> details = |
354 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 382 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
355 ASSERT_TRUE(details); | 383 ASSERT_TRUE(details); |
356 ASSERT_EQ(child.get(), details->window); | 384 ASSERT_EQ(child.get(), details->window); |
357 | 385 |
358 ASSERT_TRUE(details->event); | 386 ASSERT_TRUE(details->event); |
359 ASSERT_TRUE(details->event->IsPointerEvent()); | 387 ASSERT_TRUE(details->event->IsPointerEvent()); |
360 | 388 |
361 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 389 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
362 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); | 390 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); |
363 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); | 391 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); |
364 } | 392 } |
365 | 393 |
366 TEST_F(EventDispatcherTest, ProcessEventNoTarget) { | 394 TEST_P(EventDispatcherTest, ProcessEventNoTarget) { |
367 // Send event without a target. | 395 // Send event without a target. |
368 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 396 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
369 event_dispatcher()->ProcessEvent(key, 0, | 397 event_dispatcher()->ProcessEvent(key, 0, |
370 EventDispatcher::AcceleratorMatchPhase::ANY); | 398 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 399 RunTasks(); |
371 | 400 |
372 // Event wasn't dispatched to a target. | 401 // Event wasn't dispatched to a target. |
373 std::unique_ptr<DispatchedEventDetails> details = | 402 std::unique_ptr<DispatchedEventDetails> details = |
374 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 403 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
375 EXPECT_FALSE(details); | 404 EXPECT_FALSE(details); |
376 | 405 |
377 // Delegate was informed that there wasn't a target. | 406 // Delegate was informed that there wasn't a target. |
378 ui::Event* event_out = | 407 ui::Event* event_out = |
379 test_event_dispatcher_delegate()->last_event_target_not_found(); | 408 test_event_dispatcher_delegate()->last_event_target_not_found(); |
380 ASSERT_TRUE(event_out); | 409 ASSERT_TRUE(event_out); |
381 EXPECT_TRUE(event_out->IsKeyEvent()); | 410 EXPECT_TRUE(event_out->IsKeyEvent()); |
382 EXPECT_EQ(ui::VKEY_A, event_out->AsKeyEvent()->key_code()); | 411 EXPECT_EQ(ui::VKEY_A, event_out->AsKeyEvent()->key_code()); |
383 } | 412 } |
384 | 413 |
385 TEST_F(EventDispatcherTest, AcceleratorBasic) { | 414 TEST_P(EventDispatcherTest, AcceleratorBasic) { |
386 ClearSetup(); | 415 ClearSetup(); |
387 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); | 416 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); |
388 EventDispatcher dispatcher(&event_dispatcher_delegate); | 417 EventDispatcher dispatcher(&event_dispatcher_delegate); |
389 | 418 |
390 uint32_t accelerator_1 = 1; | 419 uint32_t accelerator_1 = 1; |
391 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( | 420 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
392 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); | 421 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
393 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); | 422 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); |
394 | 423 |
395 uint32_t accelerator_2 = 2; | 424 uint32_t accelerator_2 = 2; |
(...skipping 17 matching lines...) Expand all Loading... |
413 uint32_t accelerator_3 = 3; | 442 uint32_t accelerator_3 = 3; |
414 matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, | 443 matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
415 ui::mojom::kEventFlagNone); | 444 ui::mojom::kEventFlagNone); |
416 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); | 445 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
417 | 446 |
418 matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, | 447 matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
419 ui::mojom::kEventFlagControlDown); | 448 ui::mojom::kEventFlagControlDown); |
420 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); | 449 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
421 } | 450 } |
422 | 451 |
423 TEST_F(EventDispatcherTest, EventMatching) { | 452 TEST_P(EventDispatcherTest, EventMatching) { |
424 TestEventDispatcherDelegate* event_dispatcher_delegate = | 453 TestEventDispatcherDelegate* event_dispatcher_delegate = |
425 test_event_dispatcher_delegate(); | 454 test_event_dispatcher_delegate(); |
426 EventDispatcher* dispatcher = event_dispatcher(); | 455 EventDispatcher* dispatcher = event_dispatcher(); |
427 | 456 |
428 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( | 457 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
429 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); | 458 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
430 uint32_t accelerator_1 = 1; | 459 uint32_t accelerator_1 = 1; |
431 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); | 460 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); |
432 | 461 |
433 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 462 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
434 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 463 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 464 RunTasks(); |
435 EXPECT_EQ(accelerator_1, | 465 EXPECT_EQ(accelerator_1, |
436 event_dispatcher_delegate->GetAndClearLastAccelerator()); | 466 event_dispatcher_delegate->GetAndClearLastAccelerator()); |
437 | 467 |
438 // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to | 468 // EF_NUM_LOCK_ON should be ignored since CreateKeyMatcher defaults to |
439 // ignoring. | 469 // ignoring. |
440 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, | 470 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, |
441 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON); | 471 ui::EF_CONTROL_DOWN | ui::EF_NUM_LOCK_ON); |
442 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 472 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 473 RunTasks(); |
443 EXPECT_EQ(accelerator_1, | 474 EXPECT_EQ(accelerator_1, |
444 event_dispatcher_delegate->GetAndClearLastAccelerator()); | 475 event_dispatcher_delegate->GetAndClearLastAccelerator()); |
445 | 476 |
446 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); | 477 key = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_NONE); |
447 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 478 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 479 RunTasks(); |
448 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); | 480 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); |
449 | 481 |
450 uint32_t accelerator_2 = 2; | 482 uint32_t accelerator_2 = 2; |
451 matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::W, | 483 matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::W, |
452 ui::mojom::kEventFlagNone); | 484 ui::mojom::kEventFlagNone); |
453 dispatcher->AddAccelerator(accelerator_2, std::move(matcher)); | 485 dispatcher->AddAccelerator(accelerator_2, std::move(matcher)); |
454 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 486 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 487 RunTasks(); |
455 EXPECT_EQ(accelerator_2, | 488 EXPECT_EQ(accelerator_2, |
456 event_dispatcher_delegate->GetAndClearLastAccelerator()); | 489 event_dispatcher_delegate->GetAndClearLastAccelerator()); |
457 | 490 |
458 dispatcher->RemoveAccelerator(accelerator_2); | 491 dispatcher->RemoveAccelerator(accelerator_2); |
459 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 492 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 493 RunTasks(); |
460 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); | 494 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); |
461 } | 495 } |
462 | 496 |
463 // Tests that a post-target accelerator is not triggered by ProcessEvent. | 497 // Tests that a post-target accelerator is not triggered by ProcessEvent. |
464 TEST_F(EventDispatcherTest, PostTargetAccelerator) { | 498 TEST_P(EventDispatcherTest, PostTargetAccelerator) { |
465 TestEventDispatcherDelegate* event_dispatcher_delegate = | 499 TestEventDispatcherDelegate* event_dispatcher_delegate = |
466 test_event_dispatcher_delegate(); | 500 test_event_dispatcher_delegate(); |
467 EventDispatcher* dispatcher = event_dispatcher(); | 501 EventDispatcher* dispatcher = event_dispatcher(); |
468 | 502 |
469 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( | 503 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
470 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); | 504 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
471 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET; | 505 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET; |
472 uint32_t accelerator_1 = 1; | 506 uint32_t accelerator_1 = 1; |
473 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); | 507 dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); |
474 | 508 |
475 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 509 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
476 // The post-target accelerator should be fired if there is no focused window. | 510 // The post-target accelerator should be fired if there is no focused window. |
477 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 511 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 512 RunTasks(); |
478 EXPECT_EQ(accelerator_1, | 513 EXPECT_EQ(accelerator_1, |
479 event_dispatcher_delegate->GetAndClearLastAccelerator()); | 514 event_dispatcher_delegate->GetAndClearLastAccelerator()); |
480 std::unique_ptr<DispatchedEventDetails> details = | 515 std::unique_ptr<DispatchedEventDetails> details = |
481 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 516 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
482 EXPECT_FALSE(details); | 517 EXPECT_FALSE(details); |
483 | 518 |
484 // Set focused window for EventDispatcher dispatches key events. | 519 // Set focused window for EventDispatcher dispatches key events. |
485 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 520 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
486 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get()); | 521 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get()); |
487 | 522 |
488 // With a focused window the event should be dispatched. | 523 // With a focused window the event should be dispatched. |
489 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 524 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 525 RunTasks(); |
490 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); | 526 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); |
491 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 527 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
492 EXPECT_TRUE(details); | 528 EXPECT_TRUE(details); |
493 EXPECT_TRUE(details->accelerator); | 529 EXPECT_TRUE(details->accelerator); |
494 | 530 |
495 base::WeakPtr<Accelerator> accelerator_weak_ptr = | 531 base::WeakPtr<Accelerator> accelerator_weak_ptr = |
496 details->accelerator->GetWeakPtr(); | 532 details->accelerator->GetWeakPtr(); |
497 dispatcher->RemoveAccelerator(accelerator_1); | 533 dispatcher->RemoveAccelerator(accelerator_1); |
498 EXPECT_FALSE(accelerator_weak_ptr); | 534 EXPECT_FALSE(accelerator_weak_ptr); |
499 | 535 |
500 // Post deletion there should be no accelerator | 536 // Post deletion there should be no accelerator |
501 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 537 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 538 RunTasks(); |
502 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); | 539 EXPECT_EQ(0u, event_dispatcher_delegate->GetAndClearLastAccelerator()); |
503 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 540 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
504 EXPECT_TRUE(details); | 541 EXPECT_TRUE(details); |
505 EXPECT_FALSE(details->accelerator); | 542 EXPECT_FALSE(details->accelerator); |
506 } | 543 } |
507 | 544 |
508 TEST_F(EventDispatcherTest, ProcessPost) { | 545 TEST_P(EventDispatcherTest, ProcessPost) { |
509 TestEventDispatcherDelegate* event_dispatcher_delegate = | 546 TestEventDispatcherDelegate* event_dispatcher_delegate = |
510 test_event_dispatcher_delegate(); | 547 test_event_dispatcher_delegate(); |
511 EventDispatcher* dispatcher = event_dispatcher(); | 548 EventDispatcher* dispatcher = event_dispatcher(); |
512 | 549 |
513 uint32_t pre_id = 1; | 550 uint32_t pre_id = 1; |
514 { | 551 { |
515 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( | 552 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
516 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); | 553 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
517 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::PRE_TARGET; | 554 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::PRE_TARGET; |
518 dispatcher->AddAccelerator(pre_id, std::move(matcher)); | 555 dispatcher->AddAccelerator(pre_id, std::move(matcher)); |
519 } | 556 } |
520 | 557 |
521 uint32_t post_id = 2; | 558 uint32_t post_id = 2; |
522 { | 559 { |
523 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( | 560 mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
524 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); | 561 ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
525 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET; | 562 matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET; |
526 dispatcher->AddAccelerator(post_id, std::move(matcher)); | 563 dispatcher->AddAccelerator(post_id, std::move(matcher)); |
527 } | 564 } |
528 | 565 |
529 // Set focused window for EventDispatcher dispatches key events. | 566 // Set focused window for EventDispatcher dispatches key events. |
530 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 567 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
531 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get()); | 568 event_dispatcher_delegate->SetFocusedWindowFromEventDispatcher(child.get()); |
532 | 569 |
533 // Dispatch for ANY, which should trigger PRE and not call | 570 // Dispatch for ANY, which should trigger PRE and not call |
534 // DispatchInputEventToWindow(). | 571 // DispatchInputEventToWindow(). |
535 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 572 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
536 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 573 dispatcher->ProcessEvent(key, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 574 RunTasks(); |
537 EXPECT_EQ(EventDispatcherDelegate::AcceleratorPhase::PRE, | 575 EXPECT_EQ(EventDispatcherDelegate::AcceleratorPhase::PRE, |
538 event_dispatcher_delegate->last_accelerator_phase()); | 576 event_dispatcher_delegate->last_accelerator_phase()); |
539 EXPECT_EQ(pre_id, event_dispatcher_delegate->GetAndClearLastAccelerator()); | 577 EXPECT_EQ(pre_id, event_dispatcher_delegate->GetAndClearLastAccelerator()); |
540 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 578 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
541 | 579 |
542 // Dispatch for POST, which should trigger POST. | 580 // Dispatch for POST, which should trigger POST. |
543 dispatcher->ProcessEvent(key, 0, | 581 dispatcher->ProcessEvent(key, 0, |
544 EventDispatcher::AcceleratorMatchPhase::POST_ONLY); | 582 EventDispatcher::AcceleratorMatchPhase::POST_ONLY); |
| 583 RunTasks(); |
545 std::unique_ptr<DispatchedEventDetails> details = | 584 std::unique_ptr<DispatchedEventDetails> details = |
546 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 585 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
547 ASSERT_TRUE(details); | 586 ASSERT_TRUE(details); |
548 ASSERT_TRUE(details->accelerator); | 587 ASSERT_TRUE(details->accelerator); |
549 EXPECT_EQ(post_id, details->accelerator->id()); | 588 EXPECT_EQ(post_id, details->accelerator->id()); |
550 } | 589 } |
551 | 590 |
552 TEST_F(EventDispatcherTest, Capture) { | 591 TEST_P(EventDispatcherTest, Capture) { |
553 ServerWindow* root = root_window(); | 592 ServerWindow* root = root_window(); |
554 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 593 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
555 | 594 |
556 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 595 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
557 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 596 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
558 | 597 |
559 MouseEventTest tests[] = { | 598 MouseEventTest tests[] = { |
560 // Send a mouse down event over child. | 599 // Send a mouse down event over child. |
561 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), | 600 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), |
562 gfx::Point(20, 25), base::TimeTicks(), | 601 gfx::Point(20, 25), base::TimeTicks(), |
(...skipping 22 matching lines...) Expand all Loading... |
585 gfx::Point(50, 50), base::TimeTicks(), | 624 gfx::Point(50, 50), base::TimeTicks(), |
586 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 625 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
587 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root, | 626 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root, |
588 gfx::Point(50, 50), gfx::Point(50, 50)}, | 627 gfx::Point(50, 50), gfx::Point(50, 50)}, |
589 | 628 |
590 }; | 629 }; |
591 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 630 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
592 tests, arraysize(tests)); | 631 tests, arraysize(tests)); |
593 } | 632 } |
594 | 633 |
595 TEST_F(EventDispatcherTest, CaptureMultipleMouseButtons) { | 634 TEST_P(EventDispatcherTest, CaptureMultipleMouseButtons) { |
596 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 635 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
597 | 636 |
598 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 637 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
599 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 638 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
600 | 639 |
601 MouseEventTest tests[] = { | 640 MouseEventTest tests[] = { |
602 // Send a mouse down event over child with a left mouse button | 641 // Send a mouse down event over child with a left mouse button |
603 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), | 642 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), |
604 gfx::Point(20, 25), base::TimeTicks(), | 643 gfx::Point(20, 25), base::TimeTicks(), |
605 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 644 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
(...skipping 22 matching lines...) Expand all Loading... |
628 gfx::Point(50, 50), base::TimeTicks(), | 667 gfx::Point(50, 50), base::TimeTicks(), |
629 ui::EF_LEFT_MOUSE_BUTTON, 0), | 668 ui::EF_LEFT_MOUSE_BUTTON, 0), |
630 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr, | 669 child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr, |
631 gfx::Point(), gfx::Point()}, | 670 gfx::Point(), gfx::Point()}, |
632 | 671 |
633 }; | 672 }; |
634 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 673 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
635 tests, arraysize(tests)); | 674 tests, arraysize(tests)); |
636 } | 675 } |
637 | 676 |
638 TEST_F(EventDispatcherTest, ClientAreaGoesToOwner) { | 677 TEST_P(EventDispatcherTest, ClientAreaGoesToOwner) { |
639 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 678 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
640 | 679 |
641 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 680 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
642 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 681 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
643 | 682 |
644 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); | 683 child->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); |
645 | 684 |
646 TestEventDispatcherDelegate* event_dispatcher_delegate = | 685 TestEventDispatcherDelegate* event_dispatcher_delegate = |
647 test_event_dispatcher_delegate(); | 686 test_event_dispatcher_delegate(); |
648 EventDispatcher* dispatcher = event_dispatcher(); | 687 EventDispatcher* dispatcher = event_dispatcher(); |
649 | 688 |
650 // Start move loop by sending mouse event over non-client area. | 689 // Start move loop by sending mouse event over non-client area. |
651 const ui::PointerEvent press_event(ui::MouseEvent( | 690 const ui::PointerEvent press_event(ui::MouseEvent( |
652 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), | 691 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), |
653 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 692 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
654 dispatcher->ProcessEvent(press_event, 0, | 693 dispatcher->ProcessEvent(press_event, 0, |
655 EventDispatcher::AcceleratorMatchPhase::ANY); | 694 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 695 RunTasks(); |
656 | 696 |
657 // Events should target child and be in the non-client area. | 697 // Events should target child and be in the non-client area. |
658 std::unique_ptr<DispatchedEventDetails> details = | 698 std::unique_ptr<DispatchedEventDetails> details = |
659 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 699 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
660 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 700 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
661 ASSERT_TRUE(details); | 701 ASSERT_TRUE(details); |
662 ASSERT_EQ(child.get(), details->window); | 702 ASSERT_EQ(child.get(), details->window); |
663 EXPECT_TRUE(details->IsNonclientArea()); | 703 EXPECT_TRUE(details->IsNonclientArea()); |
664 | 704 |
665 // Move the mouse 5,6 pixels and target is the same. | 705 // Move the mouse 5,6 pixels and target is the same. |
666 const ui::PointerEvent move_event( | 706 const ui::PointerEvent move_event( |
667 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(17, 18), gfx::Point(17, 18), | 707 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(17, 18), gfx::Point(17, 18), |
668 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); | 708 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); |
669 dispatcher->ProcessEvent(move_event, 0, | 709 dispatcher->ProcessEvent(move_event, 0, |
670 EventDispatcher::AcceleratorMatchPhase::ANY); | 710 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 711 RunTasks(); |
671 | 712 |
672 // Still same target. | 713 // Still same target. |
673 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 714 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
674 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 715 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
675 ASSERT_EQ(child.get(), details->window); | 716 ASSERT_EQ(child.get(), details->window); |
676 EXPECT_TRUE(details->IsNonclientArea()); | 717 EXPECT_TRUE(details->IsNonclientArea()); |
677 | 718 |
678 // Release the mouse. | 719 // Release the mouse. |
679 const ui::PointerEvent release_event(ui::MouseEvent( | 720 const ui::PointerEvent release_event(ui::MouseEvent( |
680 ui::ET_MOUSE_RELEASED, gfx::Point(17, 18), gfx::Point(17, 18), | 721 ui::ET_MOUSE_RELEASED, gfx::Point(17, 18), gfx::Point(17, 18), |
681 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 722 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
682 dispatcher->ProcessEvent(release_event, 0, | 723 dispatcher->ProcessEvent(release_event, 0, |
683 EventDispatcher::AcceleratorMatchPhase::ANY); | 724 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 725 RunTasks(); |
684 | 726 |
685 // The event should not have been dispatched to the delegate. | 727 // The event should not have been dispatched to the delegate. |
686 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 728 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
687 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 729 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
688 ASSERT_EQ(child.get(), details->window); | 730 ASSERT_EQ(child.get(), details->window); |
689 EXPECT_TRUE(details->IsNonclientArea()); | 731 EXPECT_TRUE(details->IsNonclientArea()); |
690 | 732 |
691 // Press in the client area and verify target/client area. The non-client area | 733 // Press in the client area and verify target/client area. The non-client area |
692 // should get an exit first. | 734 // should get an exit first. |
693 const ui::PointerEvent press_event2(ui::MouseEvent( | 735 const ui::PointerEvent press_event2(ui::MouseEvent( |
694 ui::ET_MOUSE_PRESSED, gfx::Point(21, 22), gfx::Point(21, 22), | 736 ui::ET_MOUSE_PRESSED, gfx::Point(21, 22), gfx::Point(21, 22), |
695 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 737 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
696 dispatcher->ProcessEvent(press_event2, 0, | 738 dispatcher->ProcessEvent(press_event2, 0, |
697 EventDispatcher::AcceleratorMatchPhase::ANY); | 739 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 740 RunTasks(); |
698 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 741 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
699 EXPECT_TRUE(event_dispatcher_delegate->has_queued_events()); | 742 EXPECT_TRUE(event_dispatcher_delegate->has_queued_events()); |
700 ASSERT_EQ(child.get(), details->window); | 743 ASSERT_EQ(child.get(), details->window); |
701 EXPECT_TRUE(details->IsNonclientArea()); | 744 EXPECT_TRUE(details->IsNonclientArea()); |
702 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); | 745 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); |
703 | 746 |
704 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 747 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
705 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 748 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
706 ASSERT_EQ(child.get(), details->window); | 749 ASSERT_EQ(child.get(), details->window); |
707 EXPECT_TRUE(details->IsClientArea()); | 750 EXPECT_TRUE(details->IsClientArea()); |
708 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); | 751 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); |
709 } | 752 } |
710 | 753 |
711 TEST_F(EventDispatcherTest, AdditionalClientArea) { | 754 TEST_P(EventDispatcherTest, AdditionalClientArea) { |
712 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 755 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
713 | 756 |
714 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 757 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
715 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 758 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
716 | 759 |
717 std::vector<gfx::Rect> additional_client_areas; | 760 std::vector<gfx::Rect> additional_client_areas; |
718 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2)); | 761 additional_client_areas.push_back(gfx::Rect(18, 0, 2, 2)); |
719 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas); | 762 child->SetClientArea(gfx::Insets(5, 5, 5, 5), additional_client_areas); |
720 | 763 |
721 TestEventDispatcherDelegate* event_dispatcher_delegate = | 764 TestEventDispatcherDelegate* event_dispatcher_delegate = |
722 test_event_dispatcher_delegate(); | 765 test_event_dispatcher_delegate(); |
723 // Press in the additional client area, it should go to the child. | 766 // Press in the additional client area, it should go to the child. |
724 const ui::PointerEvent press_event(ui::MouseEvent( | 767 const ui::PointerEvent press_event(ui::MouseEvent( |
725 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11), | 768 ui::ET_MOUSE_PRESSED, gfx::Point(28, 11), gfx::Point(28, 11), |
726 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 769 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
727 event_dispatcher()->ProcessEvent(press_event, 0, | 770 event_dispatcher()->ProcessEvent(press_event, 0, |
728 EventDispatcher::AcceleratorMatchPhase::ANY); | 771 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 772 RunTasks(); |
729 | 773 |
730 // Events should target child and be in the client area. | 774 // Events should target child and be in the client area. |
731 std::unique_ptr<DispatchedEventDetails> details = | 775 std::unique_ptr<DispatchedEventDetails> details = |
732 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 776 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
733 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 777 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
734 ASSERT_EQ(child.get(), details->window); | 778 ASSERT_EQ(child.get(), details->window); |
735 EXPECT_TRUE(details->IsClientArea()); | 779 EXPECT_TRUE(details->IsClientArea()); |
736 } | 780 } |
737 | 781 |
738 TEST_F(EventDispatcherTest, HitTestMask) { | 782 TEST_P(EventDispatcherTest, HitTestMask) { |
739 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 783 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
740 | 784 |
741 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 785 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
742 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 786 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
743 child->SetHitTestMask(gfx::Rect(2, 2, 16, 16)); | 787 child->SetHitTestMask(gfx::Rect(2, 2, 16, 16)); |
744 | 788 |
745 // Move in the masked area. | 789 // Move in the masked area. |
746 const ui::PointerEvent move1(ui::MouseEvent( | 790 const ui::PointerEvent move1(ui::MouseEvent( |
747 ui::ET_MOUSE_MOVED, gfx::Point(11, 11), gfx::Point(11, 11), | 791 ui::ET_MOUSE_MOVED, gfx::Point(11, 11), gfx::Point(11, 11), |
748 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); | 792 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); |
749 event_dispatcher()->ProcessEvent(move1, 0, | 793 event_dispatcher()->ProcessEvent(move1, 0, |
750 EventDispatcher::AcceleratorMatchPhase::ANY); | 794 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 795 RunTasks(); |
751 | 796 |
752 // Event went through the child window and hit the root. | 797 // Event went through the child window and hit the root. |
753 std::unique_ptr<DispatchedEventDetails> details1 = | 798 std::unique_ptr<DispatchedEventDetails> details1 = |
754 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 799 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
755 EXPECT_EQ(root_window(), details1->window); | 800 EXPECT_EQ(root_window(), details1->window); |
756 EXPECT_TRUE(details1->IsClientArea()); | 801 EXPECT_TRUE(details1->IsClientArea()); |
757 | 802 |
758 child->ClearHitTestMask(); | 803 child->ClearHitTestMask(); |
759 | 804 |
760 // Move right in the same part of the window. | 805 // Move right in the same part of the window. |
761 const ui::PointerEvent move2(ui::MouseEvent( | 806 const ui::PointerEvent move2(ui::MouseEvent( |
762 ui::ET_MOUSE_MOVED, gfx::Point(11, 12), gfx::Point(11, 12), | 807 ui::ET_MOUSE_MOVED, gfx::Point(11, 12), gfx::Point(11, 12), |
763 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); | 808 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0)); |
764 event_dispatcher()->ProcessEvent(move2, 0, | 809 event_dispatcher()->ProcessEvent(move2, 0, |
765 EventDispatcher::AcceleratorMatchPhase::ANY); | 810 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 811 RunTasks(); |
766 | 812 |
767 // Mouse exits the root. | 813 // Mouse exits the root. |
768 std::unique_ptr<DispatchedEventDetails> details2 = | 814 std::unique_ptr<DispatchedEventDetails> details2 = |
769 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 815 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
770 EXPECT_EQ(ui::ET_POINTER_EXITED, details2->event->type()); | 816 EXPECT_EQ(ui::ET_POINTER_EXITED, details2->event->type()); |
771 | 817 |
772 // Mouse hits the child. | 818 // Mouse hits the child. |
773 std::unique_ptr<DispatchedEventDetails> details3 = | 819 std::unique_ptr<DispatchedEventDetails> details3 = |
774 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 820 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
775 EXPECT_EQ(child.get(), details3->window); | 821 EXPECT_EQ(child.get(), details3->window); |
776 EXPECT_TRUE(details3->IsClientArea()); | 822 EXPECT_TRUE(details3->IsClientArea()); |
777 } | 823 } |
778 | 824 |
779 TEST_F(EventDispatcherTest, DontFocusOnSecondDown) { | 825 TEST_P(EventDispatcherTest, DontFocusOnSecondDown) { |
780 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); | 826 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); |
781 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); | 827 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); |
782 | 828 |
783 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 829 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
784 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 830 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
785 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); | 831 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); |
786 | 832 |
787 TestEventDispatcherDelegate* event_dispatcher_delegate = | 833 TestEventDispatcherDelegate* event_dispatcher_delegate = |
788 test_event_dispatcher_delegate(); | 834 test_event_dispatcher_delegate(); |
789 EventDispatcher* dispatcher = event_dispatcher(); | 835 EventDispatcher* dispatcher = event_dispatcher(); |
790 | 836 |
791 // Press on child1. First press event should change focus. | 837 // Press on child1. First press event should change focus. |
792 const ui::PointerEvent press_event(ui::MouseEvent( | 838 const ui::PointerEvent press_event(ui::MouseEvent( |
793 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), | 839 ui::ET_MOUSE_PRESSED, gfx::Point(12, 12), gfx::Point(12, 12), |
794 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 840 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
795 dispatcher->ProcessEvent(press_event, 0, | 841 dispatcher->ProcessEvent(press_event, 0, |
796 EventDispatcher::AcceleratorMatchPhase::ANY); | 842 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 843 RunTasks(); |
797 std::unique_ptr<DispatchedEventDetails> details = | 844 std::unique_ptr<DispatchedEventDetails> details = |
798 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 845 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
799 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 846 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
800 EXPECT_EQ(child1.get(), details->window); | 847 EXPECT_EQ(child1.get(), details->window); |
801 EXPECT_EQ(child1.get(), | 848 EXPECT_EQ(child1.get(), |
802 event_dispatcher_delegate->GetAndClearLastFocusedWindow()); | 849 event_dispatcher_delegate->GetAndClearLastFocusedWindow()); |
803 | 850 |
804 // Press (with a different pointer id) on child2. Event should go to child2, | 851 // Press (with a different pointer id) on child2. Event should go to child2, |
805 // but focus should not change. | 852 // but focus should not change. |
806 const ui::PointerEvent touch_event(ui::TouchEvent( | 853 const ui::PointerEvent touch_event(ui::TouchEvent( |
807 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), base::TimeTicks(), | 854 ui::ET_TOUCH_PRESSED, gfx::Point(53, 54), base::TimeTicks(), |
808 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); | 855 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); |
809 dispatcher->ProcessEvent(touch_event, 0, | 856 dispatcher->ProcessEvent(touch_event, 0, |
810 EventDispatcher::AcceleratorMatchPhase::ANY); | 857 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 858 RunTasks(); |
811 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 859 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
812 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 860 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
813 EXPECT_EQ(child2.get(), details->window); | 861 EXPECT_EQ(child2.get(), details->window); |
814 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow()); | 862 EXPECT_EQ(nullptr, event_dispatcher_delegate->GetAndClearLastFocusedWindow()); |
815 } | 863 } |
816 | 864 |
817 TEST_F(EventDispatcherTest, TwoPointersActive) { | 865 TEST_P(EventDispatcherTest, TwoPointersActive) { |
818 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); | 866 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); |
819 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); | 867 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); |
820 | 868 |
821 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 869 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
822 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 870 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
823 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); | 871 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); |
824 | 872 |
825 TestEventDispatcherDelegate* event_dispatcher_delegate = | 873 TestEventDispatcherDelegate* event_dispatcher_delegate = |
826 test_event_dispatcher_delegate(); | 874 test_event_dispatcher_delegate(); |
827 EventDispatcher* dispatcher = event_dispatcher(); | 875 EventDispatcher* dispatcher = event_dispatcher(); |
828 | 876 |
829 // Press on child1. | 877 // Press on child1. |
830 const ui::PointerEvent touch_event1(ui::TouchEvent( | 878 const ui::PointerEvent touch_event1(ui::TouchEvent( |
831 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(), | 879 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(), |
832 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); | 880 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); |
833 dispatcher->ProcessEvent(touch_event1, 0, | 881 dispatcher->ProcessEvent(touch_event1, 0, |
834 EventDispatcher::AcceleratorMatchPhase::ANY); | 882 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 883 RunTasks(); |
835 std::unique_ptr<DispatchedEventDetails> details = | 884 std::unique_ptr<DispatchedEventDetails> details = |
836 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 885 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
837 EXPECT_EQ(child1.get(), details->window); | 886 EXPECT_EQ(child1.get(), details->window); |
838 | 887 |
839 // Drag over child2, child1 should get the drag. | 888 // Drag over child2, child1 should get the drag. |
840 const ui::PointerEvent drag_event1(ui::TouchEvent( | 889 const ui::PointerEvent drag_event1(ui::TouchEvent( |
841 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), base::TimeTicks(), | 890 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), base::TimeTicks(), |
842 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); | 891 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); |
843 dispatcher->ProcessEvent(drag_event1, 0, | 892 dispatcher->ProcessEvent(drag_event1, 0, |
844 EventDispatcher::AcceleratorMatchPhase::ANY); | 893 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 894 RunTasks(); |
845 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 895 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
846 EXPECT_EQ(child1.get(), details->window); | 896 EXPECT_EQ(child1.get(), details->window); |
847 | 897 |
848 // Press on child2 with a different touch id. | 898 // Press on child2 with a different touch id. |
849 const ui::PointerEvent touch_event2(ui::TouchEvent( | 899 const ui::PointerEvent touch_event2(ui::TouchEvent( |
850 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), base::TimeTicks(), | 900 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), base::TimeTicks(), |
851 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); | 901 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); |
852 dispatcher->ProcessEvent(touch_event2, 0, | 902 dispatcher->ProcessEvent(touch_event2, 0, |
853 EventDispatcher::AcceleratorMatchPhase::ANY); | 903 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 904 RunTasks(); |
854 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 905 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
855 EXPECT_EQ(child2.get(), details->window); | 906 EXPECT_EQ(child2.get(), details->window); |
856 | 907 |
857 // Drag over child1 with id 2, child2 should continue to get the drag. | 908 // Drag over child1 with id 2, child2 should continue to get the drag. |
858 const ui::PointerEvent drag_event2(ui::TouchEvent( | 909 const ui::PointerEvent drag_event2(ui::TouchEvent( |
859 ui::ET_TOUCH_MOVED, gfx::Point(13, 14), base::TimeTicks(), | 910 ui::ET_TOUCH_MOVED, gfx::Point(13, 14), base::TimeTicks(), |
860 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); | 911 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); |
861 dispatcher->ProcessEvent(drag_event2, 0, | 912 dispatcher->ProcessEvent(drag_event2, 0, |
862 EventDispatcher::AcceleratorMatchPhase::ANY); | 913 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 914 RunTasks(); |
863 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 915 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
864 EXPECT_EQ(child2.get(), details->window); | 916 EXPECT_EQ(child2.get(), details->window); |
865 | 917 |
866 // Drag again with id 1, child1 should continue to get it. | 918 // Drag again with id 1, child1 should continue to get it. |
867 dispatcher->ProcessEvent(drag_event1, 0, | 919 dispatcher->ProcessEvent(drag_event1, 0, |
868 EventDispatcher::AcceleratorMatchPhase::ANY); | 920 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 921 RunTasks(); |
869 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 922 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
870 EXPECT_EQ(child1.get(), details->window); | 923 EXPECT_EQ(child1.get(), details->window); |
871 | 924 |
872 // Release touch id 1, and click on 2. 2 should get it. | 925 // Release touch id 1, and click on 2. 2 should get it. |
873 const ui::PointerEvent touch_release(ui::TouchEvent( | 926 const ui::PointerEvent touch_release(ui::TouchEvent( |
874 ui::ET_TOUCH_RELEASED, gfx::Point(54, 55), base::TimeTicks(), | 927 ui::ET_TOUCH_RELEASED, gfx::Point(54, 55), base::TimeTicks(), |
875 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); | 928 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); |
876 dispatcher->ProcessEvent(touch_release, 0, | 929 dispatcher->ProcessEvent(touch_release, 0, |
877 EventDispatcher::AcceleratorMatchPhase::ANY); | 930 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 931 RunTasks(); |
878 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 932 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
879 EXPECT_EQ(child1.get(), details->window); | 933 EXPECT_EQ(child1.get(), details->window); |
880 const ui::PointerEvent touch_event3(ui::TouchEvent( | 934 const ui::PointerEvent touch_event3(ui::TouchEvent( |
881 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), base::TimeTicks(), | 935 ui::ET_TOUCH_PRESSED, gfx::Point(54, 55), base::TimeTicks(), |
882 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); | 936 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); |
883 dispatcher->ProcessEvent(touch_event3, 0, | 937 dispatcher->ProcessEvent(touch_event3, 0, |
884 EventDispatcher::AcceleratorMatchPhase::ANY); | 938 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 939 RunTasks(); |
885 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 940 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
886 EXPECT_EQ(child2.get(), details->window); | 941 EXPECT_EQ(child2.get(), details->window); |
887 } | 942 } |
888 | 943 |
889 TEST_F(EventDispatcherTest, DestroyWindowWhileGettingEvents) { | 944 TEST_P(EventDispatcherTest, DestroyWindowWhileGettingEvents) { |
890 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 945 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
891 | 946 |
892 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 947 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
893 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 948 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
894 | 949 |
895 TestEventDispatcherDelegate* event_dispatcher_delegate = | 950 TestEventDispatcherDelegate* event_dispatcher_delegate = |
896 test_event_dispatcher_delegate(); | 951 test_event_dispatcher_delegate(); |
897 EventDispatcher* dispatcher = event_dispatcher(); | 952 EventDispatcher* dispatcher = event_dispatcher(); |
898 | 953 |
899 // Press on child. | 954 // Press on child. |
900 const ui::PointerEvent touch_event1(ui::TouchEvent( | 955 const ui::PointerEvent touch_event1(ui::TouchEvent( |
901 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(), | 956 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(), |
902 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); | 957 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); |
903 dispatcher->ProcessEvent(touch_event1, 0, | 958 dispatcher->ProcessEvent(touch_event1, 0, |
904 EventDispatcher::AcceleratorMatchPhase::ANY); | 959 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 960 RunTasks(); |
905 std::unique_ptr<DispatchedEventDetails> details = | 961 std::unique_ptr<DispatchedEventDetails> details = |
906 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 962 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
907 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 963 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
908 EXPECT_EQ(child.get(), details->window); | 964 EXPECT_EQ(child.get(), details->window); |
909 | 965 |
910 // Delete child, and continue the drag. Event should not be dispatched. | 966 // Delete child, and continue the drag. Event should not be dispatched. |
911 child.reset(); | 967 child.reset(); |
912 | 968 |
913 const ui::PointerEvent drag_event1(ui::TouchEvent( | 969 const ui::PointerEvent drag_event1(ui::TouchEvent( |
914 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), base::TimeTicks(), | 970 ui::ET_TOUCH_MOVED, gfx::Point(53, 54), base::TimeTicks(), |
915 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); | 971 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); |
916 dispatcher->ProcessEvent(drag_event1, 0, | 972 dispatcher->ProcessEvent(drag_event1, 0, |
917 EventDispatcher::AcceleratorMatchPhase::ANY); | 973 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 974 RunTasks(); |
918 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 975 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
919 EXPECT_EQ(nullptr, details.get()); | 976 EXPECT_EQ(nullptr, details.get()); |
920 } | 977 } |
921 | 978 |
922 TEST_F(EventDispatcherTest, MouseInExtendedHitTestRegion) { | 979 TEST_P(EventDispatcherTest, MouseInExtendedHitTestRegion) { |
923 ServerWindow* root = root_window(); | 980 ServerWindow* root = root_window(); |
924 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 981 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
925 | 982 |
926 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 983 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
927 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 984 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
928 | 985 |
929 TestEventDispatcherDelegate* event_dispatcher_delegate = | 986 TestEventDispatcherDelegate* event_dispatcher_delegate = |
930 test_event_dispatcher_delegate(); | 987 test_event_dispatcher_delegate(); |
931 EventDispatcher* dispatcher = event_dispatcher(); | 988 EventDispatcher* dispatcher = event_dispatcher(); |
932 | 989 |
933 // Send event that is not over child. | 990 // Send event that is not over child. |
934 const ui::PointerEvent ui_event(ui::MouseEvent( | 991 const ui::PointerEvent ui_event(ui::MouseEvent( |
935 ui::ET_MOUSE_PRESSED, gfx::Point(8, 9), gfx::Point(8, 9), | 992 ui::ET_MOUSE_PRESSED, gfx::Point(8, 9), gfx::Point(8, 9), |
936 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 993 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
937 dispatcher->ProcessEvent(ui_event, 0, | 994 dispatcher->ProcessEvent(ui_event, 0, |
938 EventDispatcher::AcceleratorMatchPhase::ANY); | 995 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 996 RunTasks(); |
939 std::unique_ptr<DispatchedEventDetails> details = | 997 std::unique_ptr<DispatchedEventDetails> details = |
940 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 998 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
941 ASSERT_EQ(root, details->window); | 999 ASSERT_EQ(root, details->window); |
942 | 1000 |
943 // Release the mouse. | 1001 // Release the mouse. |
944 const ui::PointerEvent release_event(ui::MouseEvent( | 1002 const ui::PointerEvent release_event(ui::MouseEvent( |
945 ui::ET_MOUSE_RELEASED, gfx::Point(8, 9), gfx::Point(8, 9), | 1003 ui::ET_MOUSE_RELEASED, gfx::Point(8, 9), gfx::Point(8, 9), |
946 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1004 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
947 dispatcher->ProcessEvent(release_event, 0, | 1005 dispatcher->ProcessEvent(release_event, 0, |
948 EventDispatcher::AcceleratorMatchPhase::ANY); | 1006 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1007 RunTasks(); |
949 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1008 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
950 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 1009 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
951 ASSERT_EQ(root, details->window); | 1010 ASSERT_EQ(root, details->window); |
952 EXPECT_TRUE(details->IsClientArea()); | 1011 EXPECT_TRUE(details->IsClientArea()); |
953 | 1012 |
954 // Change the extended hit test region and send event in extended hit test | 1013 // Change the extended hit test region and send event in extended hit test |
955 // region. Should result in exit for root, followed by press for child. | 1014 // region. Should result in exit for root, followed by press for child. |
956 child->set_extended_hit_test_region(gfx::Insets(5, 5, 5, 5)); | 1015 child->set_extended_hit_test_region(gfx::Insets(5, 5, 5, 5)); |
957 dispatcher->ProcessEvent(ui_event, 0, | 1016 dispatcher->ProcessEvent(ui_event, 0, |
958 EventDispatcher::AcceleratorMatchPhase::ANY); | 1017 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1018 RunTasks(); |
959 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1019 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
960 EXPECT_EQ(root, details->window); | 1020 EXPECT_EQ(root, details->window); |
961 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); | 1021 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); |
962 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1022 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
963 ASSERT_TRUE(details); | 1023 ASSERT_TRUE(details); |
964 | 1024 |
965 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 1025 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
966 EXPECT_TRUE(details->IsNonclientArea()); | 1026 EXPECT_TRUE(details->IsNonclientArea()); |
967 ASSERT_EQ(child.get(), details->window); | 1027 ASSERT_EQ(child.get(), details->window); |
968 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); | 1028 EXPECT_EQ(ui::ET_POINTER_DOWN, details->event->type()); |
969 ASSERT_TRUE(details->event.get()); | 1029 ASSERT_TRUE(details->event.get()); |
970 ASSERT_TRUE(details->event->IsPointerEvent()); | 1030 ASSERT_TRUE(details->event->IsPointerEvent()); |
971 EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location()); | 1031 EXPECT_EQ(gfx::Point(-2, -1), details->event->AsPointerEvent()->location()); |
972 } | 1032 } |
973 | 1033 |
974 TEST_F(EventDispatcherTest, WheelWhileDown) { | 1034 TEST_P(EventDispatcherTest, WheelWhileDown) { |
975 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); | 1035 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); |
976 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); | 1036 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); |
977 | 1037 |
978 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1038 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
979 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1039 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
980 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); | 1040 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); |
981 | 1041 |
982 MouseEventTest tests[] = { | 1042 MouseEventTest tests[] = { |
983 // Send a mouse down event over child1. | 1043 // Send a mouse down event over child1. |
984 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), | 1044 {ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), |
985 gfx::Point(15, 15), base::TimeTicks(), | 1045 gfx::Point(15, 15), base::TimeTicks(), |
986 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), | 1046 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON), |
987 child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr, | 1047 child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr, |
988 gfx::Point(), gfx::Point()}, | 1048 gfx::Point(), gfx::Point()}, |
989 // Send mouse wheel over child2, should go to child1 as it has capture. | 1049 // Send mouse wheel over child2, should go to child1 as it has capture. |
990 {ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54), | 1050 {ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54), |
991 gfx::Point(53, 54), base::TimeTicks(), ui::EF_NONE, | 1051 gfx::Point(53, 54), base::TimeTicks(), ui::EF_NONE, |
992 ui::EF_NONE), | 1052 ui::EF_NONE), |
993 child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr, | 1053 child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr, |
994 gfx::Point(), gfx::Point()}, | 1054 gfx::Point(), gfx::Point()}, |
995 }; | 1055 }; |
996 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 1056 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
997 tests, arraysize(tests)); | 1057 tests, arraysize(tests)); |
998 } | 1058 } |
999 | 1059 |
1000 // Tests that when explicit capture has been set that all events go to the | 1060 // Tests that when explicit capture has been set that all events go to the |
1001 // designated window, and that when capture is cleared, events find the | 1061 // designated window, and that when capture is cleared, events find the |
1002 // appropriate target window. | 1062 // appropriate target window. |
1003 TEST_F(EventDispatcherTest, SetExplicitCapture) { | 1063 TEST_P(EventDispatcherTest, SetExplicitCapture) { |
1004 ServerWindow* root = root_window(); | 1064 ServerWindow* root = root_window(); |
1005 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1065 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
1006 | 1066 |
1007 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1067 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1008 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1068 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1009 | 1069 |
1010 TestEventDispatcherDelegate* event_dispatcher_delegate = | 1070 TestEventDispatcherDelegate* event_dispatcher_delegate = |
1011 test_event_dispatcher_delegate(); | 1071 test_event_dispatcher_delegate(); |
1012 EventDispatcher* dispatcher = event_dispatcher(); | 1072 EventDispatcher* dispatcher = event_dispatcher(); |
1013 | 1073 |
1014 { | 1074 { |
1015 // Send all pointer events to the child. | 1075 // Send all pointer events to the child. |
1016 dispatcher->SetCaptureWindow(child.get(), kClientAreaId); | 1076 dispatcher->SetCaptureWindow(child.get(), kClientAreaId); |
1017 | 1077 |
1018 // The mouse press should go to the child even though its outside its | 1078 // The mouse press should go to the child even though its outside its |
1019 // bounds. | 1079 // bounds. |
1020 const ui::PointerEvent left_press_event(ui::MouseEvent( | 1080 const ui::PointerEvent left_press_event(ui::MouseEvent( |
1021 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), | 1081 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), |
1022 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1082 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1023 dispatcher->ProcessEvent(left_press_event, 0, | 1083 dispatcher->ProcessEvent(left_press_event, 0, |
1024 EventDispatcher::AcceleratorMatchPhase::ANY); | 1084 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1085 RunTasks(); |
1025 | 1086 |
1026 // Events should target child. | 1087 // Events should target child. |
1027 std::unique_ptr<DispatchedEventDetails> details = | 1088 std::unique_ptr<DispatchedEventDetails> details = |
1028 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1089 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1029 | 1090 |
1030 ASSERT_TRUE(details); | 1091 ASSERT_TRUE(details); |
1031 ASSERT_EQ(child.get(), details->window); | 1092 ASSERT_EQ(child.get(), details->window); |
1032 EXPECT_TRUE(details->IsClientArea()); | 1093 EXPECT_TRUE(details->IsClientArea()); |
1033 EXPECT_TRUE(IsMouseButtonDown()); | 1094 EXPECT_TRUE(IsMouseButtonDown()); |
1034 | 1095 |
1035 // The mouse down state should update while capture is set. | 1096 // The mouse down state should update while capture is set. |
1036 const ui::PointerEvent right_press_event(ui::MouseEvent( | 1097 const ui::PointerEvent right_press_event(ui::MouseEvent( |
1037 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), | 1098 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), |
1038 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, | 1099 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, |
1039 ui::EF_RIGHT_MOUSE_BUTTON)); | 1100 ui::EF_RIGHT_MOUSE_BUTTON)); |
1040 dispatcher->ProcessEvent(right_press_event, 0, | 1101 dispatcher->ProcessEvent(right_press_event, 0, |
1041 EventDispatcher::AcceleratorMatchPhase::ANY); | 1102 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1103 RunTasks(); |
1042 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1104 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1043 EXPECT_TRUE(IsMouseButtonDown()); | 1105 EXPECT_TRUE(IsMouseButtonDown()); |
1044 | 1106 |
1045 // One button released should not clear mouse down | 1107 // One button released should not clear mouse down |
1046 const ui::PointerEvent left_release_event(ui::MouseEvent( | 1108 const ui::PointerEvent left_release_event(ui::MouseEvent( |
1047 ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), gfx::Point(5, 5), | 1109 ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), gfx::Point(5, 5), |
1048 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, | 1110 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, |
1049 ui::EF_LEFT_MOUSE_BUTTON)); | 1111 ui::EF_LEFT_MOUSE_BUTTON)); |
1050 dispatcher->ProcessEvent(left_release_event, 0, | 1112 dispatcher->ProcessEvent(left_release_event, 0, |
1051 EventDispatcher::AcceleratorMatchPhase::ANY); | 1113 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1114 RunTasks(); |
1052 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1115 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1053 EXPECT_TRUE(IsMouseButtonDown()); | 1116 EXPECT_TRUE(IsMouseButtonDown()); |
1054 | 1117 |
1055 // Touch Event while mouse is down should not affect state. | 1118 // Touch Event while mouse is down should not affect state. |
1056 const ui::PointerEvent touch_event(ui::TouchEvent( | 1119 const ui::PointerEvent touch_event(ui::TouchEvent( |
1057 ui::ET_TOUCH_PRESSED, gfx::Point(15, 15), base::TimeTicks(), | 1120 ui::ET_TOUCH_PRESSED, gfx::Point(15, 15), base::TimeTicks(), |
1058 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); | 1121 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 2))); |
1059 dispatcher->ProcessEvent(touch_event, 0, | 1122 dispatcher->ProcessEvent(touch_event, 0, |
1060 EventDispatcher::AcceleratorMatchPhase::ANY); | 1123 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1124 RunTasks(); |
1061 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1125 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1062 EXPECT_TRUE(IsMouseButtonDown()); | 1126 EXPECT_TRUE(IsMouseButtonDown()); |
1063 | 1127 |
1064 // Move event should not affect down | 1128 // Move event should not affect down |
1065 const ui::PointerEvent move_event( | 1129 const ui::PointerEvent move_event( |
1066 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(15, 5), gfx::Point(15, 5), | 1130 ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(15, 5), gfx::Point(15, 5), |
1067 base::TimeTicks(), ui::EF_RIGHT_MOUSE_BUTTON, | 1131 base::TimeTicks(), ui::EF_RIGHT_MOUSE_BUTTON, |
1068 ui::EF_RIGHT_MOUSE_BUTTON)); | 1132 ui::EF_RIGHT_MOUSE_BUTTON)); |
1069 dispatcher->ProcessEvent(move_event, 0, | 1133 dispatcher->ProcessEvent(move_event, 0, |
1070 EventDispatcher::AcceleratorMatchPhase::ANY); | 1134 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1135 RunTasks(); |
1071 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1136 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1072 EXPECT_TRUE(IsMouseButtonDown()); | 1137 EXPECT_TRUE(IsMouseButtonDown()); |
1073 | 1138 |
1074 // All mouse buttons up should clear mouse down. | 1139 // All mouse buttons up should clear mouse down. |
1075 const ui::PointerEvent right_release_event( | 1140 const ui::PointerEvent right_release_event( |
1076 ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), | 1141 ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(5, 5), |
1077 gfx::Point(5, 5), base::TimeTicks(), | 1142 gfx::Point(5, 5), base::TimeTicks(), |
1078 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 1143 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); |
1079 dispatcher->ProcessEvent(right_release_event, 0, | 1144 dispatcher->ProcessEvent(right_release_event, 0, |
1080 EventDispatcher::AcceleratorMatchPhase::ANY); | 1145 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1146 RunTasks(); |
1081 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1147 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1082 EXPECT_FALSE(IsMouseButtonDown()); | 1148 EXPECT_FALSE(IsMouseButtonDown()); |
1083 } | 1149 } |
1084 | 1150 |
1085 { | 1151 { |
1086 // Releasing capture and sending the same event will go to the root. | 1152 // Releasing capture and sending the same event will go to the root. |
1087 dispatcher->SetCaptureWindow(nullptr, kClientAreaId); | 1153 dispatcher->SetCaptureWindow(nullptr, kClientAreaId); |
1088 const ui::PointerEvent press_event(ui::MouseEvent( | 1154 const ui::PointerEvent press_event(ui::MouseEvent( |
1089 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), | 1155 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), |
1090 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1156 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1091 dispatcher->ProcessEvent(press_event, 0, | 1157 dispatcher->ProcessEvent(press_event, 0, |
1092 EventDispatcher::AcceleratorMatchPhase::ANY); | 1158 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1159 RunTasks(); |
1093 | 1160 |
1094 // Events should target the root. | 1161 // Events should target the root. |
1095 std::unique_ptr<DispatchedEventDetails> details = | 1162 std::unique_ptr<DispatchedEventDetails> details = |
1096 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1163 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1097 | 1164 |
1098 ASSERT_TRUE(details); | 1165 ASSERT_TRUE(details); |
1099 ASSERT_EQ(root, details->window); | 1166 ASSERT_EQ(root, details->window); |
1100 } | 1167 } |
1101 } | 1168 } |
1102 | 1169 |
1103 // This test verifies that explicit capture overrides and resets implicit | 1170 // This test verifies that explicit capture overrides and resets implicit |
1104 // capture. | 1171 // capture. |
1105 TEST_F(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) { | 1172 TEST_P(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) { |
1106 ServerWindow* root = root_window(); | 1173 ServerWindow* root = root_window(); |
1107 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1174 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
1108 | 1175 |
1109 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1176 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1110 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1177 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1111 | 1178 |
1112 TestEventDispatcherDelegate* event_dispatcher_delegate = | 1179 TestEventDispatcherDelegate* event_dispatcher_delegate = |
1113 test_event_dispatcher_delegate(); | 1180 test_event_dispatcher_delegate(); |
1114 EventDispatcher* dispatcher = event_dispatcher(); | 1181 EventDispatcher* dispatcher = event_dispatcher(); |
1115 | 1182 |
(...skipping 27 matching lines...) Expand all Loading... |
1143 RunMouseEventTests(dispatcher, event_dispatcher_delegate, tests, | 1210 RunMouseEventTests(dispatcher, event_dispatcher_delegate, tests, |
1144 arraysize(tests)); | 1211 arraysize(tests)); |
1145 | 1212 |
1146 // Add a second pointer target to the child. | 1213 // Add a second pointer target to the child. |
1147 { | 1214 { |
1148 const ui::PointerEvent touch_event(ui::TouchEvent( | 1215 const ui::PointerEvent touch_event(ui::TouchEvent( |
1149 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(), | 1216 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(), |
1150 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); | 1217 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); |
1151 dispatcher->ProcessEvent(touch_event, 0, | 1218 dispatcher->ProcessEvent(touch_event, 0, |
1152 EventDispatcher::AcceleratorMatchPhase::ANY); | 1219 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1220 RunTasks(); |
1153 } | 1221 } |
1154 | 1222 |
1155 std::unique_ptr<DispatchedEventDetails> details = | 1223 std::unique_ptr<DispatchedEventDetails> details = |
1156 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1224 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1157 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 1225 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
1158 EXPECT_EQ(child.get(), details->window); | 1226 EXPECT_EQ(child.get(), details->window); |
1159 | 1227 |
1160 // Verify that no window has explicit capture and hence we did indeed do | 1228 // Verify that no window has explicit capture and hence we did indeed do |
1161 // implicit capture. | 1229 // implicit capture. |
1162 ASSERT_EQ(nullptr, dispatcher->capture_window()); | 1230 ASSERT_EQ(nullptr, dispatcher->capture_window()); |
(...skipping 13 matching lines...) Expand all Loading... |
1176 ASSERT_TRUE(details); | 1244 ASSERT_TRUE(details); |
1177 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 1245 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
1178 EXPECT_EQ(child.get(), details->window); | 1246 EXPECT_EQ(child.get(), details->window); |
1179 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); | 1247 EXPECT_EQ(ui::ET_POINTER_EXITED, details->event->type()); |
1180 | 1248 |
1181 const ui::PointerEvent press_event(ui::MouseEvent( | 1249 const ui::PointerEvent press_event(ui::MouseEvent( |
1182 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), | 1250 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), |
1183 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1251 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1184 dispatcher->ProcessEvent(press_event, 0, | 1252 dispatcher->ProcessEvent(press_event, 0, |
1185 EventDispatcher::AcceleratorMatchPhase::ANY); | 1253 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1254 RunTasks(); |
1186 | 1255 |
1187 // Events should target the root. | 1256 // Events should target the root. |
1188 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1257 details = event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1189 ASSERT_TRUE(details); | 1258 ASSERT_TRUE(details); |
1190 ASSERT_EQ(root, details->window); | 1259 ASSERT_EQ(root, details->window); |
1191 ASSERT_TRUE(details->IsNonclientArea()); | 1260 ASSERT_TRUE(details->IsNonclientArea()); |
1192 } | 1261 } |
1193 | 1262 |
1194 // Tests that setting capture does delete active pointer targets for the capture | 1263 // Tests that setting capture does delete active pointer targets for the capture |
1195 // window. | 1264 // window. |
1196 TEST_F(EventDispatcherTest, CaptureUpdatesActivePointerTargets) { | 1265 TEST_P(EventDispatcherTest, CaptureUpdatesActivePointerTargets) { |
1197 ServerWindow* root = root_window(); | 1266 ServerWindow* root = root_window(); |
1198 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1267 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1199 | 1268 |
1200 EventDispatcher* dispatcher = event_dispatcher(); | 1269 EventDispatcher* dispatcher = event_dispatcher(); |
1201 { | 1270 { |
1202 const ui::PointerEvent press_event(ui::MouseEvent( | 1271 const ui::PointerEvent press_event(ui::MouseEvent( |
1203 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), | 1272 ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5), |
1204 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1273 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1205 dispatcher->ProcessEvent(press_event, 0, | 1274 dispatcher->ProcessEvent(press_event, 0, |
1206 EventDispatcher::AcceleratorMatchPhase::ANY); | 1275 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1276 RunTasks(); |
1207 | 1277 |
1208 std::unique_ptr<DispatchedEventDetails> details = | 1278 std::unique_ptr<DispatchedEventDetails> details = |
1209 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1279 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1210 ASSERT_TRUE(details); | 1280 ASSERT_TRUE(details); |
1211 ASSERT_EQ(root, details->window); | 1281 ASSERT_EQ(root, details->window); |
1212 } | 1282 } |
1213 { | 1283 { |
1214 const ui::PointerEvent touch_event(ui::TouchEvent( | 1284 const ui::PointerEvent touch_event(ui::TouchEvent( |
1215 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(), | 1285 ui::ET_TOUCH_PRESSED, gfx::Point(12, 13), base::TimeTicks(), |
1216 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); | 1286 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1))); |
1217 dispatcher->ProcessEvent(touch_event, 0, | 1287 dispatcher->ProcessEvent(touch_event, 0, |
1218 EventDispatcher::AcceleratorMatchPhase::ANY); | 1288 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1289 RunTasks(); |
1219 } | 1290 } |
1220 | 1291 |
1221 ASSERT_TRUE(AreAnyPointersDown()); | 1292 ASSERT_TRUE(AreAnyPointersDown()); |
1222 ASSERT_TRUE(IsWindowPointerTarget(root)); | 1293 ASSERT_TRUE(IsWindowPointerTarget(root)); |
1223 EXPECT_EQ(2, NumberPointerTargetsForWindow(root)); | 1294 EXPECT_EQ(2, NumberPointerTargetsForWindow(root)); |
1224 | 1295 |
1225 // Setting the capture should clear the implicit pointers for the specified | 1296 // Setting the capture should clear the implicit pointers for the specified |
1226 // window. | 1297 // window. |
1227 dispatcher->SetCaptureWindow(root, kNonclientAreaId); | 1298 dispatcher->SetCaptureWindow(root, kNonclientAreaId); |
1228 EXPECT_FALSE(AreAnyPointersDown()); | 1299 EXPECT_FALSE(AreAnyPointersDown()); |
1229 EXPECT_FALSE(IsWindowPointerTarget(root)); | 1300 EXPECT_FALSE(IsWindowPointerTarget(root)); |
1230 } | 1301 } |
1231 | 1302 |
1232 // Tests that when explicit capture is changed, that the previous window with | 1303 // Tests that when explicit capture is changed, that the previous window with |
1233 // capture is no longer being observed. | 1304 // capture is no longer being observed. |
1234 TEST_F(EventDispatcherTest, UpdatingCaptureStopsObservingPreviousCapture) { | 1305 TEST_P(EventDispatcherTest, UpdatingCaptureStopsObservingPreviousCapture) { |
1235 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); | 1306 std::unique_ptr<ServerWindow> child1 = CreateChildWindow(WindowId(1, 3)); |
1236 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); | 1307 std::unique_ptr<ServerWindow> child2 = CreateChildWindow(WindowId(1, 4)); |
1237 | 1308 |
1238 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1309 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1239 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1310 child1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1240 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); | 1311 child2->SetBounds(gfx::Rect(50, 51, 11, 12)); |
1241 | 1312 |
1242 EventDispatcher* dispatcher = event_dispatcher(); | 1313 EventDispatcher* dispatcher = event_dispatcher(); |
1243 ASSERT_FALSE(AreAnyPointersDown()); | 1314 ASSERT_FALSE(AreAnyPointersDown()); |
1244 ASSERT_FALSE(IsWindowPointerTarget(child1.get())); | 1315 ASSERT_FALSE(IsWindowPointerTarget(child1.get())); |
1245 ASSERT_FALSE(IsWindowPointerTarget(child2.get())); | 1316 ASSERT_FALSE(IsWindowPointerTarget(child2.get())); |
1246 dispatcher->SetCaptureWindow(child1.get(), kClientAreaId); | 1317 dispatcher->SetCaptureWindow(child1.get(), kClientAreaId); |
1247 dispatcher->SetCaptureWindow(child2.get(), kClientAreaId); | 1318 dispatcher->SetCaptureWindow(child2.get(), kClientAreaId); |
1248 EXPECT_EQ(child1.get(), | 1319 EXPECT_EQ(child1.get(), |
1249 test_event_dispatcher_delegate()->lost_capture_window()); | 1320 test_event_dispatcher_delegate()->lost_capture_window()); |
1250 | 1321 |
1251 // If observing does not stop during the capture update this crashes. | 1322 // If observing does not stop during the capture update this crashes. |
1252 child1->AddObserver(dispatcher); | 1323 child1->AddObserver(dispatcher); |
1253 } | 1324 } |
1254 | 1325 |
1255 // Tests that destroying a window with explicit capture clears the capture | 1326 // Tests that destroying a window with explicit capture clears the capture |
1256 // state. | 1327 // state. |
1257 TEST_F(EventDispatcherTest, DestroyingCaptureWindowRemovesExplicitCapture) { | 1328 TEST_P(EventDispatcherTest, DestroyingCaptureWindowRemovesExplicitCapture) { |
1258 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1329 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
1259 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1330 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1260 | 1331 |
1261 EventDispatcher* dispatcher = event_dispatcher(); | 1332 EventDispatcher* dispatcher = event_dispatcher(); |
1262 dispatcher->SetCaptureWindow(child.get(), kClientAreaId); | 1333 dispatcher->SetCaptureWindow(child.get(), kClientAreaId); |
1263 EXPECT_EQ(child.get(), dispatcher->capture_window()); | 1334 EXPECT_EQ(child.get(), dispatcher->capture_window()); |
1264 | 1335 |
1265 ServerWindow* lost_capture_window = child.get(); | 1336 ServerWindow* lost_capture_window = child.get(); |
1266 child.reset(); | 1337 child.reset(); |
1267 EXPECT_EQ(nullptr, dispatcher->capture_window()); | 1338 EXPECT_EQ(nullptr, dispatcher->capture_window()); |
1268 EXPECT_EQ(lost_capture_window, | 1339 EXPECT_EQ(lost_capture_window, |
1269 test_event_dispatcher_delegate()->lost_capture_window()); | 1340 test_event_dispatcher_delegate()->lost_capture_window()); |
1270 } | 1341 } |
1271 | 1342 |
1272 // Tests that when |client_id| is set for a window performing capture, that this | 1343 // Tests that when |client_id| is set for a window performing capture, that this |
1273 // preference is used regardless of whether an event targets the client region. | 1344 // preference is used regardless of whether an event targets the client region. |
1274 TEST_F(EventDispatcherTest, CaptureInNonClientAreaOverridesActualPoint) { | 1345 TEST_P(EventDispatcherTest, CaptureInNonClientAreaOverridesActualPoint) { |
1275 ServerWindow* root = root_window(); | 1346 ServerWindow* root = root_window(); |
1276 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1347 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1277 | 1348 |
1278 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); | 1349 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); |
1279 EventDispatcher* dispatcher = event_dispatcher(); | 1350 EventDispatcher* dispatcher = event_dispatcher(); |
1280 dispatcher->SetCaptureWindow(root, kNonclientAreaId); | 1351 dispatcher->SetCaptureWindow(root, kNonclientAreaId); |
1281 | 1352 |
1282 TestEventDispatcherDelegate* event_dispatcher_delegate = | 1353 TestEventDispatcherDelegate* event_dispatcher_delegate = |
1283 test_event_dispatcher_delegate(); | 1354 test_event_dispatcher_delegate(); |
1284 // Press in the client area, it should be marked as non client. | 1355 // Press in the client area, it should be marked as non client. |
1285 const ui::PointerEvent press_event(ui::MouseEvent( | 1356 const ui::PointerEvent press_event(ui::MouseEvent( |
1286 ui::ET_MOUSE_PRESSED, gfx::Point(6, 6), gfx::Point(6, 6), | 1357 ui::ET_MOUSE_PRESSED, gfx::Point(6, 6), gfx::Point(6, 6), |
1287 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1358 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1288 event_dispatcher()->ProcessEvent(press_event, 0, | 1359 event_dispatcher()->ProcessEvent(press_event, 0, |
1289 EventDispatcher::AcceleratorMatchPhase::ANY); | 1360 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1361 RunTasks(); |
1290 | 1362 |
1291 // Events should target child and be in the client area. | 1363 // Events should target child and be in the client area. |
1292 std::unique_ptr<DispatchedEventDetails> details = | 1364 std::unique_ptr<DispatchedEventDetails> details = |
1293 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); | 1365 event_dispatcher_delegate->GetAndAdvanceDispatchedEventDetails(); |
1294 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); | 1366 EXPECT_FALSE(event_dispatcher_delegate->has_queued_events()); |
1295 ASSERT_EQ(root, details->window); | 1367 ASSERT_EQ(root, details->window); |
1296 EXPECT_TRUE(details->IsNonclientArea()); | 1368 EXPECT_TRUE(details->IsNonclientArea()); |
1297 } | 1369 } |
1298 | 1370 |
1299 TEST_F(EventDispatcherTest, ProcessPointerEvents) { | 1371 TEST_P(EventDispatcherTest, ProcessPointerEvents) { |
1300 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1372 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
1301 | 1373 |
1302 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1374 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1303 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1375 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1304 | 1376 |
1305 { | 1377 { |
1306 const ui::PointerEvent pointer_event(ui::MouseEvent( | 1378 const ui::PointerEvent pointer_event(ui::MouseEvent( |
1307 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), | 1379 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), |
1308 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1380 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1309 event_dispatcher()->ProcessEvent( | 1381 event_dispatcher()->ProcessEvent( |
1310 pointer_event, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 1382 pointer_event, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1383 RunTasks(); |
1311 | 1384 |
1312 std::unique_ptr<DispatchedEventDetails> details = | 1385 std::unique_ptr<DispatchedEventDetails> details = |
1313 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1386 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1314 ASSERT_TRUE(details); | 1387 ASSERT_TRUE(details); |
1315 ASSERT_EQ(child.get(), details->window); | 1388 ASSERT_EQ(child.get(), details->window); |
1316 | 1389 |
1317 ASSERT_TRUE(details->event); | 1390 ASSERT_TRUE(details->event); |
1318 ASSERT_TRUE(details->event->IsPointerEvent()); | 1391 ASSERT_TRUE(details->event->IsPointerEvent()); |
1319 | 1392 |
1320 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1393 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1321 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); | 1394 EXPECT_EQ(gfx::Point(20, 25), dispatched_event->root_location()); |
1322 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); | 1395 EXPECT_EQ(gfx::Point(10, 15), dispatched_event->location()); |
1323 } | 1396 } |
1324 | 1397 |
1325 { | 1398 { |
1326 const int touch_id = 3; | 1399 const int touch_id = 3; |
1327 const ui::PointerEvent pointer_event(ui::TouchEvent( | 1400 const ui::PointerEvent pointer_event(ui::TouchEvent( |
1328 ui::ET_TOUCH_RELEASED, gfx::Point(25, 20), base::TimeTicks(), | 1401 ui::ET_TOUCH_RELEASED, gfx::Point(25, 20), base::TimeTicks(), |
1329 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, | 1402 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, |
1330 touch_id))); | 1403 touch_id))); |
1331 event_dispatcher()->ProcessEvent( | 1404 event_dispatcher()->ProcessEvent( |
1332 pointer_event, 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 1405 pointer_event, 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1406 RunTasks(); |
1333 | 1407 |
1334 std::unique_ptr<DispatchedEventDetails> details = | 1408 std::unique_ptr<DispatchedEventDetails> details = |
1335 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1409 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1336 ASSERT_TRUE(details); | 1410 ASSERT_TRUE(details); |
1337 ASSERT_EQ(child.get(), details->window); | 1411 ASSERT_EQ(child.get(), details->window); |
1338 | 1412 |
1339 ASSERT_TRUE(details->event); | 1413 ASSERT_TRUE(details->event); |
1340 ASSERT_TRUE(details->event->IsPointerEvent()); | 1414 ASSERT_TRUE(details->event->IsPointerEvent()); |
1341 | 1415 |
1342 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1416 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1343 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); | 1417 EXPECT_EQ(gfx::Point(25, 20), dispatched_event->root_location()); |
1344 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); | 1418 EXPECT_EQ(gfx::Point(15, 10), dispatched_event->location()); |
1345 EXPECT_EQ(touch_id, dispatched_event->pointer_details().id); | 1419 EXPECT_EQ(touch_id, dispatched_event->pointer_details().id); |
1346 } | 1420 } |
1347 } | 1421 } |
1348 | 1422 |
1349 TEST_F(EventDispatcherTest, ResetClearsPointerDown) { | 1423 TEST_P(EventDispatcherTest, ResetClearsPointerDown) { |
1350 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1424 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
1351 | 1425 |
1352 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1426 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1353 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1427 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1354 | 1428 |
1355 // Send event that is over child. | 1429 // Send event that is over child. |
1356 const ui::PointerEvent ui_event(ui::MouseEvent( | 1430 const ui::PointerEvent ui_event(ui::MouseEvent( |
1357 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), | 1431 ui::ET_MOUSE_PRESSED, gfx::Point(20, 25), gfx::Point(20, 25), |
1358 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1432 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1359 event_dispatcher()->ProcessEvent(ui_event, 0, | 1433 event_dispatcher()->ProcessEvent(ui_event, 0, |
1360 EventDispatcher::AcceleratorMatchPhase::ANY); | 1434 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1435 RunTasks(); |
1361 | 1436 |
1362 std::unique_ptr<DispatchedEventDetails> details = | 1437 std::unique_ptr<DispatchedEventDetails> details = |
1363 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1438 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1364 ASSERT_TRUE(details); | 1439 ASSERT_TRUE(details); |
1365 ASSERT_EQ(child.get(), details->window); | 1440 ASSERT_EQ(child.get(), details->window); |
1366 | 1441 |
1367 EXPECT_TRUE(AreAnyPointersDown()); | 1442 EXPECT_TRUE(AreAnyPointersDown()); |
1368 | 1443 |
1369 event_dispatcher()->Reset(); | 1444 event_dispatcher()->Reset(); |
1370 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); | 1445 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); |
1371 EXPECT_FALSE(AreAnyPointersDown()); | 1446 EXPECT_FALSE(AreAnyPointersDown()); |
1372 } | 1447 } |
1373 | 1448 |
1374 TEST_F(EventDispatcherTest, ResetClearsCapture) { | 1449 TEST_P(EventDispatcherTest, ResetClearsCapture) { |
1375 ServerWindow* root = root_window(); | 1450 ServerWindow* root = root_window(); |
1376 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1451 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1377 | 1452 |
1378 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); | 1453 root->SetClientArea(gfx::Insets(5, 5, 5, 5), std::vector<gfx::Rect>()); |
1379 EventDispatcher* dispatcher = event_dispatcher(); | 1454 EventDispatcher* dispatcher = event_dispatcher(); |
1380 dispatcher->SetCaptureWindow(root, kNonclientAreaId); | 1455 dispatcher->SetCaptureWindow(root, kNonclientAreaId); |
1381 | 1456 |
1382 event_dispatcher()->Reset(); | 1457 event_dispatcher()->Reset(); |
1383 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); | 1458 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); |
1384 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); | 1459 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); |
1385 } | 1460 } |
1386 | 1461 |
1387 // Tests that events on a modal parent target the modal child. | 1462 // Tests that events on a modal parent target the modal child. |
1388 TEST_F(EventDispatcherTest, ModalWindowEventOnModalParent) { | 1463 TEST_P(EventDispatcherTest, ModalWindowEventOnModalParent) { |
1389 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1464 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1390 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); | 1465 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
1391 | 1466 |
1392 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1467 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1393 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1468 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1394 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 1469 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
1395 | 1470 |
1396 w1->AddTransientWindow(w2.get()); | 1471 w1->AddTransientWindow(w2.get()); |
1397 w2->SetModalType(MODAL_TYPE_WINDOW); | 1472 w2->SetModalType(MODAL_TYPE_WINDOW); |
1398 | 1473 |
1399 // Send event that is over |w1|. | 1474 // Send event that is over |w1|. |
1400 const ui::PointerEvent mouse_pressed(ui::MouseEvent( | 1475 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
1401 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), | 1476 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), |
1402 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1477 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1403 event_dispatcher()->ProcessEvent(mouse_pressed, 0, | 1478 event_dispatcher()->ProcessEvent(mouse_pressed, 0, |
1404 EventDispatcher::AcceleratorMatchPhase::ANY); | 1479 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1480 RunTasks(); |
1405 | 1481 |
1406 std::unique_ptr<DispatchedEventDetails> details = | 1482 std::unique_ptr<DispatchedEventDetails> details = |
1407 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1483 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1408 ASSERT_TRUE(details); | 1484 ASSERT_TRUE(details); |
1409 EXPECT_EQ(w2.get(), details->window); | 1485 EXPECT_EQ(w2.get(), details->window); |
1410 EXPECT_TRUE(details->IsNonclientArea()); | 1486 EXPECT_TRUE(details->IsNonclientArea()); |
1411 | 1487 |
1412 ASSERT_TRUE(details->event); | 1488 ASSERT_TRUE(details->event); |
1413 ASSERT_TRUE(details->event->IsPointerEvent()); | 1489 ASSERT_TRUE(details->event->IsPointerEvent()); |
1414 | 1490 |
1415 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1491 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1416 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location()); | 1492 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location()); |
1417 EXPECT_EQ(gfx::Point(-35, 5), dispatched_event->location()); | 1493 EXPECT_EQ(gfx::Point(-35, 5), dispatched_event->location()); |
1418 } | 1494 } |
1419 | 1495 |
1420 // Tests that events on a modal child target the modal child itself. | 1496 // Tests that events on a modal child target the modal child itself. |
1421 TEST_F(EventDispatcherTest, ModalWindowEventOnModalChild) { | 1497 TEST_P(EventDispatcherTest, ModalWindowEventOnModalChild) { |
1422 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1498 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1423 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); | 1499 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
1424 | 1500 |
1425 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1501 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1426 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1502 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1427 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 1503 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
1428 | 1504 |
1429 w1->AddTransientWindow(w2.get()); | 1505 w1->AddTransientWindow(w2.get()); |
1430 w2->SetModalType(MODAL_TYPE_WINDOW); | 1506 w2->SetModalType(MODAL_TYPE_WINDOW); |
1431 | 1507 |
1432 // Send event that is over |w2|. | 1508 // Send event that is over |w2|. |
1433 const ui::PointerEvent mouse_pressed(ui::MouseEvent( | 1509 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
1434 ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15), | 1510 ui::ET_MOUSE_PRESSED, gfx::Point(55, 15), gfx::Point(55, 15), |
1435 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1511 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1436 event_dispatcher()->ProcessEvent(mouse_pressed, 0, | 1512 event_dispatcher()->ProcessEvent(mouse_pressed, 0, |
1437 EventDispatcher::AcceleratorMatchPhase::ANY); | 1513 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1514 RunTasks(); |
1438 | 1515 |
1439 std::unique_ptr<DispatchedEventDetails> details = | 1516 std::unique_ptr<DispatchedEventDetails> details = |
1440 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1517 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1441 ASSERT_TRUE(details); | 1518 ASSERT_TRUE(details); |
1442 EXPECT_EQ(w2.get(), details->window); | 1519 EXPECT_EQ(w2.get(), details->window); |
1443 EXPECT_TRUE(details->IsClientArea()); | 1520 EXPECT_TRUE(details->IsClientArea()); |
1444 | 1521 |
1445 ASSERT_TRUE(details->event); | 1522 ASSERT_TRUE(details->event); |
1446 ASSERT_TRUE(details->event->IsPointerEvent()); | 1523 ASSERT_TRUE(details->event->IsPointerEvent()); |
1447 | 1524 |
1448 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1525 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1449 EXPECT_EQ(gfx::Point(55, 15), dispatched_event->root_location()); | 1526 EXPECT_EQ(gfx::Point(55, 15), dispatched_event->root_location()); |
1450 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); | 1527 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); |
1451 } | 1528 } |
1452 | 1529 |
1453 // Tests that events on an unrelated window are not affected by the modal | 1530 // Tests that events on an unrelated window are not affected by the modal |
1454 // window. | 1531 // window. |
1455 TEST_F(EventDispatcherTest, ModalWindowEventOnUnrelatedWindow) { | 1532 TEST_P(EventDispatcherTest, ModalWindowEventOnUnrelatedWindow) { |
1456 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1533 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1457 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); | 1534 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
1458 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); | 1535 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 6)); |
1459 | 1536 |
1460 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1537 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1461 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1538 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1462 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 1539 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
1463 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); | 1540 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
1464 | 1541 |
1465 w1->AddTransientWindow(w2.get()); | 1542 w1->AddTransientWindow(w2.get()); |
1466 w2->SetModalType(MODAL_TYPE_WINDOW); | 1543 w2->SetModalType(MODAL_TYPE_WINDOW); |
1467 | 1544 |
1468 // Send event that is over |w3|. | 1545 // Send event that is over |w3|. |
1469 const ui::PointerEvent mouse_pressed(ui::MouseEvent( | 1546 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
1470 ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15), | 1547 ui::ET_MOUSE_PRESSED, gfx::Point(75, 15), gfx::Point(75, 15), |
1471 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1548 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1472 event_dispatcher()->ProcessEvent(mouse_pressed, 0, | 1549 event_dispatcher()->ProcessEvent(mouse_pressed, 0, |
1473 EventDispatcher::AcceleratorMatchPhase::ANY); | 1550 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1551 RunTasks(); |
1474 | 1552 |
1475 std::unique_ptr<DispatchedEventDetails> details = | 1553 std::unique_ptr<DispatchedEventDetails> details = |
1476 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1554 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1477 ASSERT_TRUE(details); | 1555 ASSERT_TRUE(details); |
1478 EXPECT_EQ(w3.get(), details->window); | 1556 EXPECT_EQ(w3.get(), details->window); |
1479 EXPECT_TRUE(details->IsClientArea()); | 1557 EXPECT_TRUE(details->IsClientArea()); |
1480 | 1558 |
1481 ASSERT_TRUE(details->event); | 1559 ASSERT_TRUE(details->event); |
1482 ASSERT_TRUE(details->event->IsPointerEvent()); | 1560 ASSERT_TRUE(details->event->IsPointerEvent()); |
1483 | 1561 |
1484 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1562 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1485 EXPECT_EQ(gfx::Point(75, 15), dispatched_event->root_location()); | 1563 EXPECT_EQ(gfx::Point(75, 15), dispatched_event->root_location()); |
1486 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); | 1564 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); |
1487 } | 1565 } |
1488 | 1566 |
1489 // Tests that events events on a descendant of a modal parent target the modal | 1567 // Tests that events events on a descendant of a modal parent target the modal |
1490 // child. | 1568 // child. |
1491 TEST_F(EventDispatcherTest, ModalWindowEventOnDescendantOfModalParent) { | 1569 TEST_P(EventDispatcherTest, ModalWindowEventOnDescendantOfModalParent) { |
1492 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1570 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1493 std::unique_ptr<ServerWindow> w11 = | 1571 std::unique_ptr<ServerWindow> w11 = |
1494 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); | 1572 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); |
1495 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); | 1573 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
1496 | 1574 |
1497 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1575 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1498 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1576 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1499 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); | 1577 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
1500 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 1578 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
1501 | 1579 |
1502 w1->AddTransientWindow(w2.get()); | 1580 w1->AddTransientWindow(w2.get()); |
1503 w2->SetModalType(MODAL_TYPE_WINDOW); | 1581 w2->SetModalType(MODAL_TYPE_WINDOW); |
1504 | 1582 |
1505 // Send event that is over |w11|. | 1583 // Send event that is over |w11|. |
1506 const ui::PointerEvent mouse_pressed(ui::MouseEvent( | 1584 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
1507 ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25), | 1585 ui::ET_MOUSE_PRESSED, gfx::Point(25, 25), gfx::Point(25, 25), |
1508 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1586 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1509 event_dispatcher()->ProcessEvent(mouse_pressed, 0, | 1587 event_dispatcher()->ProcessEvent(mouse_pressed, 0, |
1510 EventDispatcher::AcceleratorMatchPhase::ANY); | 1588 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1589 RunTasks(); |
1511 | 1590 |
1512 std::unique_ptr<DispatchedEventDetails> details = | 1591 std::unique_ptr<DispatchedEventDetails> details = |
1513 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1592 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1514 ASSERT_TRUE(details); | 1593 ASSERT_TRUE(details); |
1515 EXPECT_EQ(w2.get(), details->window); | 1594 EXPECT_EQ(w2.get(), details->window); |
1516 EXPECT_TRUE(details->IsNonclientArea()); | 1595 EXPECT_TRUE(details->IsNonclientArea()); |
1517 | 1596 |
1518 ASSERT_TRUE(details->event); | 1597 ASSERT_TRUE(details->event); |
1519 ASSERT_TRUE(details->event->IsPointerEvent()); | 1598 ASSERT_TRUE(details->event->IsPointerEvent()); |
1520 | 1599 |
1521 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1600 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1522 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); | 1601 EXPECT_EQ(gfx::Point(25, 25), dispatched_event->root_location()); |
1523 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); | 1602 EXPECT_EQ(gfx::Point(-25, 15), dispatched_event->location()); |
1524 } | 1603 } |
1525 | 1604 |
1526 // Tests that events on a system modal window target the modal window itself. | 1605 // Tests that events on a system modal window target the modal window itself. |
1527 TEST_F(EventDispatcherTest, ModalWindowEventOnSystemModal) { | 1606 TEST_P(EventDispatcherTest, ModalWindowEventOnSystemModal) { |
1528 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1607 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1529 | 1608 |
1530 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1609 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1531 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1610 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1532 w1->SetModalType(MODAL_TYPE_SYSTEM); | 1611 w1->SetModalType(MODAL_TYPE_SYSTEM); |
1533 | 1612 |
1534 // Send event that is over |w1|. | 1613 // Send event that is over |w1|. |
1535 const ui::PointerEvent mouse_pressed(ui::MouseEvent( | 1614 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
1536 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), | 1615 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), |
1537 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1616 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1538 event_dispatcher()->ProcessEvent(mouse_pressed, 0, | 1617 event_dispatcher()->ProcessEvent(mouse_pressed, 0, |
1539 EventDispatcher::AcceleratorMatchPhase::ANY); | 1618 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1619 RunTasks(); |
1540 | 1620 |
1541 std::unique_ptr<DispatchedEventDetails> details = | 1621 std::unique_ptr<DispatchedEventDetails> details = |
1542 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1622 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1543 ASSERT_TRUE(details); | 1623 ASSERT_TRUE(details); |
1544 EXPECT_EQ(w1.get(), details->window); | 1624 EXPECT_EQ(w1.get(), details->window); |
1545 EXPECT_TRUE(details->IsClientArea()); | 1625 EXPECT_TRUE(details->IsClientArea()); |
1546 | 1626 |
1547 ASSERT_TRUE(details->event); | 1627 ASSERT_TRUE(details->event); |
1548 ASSERT_TRUE(details->event->IsPointerEvent()); | 1628 ASSERT_TRUE(details->event->IsPointerEvent()); |
1549 | 1629 |
1550 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1630 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1551 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location()); | 1631 EXPECT_EQ(gfx::Point(15, 15), dispatched_event->root_location()); |
1552 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); | 1632 EXPECT_EQ(gfx::Point(5, 5), dispatched_event->location()); |
1553 } | 1633 } |
1554 | 1634 |
1555 // Tests that events outside of system modal window target the modal window. | 1635 // Tests that events outside of system modal window target the modal window. |
1556 TEST_F(EventDispatcherTest, ModalWindowEventOutsideSystemModal) { | 1636 TEST_P(EventDispatcherTest, ModalWindowEventOutsideSystemModal) { |
1557 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1637 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1558 | 1638 |
1559 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1639 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1560 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1640 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1561 w1->SetModalType(MODAL_TYPE_SYSTEM); | 1641 w1->SetModalType(MODAL_TYPE_SYSTEM); |
1562 event_dispatcher()->AddSystemModalWindow(w1.get()); | 1642 event_dispatcher()->AddSystemModalWindow(w1.get()); |
1563 | 1643 |
1564 // Send event that is over |w1|. | 1644 // Send event that is over |w1|. |
1565 const ui::PointerEvent mouse_pressed(ui::MouseEvent( | 1645 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
1566 ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15), | 1646 ui::ET_MOUSE_PRESSED, gfx::Point(45, 15), gfx::Point(45, 15), |
1567 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1647 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1568 event_dispatcher()->ProcessEvent(mouse_pressed, 0, | 1648 event_dispatcher()->ProcessEvent(mouse_pressed, 0, |
1569 EventDispatcher::AcceleratorMatchPhase::ANY); | 1649 EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1650 RunTasks(); |
1570 | 1651 |
1571 std::unique_ptr<DispatchedEventDetails> details = | 1652 std::unique_ptr<DispatchedEventDetails> details = |
1572 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1653 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1573 ASSERT_TRUE(details); | 1654 ASSERT_TRUE(details); |
1574 EXPECT_EQ(w1.get(), details->window); | 1655 EXPECT_EQ(w1.get(), details->window); |
1575 EXPECT_TRUE(details->IsNonclientArea()); | 1656 EXPECT_TRUE(details->IsNonclientArea()); |
1576 | 1657 |
1577 ASSERT_TRUE(details->event); | 1658 ASSERT_TRUE(details->event); |
1578 ASSERT_TRUE(details->event->IsPointerEvent()); | 1659 ASSERT_TRUE(details->event->IsPointerEvent()); |
1579 | 1660 |
1580 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); | 1661 ui::PointerEvent* dispatched_event = details->event->AsPointerEvent(); |
1581 EXPECT_EQ(gfx::Point(45, 15), dispatched_event->root_location()); | 1662 EXPECT_EQ(gfx::Point(45, 15), dispatched_event->root_location()); |
1582 EXPECT_EQ(gfx::Point(35, 5), dispatched_event->location()); | 1663 EXPECT_EQ(gfx::Point(35, 5), dispatched_event->location()); |
1583 } | 1664 } |
1584 | 1665 |
1585 // Tests events on a sub-window of system modal window target the window itself. | 1666 // Tests events on a sub-window of system modal window target the window itself. |
1586 TEST_F(EventDispatcherTest, ModalWindowEventSubWindowSystemModal) { | 1667 TEST_P(EventDispatcherTest, ModalWindowEventSubWindowSystemModal) { |
1587 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1668 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1588 w1->SetModalType(MODAL_TYPE_SYSTEM); | 1669 w1->SetModalType(MODAL_TYPE_SYSTEM); |
1589 event_dispatcher()->AddSystemModalWindow(w1.get()); | 1670 event_dispatcher()->AddSystemModalWindow(w1.get()); |
1590 | 1671 |
1591 std::unique_ptr<ServerWindow> w2 = | 1672 std::unique_ptr<ServerWindow> w2 = |
1592 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); | 1673 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); |
1593 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5)); | 1674 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5)); |
1594 | 1675 |
1595 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1676 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1596 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1677 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
(...skipping 12 matching lines...) Expand all Loading... |
1609 {gfx::Point(11, 31), w1.get()}, | 1690 {gfx::Point(11, 31), w1.get()}, |
1610 }; | 1691 }; |
1611 | 1692 |
1612 for (size_t i = 0; i < arraysize(kTouchData); i++) { | 1693 for (size_t i = 0; i < arraysize(kTouchData); i++) { |
1613 // Send touch press and check that the expected target receives it. | 1694 // Send touch press and check that the expected target receives it. |
1614 event_dispatcher()->ProcessEvent( | 1695 event_dispatcher()->ProcessEvent( |
1615 ui::PointerEvent(ui::TouchEvent( | 1696 ui::PointerEvent(ui::TouchEvent( |
1616 ui::ET_TOUCH_PRESSED, kTouchData[i].location, base::TimeTicks(), | 1697 ui::ET_TOUCH_PRESSED, kTouchData[i].location, base::TimeTicks(), |
1617 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0))), | 1698 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0))), |
1618 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 1699 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1700 RunTasks(); |
1619 std::unique_ptr<DispatchedEventDetails> details = | 1701 std::unique_ptr<DispatchedEventDetails> details = |
1620 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1702 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1621 ASSERT_TRUE(details) << " details is nullptr " << i; | 1703 ASSERT_TRUE(details) << " details is nullptr " << i; |
1622 EXPECT_EQ(kTouchData[i].expected_target, details->window); | 1704 EXPECT_EQ(kTouchData[i].expected_target, details->window); |
1623 | 1705 |
1624 // Release touch. | 1706 // Release touch. |
1625 event_dispatcher()->ProcessEvent( | 1707 event_dispatcher()->ProcessEvent( |
1626 ui::PointerEvent(ui::TouchEvent( | 1708 ui::PointerEvent(ui::TouchEvent( |
1627 ui::ET_TOUCH_RELEASED, kTouchData[i].location, base::TimeTicks(), | 1709 ui::ET_TOUCH_RELEASED, kTouchData[i].location, base::TimeTicks(), |
1628 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0))), | 1710 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0))), |
1629 0, EventDispatcher::AcceleratorMatchPhase::ANY); | 1711 0, EventDispatcher::AcceleratorMatchPhase::ANY); |
| 1712 RunTasks(); |
1630 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1713 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1631 } | 1714 } |
1632 } | 1715 } |
1633 | 1716 |
1634 // Tests that setting capture to a descendant of a modal parent fails. | 1717 // Tests that setting capture to a descendant of a modal parent fails. |
1635 TEST_F(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { | 1718 TEST_P(EventDispatcherTest, ModalWindowSetCaptureDescendantOfModalParent) { |
1636 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1719 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1637 std::unique_ptr<ServerWindow> w11 = | 1720 std::unique_ptr<ServerWindow> w11 = |
1638 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); | 1721 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); |
1639 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); | 1722 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
1640 | 1723 |
1641 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1724 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1642 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1725 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1643 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); | 1726 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
1644 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 1727 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
1645 | 1728 |
1646 w1->AddTransientWindow(w2.get()); | 1729 w1->AddTransientWindow(w2.get()); |
1647 w2->SetModalType(MODAL_TYPE_WINDOW); | 1730 w2->SetModalType(MODAL_TYPE_WINDOW); |
1648 | 1731 |
1649 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), kClientAreaId)); | 1732 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w11.get(), kClientAreaId)); |
1650 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); | 1733 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); |
1651 } | 1734 } |
1652 | 1735 |
1653 // Tests that setting capture to a window unrelated to a modal parent works. | 1736 // Tests that setting capture to a window unrelated to a modal parent works. |
1654 TEST_F(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) { | 1737 TEST_P(EventDispatcherTest, ModalWindowSetCaptureUnrelatedWindow) { |
1655 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1738 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1656 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); | 1739 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); |
1657 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5)); | 1740 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5)); |
1658 | 1741 |
1659 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1742 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1660 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1743 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1661 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 1744 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
1662 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); | 1745 w3->SetBounds(gfx::Rect(70, 10, 10, 10)); |
1663 | 1746 |
1664 w1->AddTransientWindow(w2.get()); | 1747 w1->AddTransientWindow(w2.get()); |
1665 w2->SetModalType(MODAL_TYPE_WINDOW); | 1748 w2->SetModalType(MODAL_TYPE_WINDOW); |
1666 | 1749 |
1667 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), kClientAreaId)); | 1750 EXPECT_TRUE(event_dispatcher()->SetCaptureWindow(w3.get(), kClientAreaId)); |
1668 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); | 1751 EXPECT_EQ(w3.get(), event_dispatcher()->capture_window()); |
1669 } | 1752 } |
1670 | 1753 |
1671 // Tests that setting capture fails when there is a system modal window. | 1754 // Tests that setting capture fails when there is a system modal window. |
1672 TEST_F(EventDispatcherTest, ModalWindowSystemSetCapture) { | 1755 TEST_P(EventDispatcherTest, ModalWindowSystemSetCapture) { |
1673 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1756 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1674 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); | 1757 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); |
1675 | 1758 |
1676 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1759 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1677 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); | 1760 w1->SetBounds(gfx::Rect(10, 10, 30, 30)); |
1678 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); | 1761 w2->SetBounds(gfx::Rect(50, 10, 10, 10)); |
1679 | 1762 |
1680 event_dispatcher()->AddSystemModalWindow(w2.get()); | 1763 event_dispatcher()->AddSystemModalWindow(w2.get()); |
1681 | 1764 |
1682 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w1.get(), kClientAreaId)); | 1765 EXPECT_FALSE(event_dispatcher()->SetCaptureWindow(w1.get(), kClientAreaId)); |
1683 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); | 1766 EXPECT_EQ(nullptr, event_dispatcher()->capture_window()); |
1684 } | 1767 } |
1685 | 1768 |
1686 // Tests having multiple system modal windows. | 1769 // Tests having multiple system modal windows. |
1687 TEST_F(EventDispatcherTest, ModalWindowMultipleSystemModals) { | 1770 TEST_P(EventDispatcherTest, ModalWindowMultipleSystemModals) { |
1688 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1771 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1689 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); | 1772 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 4)); |
1690 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5)); | 1773 std::unique_ptr<ServerWindow> w3 = CreateChildWindow(WindowId(1, 5)); |
1691 | 1774 |
1692 w2->SetVisible(false); | 1775 w2->SetVisible(false); |
1693 | 1776 |
1694 // In the beginning, there should be no active system modal window. | 1777 // In the beginning, there should be no active system modal window. |
1695 EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); | 1778 EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); |
1696 | 1779 |
1697 // Add a visible system modal window. It should become the active one. | 1780 // Add a visible system modal window. It should become the active one. |
(...skipping 21 matching lines...) Expand all Loading... |
1719 // one. | 1802 // one. |
1720 w1.reset(); | 1803 w1.reset(); |
1721 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow()); | 1804 EXPECT_EQ(w3.get(), GetActiveSystemModalWindow()); |
1722 | 1805 |
1723 // Remove the last remaining system modal window. There should be no active | 1806 // Remove the last remaining system modal window. There should be no active |
1724 // one anymore. | 1807 // one anymore. |
1725 w3.reset(); | 1808 w3.reset(); |
1726 EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); | 1809 EXPECT_EQ(nullptr, GetActiveSystemModalWindow()); |
1727 } | 1810 } |
1728 | 1811 |
1729 TEST_F(EventDispatcherTest, CaptureNotResetOnParentChange) { | 1812 TEST_P(EventDispatcherTest, CaptureNotResetOnParentChange) { |
1730 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); | 1813 std::unique_ptr<ServerWindow> w1 = CreateChildWindow(WindowId(1, 3)); |
1731 w1->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | 1814 w1->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
1732 std::unique_ptr<ServerWindow> w11 = | 1815 std::unique_ptr<ServerWindow> w11 = |
1733 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); | 1816 CreateChildWindowWithParent(WindowId(1, 4), w1.get()); |
1734 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); | 1817 std::unique_ptr<ServerWindow> w2 = CreateChildWindow(WindowId(1, 5)); |
1735 w2->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | 1818 w2->set_event_targeting_policy(mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
1736 | 1819 |
1737 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1820 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1738 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1821 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1739 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); | 1822 w11->SetBounds(gfx::Rect(10, 10, 10, 10)); |
1740 w2->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1823 w2->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1741 | 1824 |
1742 // Send event that is over |w11|. | 1825 // Send event that is over |w11|. |
1743 const ui::PointerEvent mouse_pressed(ui::MouseEvent( | 1826 const ui::PointerEvent mouse_pressed(ui::MouseEvent( |
1744 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), | 1827 ui::ET_MOUSE_PRESSED, gfx::Point(15, 15), gfx::Point(15, 15), |
1745 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 1828 base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
1746 event_dispatcher()->ProcessEvent(mouse_pressed, 0, | 1829 event_dispatcher()->ProcessEvent(mouse_pressed, 0, |
1747 EventDispatcher::AcceleratorMatchPhase::ANY); | 1830 EventDispatcher::AcceleratorMatchPhase::ANY); |
1748 event_dispatcher()->SetCaptureWindow(w11.get(), kClientAreaId); | 1831 event_dispatcher()->SetCaptureWindow(w11.get(), kClientAreaId); |
| 1832 RunTasks(); |
1749 | 1833 |
1750 std::unique_ptr<DispatchedEventDetails> details = | 1834 std::unique_ptr<DispatchedEventDetails> details = |
1751 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); | 1835 test_event_dispatcher_delegate()->GetAndAdvanceDispatchedEventDetails(); |
1752 ASSERT_TRUE(details); | 1836 ASSERT_TRUE(details); |
1753 EXPECT_EQ(w11.get(), details->window); | 1837 EXPECT_EQ(w11.get(), details->window); |
1754 EXPECT_TRUE(details->IsClientArea()); | 1838 EXPECT_TRUE(details->IsClientArea()); |
1755 | 1839 |
1756 // Move |w11| to |w2| and verify the mouse is still down, and |w11| has | 1840 // Move |w11| to |w2| and verify the mouse is still down, and |w11| has |
1757 // capture. | 1841 // capture. |
1758 w2->Add(w11.get()); | 1842 w2->Add(w11.get()); |
1759 EXPECT_TRUE(IsMouseButtonDown()); | 1843 EXPECT_TRUE(IsMouseButtonDown()); |
1760 EXPECT_EQ(w11.get(), | 1844 EXPECT_EQ(w11.get(), |
1761 EventDispatcherTestApi(event_dispatcher()).capture_window()); | 1845 EventDispatcherTestApi(event_dispatcher()).capture_window()); |
1762 } | 1846 } |
1763 | 1847 |
1764 TEST_F(EventDispatcherTest, ChangeCaptureFromClientToNonclient) { | 1848 TEST_P(EventDispatcherTest, ChangeCaptureFromClientToNonclient) { |
1765 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1849 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
1766 event_dispatcher()->SetCaptureWindow(child.get(), kNonclientAreaId); | 1850 event_dispatcher()->SetCaptureWindow(child.get(), kNonclientAreaId); |
1767 EXPECT_EQ(kNonclientAreaId, | 1851 EXPECT_EQ(kNonclientAreaId, |
1768 event_dispatcher()->capture_window_client_id()); | 1852 event_dispatcher()->capture_window_client_id()); |
1769 EXPECT_EQ(nullptr, test_event_dispatcher_delegate()->lost_capture_window()); | 1853 EXPECT_EQ(nullptr, test_event_dispatcher_delegate()->lost_capture_window()); |
1770 event_dispatcher()->SetCaptureWindow(child.get(), kClientAreaId); | 1854 event_dispatcher()->SetCaptureWindow(child.get(), kClientAreaId); |
1771 // Changing capture from client to non-client should notify the delegate. | 1855 // Changing capture from client to non-client should notify the delegate. |
1772 // The delegate can decide if it really wants to forward the event or not. | 1856 // The delegate can decide if it really wants to forward the event or not. |
1773 EXPECT_EQ(child.get(), | 1857 EXPECT_EQ(child.get(), |
1774 test_event_dispatcher_delegate()->lost_capture_window()); | 1858 test_event_dispatcher_delegate()->lost_capture_window()); |
1775 EXPECT_EQ(child.get(), event_dispatcher()->capture_window()); | 1859 EXPECT_EQ(child.get(), event_dispatcher()->capture_window()); |
1776 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id()); | 1860 EXPECT_EQ(kClientAreaId, event_dispatcher()->capture_window_client_id()); |
1777 } | 1861 } |
1778 | 1862 |
1779 TEST_F(EventDispatcherTest, MoveMouseFromNoTargetToValidTarget) { | 1863 TEST_P(EventDispatcherTest, MoveMouseFromNoTargetToValidTarget) { |
1780 ServerWindow* root = root_window(); | 1864 ServerWindow* root = root_window(); |
1781 root->set_event_targeting_policy( | 1865 root->set_event_targeting_policy( |
1782 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | 1866 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
1783 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1867 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
1784 | 1868 |
1785 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1869 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1786 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1870 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1787 | 1871 |
1788 MouseEventTest tests[] = { | 1872 MouseEventTest tests[] = { |
1789 // Send a mouse down over the root, but not the child. No event should | 1873 // Send a mouse down over the root, but not the child. No event should |
1790 // be generated. | 1874 // be generated. |
1791 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5), | 1875 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5), |
1792 base::TimeTicks(), 0, 0), | 1876 base::TimeTicks(), 0, 0), |
1793 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), | 1877 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), |
1794 gfx::Point()}, | 1878 gfx::Point()}, |
1795 | 1879 |
1796 // Move into child. | 1880 // Move into child. |
1797 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12), | 1881 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12), |
1798 gfx::Point(12, 12), base::TimeTicks(), 0, 0), | 1882 gfx::Point(12, 12), base::TimeTicks(), 0, 0), |
1799 child.get(), gfx::Point(12, 12), gfx::Point(2, 2), nullptr, gfx::Point(), | 1883 child.get(), gfx::Point(12, 12), gfx::Point(2, 2), nullptr, gfx::Point(), |
1800 gfx::Point()}}; | 1884 gfx::Point()}}; |
1801 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 1885 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
1802 tests, arraysize(tests)); | 1886 tests, arraysize(tests)); |
1803 } | 1887 } |
1804 | 1888 |
1805 TEST_F(EventDispatcherTest, NoTargetToTargetWithMouseDown) { | 1889 TEST_P(EventDispatcherTest, NoTargetToTargetWithMouseDown) { |
1806 ServerWindow* root = root_window(); | 1890 ServerWindow* root = root_window(); |
1807 root->set_event_targeting_policy( | 1891 root->set_event_targeting_policy( |
1808 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | 1892 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
1809 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); | 1893 std::unique_ptr<ServerWindow> child = CreateChildWindow(WindowId(1, 3)); |
1810 | 1894 |
1811 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1895 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1812 child->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1896 child->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1813 | 1897 |
1814 MouseEventTest tests[] = { | 1898 MouseEventTest tests[] = { |
1815 // Mouse over the root, but not the child. No event should be generated. | 1899 // Mouse over the root, but not the child. No event should be generated. |
(...skipping 12 matching lines...) Expand all Loading... |
1828 // Move into child, still no target. | 1912 // Move into child, still no target. |
1829 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12), | 1913 {ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12), |
1830 gfx::Point(12, 12), base::TimeTicks(), | 1914 gfx::Point(12, 12), base::TimeTicks(), |
1831 ui::EF_LEFT_MOUSE_BUTTON, 0), | 1915 ui::EF_LEFT_MOUSE_BUTTON, 0), |
1832 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), | 1916 nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(), |
1833 gfx::Point()}}; | 1917 gfx::Point()}}; |
1834 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 1918 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
1835 tests, arraysize(tests)); | 1919 tests, arraysize(tests)); |
1836 } | 1920 } |
1837 | 1921 |
1838 TEST_F(EventDispatcherTest, DontSendExitToSameClientWhenCaptureChanges) { | 1922 TEST_P(EventDispatcherTest, DontSendExitToSameClientWhenCaptureChanges) { |
1839 ServerWindow* root = root_window(); | 1923 ServerWindow* root = root_window(); |
1840 root->set_event_targeting_policy( | 1924 root->set_event_targeting_policy( |
1841 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | 1925 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
1842 std::unique_ptr<ServerWindow> c1 = CreateChildWindow(WindowId(1, 3)); | 1926 std::unique_ptr<ServerWindow> c1 = CreateChildWindow(WindowId(1, 3)); |
1843 std::unique_ptr<ServerWindow> c2 = CreateChildWindow(WindowId(1, 4)); | 1927 std::unique_ptr<ServerWindow> c2 = CreateChildWindow(WindowId(1, 4)); |
1844 | 1928 |
1845 root->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1929 root->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1846 c1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1930 c1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1847 c2->SetBounds(gfx::Rect(15, 15, 20, 20)); | 1931 c2->SetBounds(gfx::Rect(15, 15, 20, 20)); |
1848 | 1932 |
(...skipping 12 matching lines...) Expand all Loading... |
1861 gfx::Point()}}; | 1945 gfx::Point()}}; |
1862 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), | 1946 RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(), |
1863 tests, arraysize(tests)); | 1947 tests, arraysize(tests)); |
1864 | 1948 |
1865 // Set capture on |c1|. No events should be sent as |c1| is in the same | 1949 // Set capture on |c1|. No events should be sent as |c1| is in the same |
1866 // client. | 1950 // client. |
1867 event_dispatcher()->SetCaptureWindow(c1.get(), kClientAreaId); | 1951 event_dispatcher()->SetCaptureWindow(c1.get(), kClientAreaId); |
1868 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); | 1952 EXPECT_FALSE(test_event_dispatcher_delegate()->has_queued_events()); |
1869 } | 1953 } |
1870 | 1954 |
1871 TEST_F(EventDispatcherTest, MousePointerClearedOnDestroy) { | 1955 TEST_P(EventDispatcherTest, MousePointerClearedOnDestroy) { |
1872 root_window()->set_event_targeting_policy( | 1956 root_window()->set_event_targeting_policy( |
1873 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); | 1957 mojom::EventTargetingPolicy::DESCENDANTS_ONLY); |
1874 std::unique_ptr<ServerWindow> c1 = CreateChildWindow(WindowId(1, 3)); | 1958 std::unique_ptr<ServerWindow> c1 = CreateChildWindow(WindowId(1, 3)); |
1875 | 1959 |
1876 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1960 root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
1877 c1->SetBounds(gfx::Rect(10, 10, 20, 20)); | 1961 c1->SetBounds(gfx::Rect(10, 10, 20, 20)); |
1878 | 1962 |
1879 event_dispatcher()->SetMousePointerDisplayLocation(gfx::Point(15, 15), 0); | 1963 event_dispatcher()->SetMousePointerDisplayLocation(gfx::Point(15, 15), 0); |
| 1964 RunTasks(); |
1880 EXPECT_EQ(c1.get(), event_dispatcher()->mouse_cursor_source_window()); | 1965 EXPECT_EQ(c1.get(), event_dispatcher()->mouse_cursor_source_window()); |
1881 c1.reset(); | 1966 c1.reset(); |
1882 EXPECT_EQ(nullptr, event_dispatcher()->mouse_cursor_source_window()); | 1967 EXPECT_EQ(nullptr, event_dispatcher()->mouse_cursor_source_window()); |
1883 } | 1968 } |
1884 | 1969 |
| 1970 INSTANTIATE_TEST_CASE_P(/* no prefix */, EventDispatcherTest, testing::Bool()); |
| 1971 |
1885 } // namespace test | 1972 } // namespace test |
1886 } // namespace ws | 1973 } // namespace ws |
1887 } // namespace ui | 1974 } // namespace ui |
OLD | NEW |