OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 28 command_line->AppendSwitch(ash::switches::kAshEnableTouchExplorationMode); |
| 29 } |
| 30 |
| 31 protected: |
| 32 void SwitchTouchExplorationMode(bool on) { |
| 33 ash::AccessibilityDelegate* ad = |
| 34 ash::Shell::GetInstance()->accessibility_delegate(); |
| 35 if (on != ad->IsSpokenFeedbackEnabled()) |
| 36 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); |
| 37 } |
| 38 |
| 39 private: |
| 40 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
| 41 }; |
| 42 |
| 43 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, PRE_ToggleOnOff) { |
| 44 // TODO (mfomitchev): If the test is run by itself, there is a resize at the |
| 45 // very beginning. An in-progress resize creates a "resize lock" in |
| 46 // RenderWidgetHostViewAura, which calls |
| 47 // WindowEventDispatcher::HoldPointerMoves(), which prevents mouse events from |
| 48 // coming through. Adding a PRE_ test ensures the resize completes before the |
| 49 // actual test is executed. sadrul@ says the resize shouldn't be even |
| 50 // happening, so this needs to be looked at further. |
| 51 } |
| 52 |
| 53 // This test turns the touch exploration mode on/off and confirms that events |
| 54 // get rewritten when the touch exploration mode is on, and aren't affected |
| 55 // after the touch exploration mode is turned off. |
| 56 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { |
| 57 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); |
| 58 scoped_ptr<ui::test::TestEventHandler> |
| 59 event_handler(new ui::test::TestEventHandler()); |
| 60 root_window->AddPreTargetHandler(event_handler.get()); |
| 61 SwitchTouchExplorationMode(true); |
| 62 aura::test::EventGenerator generator(root_window); |
| 63 |
| 64 generator.PressTouchId(1); |
| 65 // Number of mouse events may be greater than 1 because of ET_MOUSE_ENTERED. |
| 66 EXPECT_GT(event_handler->num_mouse_events(), 0); |
| 67 EXPECT_EQ(0, event_handler->num_touch_events()); |
| 68 event_handler->Reset(); |
| 69 |
| 70 SwitchTouchExplorationMode(false); |
| 71 generator.MoveTouchId(gfx::Point(11, 12), 1); |
| 72 EXPECT_EQ(0, event_handler->num_mouse_events()); |
| 73 EXPECT_EQ(1, event_handler->num_touch_events()); |
| 74 event_handler->Reset(); |
| 75 |
| 76 SwitchTouchExplorationMode(true); |
| 77 generator.PressTouchId(2); |
| 78 EXPECT_GT(event_handler->num_mouse_events(), 0); |
| 79 EXPECT_EQ(0, event_handler->num_touch_events()); |
| 80 |
| 81 SwitchTouchExplorationMode(false); |
| 82 root_window->RemovePreTargetHandler(event_handler.get()); |
| 83 } |
| 84 |
| 85 } // namespace ui |
OLD | NEW |