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