OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
9 #include "ui/events/event_targeter.h" | 9 #include "ui/events/event_targeter.h" |
10 #include "ui/events/test/events_test_utils.h" | 10 #include "ui/events/test/events_test_utils.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 EF_NONE, EF_NONE); | 163 EF_NONE, EF_NONE); |
164 DispatchEvent(&second); | 164 DispatchEvent(&second); |
165 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 165 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
166 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 166 EXPECT_FALSE(parent_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
167 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 167 EXPECT_FALSE(child_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
168 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); | 168 EXPECT_TRUE(grandchild_r->DidReceiveEvent(ET_MOUSE_MOVED)); |
169 } | 169 } |
170 | 170 |
171 // ReDispatchEventHandler is used to receive mouse events and forward them | 171 // ReDispatchEventHandler is used to receive mouse events and forward them |
172 // to a specified EventProcessor. Verifies that the event has the correct | 172 // to a specified EventProcessor. Verifies that the event has the correct |
173 // target and phase both before and after the nested event processing. | 173 // target and phase both before and after the nested event processing. Also |
| 174 // verifies that the location of the event remains the same after it has |
| 175 // been processed by the second EventProcessor. |
174 class ReDispatchEventHandler : public TestEventHandler { | 176 class ReDispatchEventHandler : public TestEventHandler { |
175 public: | 177 public: |
176 ReDispatchEventHandler(EventProcessor* processor, EventTarget* target) | 178 ReDispatchEventHandler(EventProcessor* processor, EventTarget* target) |
177 : processor_(processor), expected_target_(target) {} | 179 : processor_(processor), expected_target_(target) {} |
178 virtual ~ReDispatchEventHandler() {} | 180 virtual ~ReDispatchEventHandler() {} |
179 | 181 |
180 // TestEventHandler: | 182 // TestEventHandler: |
181 virtual void OnMouseEvent(MouseEvent* event) OVERRIDE { | 183 virtual void OnMouseEvent(MouseEvent* event) OVERRIDE { |
182 TestEventHandler::OnMouseEvent(event); | 184 TestEventHandler::OnMouseEvent(event); |
183 | 185 |
184 EXPECT_EQ(expected_target_, event->target()); | 186 EXPECT_EQ(expected_target_, event->target()); |
185 EXPECT_EQ(EP_TARGET, event->phase()); | 187 EXPECT_EQ(EP_TARGET, event->phase()); |
186 | 188 |
| 189 gfx::Point location(event->location()); |
187 EventDispatchDetails details = processor_->OnEventFromSource(event); | 190 EventDispatchDetails details = processor_->OnEventFromSource(event); |
188 EXPECT_FALSE(details.dispatcher_destroyed); | 191 EXPECT_FALSE(details.dispatcher_destroyed); |
189 EXPECT_FALSE(details.target_destroyed); | 192 EXPECT_FALSE(details.target_destroyed); |
190 | 193 |
191 // The nested event-processing should not have mutated the target or | 194 // The nested event-processing should not have mutated the target, |
192 // phase of |event|. | 195 // phase, or location of |event|. |
193 EXPECT_EQ(expected_target_, event->target()); | 196 EXPECT_EQ(expected_target_, event->target()); |
194 EXPECT_EQ(EP_TARGET, event->phase()); | 197 EXPECT_EQ(EP_TARGET, event->phase()); |
| 198 EXPECT_EQ(location, event->location()); |
195 } | 199 } |
196 | 200 |
197 private: | 201 private: |
198 EventProcessor* processor_; | 202 EventProcessor* processor_; |
199 EventTarget* expected_target_; | 203 EventTarget* expected_target_; |
200 | 204 |
201 DISALLOW_COPY_AND_ASSIGN(ReDispatchEventHandler); | 205 DISALLOW_COPY_AND_ASSIGN(ReDispatchEventHandler); |
202 }; | 206 }; |
203 | 207 |
204 // Verifies that the phase and target information of an event is not mutated | 208 // Verifies that the phase and target information of an event is not mutated |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 DispatchEvent(&mouse); | 454 DispatchEvent(&mouse); |
451 | 455 |
452 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", | 456 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", |
453 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; | 457 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; |
454 EXPECT_EQ(std::vector<std::string>( | 458 EXPECT_EQ(std::vector<std::string>( |
455 expected, expected + arraysize(expected)), recorder); | 459 expected, expected + arraysize(expected)), recorder); |
456 } | 460 } |
457 | 461 |
458 } // namespace test | 462 } // namespace test |
459 } // namespace ui | 463 } // namespace ui |
OLD | NEW |