Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/chromeos/touch_exploration_controller.h" | 5 #include "ui/chromeos/touch_exploration_controller.h" |
| 6 | 6 |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "ui/aura/client/cursor_client.h" | 8 #include "ui/aura/client/cursor_client.h" |
| 9 #include "ui/aura/test/aura_test_base.h" | 9 #include "ui/aura/test/aura_test_base.h" |
| 10 #include "ui/aura/test/event_generator.h" | 10 #include "ui/aura/test/event_generator.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 148 |
| 149 // TODO(mfomitchev): Need to investigate why we don't get mouse enter/exit | 149 // TODO(mfomitchev): Need to investigate why we don't get mouse enter/exit |
| 150 // events when running these tests as part of ui_unittests. We do get them when | 150 // events when running these tests as part of ui_unittests. We do get them when |
| 151 // the tests are run as part of ash unit tests. | 151 // the tests are run as part of ash unit tests. |
| 152 | 152 |
| 153 // Simple test to confirm one-finger touches are transformed into mouse moves. | 153 // Simple test to confirm one-finger touches are transformed into mouse moves. |
| 154 TEST_F(TouchExplorationTest, OneFingerTouch) { | 154 TEST_F(TouchExplorationTest, OneFingerTouch) { |
| 155 SwitchTouchExplorationMode(true); | 155 SwitchTouchExplorationMode(true); |
| 156 cursor_client()->ShowCursor(); | 156 cursor_client()->ShowCursor(); |
| 157 cursor_client()->DisableMouseEvents(); | 157 cursor_client()->DisableMouseEvents(); |
| 158 | |
| 158 aura::test::EventGenerator generator(root_window()); | 159 aura::test::EventGenerator generator(root_window()); |
| 159 gfx::Point location_start = generator.current_location(); | 160 gfx::Point location_start(11, 12); |
| 160 gfx::Point location_end(11, 12); | 161 gfx::Point location_end(13, 14); |
| 162 generator.set_current_location(location_start); | |
| 163 generator.set_simulated_time(base::TimeDelta::FromMilliseconds(1000)); | |
| 161 generator.PressTouch(); | 164 generator.PressTouch(); |
| 165 EXPECT_FALSE(IsInTouchToMouseMode()); | |
| 166 | |
| 167 generator.set_simulated_time(base::TimeDelta::FromMilliseconds(2000)); | |
| 168 generator.MoveTouch(location_end); | |
| 162 EXPECT_TRUE(IsInTouchToMouseMode()); | 169 EXPECT_TRUE(IsInTouchToMouseMode()); |
|
mfomitchev
2014/05/28 17:47:45
Can we move this check up before the move?
dmazzoni
2014/05/31 06:53:24
Yes, that makes sense. To do that I had to create
| |
| 163 generator.MoveTouch(location_end); | 170 |
| 164 // Confirm the actual mouse moves are unaffected. | 171 // Confirm the actual mouse moves are unaffected. |
| 172 gfx::Point location_real_mouse_move(13, 14); | |
| 165 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, | 173 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, |
| 166 gfx::Point(13, 14), | 174 location_real_mouse_move, |
| 167 gfx::Point(13, 14), | 175 location_real_mouse_move, |
| 168 0, | 176 0, |
| 169 0); | 177 0); |
| 170 generator.Dispatch(&mouse_move); | 178 generator.Dispatch(&mouse_move); |
| 171 generator.ReleaseTouch(); | 179 generator.ReleaseTouch(); |
| 172 | 180 |
| 173 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); | 181 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
| 174 ScopedVector<ui::LocatedEvent>::const_iterator it; | 182 ScopedVector<ui::LocatedEvent>::const_iterator it; |
| 175 // TODO(mfomitchev): mouse enter/exit events | 183 // TODO(mfomitchev): mouse enter/exit events |
| 176 int num_mouse_moves = 0; | 184 int num_mouse_moves = 0; |
| 177 for (it = captured_events.begin(); it != captured_events.end(); ++it) { | 185 for (it = captured_events.begin(); it != captured_events.end(); ++it) { |
| 178 int type = (*it)->type(); | 186 int type = (*it)->type(); |
| 179 // Ignore enter and exit mouse events synthesized when the mouse cursor is | 187 // Ignore enter and exit mouse events synthesized when the mouse cursor is |
| 180 // shown or hidden. | 188 // shown or hidden. |
| 181 if (type == ui::ET_MOUSE_ENTERED || type == ui::ET_MOUSE_EXITED) | 189 if (type == ui::ET_MOUSE_ENTERED || type == ui::ET_MOUSE_EXITED) |
| 182 continue; | 190 continue; |
| 183 EXPECT_EQ(ui::ET_MOUSE_MOVED, (*it)->type()); | 191 EXPECT_EQ(ui::ET_MOUSE_MOVED, (*it)->type()); |
| 184 if (num_mouse_moves == 0) | 192 |
| 185 EXPECT_EQ(location_start, (*it)->location()); | 193 if (num_mouse_moves == 0) { |
|
mfomitchev
2014/05/28 17:47:45
I think there should be a synthesized mouse move a
dmazzoni
2014/05/31 06:53:24
Agreed, you see all of those now.
(The one for th
| |
| 186 if (num_mouse_moves == 1 || num_mouse_moves == 3) | |
| 187 EXPECT_EQ(location_end, (*it)->location()); | 194 EXPECT_EQ(location_end, (*it)->location()); |
| 188 if (num_mouse_moves == 2) | |
| 189 CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(*it, &mouse_move); | |
| 190 if (num_mouse_moves != 2) { | |
| 191 EXPECT_TRUE((*it)->flags() & ui::EF_IS_SYNTHESIZED); | 195 EXPECT_TRUE((*it)->flags() & ui::EF_IS_SYNTHESIZED); |
| 192 EXPECT_TRUE((*it)->flags() & ui::EF_FROM_TOUCH); | 196 EXPECT_TRUE((*it)->flags() & ui::EF_FROM_TOUCH); |
| 193 } | 197 } |
| 198 if (num_mouse_moves == 1) { | |
| 199 EXPECT_EQ(location_real_mouse_move, (*it)->location()); | |
| 200 CONFIRM_EVENTS_ARE_MOUSE_AND_EQUAL(*it, &mouse_move); | |
| 201 } | |
| 202 | |
| 194 num_mouse_moves++; | 203 num_mouse_moves++; |
| 195 } | 204 } |
| 196 EXPECT_EQ(4, num_mouse_moves); | 205 EXPECT_EQ(2, num_mouse_moves); |
| 197 } | 206 } |
| 198 | 207 |
| 199 // Turn the touch exploration mode on in the middle of the touch gesture. | 208 // Turn the touch exploration mode on in the middle of the touch gesture. |
| 200 // Confirm that events from the finger which was touching when the mode was | 209 // Confirm that events from the finger which was touching when the mode was |
| 201 // turned on don't get rewritten. | 210 // turned on don't get rewritten. |
| 202 TEST_F(TouchExplorationTest, TurnOnMidTouch) { | 211 TEST_F(TouchExplorationTest, TurnOnMidTouch) { |
| 203 SwitchTouchExplorationMode(false); | 212 SwitchTouchExplorationMode(false); |
| 204 cursor_client()->ShowCursor(); | 213 cursor_client()->ShowCursor(); |
| 205 cursor_client()->DisableMouseEvents(); | 214 cursor_client()->DisableMouseEvents(); |
| 206 aura::test::EventGenerator generator(root_window()); | 215 aura::test::EventGenerator generator(root_window()); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 for (it = captured_events.begin(); it != captured_events.end(); ++it) { | 459 for (it = captured_events.begin(); it != captured_events.end(); ++it) { |
| 451 if ((*it)->type() == ui::ET_MOUSE_MOVED) { | 460 if ((*it)->type() == ui::ET_MOUSE_MOVED) { |
| 452 EXPECT_EQ(touch3_location, (*it)->location()); | 461 EXPECT_EQ(touch3_location, (*it)->location()); |
| 453 break; | 462 break; |
| 454 } | 463 } |
| 455 } | 464 } |
| 456 EXPECT_NE(captured_events.end(), it); | 465 EXPECT_NE(captured_events.end(), it); |
| 457 } | 466 } |
| 458 | 467 |
| 459 } // namespace ui | 468 } // namespace ui |
| OLD | NEW |