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

Side by Side Diff: services/ui/ws/event_dispatcher_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698