| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
| 6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 8 #include "ash/wm/overview/window_selector_controller.h" | 8 #include "ash/wm/overview/window_selector_controller.h" |
| 9 #include "ui/aura/test/event_generator.h" |
| 9 #include "ui/aura/test/test_window_delegate.h" | 10 #include "ui/aura/test/test_window_delegate.h" |
| 10 #include "ui/aura/test/test_windows.h" | 11 #include "ui/aura/test/test_windows.h" |
| 11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
| 13 #include "ui/events/test/event_generator.h" | |
| 14 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 15 | 15 |
| 16 namespace ash { | 16 namespace ash { |
| 17 | 17 |
| 18 class OverviewGestureHandlerTest : public test::AshTestBase { | 18 class OverviewGestureHandlerTest : public test::AshTestBase { |
| 19 public: | 19 public: |
| 20 OverviewGestureHandlerTest() {} | 20 OverviewGestureHandlerTest() {} |
| 21 virtual ~OverviewGestureHandlerTest() {} | 21 virtual ~OverviewGestureHandlerTest() {} |
| 22 | 22 |
| 23 aura::Window* CreateWindow(const gfx::Rect& bounds) { | 23 aura::Window* CreateWindow(const gfx::Rect& bounds) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest); | 35 DISALLOW_COPY_AND_ASSIGN(OverviewGestureHandlerTest); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Tests a swipe up with three fingers to enter and a swipe down to exit | 38 // Tests a swipe up with three fingers to enter and a swipe down to exit |
| 39 // overview. | 39 // overview. |
| 40 TEST_F(OverviewGestureHandlerTest, VerticalSwipes) { | 40 TEST_F(OverviewGestureHandlerTest, VerticalSwipes) { |
| 41 gfx::Rect bounds(0, 0, 400, 400); | 41 gfx::Rect bounds(0, 0, 400, 400); |
| 42 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 42 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 43 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 43 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 44 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 44 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 45 ui::test::EventGenerator generator(root_window, root_window); | 45 aura::test::EventGenerator generator(root_window, root_window); |
| 46 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 46 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 47 0, -500, 100, 3); | 47 0, -500, 100, 3); |
| 48 EXPECT_TRUE(IsSelecting()); | 48 EXPECT_TRUE(IsSelecting()); |
| 49 | 49 |
| 50 // Swiping up again does nothing. | 50 // Swiping up again does nothing. |
| 51 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 51 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 52 0, -500, 100, 3); | 52 0, -500, 100, 3); |
| 53 EXPECT_TRUE(IsSelecting()); | 53 EXPECT_TRUE(IsSelecting()); |
| 54 | 54 |
| 55 // Swiping down exits. | 55 // Swiping down exits. |
| 56 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 56 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 57 0, 500, 100, 3); | 57 0, 500, 100, 3); |
| 58 EXPECT_FALSE(IsSelecting()); | 58 EXPECT_FALSE(IsSelecting()); |
| 59 | 59 |
| 60 // Swiping down again does nothing. | 60 // Swiping down again does nothing. |
| 61 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 61 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 62 0, 500, 100, 3); | 62 0, 500, 100, 3); |
| 63 EXPECT_FALSE(IsSelecting()); | 63 EXPECT_FALSE(IsSelecting()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Tests that a mostly horizontal swipe does not trigger overview. | 66 // Tests that a mostly horizontal swipe does not trigger overview. |
| 67 TEST_F(OverviewGestureHandlerTest, HorizontalSwipes) { | 67 TEST_F(OverviewGestureHandlerTest, HorizontalSwipes) { |
| 68 gfx::Rect bounds(0, 0, 400, 400); | 68 gfx::Rect bounds(0, 0, 400, 400); |
| 69 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 69 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 70 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 70 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 71 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 71 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 72 ui::test::EventGenerator generator(root_window, root_window); | 72 aura::test::EventGenerator generator(root_window, root_window); |
| 73 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 73 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 74 600, -500, 100, 3); | 74 600, -500, 100, 3); |
| 75 EXPECT_FALSE(IsSelecting()); | 75 EXPECT_FALSE(IsSelecting()); |
| 76 | 76 |
| 77 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), | 77 generator.ScrollSequence(gfx::Point(), base::TimeDelta::FromMilliseconds(5), |
| 78 -600, -500, 100, 3); | 78 -600, -500, 100, 3); |
| 79 EXPECT_FALSE(IsSelecting()); | 79 EXPECT_FALSE(IsSelecting()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Tests a swipe up with three fingers without releasing followed by a swipe | 82 // Tests a swipe up with three fingers without releasing followed by a swipe |
| 83 // down by a lesser amount which should still be enough to exit. | 83 // down by a lesser amount which should still be enough to exit. |
| 84 TEST_F(OverviewGestureHandlerTest, SwipeUpDownWithoutReleasing) { | 84 TEST_F(OverviewGestureHandlerTest, SwipeUpDownWithoutReleasing) { |
| 85 gfx::Rect bounds(0, 0, 400, 400); | 85 gfx::Rect bounds(0, 0, 400, 400); |
| 86 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 86 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 87 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 87 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 88 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 88 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 89 ui::test::EventGenerator generator(root_window, root_window); | 89 aura::test::EventGenerator generator(root_window, root_window); |
| 90 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( | 90 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( |
| 91 base::TimeTicks::Now().ToInternalValue()); | 91 base::TimeTicks::Now().ToInternalValue()); |
| 92 gfx::Point start; | 92 gfx::Point start; |
| 93 int num_fingers = 3; | 93 int num_fingers = 3; |
| 94 base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5)); | 94 base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5)); |
| 95 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 95 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| 96 start, | 96 start, |
| 97 timestamp, | 97 timestamp, |
| 98 0, | 98 0, |
| 99 0, 0, | 99 0, 0, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 num_fingers); | 139 num_fingers); |
| 140 generator.Dispatch(&fling_start); | 140 generator.Dispatch(&fling_start); |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Tests a swipe down from the top of the screen to enter and exit overview. | 143 // Tests a swipe down from the top of the screen to enter and exit overview. |
| 144 TEST_F(OverviewGestureHandlerTest, GestureSwipe) { | 144 TEST_F(OverviewGestureHandlerTest, GestureSwipe) { |
| 145 gfx::Rect bounds(0, 0, 400, 400); | 145 gfx::Rect bounds(0, 0, 400, 400); |
| 146 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 146 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 147 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 147 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 148 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 148 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 149 ui::test::EventGenerator generator(root_window, root_window); | 149 aura::test::EventGenerator generator(root_window, root_window); |
| 150 gfx::Point start_points[3]; | 150 gfx::Point start_points[3]; |
| 151 start_points[0] = start_points[1] = start_points[2] = gfx::Point(); | 151 start_points[0] = start_points[1] = start_points[2] = gfx::Point(); |
| 152 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100); | 152 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100); |
| 153 EXPECT_TRUE(IsSelecting()); | 153 EXPECT_TRUE(IsSelecting()); |
| 154 | 154 |
| 155 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100); | 155 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100); |
| 156 EXPECT_FALSE(IsSelecting()); | 156 EXPECT_FALSE(IsSelecting()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Tests that a swipe down from the top of a window doesn't enter overview. | 159 // Tests that a swipe down from the top of a window doesn't enter overview. |
| 160 // http://crbug.com/313859 | 160 // http://crbug.com/313859 |
| 161 TEST_F(OverviewGestureHandlerTest, GestureSwipeTopOfWindow) { | 161 TEST_F(OverviewGestureHandlerTest, GestureSwipeTopOfWindow) { |
| 162 gfx::Rect bounds(100, 100, 400, 400); | 162 gfx::Rect bounds(100, 100, 400, 400); |
| 163 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 163 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 164 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 164 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 165 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 165 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 166 ui::test::EventGenerator generator(root_window, window2.get()); | 166 aura::test::EventGenerator generator(root_window, window2.get()); |
| 167 gfx::Point start_points[3]; | 167 gfx::Point start_points[3]; |
| 168 start_points[0] = start_points[1] = start_points[2] = gfx::Point(105, 105); | 168 start_points[0] = start_points[1] = start_points[2] = gfx::Point(105, 105); |
| 169 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100); | 169 generator.GestureMultiFingerScroll(3, start_points, 5, 10, 0, 100); |
| 170 EXPECT_FALSE(IsSelecting()); | 170 EXPECT_FALSE(IsSelecting()); |
| 171 } | 171 } |
| 172 | 172 |
| 173 } // namespace ash | 173 } // namespace ash |
| OLD | NEW |