Home | History | Annotate | Download | only in accessibility
      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
      3 // found in the LICENSE file.
      4 
      5 #include "ui/chromeos/touch_exploration_controller.h"
      6 
      7 #include "ash/accessibility_delegate.h"
      8 #include "ash/ash_switches.h"
      9 #include "ash/shell.h"
     10 #include "ash/test/ash_test_base.h"
     11 #include "base/command_line.h"
     12 #include "chrome/test/base/in_process_browser_test.h"
     13 #include "chrome/test/base/ui_test_utils.h"
     14 #include "ui/aura/test/event_generator.h"
     15 #include "ui/aura/window_tree_host.h"
     16 #include "ui/compositor/compositor.h"
     17 #include "ui/compositor/test/draw_waiter_for_test.h"
     18 #include "ui/events/test/test_event_handler.h"
     19 
     20 namespace ui {
     21 
     22 class TouchExplorationTest : public InProcessBrowserTest {
     23  public:
     24   TouchExplorationTest() {}
     25   virtual ~TouchExplorationTest() {}
     26 
     27  protected:
     28   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE {
     29     base::CommandLine::ForCurrentProcess()->AppendSwitch(
     30         ash::switches::kAshEnableTouchExplorationMode);
     31   }
     32 
     33   void SwitchTouchExplorationMode(bool on) {
     34     ash::AccessibilityDelegate* ad =
     35         ash::Shell::GetInstance()->accessibility_delegate();
     36     if (on != ad->IsSpokenFeedbackEnabled())
     37       ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE);
     38   }
     39 
     40 private:
     41   DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest);
     42 };
     43 
     44 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, PRE_ToggleOnOff) {
     45   // TODO (mfomitchev): If the test is run by itself, there is a resize at the
     46   //  very beginning. An in-progress resize creates a "resize lock" in
     47   // RenderWidgetHostViewAura, which calls
     48   // WindowEventDispatcher::HoldPointerMoves(), which prevents mouse events from
     49   // coming through. Adding a PRE_ test ensures the resize completes before the
     50   // actual test is executed. sadrul@ says the resize shouldn't be even
     51   // happening, so this needs to be looked at further.
     52 }
     53 
     54 // This test turns the touch exploration mode on/off and confirms that events
     55 // get rewritten when the touch exploration mode is on, and aren't affected
     56 // after the touch exploration mode is turned off.
     57 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) {
     58   aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
     59   scoped_ptr<ui::test::TestEventHandler>
     60       event_handler(new ui::test::TestEventHandler());
     61   root_window->AddPreTargetHandler(event_handler.get());
     62   SwitchTouchExplorationMode(true);
     63   aura::test::EventGenerator generator(root_window);
     64 
     65   generator.set_current_location(gfx::Point(100, 200));
     66   generator.PressTouchId(1);
     67   // Since the touch exploration controller doesn't know if the user is
     68   // double-tapping or not, touch exploration is only initiated if the
     69   // user moves more than 8 pixels away from the initial location (the "slop"),
     70   // or after 300 ms has elapsed.
     71   generator.MoveTouchId(gfx::Point(109, 209), 1);
     72   // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED.
     73   EXPECT_GT(event_handler->num_mouse_events(), 0);
     74   EXPECT_EQ(0, event_handler->num_touch_events());
     75   event_handler->Reset();
     76 
     77   SwitchTouchExplorationMode(false);
     78   generator.MoveTouchId(gfx::Point(11, 12), 1);
     79   EXPECT_EQ(0, event_handler->num_mouse_events());
     80   EXPECT_EQ(1, event_handler->num_touch_events());
     81   event_handler->Reset();
     82 
     83   SwitchTouchExplorationMode(true);
     84   generator.set_current_location(gfx::Point(500, 600));
     85   generator.PressTouchId(2);
     86   generator.MoveTouchId(gfx::Point(509, 609), 2);
     87   EXPECT_GT(event_handler->num_mouse_events(), 0);
     88   EXPECT_EQ(0, event_handler->num_touch_events());
     89 
     90   SwitchTouchExplorationMode(false);
     91   root_window->RemovePreTargetHandler(event_handler.get());
     92 }
     93 
     94 }  // namespace ui
     95