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" |
| 11 #include "base/time/time.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" |
15 #include "ui/aura/test/event_generator.h" | 17 #include "ui/aura/test/event_generator.h" |
16 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
17 #include "ui/compositor/compositor.h" | 19 #include "ui/compositor/compositor.h" |
18 #include "ui/compositor/test/draw_waiter_for_test.h" | 20 #include "ui/compositor/test/draw_waiter_for_test.h" |
| 21 #include "ui/events/event.h" |
| 22 #include "ui/events/event_utils.h" |
19 #include "ui/events/test/test_event_handler.h" | 23 #include "ui/events/test/test_event_handler.h" |
20 | 24 |
21 namespace ui { | 25 namespace ui { |
22 | 26 |
23 class TouchExplorationTest : public InProcessBrowserTest { | 27 class TouchExplorationTest : public InProcessBrowserTest { |
24 public: | 28 public: |
25 TouchExplorationTest() {} | 29 TouchExplorationTest() : simulated_clock_(new base::SimpleTestTickClock()) { |
| 30 // Tests fail if time is ever 0. |
| 31 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(10)); |
| 32 } |
26 virtual ~TouchExplorationTest() {} | 33 virtual ~TouchExplorationTest() {} |
27 | 34 |
28 protected: | 35 protected: |
29 void SwitchTouchExplorationMode(bool on) { | 36 void SwitchTouchExplorationMode(bool on) { |
30 ash::AccessibilityDelegate* ad = | 37 ash::AccessibilityDelegate* ad = |
31 ash::Shell::GetInstance()->accessibility_delegate(); | 38 ash::Shell::GetInstance()->accessibility_delegate(); |
32 if (on != ad->IsSpokenFeedbackEnabled()) | 39 if (on != ad->IsSpokenFeedbackEnabled()) |
33 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); | 40 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); |
34 } | 41 } |
35 | 42 |
| 43 base::TimeDelta Now() { |
| 44 return base::TimeDelta::FromInternalValue( |
| 45 simulated_clock_->NowTicks().ToInternalValue()); |
| 46 } |
| 47 |
| 48 ui::GestureDetector::Config gesture_detector_config_; |
| 49 base::SimpleTestTickClock* simulated_clock_; |
| 50 |
36 private: | 51 private: |
37 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 52 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
38 }; | 53 }; |
39 | 54 |
40 // This test turns the touch exploration mode on/off and confirms that events | 55 // 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 | 56 // get rewritten when the touch exploration mode is on, and aren't affected |
42 // after the touch exploration mode is turned off. | 57 // after the touch exploration mode is turned off. |
43 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { | 58 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { |
44 // The RenderView for WebContents is created as a result of the navigation | 59 // 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 | 60 // 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 | 61 // involves sending a resize message to the renderer process. Here we wait |
47 // for the resize ack to be received, because currently WindowEventDispatcher | 62 // for the resize ack to be received, because currently WindowEventDispatcher |
48 // has code to hold touch and mouse move events until resize is complete | 63 // has code to hold touch and mouse move events until resize is complete |
49 // (crbug.com/384342) which interferes with this test. | 64 // (crbug.com/384342) which interferes with this test. |
50 content::WebContents* web_contents = | 65 content::WebContents* web_contents = |
51 browser()->tab_strip_model()->GetActiveWebContents(); | 66 browser()->tab_strip_model()->GetActiveWebContents(); |
52 content::WaitForResizeComplete(web_contents); | 67 content::WaitForResizeComplete(web_contents); |
53 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); | 68 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); |
54 scoped_ptr<ui::test::TestEventHandler> | 69 scoped_ptr<ui::test::TestEventHandler> |
55 event_handler(new ui::test::TestEventHandler()); | 70 event_handler(new ui::test::TestEventHandler()); |
56 root_window->AddPreTargetHandler(event_handler.get()); | 71 root_window->AddPreTargetHandler(event_handler.get()); |
57 SwitchTouchExplorationMode(true); | 72 SwitchTouchExplorationMode(true); |
58 aura::test::EventGenerator generator(root_window); | 73 aura::test::EventGenerator generator(root_window); |
59 | 74 |
60 generator.set_current_location(gfx::Point(100, 200)); | 75 base::TimeDelta initial_time = Now(); |
61 generator.PressTouchId(1); | 76 ui::TouchEvent initial_press( |
| 77 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); |
| 88 |
62 // Since the touch exploration controller doesn't know if the user is | 89 // Since the touch exploration controller doesn't know if the user is |
63 // double-tapping or not, touch exploration is only initiated if the | 90 // 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"), | 91 // user moves more than 8 pixels away from the initial location (the "slop"), |
65 // or after 300 ms has elapsed. | 92 // or after 300 ms has elapsed if the finger does not move fast enough. |
66 generator.MoveTouchId(gfx::Point(109, 209), 1); | 93 generator.Dispatch(&touch_move); |
| 94 |
67 // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED. | 95 // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED. |
68 EXPECT_GT(event_handler->num_mouse_events(), 0); | 96 EXPECT_GT(event_handler->num_mouse_events(), 0); |
69 EXPECT_EQ(0, event_handler->num_touch_events()); | 97 EXPECT_EQ(0, event_handler->num_touch_events()); |
70 event_handler->Reset(); | 98 event_handler->Reset(); |
71 | 99 |
72 SwitchTouchExplorationMode(false); | 100 SwitchTouchExplorationMode(false); |
73 generator.MoveTouchId(gfx::Point(11, 12), 1); | 101 generator.MoveTouchId(gfx::Point(11, 12), 1); |
74 EXPECT_EQ(0, event_handler->num_mouse_events()); | 102 EXPECT_EQ(0, event_handler->num_mouse_events()); |
75 EXPECT_EQ(1, event_handler->num_touch_events()); | 103 EXPECT_EQ(1, event_handler->num_touch_events()); |
76 event_handler->Reset(); | 104 event_handler->Reset(); |
77 | 105 |
78 SwitchTouchExplorationMode(true); | 106 SwitchTouchExplorationMode(true); |
79 generator.set_current_location(gfx::Point(500, 600)); | 107 initial_time = Now(); |
80 generator.PressTouchId(2); | 108 ui::TouchEvent second_initial_press( |
81 generator.MoveTouchId(gfx::Point(509, 609), 2); | 109 ui::ET_TOUCH_PRESSED, gfx::Point(500, 600), 2, initial_time); |
| 110 delta_time = |
| 111 (second_initial_press.location() - gfx::Point(509, 609)).Length() / |
| 112 gesture_detector_config_.minimum_swipe_velocity; |
| 113 ui::TouchEvent second_move( |
| 114 ui::ET_TOUCH_MOVED, |
| 115 gfx::Point(509, 609), |
| 116 2, |
| 117 initial_time + base::TimeDelta::FromSecondsD(delta_time)); |
| 118 |
| 119 generator.Dispatch(&second_initial_press); |
| 120 generator.Dispatch(&second_move); |
82 EXPECT_GT(event_handler->num_mouse_events(), 0); | 121 EXPECT_GT(event_handler->num_mouse_events(), 0); |
83 EXPECT_EQ(0, event_handler->num_touch_events()); | 122 EXPECT_EQ(0, event_handler->num_touch_events()); |
84 | 123 |
85 SwitchTouchExplorationMode(false); | 124 SwitchTouchExplorationMode(false); |
86 root_window->RemovePreTargetHandler(event_handler.get()); | 125 root_window->RemovePreTargetHandler(event_handler.get()); |
87 } | 126 } |
88 | 127 |
89 } // namespace ui | 128 } // namespace ui |
OLD | NEW |