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 "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/test/browser_test_utils.h" |
12 #include "ui/aura/test/event_generator.h" | 15 #include "ui/aura/test/event_generator.h" |
13 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
14 #include "ui/compositor/compositor.h" | 17 #include "ui/compositor/compositor.h" |
15 #include "ui/compositor/test/draw_waiter_for_test.h" | 18 #include "ui/compositor/test/draw_waiter_for_test.h" |
16 #include "ui/events/test/test_event_handler.h" | 19 #include "ui/events/test/test_event_handler.h" |
17 | 20 |
18 namespace ui { | 21 namespace ui { |
19 | 22 |
20 class TouchExplorationTest : public InProcessBrowserTest { | 23 class TouchExplorationTest : public InProcessBrowserTest { |
21 public: | 24 public: |
22 TouchExplorationTest() {} | 25 TouchExplorationTest() {} |
23 virtual ~TouchExplorationTest() {} | 26 virtual ~TouchExplorationTest() {} |
24 | 27 |
25 protected: | 28 protected: |
26 void SwitchTouchExplorationMode(bool on) { | 29 void SwitchTouchExplorationMode(bool on) { |
27 ash::AccessibilityDelegate* ad = | 30 ash::AccessibilityDelegate* ad = |
28 ash::Shell::GetInstance()->accessibility_delegate(); | 31 ash::Shell::GetInstance()->accessibility_delegate(); |
29 if (on != ad->IsSpokenFeedbackEnabled()) | 32 if (on != ad->IsSpokenFeedbackEnabled()) |
30 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); | 33 ad->ToggleSpokenFeedback(ash::A11Y_NOTIFICATION_NONE); |
31 } | 34 } |
32 | 35 |
33 private: | 36 private: |
34 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); | 37 DISALLOW_COPY_AND_ASSIGN(TouchExplorationTest); |
35 }; | 38 }; |
36 | 39 |
37 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, PRE_ToggleOnOff) { | |
38 // TODO (mfomitchev): If the test is run by itself, there is a resize at the | |
39 // very beginning. An in-progress resize creates a "resize lock" in | |
40 // RenderWidgetHostViewAura, which calls | |
41 // WindowEventDispatcher::HoldPointerMoves(), which prevents mouse events from | |
42 // coming through. Adding a PRE_ test ensures the resize completes before the | |
43 // actual test is executed. sadrul@ says the resize shouldn't be even | |
44 // happening, so this needs to be looked at further. | |
45 } | |
46 | |
47 // 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 |
48 // 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 |
49 // after the touch exploration mode is turned off. | 42 // after the touch exploration mode is turned off. |
50 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { | 43 IN_PROC_BROWSER_TEST_F(TouchExplorationTest, ToggleOnOff) { |
| 44 // 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 |
| 46 // involves sending a resize message to the renderer process. Here we wait |
| 47 // for the resize ack to be received, because currently WindowEventDispatcher |
| 48 // has code to hold touch and mouse move events until resize is complete |
| 49 // (crbug.com/384342) which interferes with this test. |
| 50 content::WebContents* web_contents = |
| 51 browser()->tab_strip_model()->GetActiveWebContents(); |
| 52 content::WaitForResizeComplete(web_contents); |
51 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); | 53 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow(); |
52 scoped_ptr<ui::test::TestEventHandler> | 54 scoped_ptr<ui::test::TestEventHandler> |
53 event_handler(new ui::test::TestEventHandler()); | 55 event_handler(new ui::test::TestEventHandler()); |
54 root_window->AddPreTargetHandler(event_handler.get()); | 56 root_window->AddPreTargetHandler(event_handler.get()); |
55 SwitchTouchExplorationMode(true); | 57 SwitchTouchExplorationMode(true); |
56 aura::test::EventGenerator generator(root_window); | 58 aura::test::EventGenerator generator(root_window); |
57 | 59 |
58 generator.set_current_location(gfx::Point(100, 200)); | 60 generator.set_current_location(gfx::Point(100, 200)); |
59 generator.PressTouchId(1); | 61 generator.PressTouchId(1); |
60 // 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 |
(...skipping 17 matching lines...) Expand all Loading... |
78 generator.PressTouchId(2); | 80 generator.PressTouchId(2); |
79 generator.MoveTouchId(gfx::Point(509, 609), 2); | 81 generator.MoveTouchId(gfx::Point(509, 609), 2); |
80 EXPECT_GT(event_handler->num_mouse_events(), 0); | 82 EXPECT_GT(event_handler->num_mouse_events(), 0); |
81 EXPECT_EQ(0, event_handler->num_touch_events()); | 83 EXPECT_EQ(0, event_handler->num_touch_events()); |
82 | 84 |
83 SwitchTouchExplorationMode(false); | 85 SwitchTouchExplorationMode(false); |
84 root_window->RemovePreTargetHandler(event_handler.get()); | 86 root_window->RemovePreTargetHandler(event_handler.get()); |
85 } | 87 } |
86 | 88 |
87 } // namespace ui | 89 } // namespace ui |
OLD | NEW |