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

Side by Side Diff: components/mus/ws/event_dispatcher_unittest.cc

Issue 1487333004: mus: Notify the client whether adding an accelerator was successful. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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 unified diff | Download patch
« no previous file with comments | « components/mus/ws/event_dispatcher.cc ('k') | components/mus/ws/window_tree_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/mus/ws/event_dispatcher.h" 5 #include "components/mus/ws/event_dispatcher.h"
6 6
7 #include "components/mus/public/cpp/event_matcher.h" 7 #include "components/mus/public/cpp/event_matcher.h"
8 #include "components/mus/ws/event_dispatcher_delegate.h" 8 #include "components/mus/ws/event_dispatcher_delegate.h"
9 #include "components/mus/ws/server_window.h" 9 #include "components/mus/ws/server_window.h"
10 #include "components/mus/ws/server_window_surface_manager_test_api.h" 10 #include "components/mus/ws/server_window_surface_manager_test_api.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 scoped_ptr<ui::Event> dispatched_event( 159 scoped_ptr<ui::Event> dispatched_event(
160 dispatched_event_mojo.To<scoped_ptr<ui::Event>>()); 160 dispatched_event_mojo.To<scoped_ptr<ui::Event>>());
161 ASSERT_TRUE(dispatched_event.get()); 161 ASSERT_TRUE(dispatched_event.get());
162 ASSERT_TRUE(dispatched_event->IsMouseEvent()); 162 ASSERT_TRUE(dispatched_event->IsMouseEvent());
163 ui::MouseEvent* dispatched_mouse_event = 163 ui::MouseEvent* dispatched_mouse_event =
164 static_cast<ui::MouseEvent*>(dispatched_event.get()); 164 static_cast<ui::MouseEvent*>(dispatched_event.get());
165 EXPECT_EQ(gfx::Point(20, 25), dispatched_mouse_event->root_location()); 165 EXPECT_EQ(gfx::Point(20, 25), dispatched_mouse_event->root_location());
166 EXPECT_EQ(gfx::Point(10, 15), dispatched_mouse_event->location()); 166 EXPECT_EQ(gfx::Point(10, 15), dispatched_mouse_event->location());
167 } 167 }
168 168
169 TEST(EventDispatcherTest, AcceleratorBasic) {
170 TestEventDispatcherDelegate event_dispatcher_delegate(nullptr);
171 EventDispatcher dispatcher(&event_dispatcher_delegate);
172 uint32_t accelerator_1 = 1;
173 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher(
174 mus::mojom::KEYBOARD_CODE_W, mus::mojom::EVENT_FLAGS_CONTROL_DOWN);
175 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_1, matcher.Pass()));
176
177 uint32_t accelerator_2 = 2;
178 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_N,
179 mus::mojom::EVENT_FLAGS_NONE);
180 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, matcher.Pass()));
181
182 // Attempting to add a new accelerator with the same id should fail.
183 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T,
184 mus::mojom::EVENT_FLAGS_NONE);
185 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_2, matcher.Pass()));
186
187 // Adding the accelerator with the same id should succeed once the existing
188 // accelerator is removed.
189 dispatcher.RemoveAccelerator(accelerator_2);
190 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T,
191 mus::mojom::EVENT_FLAGS_NONE);
192 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_2, matcher.Pass()));
193
194 // Attempting to add an accelerator with the same matcher should fail.
195 uint32_t accelerator_3 = 3;
196 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T,
197 mus::mojom::EVENT_FLAGS_NONE);
198 EXPECT_FALSE(dispatcher.AddAccelerator(accelerator_3, matcher.Pass()));
199
200 matcher = mus::CreateKeyMatcher(mus::mojom::KEYBOARD_CODE_T,
201 mus::mojom::EVENT_FLAGS_CONTROL_DOWN);
202 EXPECT_TRUE(dispatcher.AddAccelerator(accelerator_3, matcher.Pass()));
203 }
204
169 TEST(EventDispatcherTest, EventMatching) { 205 TEST(EventDispatcherTest, EventMatching) {
170 TestServerWindowDelegate window_delegate; 206 TestServerWindowDelegate window_delegate;
171 ServerWindow root(&window_delegate, WindowId(1, 2)); 207 ServerWindow root(&window_delegate, WindowId(1, 2));
172 TestEventDispatcherDelegate event_dispatcher_delegate(&root); 208 TestEventDispatcherDelegate event_dispatcher_delegate(&root);
173 EventDispatcher dispatcher(&event_dispatcher_delegate); 209 EventDispatcher dispatcher(&event_dispatcher_delegate);
174 dispatcher.set_root(&root); 210 dispatcher.set_root(&root);
175 211
176 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher( 212 mojom::EventMatcherPtr matcher = mus::CreateKeyMatcher(
177 mus::mojom::KEYBOARD_CODE_W, mus::mojom::EVENT_FLAGS_CONTROL_DOWN); 213 mus::mojom::KEYBOARD_CODE_W, mus::mojom::EVENT_FLAGS_CONTROL_DOWN);
178 uint32_t accelerator_1 = 1; 214 uint32_t accelerator_1 = 1;
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 dispatched_event_mojo.To<scoped_ptr<ui::Event>>()); 599 dispatched_event_mojo.To<scoped_ptr<ui::Event>>());
564 ASSERT_TRUE(dispatched_event.get()); 600 ASSERT_TRUE(dispatched_event.get());
565 ASSERT_TRUE(dispatched_event->IsMouseEvent()); 601 ASSERT_TRUE(dispatched_event->IsMouseEvent());
566 ui::MouseEvent* dispatched_mouse_event = 602 ui::MouseEvent* dispatched_mouse_event =
567 static_cast<ui::MouseEvent*>(dispatched_event.get()); 603 static_cast<ui::MouseEvent*>(dispatched_event.get());
568 EXPECT_EQ(gfx::Point(-2, -1), dispatched_mouse_event->location()); 604 EXPECT_EQ(gfx::Point(-2, -1), dispatched_mouse_event->location());
569 } 605 }
570 606
571 } // namespace ws 607 } // namespace ws
572 } // namespace mus 608 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/event_dispatcher.cc ('k') | components/mus/ws/window_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698