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 "ash/accessibility_delegate.h" | 7 #include "ash/accessibility_delegate.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 17 #include "ui/aura/client/cursor_client.h" | |
| 17 #include "ui/aura/test/event_generator.h" | 18 #include "ui/aura/test/event_generator.h" |
| 18 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/compositor/compositor.h" | 20 #include "ui/compositor/compositor.h" |
| 20 #include "ui/compositor/test/draw_waiter_for_test.h" | 21 #include "ui/compositor/test/draw_waiter_for_test.h" |
| 21 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 22 #include "ui/events/event_utils.h" | 23 #include "ui/events/event_utils.h" |
| 23 #include "ui/events/test/test_event_handler.h" | 24 #include "ui/events/test/test_event_handler.h" |
| 24 | 25 |
| 25 namespace ui { | 26 namespace ui { |
| 26 | 27 |
| 27 class TouchExplorationTest : public InProcessBrowserTest { | 28 class TouchExplorationTest : public InProcessBrowserTest { |
| 28 public: | 29 public: |
| 29 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { | 30 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { |
| 30 // Tests fail if time is ever 0. | 31 // Tests fail if time is ever 0. |
| 31 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); | 32 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
| 32 } | 33 } |
| 33 virtual ~TouchExplorationTest() {} | 34 virtual ~TouchExplorationTest() {} |
| 34 | 35 |
| 35 protected: | 36 protected: |
| 37 virtual void SetUpOnMainThread() OVERRIDE { | |
| 38 // The RenderView for WebContents is created as a result of the | |
| 39 // navigation to the New Tab page which is done as part of the test | |
| 40 // SetUp. The creation involves sending a resize message to the renderer | |
| 41 // process. Here we wait for the resize ack to be received, because | |
| 42 // currently WindowEventDispatcher has code to hold touch and mouse | |
| 43 // move events until resize is complete (crbug.com/384342) which | |
| 44 // interferes with this test. | |
| 45 content::WebContents* web_contents = | |
| 46 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 47 content::WaitForResizeComplete(web_contents); | |
| 48 root_window_ = ash::Shell::GetInstance()->GetPrimaryRootWindow(); | |
| 49 event_handler_.reset(new ui::test::TestEventHandler()); | |
| 50 root_window_->AddPreTargetHandler(event_handler_.get()); | |
| 51 } | |
| 52 | |
| 53 virtual void CleanUpOnMainThread() OVERRIDE { | |
| 54 SwitchTouchExplorationMode(false); | |
| 55 root_window_->RemovePreTargetHandler(event_handler_.get()); | |
| 56 } | |
| 57 | |
| 36 void SwitchTouchExplorationMode(bool on) { | 58 void SwitchTouchExplorationMode(bool on) { |
| 37 ash::AccessibilityDelegate* ad = | 59 ash::AccessibilityDelegate* ad = |
| 38 ash::Shell::GetInstance()->accessibility_delegate(); | 60 ash::Shell::GetInstance()->accessibility_delegate(); |
| 39 if (on != ad->IsSpokenFeedbackEnabled()) | 61 if (on != ad->IsSpokenFeedbackEnabled()) |
| 40 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); | 62 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); |
| 41 } | 63 } |
| 42 | 64 |
| 43 base::TimeDelta Now() { | 65 base::TimeDelta Now() { |
| 44 return base::TimeDelta::FromInternalValue( | 66 return base::TimeDelta::FromInternalValue( |
| 45 simulated_clock_->NowTicks().ToInternalValue()); | 67 simulated_clock_->NowTicks().ToInternalValue()); |
| 46 } | 68 } |
| 47 | 69 |
| 48 ui::GestureDetector::Config gesture_detector_config_; | 70 ui::GestureDetector::Config gesture_detector_config_; |
| 49 base::SimpleTestTickClock* simulated_clock_; | 71 base::SimpleTestTickClock* simulated_clock_; |
| 72 aura::Window* root_window_; | |
| 73 scoped_ptr<ui::test::TestEventHandler> event_handler_; | |
| 50 | 74 |
| 51 private: | 75 private: |
| 52 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 76 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
| 53 }; | 77 }; |
| 54 | 78 |
| 55 // This test turns the touch exploration mode on/off and confirms that events | 79 // This test turns the touch exploration mode on/off and confirms that events |
| 56 // get rewritten when the touch exploration mode is on, and aren't affected | 80 // get rewritten when the touch exploration mode is on, and aren't affected |
| 57 // after the touch exploration mode is turned off. | 81 // after the touch exploration mode is turned off. |
| 58 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { | 82 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { |
| 59 // The RenderView for WebContents is created as a result of the navigation | |
| 60 // to the New Tab page which is done as part of the test SetUp. The creation | |
| 61 // involves sending a resize message to the renderer process. Here we wait | |
| 62 // for the resize ack to be received, because currently WindowEventDispatcher | |
| 63 // has code to hold touch and mouse move events until resize is complete | |
| 64 // (crbug.com/384342) which interferes with this test. | |
| 65 content::WebContents* web_contents = | |
| 66 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 67 content::WaitForResizeComplete(web_contents); | |
| 68 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); | |
| 69 scoped_ptr<ui::test::TestEventHandler> | |
| 70 event_handler(new ui::test::TestEventHandler()); | |
| 71 root_window->AddPreTargetHandler(event_handler.get()); | |
| 72 SwitchTouchExplorationMode(true); | 83 SwitchTouchExplorationMode(true); |
| 73 aura::test::EventGenerator generator(root_window); | 84 aura::test::EventGenerator generator(root_window_); |
| 74 | 85 |
| 75 base::TimeDelta initial_time = Now(); | 86 base::TimeDelta initial_time = Now(); |
| 76 ui::TouchEvent initial_press( | 87 ui::TouchEvent initial_press( |
| 77 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); | 88 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); |
| 78 float delta_time = | |
| 79 (initial_press.location() - gfx::Point(109,209)).Length() / | |
| 80 gesture_detector_config_.minimum_swipe_velocity; | |
| 81 ui::TouchEvent touch_move( | |
| 82 ui::ET_TOUCH_MOVED, | |
| 83 gfx::Point(109, 209), | |
| 84 1, | |
| 85 initial_time + base::TimeDelta::FromSecondsD(delta_time)); | |
| 86 | |
| 87 generator.Dispatch(&initial_press); | 89 generator.Dispatch(&initial_press); |
| 88 | 90 |
| 89 // Since the touch exploration controller doesn't know if the user is | 91 // Since the touch exploration controller doesn't know if the user is |
| 90 // double-tapping or not, touch exploration is only initiated if the | 92 // double-tapping or not, touch exploration is only initiated if the |
| 91 // user moves more than 8 pixels away from the initial location (the "slop"), | 93 // 300 ms has elapsed and the finger does not move fast enough to begin |
| 92 // or after 300 ms has elapsed if the finger does not move fast enough. | 94 // gestures. |
| 95 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED, | |
| 96 gfx::Point(100, 200), | |
| 97 1, | |
| 98 initial_time + | |
| 99 gesture_detector_config_.double_tap_timeout + | |
| 100 base::TimeDelta::FromMilliseconds(1)); | |
| 93 generator.Dispatch(&touch_move); | 101 generator.Dispatch(&touch_move); |
| 94 | 102 |
| 95 // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED. | 103 // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED. |
| 96 EXPECT_GT(event_handler->num_mouse_events(), 0); | 104 EXPECT_GT(event_handler_->num_mouse_events(), 0); |
| 97 EXPECT_EQ(0, event_handler->num_touch_events()); | 105 EXPECT_EQ(0, event_handler_->num_touch_events()); |
| 98 event_handler->Reset(); | 106 event_handler_->Reset(); |
| 99 | 107 |
| 100 SwitchTouchExplorationMode(false); | 108 SwitchTouchExplorationMode(false); |
| 101 generator.MoveTouchId(gfx::Point(11, 12), 1); | 109 generator.MoveTouchId(gfx::Point(11, 12), 1); |
| 102 EXPECT_EQ(0, event_handler->num_mouse_events()); | 110 EXPECT_EQ(0, event_handler_->num_mouse_events()); |
| 103 EXPECT_EQ(1, event_handler->num_touch_events()); | 111 EXPECT_EQ(1, event_handler_->num_touch_events()); |
| 104 event_handler->Reset(); | 112 event_handler_->Reset(); |
| 105 | 113 |
| 106 SwitchTouchExplorationMode(true); | 114 SwitchTouchExplorationMode(true); |
| 107 initial_time = Now(); | 115 initial_time = Now(); |
| 108 ui::TouchEvent second_initial_press( | 116 ui::TouchEvent second_initial_press( |
| 109 ui::ET_TOUCH_PRESSED, gfx::Point(500, 600), 2, initial_time); | 117 ui::ET_TOUCH_PRESSED, gfx::Point(500, 600), 2, initial_time); |
| 110 delta_time = | 118 ui::TouchEvent second_move(ui::ET_TOUCH_MOVED, |
| 111 (second_initial_press.location() - gfx::Point(509, 609)).Length() / | 119 gfx::Point(500, 600), |
| 112 gesture_detector_config_.minimum_swipe_velocity; | 120 2, |
| 113 ui::TouchEvent second_move( | 121 initial_time + |
| 114 ui::ET_TOUCH_MOVED, | 122 gesture_detector_config_.double_tap_timeout + |
| 115 gfx::Point(509, 609), | 123 base::TimeDelta::FromMilliseconds(1)); |
| 116 2, | |
| 117 initial_time + base::TimeDelta::FromSecondsD(delta_time)); | |
| 118 | 124 |
| 119 generator.Dispatch(&second_initial_press); | 125 generator.Dispatch(&second_initial_press); |
| 120 generator.Dispatch(&second_move); | 126 generator.Dispatch(&second_move); |
| 121 EXPECT_GT(event_handler->num_mouse_events(), 0); | 127 EXPECT_GT(event_handler_->num_mouse_events(), 0); |
| 122 EXPECT_EQ(0, event_handler->num_touch_events()); | 128 EXPECT_EQ(0, event_handler_->num_touch_events()); |
| 129 } | |
| 123 | 130 |
| 124 SwitchTouchExplorationMode(false); | 131 // This test makes sure that after the user clicks with split tap, |
| 125 root_window->RemovePreTargetHandler(event_handler.get()); | 132 // they continue to touch exploration mode if the original touch exploration |
| 133 // finger is still on the screen. | |
| 134 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, SplitTapExplore) { | |
| 135 SwitchTouchExplorationMode(true); | |
| 136 aura::test::EventGenerator generator(root_window_); | |
| 137 aura::client::CursorClient* cursor_client = | |
| 138 aura::client::GetCursorClient(root_window_); | |
| 139 | |
| 140 // Mouse events should show the cursor. | |
| 141 generator.MoveMouseTo(gfx::Point(30, 31)); | |
| 142 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
| 143 EXPECT_TRUE(cursor_client->IsCursorVisible()); | |
| 144 | |
| 145 // The cursor should be shown immediately after the press, and hidden | |
| 146 // after the move. | |
| 147 base::TimeDelta initial_time = Now(); | |
| 148 ui::TouchEvent initial_press( | |
| 149 ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time); | |
| 150 generator.Dispatch(&initial_press); | |
| 151 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
| 152 EXPECT_TRUE(cursor_client->IsCursorVisible()); | |
| 153 | |
| 154 // Initiate touch explore by moving out of the slop slowly. | |
| 155 ui::TouchEvent touch_move(ui::ET_TOUCH_MOVED, | |
| 156 gfx::Point(109, 209), | |
| 157 1, | |
| 158 initial_time + | |
| 159 gesture_detector_config_.double_tap_timeout + | |
|
mfomitchev
2014/07/09 19:20:37
Using double_tap_timeout this way doesn't seem rig
evy
2014/07/09 19:36:00
I need to change the comment to "Initiate touch ex
mfomitchev
2014/07/09 20:47:21
I think this is a bit artificial, but not terrible
evy
2014/07/09 21:32:09
I think the only cleaner thing (this might be what
mfomitchev
2014/07/09 21:53:02
I was actually referring to performing a move like
evy
2014/07/10 02:44:20
I'm more comfortable with what I have now, mostly
| |
| 160 base::TimeDelta::FromMilliseconds(1)); | |
| 161 generator.Dispatch(&touch_move); | |
| 162 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
| 163 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
| 164 event_handler_->Reset(); | |
| 165 | |
| 166 // Press and release with a second finger for split tap. This should send | |
| 167 // touch press and release events which should send a click press and release. | |
| 168 // Once the press is passed through, mouse events should be disabled. | |
| 169 // Mouse events are reenabled after the release. | |
| 170 generator.set_current_location(gfx::Point(102, 202)); | |
| 171 generator.PressTouchId(2); | |
| 172 EXPECT_FALSE(cursor_client->IsMouseEventsEnabled()); | |
| 173 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
| 174 generator.ReleaseTouchId(2); | |
| 175 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
| 176 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
| 177 EXPECT_EQ(2, event_handler_->num_touch_events()); | |
| 178 event_handler_->Reset(); | |
| 179 | |
| 180 // Continuing to move the touch exploration finger should send more mouse | |
| 181 // events. | |
| 182 generator.MoveTouchId(gfx::Point(509, 609), 1); | |
| 183 EXPECT_EQ(0, event_handler_->num_touch_events()); | |
| 184 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
| 185 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
| 126 } | 186 } |
| 127 | 187 |
| 128 } // namespace ui | 188 } // namespace ui |
| OLD | NEW |