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

Side by Side Diff: ash/shelf/shelf_view_unittest.cc

Issue 2575613002: Remove ShelfItemDelegate::IsDraggable; check for app list button. (Closed)
Patch Set: Address comments. Created 4 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/shelf/shelf_view.h" 5 #include "ash/common/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); 432 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds();
433 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); 433 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i);
434 EXPECT_GE(item_bounds.x(), 0); 434 EXPECT_GE(item_bounds.x(), 0);
435 EXPECT_GE(item_bounds.y(), 0); 435 EXPECT_GE(item_bounds.y(), 0);
436 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); 436 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width());
437 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); 437 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height());
438 } 438 }
439 } 439 }
440 } 440 }
441 441
442 // Simulate a mouse press event on the shelf's view at |view_index|.
443 views::View* SimulateViewPressed(ShelfView::Pointer pointer, int view_index) {
444 views::View* view = test_api_->GetViewAt(view_index);
445 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(),
446 view->GetBoundsInScreen().origin(),
447 ui::EventTimeForNow(), 0, 0);
448 shelf_view_->PointerPressedOnButton(view, pointer, pressed_event);
449 return view;
450 }
451
452 // Similar to SimulateViewPressed, but the index must not be for the app list,
453 // since the app list button is not a ShelfButton.
442 ShelfButton* SimulateButtonPressed(ShelfView::Pointer pointer, 454 ShelfButton* SimulateButtonPressed(ShelfView::Pointer pointer,
443 int button_index) { 455 int button_index) {
456 EXPECT_NE(TYPE_APP_LIST, model_->items()[button_index].type);
444 ShelfButton* button = test_api_->GetButton(button_index); 457 ShelfButton* button = test_api_->GetButton(button_index);
445 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, gfx::Point(), 458 EXPECT_EQ(button, SimulateViewPressed(pointer, button_index));
446 button->GetBoundsInScreen().origin(),
447 ui::EventTimeForNow(), 0, 0);
448 shelf_view_->PointerPressedOnButton(button, pointer, click_event);
449 return button; 459 return button;
450 } 460 }
451 461
452 // Simulates a single mouse click. 462 // Simulates a single mouse click.
453 void SimulateClick(int button_index) { 463 void SimulateClick(int button_index) {
454 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index); 464 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index);
455 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), 465 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(),
456 button->GetBoundsInScreen().origin(), 466 button->GetBoundsInScreen().origin(),
457 ui::EventTimeForNow(), 0, 0); 467 ui::EventTimeForNow(), 0, 0);
458 test_api_->ButtonPressed( 468 test_api_->ButtonPressed(
(...skipping 30 matching lines...) Expand all
489 * Trigger ContinueDrag of the shelf 499 * Trigger ContinueDrag of the shelf
490 * The argument progressively means whether to simulate the drag progress (a 500 * The argument progressively means whether to simulate the drag progress (a
491 * series of changes of the posistion of dragged item), like the normal user 501 * series of changes of the posistion of dragged item), like the normal user
492 * drag behavior. 502 * drag behavior.
493 */ 503 */
494 void ContinueDrag(views::View* button, 504 void ContinueDrag(views::View* button,
495 ShelfView::Pointer pointer, 505 ShelfView::Pointer pointer,
496 int from_index, 506 int from_index,
497 int to_index, 507 int to_index,
498 bool progressively) { 508 bool progressively) {
499 views::View* to = test_api_->GetButton(to_index); 509 views::View* to = test_api_->GetViewAt(to_index);
500 views::View* from = test_api_->GetButton(from_index); 510 views::View* from = test_api_->GetViewAt(from_index);
501 int dist_x = to->x() - from->x(); 511 int dist_x = to->x() - from->x();
502 int dist_y = to->y() - from->y(); 512 int dist_y = to->y() - from->y();
503 if (progressively) { 513 if (progressively) {
504 int sgn = dist_x > 0 ? 1 : -1; 514 int sgn = dist_x > 0 ? 1 : -1;
505 dist_x = abs(dist_x); 515 dist_x = abs(dist_x);
506 for (; dist_x; dist_x -= std::min(10, dist_x)) 516 for (; dist_x; dist_x -= std::min(10, dist_x))
507 DoDrag(sgn * std::min(10, abs(dist_x)), 0, button, pointer, to); 517 DoDrag(sgn * std::min(10, abs(dist_x)), 0, button, pointer, to);
508 } else { 518 } else {
509 DoDrag(dist_x, dist_y, button, pointer, to); 519 DoDrag(dist_x, dist_y, button, pointer, to);
510 } 520 }
511 } 521 }
512 522
513 /* 523 /*
514 * Simulate drag operation. 524 * Simulate drag operation.
515 * Argument progressively means whether to simulate the drag progress (a 525 * Argument progressively means whether to simulate the drag progress (a
516 * series of changes of the posistion of dragged item) like the behavior of 526 * series of changes of the posistion of dragged item) like the behavior of
517 * user drags. 527 * user drags.
518 */ 528 */
519 views::View* SimulateDrag(ShelfView::Pointer pointer, 529 views::View* SimulateDrag(ShelfView::Pointer pointer,
520 int button_index, 530 int button_index,
521 int destination_index, 531 int destination_index,
522 bool progressively) { 532 bool progressively) {
523 views::View* button = SimulateButtonPressed(pointer, button_index); 533 views::View* button = SimulateViewPressed(pointer, button_index);
524 534
525 if (!progressively) { 535 if (!progressively) {
526 ContinueDrag(button, pointer, button_index, destination_index, false); 536 ContinueDrag(button, pointer, button_index, destination_index, false);
527 } else if (button_index < destination_index) { 537 } else if (button_index < destination_index) {
528 for (int cur_index = button_index + 1; cur_index <= destination_index; 538 for (int cur_index = button_index + 1; cur_index <= destination_index;
529 cur_index++) 539 cur_index++)
530 ContinueDrag(button, pointer, cur_index - 1, cur_index, true); 540 ContinueDrag(button, pointer, cur_index - 1, cur_index, true);
531 } else if (button_index > destination_index) { 541 } else if (button_index > destination_index) {
532 for (int cur_index = button_index - 1; cur_index >= destination_index; 542 for (int cur_index = button_index - 1; cur_index >= destination_index;
533 cur_index--) 543 cur_index--)
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 dragged_button_mouse = SimulateDrag(ShelfView::MOUSE, 1, 2, false); 1168 dragged_button_mouse = SimulateDrag(ShelfView::MOUSE, 1, 2, false);
1159 1169
1160 // Nothing changes since 2nd drag is ignored. 1170 // Nothing changes since 2nd drag is ignored.
1161 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1171 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1162 1172
1163 shelf_view_->PointerReleasedOnButton(dragged_button_touch, ShelfView::TOUCH, 1173 shelf_view_->PointerReleasedOnButton(dragged_button_touch, ShelfView::TOUCH,
1164 false); 1174 false);
1165 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1175 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1166 } 1176 }
1167 1177
1168 // Check that whether the ash behaves correctly if not draggable 1178 // Ensure the app list button cannot be dragged and other items cannot be
1169 // item are in front of the shelf. 1179 // dragged in front of the app list button.
1170 TEST_F(ShelfViewTest, DragWithNotDraggableItemInFront) { 1180 TEST_F(ShelfViewTest, DragWithNotDraggableItemInFront) {
1181 // The expected id order is initialized as: 1, 2, 3, 4, 5, 6, 7
1171 std::vector<std::pair<ShelfID, views::View*>> id_map; 1182 std::vector<std::pair<ShelfID, views::View*>> id_map;
1172 SetupForDragTest(&id_map); 1183 SetupForDragTest(&id_map);
1184 ASSERT_EQ(TYPE_APP_LIST, model_->items()[0].type);
1173 1185
1174 (static_cast<TestShelfItemDelegate*>( 1186 // Ensure that the app list button cannot be dragged.
1175 model_->GetShelfItemDelegate(id_map[1].first))) 1187 // The expected id order is unchanged: 1, 2, 3, 4, 5, 6, 7
1176 ->set_is_draggable(false); 1188 ASSERT_NO_FATAL_FAILURE(DragAndVerify(0, 1, shelf_view_, id_map));
1177 (static_cast<TestShelfItemDelegate*>( 1189 ASSERT_NO_FATAL_FAILURE(DragAndVerify(0, 2, shelf_view_, id_map));
1178 model_->GetShelfItemDelegate(id_map[2].first))) 1190 ASSERT_NO_FATAL_FAILURE(DragAndVerify(0, 5, shelf_view_, id_map));
1179 ->set_is_draggable(false);
1180 1191
1181 ASSERT_NO_FATAL_FAILURE(DragAndVerify(3, 1, shelf_view_, id_map)); 1192 // Ensure that items cannot be dragged in front of the app list button.
1182 ASSERT_NO_FATAL_FAILURE(DragAndVerify(3, 2, shelf_view_, id_map)); 1193 // Attempting to do so will order buttons immediately after the app list.
1183 1194 // Dragging the second button in front should no-op: 1, 2, 3, 4, 5, 6, 7
1184 std::rotate(id_map.begin() + 3, id_map.begin() + 4, id_map.begin() + 5); 1195 ASSERT_NO_FATAL_FAILURE(DragAndVerify(1, 0, shelf_view_, id_map));
1185 ASSERT_NO_FATAL_FAILURE(DragAndVerify(4, 1, shelf_view_, id_map)); 1196 // Dragging the third button in front should yield: 1, 3, 2, 4, 5, 6, 7
1186 std::rotate(id_map.begin() + 3, id_map.begin() + 5, id_map.begin() + 6); 1197 std::rotate(id_map.begin() + 1, id_map.begin() + 2, id_map.begin() + 3);
1187 ASSERT_NO_FATAL_FAILURE(DragAndVerify(5, 1, shelf_view_, id_map)); 1198 ASSERT_NO_FATAL_FAILURE(DragAndVerify(2, 0, shelf_view_, id_map));
1199 // Dragging the sixth button in front should yield: 1, 6, 3, 2, 4, 5, 7
1200 std::rotate(id_map.begin() + 1, id_map.begin() + 5, id_map.begin() + 6);
1201 ASSERT_NO_FATAL_FAILURE(DragAndVerify(5, 0, shelf_view_, id_map));
1188 } 1202 }
1189 1203
1190 // Check that clicking first on one item and then dragging another works as 1204 // Check that clicking first on one item and then dragging another works as
1191 // expected. 1205 // expected.
1192 TEST_F(ShelfViewTest, ClickOneDragAnother) { 1206 TEST_F(ShelfViewTest, ClickOneDragAnother) {
1193 std::vector<std::pair<ShelfID, views::View*>> id_map; 1207 std::vector<std::pair<ShelfID, views::View*>> id_map;
1194 SetupForDragTest(&id_map); 1208 SetupForDragTest(&id_map);
1195 1209
1196 // A click on item 1 is simulated. 1210 // A click on item 1 is simulated.
1197 SimulateClick(1); 1211 SimulateClick(1);
(...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 3128 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
3115 IsEmpty()); 3129 IsEmpty());
3116 3130
3117 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); 3131 ASSERT_TRUE(test_api_->IsShowingOverflowBubble());
3118 } 3132 }
3119 3133
3120 #endif // !defined(OS_WIN) 3134 #endif // !defined(OS_WIN)
3121 3135
3122 } // namespace test 3136 } // namespace test
3123 } // namespace ash 3137 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/test/test_shelf_item_delegate.cc ('k') | ash/shell/window_watcher_shelf_item_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698