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

Unified Diff: services/ui/ws/event_dispatcher_unittest.cc

Issue 2520093003: WindowManagerClient::AddAccelerator() should take an array (Closed)
Patch Set: Modify helper to return vector and leverage helper in other files.Rename/format code. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..da531c326054d3eaa1fbafef4314280d1ad59bb8 100644
--- a/services/ui/ws/event_dispatcher_unittest.cc
+++ b/services/ui/ws/event_dispatcher_unittest.cc
@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
+#include "services/ui/common/accelerator_transport_util.h"
#include "services/ui/common/event_matcher_util.h"
#include "services/ui/ws/accelerator.h"
#include "services/ui/ws/event_dispatcher_delegate.h"
@@ -385,34 +386,54 @@ 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)));
+
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_1;
+ accelerators_1 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_1), accelerator_1, std::move(matcher));
+ EXPECT_TRUE(dispatcher.AddAccelerators(std::move(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)));
+
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_2;
+ accelerators_2 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_2), accelerator_2, std::move(matcher));
+ EXPECT_TRUE(dispatcher.AddAccelerators(std::move(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)));
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_3;
+ accelerators_3 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_3), accelerator_2, std::move(matcher));
+ EXPECT_FALSE(dispatcher.AddAccelerators(std::move(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)));
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_4;
+ accelerators_4 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_4), accelerator_2, std::move(matcher));
+ EXPECT_TRUE(dispatcher.AddAccelerators(std::move(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)));
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_5;
+ accelerators_5 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_5), accelerator_3, std::move(matcher));
+ EXPECT_FALSE(dispatcher.AddAccelerators(std::move(accelerators_5)));
matcher = ui::CreateKeyMatcher(ui::mojom::KeyboardCode::T,
ui::mojom::kEventFlagControlDown);
- EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, std::move(matcher)));
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_6;
+ accelerators_6 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_6), accelerator_3, std::move(matcher));
+ EXPECT_TRUE(dispatcher.AddAccelerators(std::move(accelerators_6)));
}
TEST_F(EventDispatcherTest, EventMatching) {
@@ -423,7 +444,10 @@ 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));
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_1;
+ accelerators_1 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_1), accelerator_1, std::move(matcher));
+ dispatcher->AddAccelerators(std::move(accelerators_1));
ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
@@ -445,7 +469,10 @@ 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));
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_2;
+ accelerators_2 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_2), accelerator_2, std::move(matcher));
+ dispatcher->AddAccelerators(std::move(accelerators_2));
dispatcher->ProcessEvent(key, EventDispatcher::AcceleratorMatchPhase::ANY);
EXPECT_EQ(accelerator_2,
event_dispatcher_delegate->GetAndClearLastAccelerator());
@@ -465,7 +492,11 @@ 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));
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_1;
+ accelerators_1 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_1), accelerator_1, std::move(matcher));
+
+ dispatcher->AddAccelerators(std::move(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 +541,12 @@ 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));
+
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_1;
+ accelerators_1 = ash::mus::AddAcceleratorHelper(std::move(accelerators_1),
+ pre_id, std::move(matcher));
+
+ dispatcher->AddAccelerators(std::move(accelerators_1));
}
uint32_t post_id = 2;
@@ -518,7 +554,12 @@ 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));
+
+ std::vector<ui::mojom::AcceleratorTransportPtr> accelerators_2;
+ accelerators_2 = ash::mus::AddAcceleratorHelper(
+ std::move(accelerators_2), post_id, std::move(matcher));
+
+ dispatcher->AddAccelerators(std::move(accelerators_2));
}
// Set focused window for EventDispatcher dispatches key events.

Powered by Google App Engine
This is Rietveld 408576698