Add abhijeet.k@samsung.com to AUTHORS list.
[chromium-blink-merge.git] / ash / utility / partial_screenshot_controller_unittest.cc
blob4233723c3d077912b3d1ca30daeb1d140ff0e273
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.
5 #include "ash/utility/partial_screenshot_controller.h"
7 #include "ash/display/cursor_window_controller.h"
8 #include "ash/display/display_controller.h"
9 #include "ash/screenshot_delegate.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/mirror_window_test_api.h"
13 #include "ash/test/test_screenshot_delegate.h"
14 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/base/cursor/cursor.h"
16 #include "ui/events/test/event_generator.h"
17 #include "ui/wm/core/cursor_manager.h"
19 namespace ash {
21 class PartialScreenshotControllerTest : public test::AshTestBase {
22 public:
23 PartialScreenshotControllerTest() {}
24 ~PartialScreenshotControllerTest() override {}
26 protected:
27 PartialScreenshotController* partial_screenshot_controller() {
28 return Shell::GetInstance()->partial_screenshot_controller();
31 void StartPartialScreenshotSession() {
32 partial_screenshot_controller()->StartPartialScreenshotSession(
33 GetScreenshotDelegate());
36 bool IsActive() {
37 return partial_screenshot_controller()->screenshot_delegate_ != nullptr;
40 const gfx::Point& GetStartPosition() const {
41 return Shell::GetInstance()
42 ->partial_screenshot_controller()
43 ->start_position_;
46 private:
47 DISALLOW_COPY_AND_ASSIGN(PartialScreenshotControllerTest);
50 TEST_F(PartialScreenshotControllerTest, BasicMouse) {
51 StartPartialScreenshotSession();
52 test::TestScreenshotDelegate* test_delegate = GetScreenshotDelegate();
53 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
55 generator.MoveMouseTo(100, 100);
56 generator.PressLeftButton();
57 EXPECT_EQ("100,100", GetStartPosition().ToString());
58 EXPECT_EQ(0, test_delegate->handle_take_partial_screenshot_count());
60 generator.MoveMouseTo(200, 200);
61 EXPECT_EQ(0, test_delegate->handle_take_partial_screenshot_count());
63 generator.ReleaseLeftButton();
64 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString());
65 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
67 RunAllPendingInMessageLoop();
68 EXPECT_FALSE(IsActive());
71 TEST_F(PartialScreenshotControllerTest, JustClick) {
72 StartPartialScreenshotSession();
73 test::TestScreenshotDelegate* test_delegate = GetScreenshotDelegate();
74 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
76 generator.MoveMouseTo(100, 100);
78 // No moves, just clicking at the same position.
79 generator.ClickLeftButton();
80 EXPECT_EQ(0, test_delegate->handle_take_partial_screenshot_count());
82 RunAllPendingInMessageLoop();
83 EXPECT_FALSE(IsActive());
86 TEST_F(PartialScreenshotControllerTest, BasicTouch) {
87 StartPartialScreenshotSession();
88 test::TestScreenshotDelegate* test_delegate = GetScreenshotDelegate();
89 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
91 generator.set_current_location(gfx::Point(100, 100));
92 generator.PressTouch();
93 EXPECT_EQ(0, test_delegate->handle_take_partial_screenshot_count());
94 EXPECT_EQ("100,100", GetStartPosition().ToString());
96 generator.MoveTouch(gfx::Point(200, 200));
97 EXPECT_EQ(0, test_delegate->handle_take_partial_screenshot_count());
99 generator.ReleaseTouch();
100 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString());
101 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
103 RunAllPendingInMessageLoop();
104 EXPECT_FALSE(IsActive());
107 TEST_F(PartialScreenshotControllerTest, TwoFingerTouch) {
108 StartPartialScreenshotSession();
109 test::TestScreenshotDelegate* test_delegate = GetScreenshotDelegate();
110 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
112 generator.set_current_location(gfx::Point(100, 100));
113 generator.PressTouch();
114 EXPECT_EQ(0, test_delegate->handle_take_partial_screenshot_count());
115 EXPECT_EQ("100,100", GetStartPosition().ToString());
117 generator.set_current_location(gfx::Point(200, 200));
118 generator.PressTouchId(1);
119 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString());
120 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
122 RunAllPendingInMessageLoop();
123 EXPECT_FALSE(IsActive());
126 TEST_F(PartialScreenshotControllerTest, MultipleDisplays) {
127 if (!SupportsMultipleDisplays())
128 return;
130 StartPartialScreenshotSession();
131 EXPECT_TRUE(IsActive());
132 UpdateDisplay("400x400,500x500");
133 RunAllPendingInMessageLoop();
134 EXPECT_FALSE(IsActive());
136 StartPartialScreenshotSession();
137 EXPECT_TRUE(IsActive());
138 UpdateDisplay("400x400");
139 RunAllPendingInMessageLoop();
140 EXPECT_FALSE(IsActive());
143 #if defined(OS_CHROMEOS)
144 // Make sure PartialScreenshotController doesn't prevent handling of large
145 // cursor. See http://crbug.com/459214
146 TEST_F(PartialScreenshotControllerTest, LargeCursor) {
147 Shell::GetInstance()->cursor_manager()->SetCursorSet(ui::CURSOR_SET_LARGE);
148 Shell::GetInstance()
149 ->display_controller()
150 ->cursor_window_controller()
151 ->SetCursorCompositingEnabled(true);
153 // Large cursor is represented as cursor window.
154 test::MirrorWindowTestApi test_api;
155 ASSERT_NE(nullptr, test_api.GetCursorWindow());
157 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow());
158 gfx::Point cursor_location;
159 event_generator.MoveMouseTo(cursor_location);
160 EXPECT_EQ(cursor_location.ToString(),
161 test_api.GetCursorLocation().ToString());
163 StartPartialScreenshotSession();
164 EXPECT_TRUE(IsActive());
166 cursor_location += gfx::Vector2d(1, 1);
167 event_generator.MoveMouseTo(cursor_location);
168 EXPECT_EQ(cursor_location.ToString(),
169 test_api.GetCursorLocation().ToString());
171 event_generator.PressLeftButton();
172 cursor_location += gfx::Vector2d(5, 5);
173 event_generator.MoveMouseTo(cursor_location);
174 EXPECT_EQ(cursor_location.ToString(),
175 test_api.GetCursorLocation().ToString());
177 event_generator.ReleaseLeftButton();
179 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
180 EXPECT_EQ("1,1 5x5", GetScreenshotDelegate()->last_rect().ToString());
181 RunAllPendingInMessageLoop();
182 EXPECT_FALSE(IsActive());
184 #endif
186 } // namespace ash