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/root_window_controller.h" | |
8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "base/test/simple_test_tick_clock.h" | |
10 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
14 #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" | |
15 #include "ui/aura/test/event_generator.h" | 18 #include "ui/aura/test/event_generator.h" |
16 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
17 #include "ui/compositor/compositor.h" | 20 #include "ui/compositor/compositor.h" |
18 #include "ui/compositor/test/draw_waiter_for_test.h" | 21 #include "ui/compositor/test/draw_waiter_for_test.h" |
19 #include "ui/events/test/test_event_handler.h" | 22 #include "ui/events/test/test_event_handler.h" |
20 | 23 |
21 namespace ui { | 24 namespace ui { |
22 | 25 |
23 class TouchExplorationTest : public InProcessBrowserTest { | 26 class TouchExplorationTest : public InProcessBrowserTest { |
24 public: | 27 public: |
25 TouchExplorationTest() {} | 28 TouchExplorationTest() |
29 : simulated_clock_(new base::SimpleTestTickClock()) {} | |
26 virtual ~TouchExplorationTest() {} | 30 virtual ~TouchExplorationTest() {} |
27 | |
28 protected: | 31 protected: |
29 void SwitchTouchExplorationMode(bool on) { | 32 void SwitchTouchExplorationMode(bool on) { |
30 ash::AccessibilityDelegate* ad = | 33 ash::AccessibilityDelegate* ad = |
31 ash::Shell::GetInstance()->accessibility_delegate(); | 34 ash::Shell::GetInstance()->accessibility_delegate(); |
32 if (on != ad->IsSpokenFeedbackEnabled()) | 35 if (on != ad->IsSpokenFeedbackEnabled()) |
33 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); | 36 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); |
34 } | 37 } |
38 ui::GestureDetector::Config gesture_detector_config_; | |
39 // Owned by |generator|. | |
40 base::SimpleTestTickClock* simulated_clock_; | |
35 | 41 |
36 private: | 42 private: |
37 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 43 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
38 }; | 44 }; |
39 | 45 |
40 // This test turns the touch exploration mode on/off and confirms that events | 46 // This test turns the touch exploration mode on/off and confirms that events |
41 // get rewritten when the touch exploration mode is on, and aren't affected | 47 // get rewritten when the touch exploration mode is on, and aren't affected |
42 // after the touch exploration mode is turned off. | 48 // after the touch exploration mode is turned off. |
43 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { | 49 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { |
44 // The RenderView for WebContents is created as a result of the navigation | 50 // The RenderView for WebContents is created as a result of the navigation |
45 // to the New Tab page which is done as part of the test SetUp. The creation | 51 // to the New Tab page which is done as part of the test SetUp. The creation |
46 // involves sending a resize message to the renderer process. Here we wait | 52 // involves sending a resize message to the renderer process. Here we wait |
47 // for the resize ack to be received, because currently WindowEventDispatcher | 53 // for the resize ack to be received, because currently WindowEventDispatcher |
48 // has code to hold touch and mouse move events until resize is complete | 54 // has code to hold touch and mouse move events until resize is complete |
55 | |
49 // (crbug.com/384342) which interferes with this test. | 56 // (crbug.com/384342) which interferes with this test. |
50 content::WebContents* web_contents = | 57 content::WebContents* web_contents = |
51 browser()->tab_strip_model()->GetActiveWebContents(); | 58 browser()->tab_strip_model()->GetActiveWebContents(); |
52 content::WaitForResizeComplete(web_contents); | 59 content::WaitForResizeComplete(web_contents); |
53 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); | 60 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); |
54 scoped_ptr<ui::test::TestEventHandler> | 61 scoped_ptr<ui::test::TestEventHandler> event_handler( |
55 event_handler(new ui::test::TestEventHandler()); | 62 new ui::test::TestEventHandler()); |
56 root_window->AddPreTargetHandler(event_handler.get()); | 63 root_window->AddPreTargetHandler(event_handler.get()); |
57 SwitchTouchExplorationMode(true); | 64 SwitchTouchExplorationMode(true); |
58 aura::test::EventGenerator generator(root_window); | 65 aura::test::EventGenerator generator(root_window); |
59 | 66 |
60 generator.set_current_location(gfx::Point(100, 200)); | 67 generator.set_current_location(gfx::Point(100, 200)); |
61 generator.PressTouchId(1); | 68 generator.PressTouchId(1); |
62 // Since the touch exploration controller doesn't know if the user is | 69 // Since the touch exploration controller doesn't know if the user is |
63 // double-tapping or not, touch exploration is only initiated if the | 70 // double-tapping or not, touch exploration is only initiated if the |
64 // user moves more than 8 pixels away from the initial location (the "slop"), | 71 // user moves more than 8 pixels away from the initial location (the "slop"), |
65 // or after 300 ms has elapsed. | 72 // or after 300 ms has elapsed. |
(...skipping 13 matching lines...) Expand all Loading... | |
79 generator.set_current_location(gfx::Point(500, 600)); | 86 generator.set_current_location(gfx::Point(500, 600)); |
80 generator.PressTouchId(2); | 87 generator.PressTouchId(2); |
81 generator.MoveTouchId(gfx::Point(509, 609), 2); | 88 generator.MoveTouchId(gfx::Point(509, 609), 2); |
82 EXPECT_GT(event_handler->num_mouse_events(), 0); | 89 EXPECT_GT(event_handler->num_mouse_events(), 0); |
83 EXPECT_EQ(0, event_handler->num_touch_events()); | 90 EXPECT_EQ(0, event_handler->num_touch_events()); |
84 | 91 |
85 SwitchTouchExplorationMode(false); | 92 SwitchTouchExplorationMode(false); |
86 root_window->RemovePreTargetHandler(event_handler.get()); | 93 root_window->RemovePreTargetHandler(event_handler.get()); |
87 } | 94 } |
88 | 95 |
96 | |
97 // This test makes sure that after the user clicks with split tap, | |
98 // they continue to touch exploration mode if the original touch exploration | |
99 // finger is still on the screen. | |
100 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, SplitTapExplore) { | |
101 content::WebContents* web_contents = | |
102 browser()->tab_strip_model()->GetActiveWebContents(); | |
103 content::WaitForResizeComplete(web_contents); | |
104 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); | |
105 scoped_ptr<ui::test::TestEventHandler> | |
106 event_handler(new ui::test::TestEventHandler()); | |
107 root_window->AddPreTargetHandler(event_handler.get()); | |
108 SwitchTouchExplorationMode(true); | |
109 aura::test::EventGenerator generator(root_window); | |
110 aura::client::CursorClient* cursor_client = | |
111 aura::client::GetCursorClient(root_window); | |
112 | |
113 // Mouse events should show the cursor. | |
114 generator.MoveMouseTo(gfx::Point(30, 31)); | |
115 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
116 EXPECT_TRUE(cursor_client->IsCursorVisible()); | |
117 | |
118 // After a press the cursor should be shown after immediately after press, | |
119 // hidden after move. | |
120 generator.set_current_location(gfx::Point(100, 200)); | |
121 generator.PressTouchId(1); | |
122 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
123 EXPECT_TRUE(cursor_client->IsCursorVisible()); | |
124 // Initiate touch explore by moving out of the slop. | |
125 generator.MoveTouchId(gfx::Point(109, 209), 1); | |
126 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
127 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
128 event_handler->Reset(); | |
129 | |
130 // Press and release with a second finger for split tap. This should send | |
131 // touch press and release events which should send a click press and release. | |
132 // Once the press is passed through, mouse events should be disabled. | |
133 // Mouse events are reenabled after the release. | |
134 generator.set_current_location(gfx::Point(102, 202)); | |
135 generator.PressTouchId(2); | |
136 EXPECT_FALSE(cursor_client->IsMouseEventsEnabled()); | |
137 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
138 generator.ReleaseTouchId(2); | |
139 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
140 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
141 EXPECT_EQ(2, event_handler->num_touch_events()); | |
142 event_handler->Reset(); | |
143 | |
144 // Continuing to move the touch exploration finger should send more mouse | |
145 // events. | |
146 generator.MoveTouchId(gfx::Point(509, 609), 1); | |
147 EXPECT_EQ(0, event_handler->num_touch_events()); | |
148 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
149 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
150 | |
151 SwitchTouchExplorationMode(false); | |
152 root_window->RemovePreTargetHandler(event_handler.get()); | |
153 } | |
154 | |
155 // This test checks that the cursor is hidden after a user presses and waits | |
156 // for 300ms, which generates a mouse move. | |
157 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, PressMouseMove) { | |
158 content::WebContents* web_contents = | |
159 browser()->tab_strip_model()->GetActiveWebContents(); | |
160 content::WaitForResizeComplete(web_contents); | |
mfomitchev
2014/07/02 16:46:47
Can you please put this setup logic into SetupOnMa
| |
161 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); | |
162 scoped_ptr<ui::test::TestEventHandler> | |
163 event_handler(new ui::test::TestEventHandler()); | |
164 root_window->AddPreTargetHandler(event_handler.get()); | |
165 SwitchTouchExplorationMode(true); | |
166 ash::RootWindowController* root_window_controller = | |
167 ash::GetRootWindowController(root_window); | |
168 ui::TouchExplorationController* touch_exploration_controller = | |
169 root_window_controller->GetTouchExplorationController(); | |
170 aura::test::EventGenerator generator(root_window); | |
171 aura::client::CursorClient* cursor_client = | |
172 aura::client::GetCursorClient(root_window); | |
173 generator.SetTickClock(scoped_ptr<base::TickClock>(simulated_clock_)); | |
mfomitchev
2014/07/02 16:46:47
I'd just make simulated_clock_ into a local variab
| |
174 | |
175 | |
176 | |
177 generator.set_current_location(gfx::Point(100, 200)); | |
178 generator.PressTouchId(1); | |
179 simulated_clock_->Advance(gesture_detector_config_.double_tap_timeout); | |
180 touch_exploration_controller->CallTapTimerNowForTesting(); | |
181 | |
182 // A single touch and release will send a mouse move to that location. | |
183 EXPECT_EQ(0, event_handler->num_touch_events()); | |
184 EXPECT_GT(event_handler->num_mouse_events(), 0); | |
185 EXPECT_TRUE(cursor_client->IsMouseEventsEnabled()); | |
186 EXPECT_FALSE(cursor_client->IsCursorVisible()); | |
187 | |
188 SwitchTouchExplorationMode(false); | |
189 root_window->RemovePreTargetHandler(event_handler.get()); | |
190 } | |
191 | |
89 } // namespace ui | 192 } // namespace ui |
OLD | NEW |