| 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..2263c9c21b732de85d0cfa2c46236c1f37eb71f9 100644
|
| --- a/services/ui/ws/event_dispatcher_unittest.cc
|
| +++ b/services/ui/ws/event_dispatcher_unittest.cc
|
| @@ -385,34 +385,70 @@ 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)));
|
| +
|
| + ui::mojom::AcceleratorEventPtr accelerator_event(
|
| + ui::mojom::AcceleratorEvent::New());
|
| + accelerator_event->id = accelerator_1;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_1;
|
| + multi_accelerators_1.push_back(std::move(accelerator_event));
|
| +
|
| + EXPECT_TRUE(dispatcher.AddAccelerator(std::move(multi_accelerators_1)));
|
|
|
| uint32_t accelerator_2 = 2;
|
| matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::N,
|
| ui::mojom::kEventFlagNone);
|
| - EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, std::move(matcher)));
|
| +
|
| + accelerator_event = ui::mojom::AcceleratorEvent::New();
|
| + accelerator_event->id = accelerator_2;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_2;
|
| + multi_accelerators_2.push_back(std::move(accelerator_event));
|
| +
|
| + EXPECT_TRUE(dispatcher.AddAccelerator(std::move(multi_accelerators_2)));
|
|
|
| // 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)));
|
| + accelerator_event = ui::mojom::AcceleratorEvent::New();
|
| + accelerator_event->id = accelerator_2;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_3;
|
| + multi_accelerators_3.push_back(std::move(accelerator_event));
|
| + EXPECT_FALSE(dispatcher.AddAccelerator(std::move(multi_accelerators_3)));
|
|
|
| // 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)));
|
| +
|
| + accelerator_event = ui::mojom::AcceleratorEvent::New();
|
| + accelerator_event->id = accelerator_2;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_4;
|
| + multi_accelerators_4.push_back(std::move(accelerator_event));
|
| + EXPECT_TRUE(dispatcher.AddAccelerator(std::move(multi_accelerators_4)));
|
|
|
| // 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)));
|
| + accelerator_event = ui::mojom::AcceleratorEvent::New();
|
| + accelerator_event->id = accelerator_3;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_5;
|
| + multi_accelerators_5.push_back(std::move(accelerator_event));
|
| + EXPECT_FALSE(dispatcher.AddAccelerator(std::move(multi_accelerators_5)));
|
|
|
| matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T,
|
| ui::mojom::kEventFlagControlDown);
|
| - EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher)));
|
| + accelerator_event = ui::mojom::AcceleratorEvent::New();
|
| + accelerator_event->id = accelerator_3;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_6;
|
| + multi_accelerators_6.push_back(std::move(accelerator_event));
|
| + EXPECT_TRUE(dispatcher.AddAccelerator(std::move(multi_accelerators_6)));
|
| }
|
|
|
| TEST_F(EventDispatcherTest, EventMatching) {
|
| @@ -423,7 +459,14 @@ 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));
|
| +
|
| + ui::mojom::AcceleratorEventPtr accelerator_event(
|
| + ui::mojom::AcceleratorEvent::New());
|
| + accelerator_event->id = accelerator_1;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_1;
|
| + multi_accelerators_1.push_back(std::move(accelerator_event));
|
| + dispatcher->AddAccelerator(std::move(multi_accelerators_1));
|
|
|
| ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
|
| dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
|
| @@ -445,7 +488,12 @@ 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));
|
| + accelerator_event = ui::mojom::AcceleratorEvent::New();
|
| + accelerator_event->id = accelerator_2;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_2;
|
| + multi_accelerators_2.push_back(std::move(accelerator_event));
|
| + dispatcher->AddAccelerator(std::move(multi_accelerators_2));
|
| dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
|
| EXPECT_EQ(accelerator_2,
|
| event_dispatcher_delegate->GetAndClearLastAccelerator());
|
| @@ -465,7 +513,13 @@ 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));
|
| + ui::mojom::AcceleratorEventPtr accelerator_event(
|
| + ui::mojom::AcceleratorEvent::New());
|
| + accelerator_event->id = accelerator_1;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_1;
|
| + multi_accelerators_1.push_back(std::move(accelerator_event));
|
| + dispatcher->AddAccelerator(std::move(multi_accelerators_1));
|
|
|
| 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 +564,14 @@ 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));
|
| +
|
| + ui::mojom::AcceleratorEventPtr accelerator_event(
|
| + ui::mojom::AcceleratorEvent::New());
|
| + accelerator_event->id = pre_id;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_1;
|
| + multi_accelerators_1.push_back(std::move(accelerator_event));
|
| + dispatcher->AddAccelerator(std::move(multi_accelerators_1));
|
| }
|
|
|
| uint32_t post_id = 2;
|
| @@ -518,7 +579,13 @@ 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));
|
| + ui::mojom::AcceleratorEventPtr accelerator_event(
|
| + ui::mojom::AcceleratorEvent::New());
|
| + accelerator_event->id = post_id;
|
| + accelerator_event->event_matcher = std::move(matcher);
|
| + mojo::Array<ui::mojom::AcceleratorEventPtr> multi_accelerators_2;
|
| + multi_accelerators_2.push_back(std::move(accelerator_event));
|
| + dispatcher->AddAccelerator(std::move(multi_accelerators_2));
|
| }
|
|
|
| // Set focused window for EventDispatcher dispatches key events.
|
|
|