Chromium Code Reviews| Index: services/ui/ws/event_dispatcher_unittest.cc |
| diff --git a/services/ui/ws/event_dispatcher_unittest.cc b/services/ui/ws/event_dispatcher_unittest.cc |
| index e06b70ef6fc6d71a862e065b0c894fc5eeec9635..1a3f87bdea60d52d43162bcca7c383b8a39f037f 100644 |
| --- a/services/ui/ws/event_dispatcher_unittest.cc |
| +++ b/services/ui/ws/event_dispatcher_unittest.cc |
| @@ -11,7 +11,7 @@ |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| -#include "services/ui/common/event_matcher_util.h" |
| +#include "services/ui/common/accelerator_util.h" |
| #include "services/ui/ws/accelerator.h" |
| #include "services/ui/ws/event_dispatcher_delegate.h" |
| #include "services/ui/ws/server_window.h" |
| @@ -385,34 +385,115 @@ TEST_F(EventDispatcherTest, AcceleratorBasic) { |
| uint32_t accelerator_1 = 1; |
| mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
| ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| - EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, std::move(matcher))); |
| + EXPECT_TRUE(dispatcher.AddAccelerators( |
| + CreateAcceleratorVector(accelerator_1, std::move(matcher)))); |
| uint32_t accelerator_2 = 2; |
| matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::N, |
| ui::mojom::kEventFlagNone); |
| - EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| + EXPECT_TRUE(dispatcher.AddAccelerators( |
| + CreateAcceleratorVector(accelerator_2, std::move(matcher)))); |
| // Attempting to add a new accelerator with the same id should fail. |
| matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| ui::mojom::kEventFlagNone); |
| - EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| + EXPECT_FALSE(dispatcher.AddAccelerators( |
| + CreateAcceleratorVector(accelerator_2, std::move(matcher)))); |
| // Adding the accelerator with the same id should succeed once the existing |
| // accelerator is removed. |
| dispatcher.RemoveAccelerator(accelerator_2); |
| matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| ui::mojom::kEventFlagNone); |
| - EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher))); |
| + EXPECT_TRUE(dispatcher.AddAccelerators( |
| + CreateAcceleratorVector(accelerator_2, std::move(matcher)))); |
| // Attempting to add an accelerator with the same matcher should fail. |
| uint32_t accelerator_3 = 3; |
| matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| ui::mojom::kEventFlagNone); |
| - EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
| + EXPECT_FALSE(dispatcher.AddAccelerators( |
| + CreateAcceleratorVector(accelerator_3, std::move(matcher)))); |
| matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| ui::mojom::kEventFlagControlDown); |
| - EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher))); |
| + EXPECT_TRUE(dispatcher.AddAccelerators( |
| + CreateAcceleratorVector(accelerator_3, std::move(matcher)))); |
| +} |
| + |
| +TEST_F(EventDispatcherTest, AddAccelerators) { |
| + ClearSetup(); |
| + TestEventDispatcherDelegate event_dispatcher_delegate(nullptr); |
| + EventDispatcher dispatcher(&event_dispatcher_delegate); |
| + |
| + std::vector<ui::mojom::AcceleratorTransportPtr> accelerators; |
| + |
| + uint32_t accelerator_1 = 1; |
| + mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
| + ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| + accelerators.push_back( |
| + CreateAcceleratorTransport(accelerator_1, std::move(matcher))); |
| + |
| + uint32_t accelerator_2 = 2; |
| + matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::N, |
| + ui::mojom::kEventFlagNone); |
| + accelerators.push_back( |
| + CreateAcceleratorTransport(accelerator_2, std::move(matcher))); |
| + |
| + uint32_t accelerator_3 = 3; |
| + matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| + ui::mojom::kEventFlagNone); |
| + accelerators.push_back( |
| + CreateAcceleratorTransport(accelerator_3, std::move(matcher))); |
| + |
| + // Adding unique accelerators should pass. |
| + EXPECT_TRUE(dispatcher.AddAccelerators(std::move(accelerators))); |
| + |
| + accelerators.clear(); |
| + |
| + uint32_t accelerator_4 = 4; |
| + matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::W, |
| + ui::mojom::kEventFlagControlDown); |
| + accelerators.push_back( |
| + CreateAcceleratorTransport(accelerator_4, std::move(matcher))); |
| + |
| + uint32_t accelerator_5 = 5; |
| + matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::W, |
| + ui::mojom::kEventFlagControlDown); |
| + accelerators.push_back( |
| + CreateAcceleratorTransport(accelerator_5, std::move(matcher))); |
| + |
| + uint32_t accelerator_6 = accelerator_5; |
| + matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| + ui::mojom::kEventFlagNone); |
| + accelerators.push_back( |
| + CreateAcceleratorTransport(accelerator_6, std::move(matcher))); |
| + |
| + // Adding accelerator_6 with the same id accelerator_5 should fail. |
| + EXPECT_FALSE(dispatcher.AddAccelerators(std::move(accelerators))); |
| + |
| + accelerators.clear(); |
| + |
| + matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T, |
| + ui::mojom::kEventFlagNone); |
| + accelerators.push_back( |
| + CreateAcceleratorTransport(accelerator_4, std::move(matcher))); |
| + |
| + // Check if accelerator_4 is already added to the dispatcher. |
| + EXPECT_FALSE(dispatcher.AddAccelerators(std::move(accelerators))); |
| + |
| + ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| + dispatcher.ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY); |
| + |
| + // Check if accelerator_1 is already added to the dispatcher. |
| + EXPECT_EQ(accelerator_1, |
| + event_dispatcher_delegate.GetAndClearLastAccelerator()); |
| + |
| + dispatcher.RemoveAccelerator(accelerator_1); |
|
mfomitchev
2016/11/30 02:33:04
I don't think we need to test Remove here - it's t
thanhph
2016/11/30 14:24:51
Done.
|
| + dispatcher.ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY); |
| + |
| + // Check if accelerator_1 is remove added to the dispatcher. |
| + EXPECT_EQ(0u, event_dispatcher_delegate.GetAndClearLastAccelerator()); |
| } |
| TEST_F(EventDispatcherTest, EventMatching) { |
| @@ -423,7 +504,8 @@ TEST_F(EventDispatcherTest, EventMatching) { |
| mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
| ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| uint32_t accelerator_1 = 1; |
| - dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); |
| + dispatcher->AddAccelerators( |
| + CreateAcceleratorVector(accelerator_1, std::move(matcher))); |
| ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY); |
| @@ -445,7 +527,8 @@ TEST_F(EventDispatcherTest, EventMatching) { |
| uint32_t accelerator_2 = 2; |
| matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::W, |
| ui::mojom::kEventFlagNone); |
| - dispatcher->AddAccelerator(accelerator_2, std::move(matcher)); |
| + dispatcher->AddAccelerators( |
| + CreateAcceleratorVector(accelerator_2, std::move(matcher))); |
| dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY); |
| EXPECT_EQ(accelerator_2, |
| event_dispatcher_delegate->GetAndClearLastAccelerator()); |
| @@ -465,7 +548,8 @@ TEST_F(EventDispatcherTest, PostTargetAccelerator) { |
| ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET; |
| uint32_t accelerator_1 = 1; |
| - dispatcher->AddAccelerator(accelerator_1, std::move(matcher)); |
| + dispatcher->AddAccelerators( |
| + CreateAcceleratorVector(accelerator_1, std::move(matcher))); |
| ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| // The post-target accelerator should be fired if there is no focused window. |
| @@ -510,7 +594,8 @@ TEST_F(EventDispatcherTest, ProcessPost) { |
| mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
| ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| matcher->accelerator_phase = ui::mojom::AcceleratorPhase::PRE_TARGET; |
| - dispatcher->AddAccelerator(pre_id, std::move(matcher)); |
| + dispatcher->AddAccelerators( |
| + CreateAcceleratorVector(pre_id, std::move(matcher))); |
| } |
| uint32_t post_id = 2; |
| @@ -518,7 +603,8 @@ TEST_F(EventDispatcherTest, ProcessPost) { |
| mojom::EventMatcherPtr matcher = ui::CreateKeyMatcher( |
| ui::mojom::KeyboardCode::W, ui::mojom::kEventFlagControlDown); |
| matcher->accelerator_phase = ui::mojom::AcceleratorPhase::POST_TARGET; |
| - dispatcher->AddAccelerator(post_id, std::move(matcher)); |
| + dispatcher->AddAccelerators( |
| + CreateAcceleratorVector(post_id, std::move(matcher))); |
| } |
| // Set focused window for EventDispatcher dispatches key events. |