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