| 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_target_iterator.h" | 9 #include "ui/events/event_target_iterator.h" |
| 10 #include "ui/events/event_targeter.h" | 10 #include "ui/events/event_targeter.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 DISALLOW_COPY_AND_ASSIGN(EventProcessorTest); | 57 DISALLOW_COPY_AND_ASSIGN(EventProcessorTest); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 TEST_F(EventProcessorTest, Basic) { | 60 TEST_F(EventProcessorTest, Basic) { |
| 61 scoped_ptr<TestEventTarget> child(new TestEventTarget()); | 61 scoped_ptr<TestEventTarget> child(new TestEventTarget()); |
| 62 child->SetEventTargeter( | 62 child->SetEventTargeter( |
| 63 make_scoped_ptr(new TestEventTargeter(child.get(), false))); | 63 make_scoped_ptr(new TestEventTargeter(child.get(), false))); |
| 64 SetTarget(child.get()); | 64 SetTarget(child.get()); |
| 65 root()->AddChild(child.Pass()); | 65 root()->AddChild(child.Pass()); |
| 66 | 66 |
| 67 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 67 MouseEvent mouse(ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 68 EventTimeForNow(), EF_NONE, EF_NONE); | 68 gfx::PointF(10.f, 10.f), EventTimeForNow(), EF_NONE, |
| 69 EF_NONE); |
| 69 DispatchEvent(&mouse); | 70 DispatchEvent(&mouse); |
| 70 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 71 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 71 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 72 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 72 | 73 |
| 73 SetTarget(root()); | 74 SetTarget(root()); |
| 74 root()->RemoveChild(root()->child_at(0)); | 75 root()->RemoveChild(root()->child_at(0)); |
| 75 DispatchEvent(&mouse); | 76 DispatchEvent(&mouse); |
| 76 EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 77 EXPECT_TRUE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 77 } | 78 } |
| 78 | 79 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 138 |
| 138 // Indicate that an event which is dispatched to the child target owned by the | 139 // Indicate that an event which is dispatched to the child target owned by the |
| 139 // first event processor should be handled by |target_handler| instead. | 140 // first event processor should be handled by |target_handler| instead. |
| 140 scoped_ptr<TestEventHandler> target_handler( | 141 scoped_ptr<TestEventHandler> target_handler( |
| 141 new ReDispatchEventHandler(second_processor.get(), root()->child_at(0))); | 142 new ReDispatchEventHandler(second_processor.get(), root()->child_at(0))); |
| 142 root()->child_at(0)->set_target_handler(target_handler.get()); | 143 root()->child_at(0)->set_target_handler(target_handler.get()); |
| 143 | 144 |
| 144 // Dispatch a mouse event to the tree of event targets owned by the first | 145 // Dispatch a mouse event to the tree of event targets owned by the first |
| 145 // event processor, checking in ReDispatchEventHandler that the phase and | 146 // event processor, checking in ReDispatchEventHandler that the phase and |
| 146 // target information of the event is correct. | 147 // target information of the event is correct. |
| 147 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 148 MouseEvent mouse(ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 148 EventTimeForNow(), EF_NONE, EF_NONE); | 149 gfx::PointF(10.f, 10.f), EventTimeForNow(), EF_NONE, |
| 150 EF_NONE); |
| 149 DispatchEvent(&mouse); | 151 DispatchEvent(&mouse); |
| 150 | 152 |
| 151 // Verify also that |mouse| was seen by the child nodes contained in both | 153 // Verify also that |mouse| was seen by the child nodes contained in both |
| 152 // event processors and that the event was not handled. | 154 // event processors and that the event was not handled. |
| 153 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 155 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 154 EXPECT_TRUE(second_root->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 156 EXPECT_TRUE(second_root->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 155 EXPECT_FALSE(mouse.handled()); | 157 EXPECT_FALSE(mouse.handled()); |
| 156 second_root->child_at(0)->ResetReceivedEvents(); | 158 second_root->child_at(0)->ResetReceivedEvents(); |
| 157 root()->child_at(0)->ResetReceivedEvents(); | 159 root()->child_at(0)->ResetReceivedEvents(); |
| 158 | 160 |
| 159 // Indicate that the child of the second root should handle events, and | 161 // Indicate that the child of the second root should handle events, and |
| 160 // dispatch another mouse event to verify that it is marked as handled. | 162 // dispatch another mouse event to verify that it is marked as handled. |
| 161 second_root->child_at(0)->set_mark_events_as_handled(true); | 163 second_root->child_at(0)->set_mark_events_as_handled(true); |
| 162 MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 164 MouseEvent mouse2(ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 163 EventTimeForNow(), EF_NONE, EF_NONE); | 165 gfx::PointF(10.f, 10.f), EventTimeForNow(), EF_NONE, |
| 166 EF_NONE); |
| 164 DispatchEvent(&mouse2); | 167 DispatchEvent(&mouse2); |
| 165 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 168 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 166 EXPECT_TRUE(second_root->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 169 EXPECT_TRUE(second_root->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 167 EXPECT_TRUE(mouse2.handled()); | 170 EXPECT_TRUE(mouse2.handled()); |
| 168 } | 171 } |
| 169 | 172 |
| 170 // Verifies that OnEventProcessingFinished() is called when an event | 173 // Verifies that OnEventProcessingFinished() is called when an event |
| 171 // has been handled. | 174 // has been handled. |
| 172 TEST_F(EventProcessorTest, OnEventProcessingFinished) { | 175 TEST_F(EventProcessorTest, OnEventProcessingFinished) { |
| 173 scoped_ptr<TestEventTarget> child(new TestEventTarget()); | 176 scoped_ptr<TestEventTarget> child(new TestEventTarget()); |
| 174 child->set_mark_events_as_handled(true); | 177 child->set_mark_events_as_handled(true); |
| 175 SetTarget(child.get()); | 178 SetTarget(child.get()); |
| 176 root()->AddChild(child.Pass()); | 179 root()->AddChild(child.Pass()); |
| 177 | 180 |
| 178 // Dispatch a mouse event. We expect the event to be seen by the target, | 181 // Dispatch a mouse event. We expect the event to be seen by the target, |
| 179 // handled, and we expect OnEventProcessingFinished() to be invoked once. | 182 // handled, and we expect OnEventProcessingFinished() to be invoked once. |
| 180 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 183 MouseEvent mouse(ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 181 EventTimeForNow(), EF_NONE, EF_NONE); | 184 gfx::PointF(10.f, 10.f), EventTimeForNow(), EF_NONE, |
| 185 EF_NONE); |
| 182 DispatchEvent(&mouse); | 186 DispatchEvent(&mouse); |
| 183 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 187 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 184 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 188 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 185 EXPECT_TRUE(mouse.handled()); | 189 EXPECT_TRUE(mouse.handled()); |
| 186 EXPECT_EQ(1, processor()->num_times_processing_finished()); | 190 EXPECT_EQ(1, processor()->num_times_processing_finished()); |
| 187 } | 191 } |
| 188 | 192 |
| 189 // Verifies that OnEventProcessingStarted() has been called when starting to | 193 // Verifies that OnEventProcessingStarted() has been called when starting to |
| 190 // process an event, and that processing does not take place if | 194 // process an event, and that processing does not take place if |
| 191 // OnEventProcessingStarted() marks the event as handled. Also verifies that | 195 // OnEventProcessingStarted() marks the event as handled. Also verifies that |
| 192 // OnEventProcessingFinished() is also called in either case. | 196 // OnEventProcessingFinished() is also called in either case. |
| 193 TEST_F(EventProcessorTest, OnEventProcessingStarted) { | 197 TEST_F(EventProcessorTest, OnEventProcessingStarted) { |
| 194 scoped_ptr<TestEventTarget> child(new TestEventTarget()); | 198 scoped_ptr<TestEventTarget> child(new TestEventTarget()); |
| 195 SetTarget(child.get()); | 199 SetTarget(child.get()); |
| 196 root()->AddChild(child.Pass()); | 200 root()->AddChild(child.Pass()); |
| 197 | 201 |
| 198 // Dispatch a mouse event. We expect the event to be seen by the target, | 202 // Dispatch a mouse event. We expect the event to be seen by the target, |
| 199 // OnEventProcessingStarted() should be called once, and | 203 // OnEventProcessingStarted() should be called once, and |
| 200 // OnEventProcessingFinished() should be called once. The event should | 204 // OnEventProcessingFinished() should be called once. The event should |
| 201 // remain unhandled. | 205 // remain unhandled. |
| 202 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 206 MouseEvent mouse(ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 203 EventTimeForNow(), EF_NONE, EF_NONE); | 207 gfx::PointF(10.f, 10.f), EventTimeForNow(), EF_NONE, |
| 208 EF_NONE); |
| 204 DispatchEvent(&mouse); | 209 DispatchEvent(&mouse); |
| 205 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 210 EXPECT_TRUE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 206 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 211 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 207 EXPECT_FALSE(mouse.handled()); | 212 EXPECT_FALSE(mouse.handled()); |
| 208 EXPECT_EQ(1, processor()->num_times_processing_started()); | 213 EXPECT_EQ(1, processor()->num_times_processing_started()); |
| 209 EXPECT_EQ(1, processor()->num_times_processing_finished()); | 214 EXPECT_EQ(1, processor()->num_times_processing_finished()); |
| 210 processor()->Reset(); | 215 processor()->Reset(); |
| 211 root()->ResetReceivedEvents(); | 216 root()->ResetReceivedEvents(); |
| 212 root()->child_at(0)->ResetReceivedEvents(); | 217 root()->child_at(0)->ResetReceivedEvents(); |
| 213 | 218 |
| 214 // Dispatch another mouse event, but with OnEventProcessingStarted() marking | 219 // Dispatch another mouse event, but with OnEventProcessingStarted() marking |
| 215 // the event as handled to prevent processing. We expect the event to not be | 220 // the event as handled to prevent processing. We expect the event to not be |
| 216 // seen by the target this time, but OnEventProcessingStarted() and | 221 // seen by the target this time, but OnEventProcessingStarted() and |
| 217 // OnEventProcessingFinished() should both still be called once. | 222 // OnEventProcessingFinished() should both still be called once. |
| 218 processor()->set_should_processing_occur(false); | 223 processor()->set_should_processing_occur(false); |
| 219 MouseEvent mouse2(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 224 MouseEvent mouse2(ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 220 EventTimeForNow(), EF_NONE, EF_NONE); | 225 gfx::PointF(10.f, 10.f), EventTimeForNow(), EF_NONE, |
| 226 EF_NONE); |
| 221 DispatchEvent(&mouse2); | 227 DispatchEvent(&mouse2); |
| 222 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); | 228 EXPECT_FALSE(root()->child_at(0)->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 223 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); | 229 EXPECT_FALSE(root()->DidReceiveEvent(ET_MOUSE_MOVED)); |
| 224 EXPECT_TRUE(mouse2.handled()); | 230 EXPECT_TRUE(mouse2.handled()); |
| 225 EXPECT_EQ(1, processor()->num_times_processing_started()); | 231 EXPECT_EQ(1, processor()->num_times_processing_started()); |
| 226 EXPECT_EQ(1, processor()->num_times_processing_finished()); | 232 EXPECT_EQ(1, processor()->num_times_processing_finished()); |
| 227 } | 233 } |
| 228 | 234 |
| 229 // Tests that unhandled events are correctly dispatched to the next-best | 235 // Tests that unhandled events are correctly dispatched to the next-best |
| 230 // target as decided by the TestEventTargeter. | 236 // target as decided by the TestEventTargeter. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 TestEventHandler post_child; | 356 TestEventHandler post_child; |
| 351 post_child.set_handler_name("PostC"); | 357 post_child.set_handler_name("PostC"); |
| 352 post_child.set_recorder(&recorder); | 358 post_child.set_recorder(&recorder); |
| 353 child_r->AddPostTargetHandler(&post_child); | 359 child_r->AddPostTargetHandler(&post_child); |
| 354 | 360 |
| 355 TestEventHandler post_grandchild; | 361 TestEventHandler post_grandchild; |
| 356 post_grandchild.set_handler_name("PostG"); | 362 post_grandchild.set_handler_name("PostG"); |
| 357 post_grandchild.set_recorder(&recorder); | 363 post_grandchild.set_recorder(&recorder); |
| 358 grandchild_r->AddPostTargetHandler(&post_grandchild); | 364 grandchild_r->AddPostTargetHandler(&post_grandchild); |
| 359 | 365 |
| 360 MouseEvent mouse(ET_MOUSE_MOVED, gfx::Point(10, 10), gfx::Point(10, 10), | 366 MouseEvent mouse(ET_MOUSE_MOVED, gfx::PointF(10.f, 10.f), |
| 361 EventTimeForNow(), EF_NONE, EF_NONE); | 367 gfx::PointF(10.f, 10.f), EventTimeForNow(), EF_NONE, |
| 368 EF_NONE); |
| 362 DispatchEvent(&mouse); | 369 DispatchEvent(&mouse); |
| 363 | 370 |
| 364 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", | 371 std::string expected[] = { "PreR", "PreC", "PreG", "G", "PostG", "PostC", |
| 365 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; | 372 "PostR", "PreR", "PreC", "C", "PostC", "PostR", "PreR", "R", "PostR" }; |
| 366 EXPECT_EQ(std::vector<std::string>( | 373 EXPECT_EQ(std::vector<std::string>( |
| 367 expected, expected + arraysize(expected)), recorder); | 374 expected, expected + arraysize(expected)), recorder); |
| 368 } | 375 } |
| 369 | 376 |
| 370 } // namespace test | 377 } // namespace test |
| 371 } // namespace ui | 378 } // namespace ui |
| OLD | NEW |