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