Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: ash/frame/caption_buttons/frame_size_button_unittest.cc

Issue 406413004: Cleanups for aura/test/event_generator.h (resolve TODOs) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase at r285842 Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/focus_cycler_unittest.cc ('k') | ash/ime/candidate_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/frame/caption_buttons/frame_size_button.h" 5 #include "ash/frame/caption_buttons/frame_size_button.h"
6 6
7 #include "ash/frame/caption_buttons/frame_caption_button.h" 7 #include "ash/frame/caption_buttons/frame_caption_button.h"
8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/wm/window_state.h" 11 #include "ash/wm/window_state.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "grit/ash_resources.h" 13 #include "grit/ash_resources.h"
14 #include "ui/aura/test/event_generator.h"
15 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
16 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/events/gestures/gesture_configuration.h" 16 #include "ui/events/gestures/gesture_configuration.h"
17 #include "ui/events/test/event_generator.h"
18 #include "ui/gfx/display.h" 18 #include "ui/gfx/display.h"
19 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
20 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
21 #include "ui/views/widget/widget_delegate.h" 21 #include "ui/views/widget/widget_delegate.h"
22 22
23 namespace ash { 23 namespace ash {
24 namespace test { 24 namespace test {
25 25
26 namespace { 26 namespace {
27 27
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 FrameCaptionButton* minimize_button_; 152 FrameCaptionButton* minimize_button_;
153 FrameCaptionButton* size_button_; 153 FrameCaptionButton* size_button_;
154 FrameCaptionButton* close_button_; 154 FrameCaptionButton* close_button_;
155 155
156 DISALLOW_COPY_AND_ASSIGN(FrameSizeButtonTest); 156 DISALLOW_COPY_AND_ASSIGN(FrameSizeButtonTest);
157 }; 157 };
158 158
159 // Tests that pressing the left mouse button or tapping down on the size button 159 // Tests that pressing the left mouse button or tapping down on the size button
160 // puts the button into the pressed state. 160 // puts the button into the pressed state.
161 TEST_F(FrameSizeButtonTest, PressedState) { 161 TEST_F(FrameSizeButtonTest, PressedState) {
162 aura::test::EventGenerator& generator = GetEventGenerator(); 162 ui::test::EventGenerator& generator = GetEventGenerator();
163 generator.MoveMouseTo(CenterPointInScreen(size_button())); 163 generator.MoveMouseTo(CenterPointInScreen(size_button()));
164 generator.PressLeftButton(); 164 generator.PressLeftButton();
165 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state()); 165 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
166 generator.ReleaseLeftButton(); 166 generator.ReleaseLeftButton();
167 RunAllPendingInMessageLoop(); 167 RunAllPendingInMessageLoop();
168 EXPECT_EQ(views::Button::STATE_NORMAL, size_button()->state()); 168 EXPECT_EQ(views::Button::STATE_NORMAL, size_button()->state());
169 169
170 generator.MoveMouseTo(CenterPointInScreen(size_button())); 170 generator.MoveMouseTo(CenterPointInScreen(size_button()));
171 generator.PressTouchId(3); 171 generator.PressTouchId(3);
172 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state()); 172 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
173 generator.ReleaseTouchId(3); 173 generator.ReleaseTouchId(3);
174 RunAllPendingInMessageLoop(); 174 RunAllPendingInMessageLoop();
175 EXPECT_EQ(views::Button::STATE_NORMAL, size_button()->state()); 175 EXPECT_EQ(views::Button::STATE_NORMAL, size_button()->state());
176 } 176 }
177 177
178 // Tests that clicking on the size button toggles between the maximized and 178 // Tests that clicking on the size button toggles between the maximized and
179 // normal state. 179 // normal state.
180 TEST_F(FrameSizeButtonTest, ClickSizeButtonTogglesMaximize) { 180 TEST_F(FrameSizeButtonTest, ClickSizeButtonTogglesMaximize) {
181 EXPECT_FALSE(window_state()->IsMaximized()); 181 EXPECT_FALSE(window_state()->IsMaximized());
182 182
183 aura::test::EventGenerator& generator = GetEventGenerator(); 183 ui::test::EventGenerator& generator = GetEventGenerator();
184 generator.MoveMouseTo(CenterPointInScreen(size_button())); 184 generator.MoveMouseTo(CenterPointInScreen(size_button()));
185 generator.ClickLeftButton(); 185 generator.ClickLeftButton();
186 RunAllPendingInMessageLoop(); 186 RunAllPendingInMessageLoop();
187 EXPECT_TRUE(window_state()->IsMaximized()); 187 EXPECT_TRUE(window_state()->IsMaximized());
188 188
189 generator.MoveMouseTo(CenterPointInScreen(size_button())); 189 generator.MoveMouseTo(CenterPointInScreen(size_button()));
190 generator.ClickLeftButton(); 190 generator.ClickLeftButton();
191 RunAllPendingInMessageLoop(); 191 RunAllPendingInMessageLoop();
192 EXPECT_FALSE(window_state()->IsMaximized()); 192 EXPECT_FALSE(window_state()->IsMaximized());
193 193
194 generator.GestureTapAt(CenterPointInScreen(size_button())); 194 generator.GestureTapAt(CenterPointInScreen(size_button()));
195 RunAllPendingInMessageLoop(); 195 RunAllPendingInMessageLoop();
196 EXPECT_TRUE(window_state()->IsMaximized()); 196 EXPECT_TRUE(window_state()->IsMaximized());
197 197
198 generator.GestureTapAt(CenterPointInScreen(size_button())); 198 generator.GestureTapAt(CenterPointInScreen(size_button()));
199 RunAllPendingInMessageLoop(); 199 RunAllPendingInMessageLoop();
200 EXPECT_FALSE(window_state()->IsMaximized()); 200 EXPECT_FALSE(window_state()->IsMaximized());
201 } 201 }
202 202
203 // Test that clicking + dragging to a button adjacent to the size button snaps 203 // Test that clicking + dragging to a button adjacent to the size button snaps
204 // the window left or right. 204 // the window left or right.
205 TEST_F(FrameSizeButtonTest, ButtonDrag) { 205 TEST_F(FrameSizeButtonTest, ButtonDrag) {
206 EXPECT_TRUE(window_state()->IsNormalStateType()); 206 EXPECT_TRUE(window_state()->IsNormalStateType());
207 207
208 // 1) Test by dragging the mouse. 208 // 1) Test by dragging the mouse.
209 // Snap right. 209 // Snap right.
210 aura::test::EventGenerator& generator = GetEventGenerator(); 210 ui::test::EventGenerator& generator = GetEventGenerator();
211 generator.MoveMouseTo(CenterPointInScreen(size_button())); 211 generator.MoveMouseTo(CenterPointInScreen(size_button()));
212 generator.PressLeftButton(); 212 generator.PressLeftButton();
213 generator.MoveMouseTo(CenterPointInScreen(close_button())); 213 generator.MoveMouseTo(CenterPointInScreen(close_button()));
214 generator.ReleaseLeftButton(); 214 generator.ReleaseLeftButton();
215 RunAllPendingInMessageLoop(); 215 RunAllPendingInMessageLoop();
216 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED)); 216 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED));
217 217
218 // Snap left. 218 // Snap left.
219 generator.MoveMouseTo(CenterPointInScreen(size_button())); 219 generator.MoveMouseTo(CenterPointInScreen(size_button()));
220 generator.PressLeftButton(); 220 generator.PressLeftButton();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 RunAllPendingInMessageLoop(); 257 RunAllPendingInMessageLoop();
258 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED)); 258 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED));
259 ui::GestureConfiguration::set_default_radius(touch_default_radius); 259 ui::GestureConfiguration::set_default_radius(touch_default_radius);
260 } 260 }
261 261
262 // Test that clicking, dragging, and overshooting the minimize button a bit 262 // Test that clicking, dragging, and overshooting the minimize button a bit
263 // horizontally still snaps the window left. 263 // horizontally still snaps the window left.
264 TEST_F(FrameSizeButtonTest, SnapLeftOvershootMinimize) { 264 TEST_F(FrameSizeButtonTest, SnapLeftOvershootMinimize) {
265 EXPECT_TRUE(window_state()->IsNormalStateType()); 265 EXPECT_TRUE(window_state()->IsNormalStateType());
266 266
267 aura::test::EventGenerator& generator = GetEventGenerator(); 267 ui::test::EventGenerator& generator = GetEventGenerator();
268 generator.MoveMouseTo(CenterPointInScreen(size_button())); 268 generator.MoveMouseTo(CenterPointInScreen(size_button()));
269 269
270 generator.PressLeftButton(); 270 generator.PressLeftButton();
271 // Move to the minimize button. 271 // Move to the minimize button.
272 generator.MoveMouseTo(CenterPointInScreen(minimize_button())); 272 generator.MoveMouseTo(CenterPointInScreen(minimize_button()));
273 // Overshoot the minimize button. 273 // Overshoot the minimize button.
274 generator.MoveMouseBy(-minimize_button()->width(), 0); 274 generator.MoveMouseBy(-minimize_button()->width(), 0);
275 generator.ReleaseLeftButton(); 275 generator.ReleaseLeftButton();
276 RunAllPendingInMessageLoop(); 276 RunAllPendingInMessageLoop();
277 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED)); 277 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED));
278 } 278 }
279 279
280 // Test that right clicking the size button has no effect. 280 // Test that right clicking the size button has no effect.
281 TEST_F(FrameSizeButtonTest, RightMouseButton) { 281 TEST_F(FrameSizeButtonTest, RightMouseButton) {
282 EXPECT_TRUE(window_state()->IsNormalStateType()); 282 EXPECT_TRUE(window_state()->IsNormalStateType());
283 283
284 aura::test::EventGenerator& generator = GetEventGenerator(); 284 ui::test::EventGenerator& generator = GetEventGenerator();
285 generator.MoveMouseTo(CenterPointInScreen(size_button())); 285 generator.MoveMouseTo(CenterPointInScreen(size_button()));
286 generator.PressRightButton(); 286 generator.PressRightButton();
287 generator.ReleaseRightButton(); 287 generator.ReleaseRightButton();
288 RunAllPendingInMessageLoop(); 288 RunAllPendingInMessageLoop();
289 EXPECT_TRUE(window_state()->IsNormalStateType()); 289 EXPECT_TRUE(window_state()->IsNormalStateType());
290 } 290 }
291 291
292 // Test that upon releasing the mouse button after having pressed the size 292 // Test that upon releasing the mouse button after having pressed the size
293 // button 293 // button
294 // - The state of all the caption buttons is reset. 294 // - The state of all the caption buttons is reset.
295 // - The icon displayed by all of the caption buttons is reset. 295 // - The icon displayed by all of the caption buttons is reset.
296 TEST_F(FrameSizeButtonTest, ResetButtonsAfterClick) { 296 TEST_F(FrameSizeButtonTest, ResetButtonsAfterClick) {
297 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon()); 297 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
298 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon()); 298 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
299 EXPECT_TRUE(AllButtonsInNormalState()); 299 EXPECT_TRUE(AllButtonsInNormalState());
300 300
301 // Pressing the size button should result in the size button being pressed and 301 // Pressing the size button should result in the size button being pressed and
302 // the minimize and close button icons changing. 302 // the minimize and close button icons changing.
303 aura::test::EventGenerator& generator = GetEventGenerator(); 303 ui::test::EventGenerator& generator = GetEventGenerator();
304 generator.MoveMouseTo(CenterPointInScreen(size_button())); 304 generator.MoveMouseTo(CenterPointInScreen(size_button()));
305 generator.PressLeftButton(); 305 generator.PressLeftButton();
306 EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state()); 306 EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state());
307 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state()); 307 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
308 EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state()); 308 EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
309 EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon()); 309 EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon());
310 EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon()); 310 EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon());
311 311
312 // Dragging the mouse over the minimize button should hover the minimize 312 // Dragging the mouse over the minimize button should hover the minimize
313 // button and the minimize and close button icons should stay changed. 313 // button and the minimize and close button icons should stay changed.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 364
365 // Test that the size button is pressed whenever the snap left/right buttons 365 // Test that the size button is pressed whenever the snap left/right buttons
366 // are hovered. 366 // are hovered.
367 TEST_F(FrameSizeButtonTest, SizeButtonPressedWhenSnapButtonHovered) { 367 TEST_F(FrameSizeButtonTest, SizeButtonPressedWhenSnapButtonHovered) {
368 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon()); 368 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
369 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon()); 369 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
370 EXPECT_TRUE(AllButtonsInNormalState()); 370 EXPECT_TRUE(AllButtonsInNormalState());
371 371
372 // Pressing the size button should result in the size button being pressed and 372 // Pressing the size button should result in the size button being pressed and
373 // the minimize and close button icons changing. 373 // the minimize and close button icons changing.
374 aura::test::EventGenerator& generator = GetEventGenerator(); 374 ui::test::EventGenerator& generator = GetEventGenerator();
375 generator.MoveMouseTo(CenterPointInScreen(size_button())); 375 generator.MoveMouseTo(CenterPointInScreen(size_button()));
376 generator.PressLeftButton(); 376 generator.PressLeftButton();
377 EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state()); 377 EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state());
378 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state()); 378 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
379 EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state()); 379 EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
380 EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon()); 380 EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, minimize_button()->icon());
381 EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon()); 381 EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, close_button()->icon());
382 382
383 // Dragging the mouse over the minimize button (snap left button) should hover 383 // Dragging the mouse over the minimize button (snap left button) should hover
384 // the minimize button and keep the size button pressed. 384 // the minimize button and keep the size button pressed.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 minimize_button()->GetBoundsInScreen().x()); 434 minimize_button()->GetBoundsInScreen().x());
435 435
436 // Test initial state. 436 // Test initial state.
437 EXPECT_TRUE(window_state()->IsNormalStateType()); 437 EXPECT_TRUE(window_state()->IsNormalStateType());
438 EXPECT_TRUE(AllButtonsInNormalState()); 438 EXPECT_TRUE(AllButtonsInNormalState());
439 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon()); 439 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
440 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon()); 440 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
441 441
442 // Pressing the size button should swap the icons of the minimize and close 442 // Pressing the size button should swap the icons of the minimize and close
443 // buttons to icons for snapping right and for snapping left respectively. 443 // buttons to icons for snapping right and for snapping left respectively.
444 aura::test::EventGenerator& generator = GetEventGenerator(); 444 ui::test::EventGenerator& generator = GetEventGenerator();
445 generator.MoveMouseTo(CenterPointInScreen(size_button())); 445 generator.MoveMouseTo(CenterPointInScreen(size_button()));
446 generator.PressLeftButton(); 446 generator.PressLeftButton();
447 EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state()); 447 EXPECT_EQ(views::Button::STATE_NORMAL, minimize_button()->state());
448 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state()); 448 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
449 EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state()); 449 EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
450 EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, minimize_button()->icon()); 450 EXPECT_EQ(CAPTION_BUTTON_ICON_RIGHT_SNAPPED, minimize_button()->icon());
451 EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, close_button()->icon()); 451 EXPECT_EQ(CAPTION_BUTTON_ICON_LEFT_SNAPPED, close_button()->icon());
452 452
453 // Dragging over to the minimize button should press it. 453 // Dragging over to the minimize button should press it.
454 generator.MoveMouseTo(CenterPointInScreen(minimize_button())); 454 generator.MoveMouseTo(CenterPointInScreen(minimize_button()));
455 EXPECT_EQ(views::Button::STATE_HOVERED, minimize_button()->state()); 455 EXPECT_EQ(views::Button::STATE_HOVERED, minimize_button()->state());
456 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state()); 456 EXPECT_EQ(views::Button::STATE_PRESSED, size_button()->state());
457 EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state()); 457 EXPECT_EQ(views::Button::STATE_NORMAL, close_button()->state());
458 458
459 // Releasing should snap the window right. 459 // Releasing should snap the window right.
460 generator.ReleaseLeftButton(); 460 generator.ReleaseLeftButton();
461 RunAllPendingInMessageLoop(); 461 RunAllPendingInMessageLoop();
462 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED)); 462 EXPECT_TRUE(HasStateType(wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED));
463 463
464 // None of the buttons should stay pressed and the buttons should have their 464 // None of the buttons should stay pressed and the buttons should have their
465 // regular icons. 465 // regular icons.
466 EXPECT_TRUE(AllButtonsInNormalState()); 466 EXPECT_TRUE(AllButtonsInNormalState());
467 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon()); 467 EXPECT_EQ(CAPTION_BUTTON_ICON_MINIMIZE, minimize_button()->icon());
468 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon()); 468 EXPECT_EQ(CAPTION_BUTTON_ICON_CLOSE, close_button()->icon());
469 } 469 }
470 470
471 } // namespace test 471 } // namespace test
472 } // namespace ash 472 } // namespace ash
OLDNEW
« no previous file with comments | « ash/focus_cycler_unittest.cc ('k') | ash/ime/candidate_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698