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

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

Issue 2575613002: Remove ShelfItemDelegate::IsDraggable; check for app list button. (Closed)
Patch Set: 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) {
James Cook 2016/12/14 17:41:54 Is |pointer| always ShelfView::MOUSE? If so, it s
msw 2016/12/14 19:46:50 ShelfView::TOUCH is used here via SimulateDrag, an
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,
James Cook 2016/12/14 17:41:54 Can it DCHECK that button_index is not the app_lis
msw 2016/12/14 19:46:50 Done.
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) {
444 ShelfButton* button = test_api_->GetButton(button_index); 456 ShelfButton* button = test_api_->GetButton(button_index);
445 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, gfx::Point(), 457 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; 458 return button;
450 } 459 }
451 460
452 // Simulates a single mouse click. 461 // Simulates a single mouse click.
453 void SimulateClick(int button_index) { 462 void SimulateClick(int button_index) {
454 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index); 463 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index);
455 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), 464 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(),
456 button->GetBoundsInScreen().origin(), 465 button->GetBoundsInScreen().origin(),
457 ui::EventTimeForNow(), 0, 0); 466 ui::EventTimeForNow(), 0, 0);
458 test_api_->ButtonPressed( 467 test_api_->ButtonPressed(
(...skipping 30 matching lines...) Expand all
489 * Trigger ContinueDrag of the shelf 498 * Trigger ContinueDrag of the shelf
490 * The argument progressively means whether to simulate the drag progress (a 499 * 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 500 * series of changes of the posistion of dragged item), like the normal user
492 * drag behavior. 501 * drag behavior.
493 */ 502 */
494 void ContinueDrag(views::View* button, 503 void ContinueDrag(views::View* button,
495 ShelfView::Pointer pointer, 504 ShelfView::Pointer pointer,
496 int from_index, 505 int from_index,
497 int to_index, 506 int to_index,
498 bool progressively) { 507 bool progressively) {
499 views::View* to = test_api_->GetButton(to_index); 508 views::View* to = test_api_->GetViewAt(to_index);
500 views::View* from = test_api_->GetButton(from_index); 509 views::View* from = test_api_->GetViewAt(from_index);
501 int dist_x = to->x() - from->x(); 510 int dist_x = to->x() - from->x();
502 int dist_y = to->y() - from->y(); 511 int dist_y = to->y() - from->y();
503 if (progressively) { 512 if (progressively) {
504 int sgn = dist_x > 0 ? 1 : -1; 513 int sgn = dist_x > 0 ? 1 : -1;
505 dist_x = abs(dist_x); 514 dist_x = abs(dist_x);
506 for (; dist_x; dist_x -= std::min(10, dist_x)) 515 for (; dist_x; dist_x -= std::min(10, dist_x))
507 DoDrag(sgn * std::min(10, abs(dist_x)), 0, button, pointer, to); 516 DoDrag(sgn * std::min(10, abs(dist_x)), 0, button, pointer, to);
508 } else { 517 } else {
509 DoDrag(dist_x, dist_y, button, pointer, to); 518 DoDrag(dist_x, dist_y, button, pointer, to);
510 } 519 }
511 } 520 }
512 521
513 /* 522 /*
514 * Simulate drag operation. 523 * Simulate drag operation.
515 * Argument progressively means whether to simulate the drag progress (a 524 * Argument progressively means whether to simulate the drag progress (a
516 * series of changes of the posistion of dragged item) like the behavior of 525 * series of changes of the posistion of dragged item) like the behavior of
517 * user drags. 526 * user drags.
518 */ 527 */
519 views::View* SimulateDrag(ShelfView::Pointer pointer, 528 views::View* SimulateDrag(ShelfView::Pointer pointer,
520 int button_index, 529 int button_index,
521 int destination_index, 530 int destination_index,
522 bool progressively) { 531 bool progressively) {
523 views::View* button = SimulateButtonPressed(pointer, button_index); 532 views::View* button = SimulateViewPressed(pointer, button_index);
524 533
525 if (!progressively) { 534 if (!progressively) {
526 ContinueDrag(button, pointer, button_index, destination_index, false); 535 ContinueDrag(button, pointer, button_index, destination_index, false);
527 } else if (button_index < destination_index) { 536 } else if (button_index < destination_index) {
528 for (int cur_index = button_index + 1; cur_index <= destination_index; 537 for (int cur_index = button_index + 1; cur_index <= destination_index;
529 cur_index++) 538 cur_index++)
530 ContinueDrag(button, pointer, cur_index - 1, cur_index, true); 539 ContinueDrag(button, pointer, cur_index - 1, cur_index, true);
531 } else if (button_index > destination_index) { 540 } else if (button_index > destination_index) {
532 for (int cur_index = button_index - 1; cur_index >= destination_index; 541 for (int cur_index = button_index - 1; cur_index >= destination_index;
533 cur_index--) 542 cur_index--)
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 dragged_button_mouse = SimulateDrag(ShelfView::MOUSE, 1, 2, false); 1167 dragged_button_mouse = SimulateDrag(ShelfView::MOUSE, 1, 2, false);
1159 1168
1160 // Nothing changes since 2nd drag is ignored. 1169 // Nothing changes since 2nd drag is ignored.
1161 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1170 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1162 1171
1163 shelf_view_->PointerReleasedOnButton(dragged_button_touch, ShelfView::TOUCH, 1172 shelf_view_->PointerReleasedOnButton(dragged_button_touch, ShelfView::TOUCH,
1164 false); 1173 false);
1165 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1174 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1166 } 1175 }
1167 1176
1168 // Check that whether the ash behaves correctly if not draggable 1177 // Ensure the app list button cannot be dragged and other items cannot be
1169 // item are in front of the shelf. 1178 // dragged in front of the app list button.
1170 TEST_F(ShelfViewTest, DragWithNotDraggableItemInFront) { 1179 TEST_F(ShelfViewTest, DragWithNotDraggableItemInFront) {
1180 // The expected id order is initialized as: 1, 2, 3, 4, 5, 6, 7
1171 std::vector<std::pair<ShelfID, views::View*>> id_map; 1181 std::vector<std::pair<ShelfID, views::View*>> id_map;
1172 SetupForDragTest(&id_map); 1182 SetupForDragTest(&id_map);
1183 ASSERT_EQ(TYPE_APP_LIST, model_->items()[0].type);
1173 1184
1174 (static_cast<TestShelfItemDelegate*>( 1185 // Ensure that the app list button cannot be dragged.
1175 model_->GetShelfItemDelegate(id_map[1].first))) 1186 // The expected id order is unchanged: 1, 2, 3, 4, 5, 6, 7
1176 ->set_is_draggable(false); 1187 ASSERT_NO_FATAL_FAILURE(DragAndVerify(0, 1, shelf_view_, id_map));
1177 (static_cast<TestShelfItemDelegate*>( 1188 ASSERT_NO_FATAL_FAILURE(DragAndVerify(0, 2, shelf_view_, id_map));
1178 model_->GetShelfItemDelegate(id_map[2].first))) 1189 ASSERT_NO_FATAL_FAILURE(DragAndVerify(0, 5, shelf_view_, id_map));
1179 ->set_is_draggable(false);
1180 1190
1181 ASSERT_NO_FATAL_FAILURE(DragAndVerify(3, 1, shelf_view_, id_map)); 1191 // 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)); 1192 // Attempting to do so will order buttons immediately after the app list.
1183 1193 // 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); 1194 ASSERT_NO_FATAL_FAILURE(DragAndVerify(1, 0, shelf_view_, id_map));
1185 ASSERT_NO_FATAL_FAILURE(DragAndVerify(4, 1, shelf_view_, id_map)); 1195 // 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); 1196 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)); 1197 ASSERT_NO_FATAL_FAILURE(DragAndVerify(2, 0, shelf_view_, id_map));
1198 // Dragging the sixth button in front should yield: 1, 6, 3, 2, 4, 5, 7
1199 std::rotate(id_map.begin() + 1, id_map.begin() + 5, id_map.begin() + 6);
1200 ASSERT_NO_FATAL_FAILURE(DragAndVerify(5, 0, shelf_view_, id_map));
James Cook 2016/12/14 17:41:54 Thanks for documenting all this.
msw 2016/12/14 19:46:50 Acknowledged.
1188 } 1201 }
1189 1202
1190 // Check that clicking first on one item and then dragging another works as 1203 // Check that clicking first on one item and then dragging another works as
1191 // expected. 1204 // expected.
1192 TEST_F(ShelfViewTest, ClickOneDragAnother) { 1205 TEST_F(ShelfViewTest, ClickOneDragAnother) {
1193 std::vector<std::pair<ShelfID, views::View*>> id_map; 1206 std::vector<std::pair<ShelfID, views::View*>> id_map;
1194 SetupForDragTest(&id_map); 1207 SetupForDragTest(&id_map);
1195 1208
1196 // A click on item 1 is simulated. 1209 // A click on item 1 is simulated.
1197 SimulateClick(1); 1210 SimulateClick(1);
(...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 3127 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
3115 IsEmpty()); 3128 IsEmpty());
3116 3129
3117 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); 3130 ASSERT_TRUE(test_api_->IsShowingOverflowBubble());
3118 } 3131 }
3119 3132
3120 #endif // !defined(OS_WIN) 3133 #endif // !defined(OS_WIN)
3121 3134
3122 } // namespace test 3135 } // namespace test
3123 } // namespace ash 3136 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698