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

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

Issue 1816753002: Enable mash shelf tooltips. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address destructor comment. Created 4 years, 9 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
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/test/shelf_test_api.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 (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/shelf/shelf_view.h" 5 #include "ash/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 shelf_view_test_->SetAnimationDuration(1); 99 shelf_view_test_->SetAnimationDuration(1);
100 } 100 }
101 101
102 void TearDown() override { 102 void TearDown() override {
103 observer_.reset(); 103 observer_.reset();
104 AshTestBase::TearDown(); 104 AshTestBase::TearDown();
105 } 105 }
106 106
107 TestShelfIconObserver* observer() { return observer_.get(); } 107 TestShelfIconObserver* observer() { return observer_.get(); }
108 108
109 ShelfViewTestAPI* shelf_view_test() { 109 ShelfViewTestAPI* shelf_view_test() { return shelf_view_test_.get(); }
110 return shelf_view_test_.get();
111 }
112 110
113 Shelf* ShelfForSecondaryDisplay() { 111 Shelf* ShelfForSecondaryDisplay() {
114 return Shelf::ForWindow(Shell::GetAllRootWindows()[1]); 112 return Shelf::ForWindow(Shell::GetAllRootWindows()[1]);
115 } 113 }
116 114
117 private: 115 private:
118 scoped_ptr<TestShelfIconObserver> observer_; 116 scoped_ptr<TestShelfIconObserver> observer_;
119 scoped_ptr<ShelfViewTestAPI> shelf_view_test_; 117 scoped_ptr<ShelfViewTestAPI> shelf_view_test_;
120 118
121 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest); 119 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); 423 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds();
426 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); 424 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i);
427 EXPECT_GE(item_bounds.x(), 0); 425 EXPECT_GE(item_bounds.x(), 0);
428 EXPECT_GE(item_bounds.y(), 0); 426 EXPECT_GE(item_bounds.y(), 0);
429 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); 427 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width());
430 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); 428 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height());
431 } 429 }
432 } 430 }
433 } 431 }
434 432
435 ShelfButton* SimulateButtonPressed(ShelfButtonHost::Pointer pointer, 433 ShelfButton* SimulateButtonPressed(ShelfView::Pointer pointer,
436 int button_index) { 434 int button_index) {
437 ShelfButtonHost* button_host = shelf_view_;
438 ShelfButton* button = test_api_->GetButton(button_index); 435 ShelfButton* button = test_api_->GetButton(button_index);
439 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, gfx::Point(), 436 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, gfx::Point(),
440 button->GetBoundsInScreen().origin(), 437 button->GetBoundsInScreen().origin(),
441 ui::EventTimeForNow(), 0, 0); 438 ui::EventTimeForNow(), 0, 0);
442 button_host->PointerPressedOnButton(button, pointer, click_event); 439 shelf_view_->PointerPressedOnButton(button, pointer, click_event);
443 return button; 440 return button;
444 } 441 }
445 442
446 // Simulates a single mouse click. 443 // Simulates a single mouse click.
447 void SimulateClick(int button_index) { 444 void SimulateClick(int button_index) {
448 ShelfButtonHost* button_host = shelf_view_; 445 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index);
449 ShelfButton* button =
450 SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index);
451 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), 446 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(),
452 button->GetBoundsInScreen().origin(), 447 button->GetBoundsInScreen().origin(),
453 ui::EventTimeForNow(), 0, 0); 448 ui::EventTimeForNow(), 0, 0);
454 test_api_->ButtonPressed(button, release_event); 449 test_api_->ButtonPressed(button, release_event);
455 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); 450 shelf_view_->PointerReleasedOnButton(button, ShelfView::MOUSE, false);
456 } 451 }
457 452
458 // Simulates the second click of a double click. 453 // Simulates the second click of a double click.
459 void SimulateDoubleClick(int button_index) { 454 void SimulateDoubleClick(int button_index) {
460 ShelfButtonHost* button_host = shelf_view_; 455 ShelfButton* button = SimulateButtonPressed(ShelfView::MOUSE, button_index);
461 ShelfButton* button =
462 SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index);
463 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), 456 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(),
464 button->GetBoundsInScreen().origin(), 457 button->GetBoundsInScreen().origin(),
465 ui::EventTimeForNow(), ui::EF_IS_DOUBLE_CLICK, 458 ui::EventTimeForNow(), ui::EF_IS_DOUBLE_CLICK,
466 0); 459 0);
467 test_api_->ButtonPressed(button, release_event); 460 test_api_->ButtonPressed(button, release_event);
468 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); 461 shelf_view_->PointerReleasedOnButton(button, ShelfView::MOUSE, false);
469 } 462 }
470 463
471 void DoDrag(int dist_x, 464 void DoDrag(int dist_x,
472 int dist_y, 465 int dist_y,
473 views::View* button, 466 views::View* button,
474 ShelfButtonHost::Pointer pointer, 467 ShelfView::Pointer pointer,
475 views::View* to) { 468 views::View* to) {
476 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, gfx::Point(dist_x, dist_y), 469 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, gfx::Point(dist_x, dist_y),
477 to->GetBoundsInScreen().origin(), 470 to->GetBoundsInScreen().origin(),
478 ui::EventTimeForNow(), 0, 0); 471 ui::EventTimeForNow(), 0, 0);
479 static_cast<ShelfButtonHost*>(shelf_view_) 472 shelf_view_->PointerDraggedOnButton(button, pointer, drag_event);
480 ->PointerDraggedOnButton(button, pointer, drag_event);
481 } 473 }
482 474
483 /* 475 /*
484 * Trigger ContinueDrag of the shelf 476 * Trigger ContinueDrag of the shelf
485 * The argument progressively means whether to simulate the drag progress (a 477 * The argument progressively means whether to simulate the drag progress (a
486 * series of changes of the posistion of dragged item), like the normal user 478 * series of changes of the posistion of dragged item), like the normal user
487 * drag behavior. 479 * drag behavior.
488 */ 480 */
489 void ContinueDrag(views::View* button, 481 void ContinueDrag(views::View* button,
490 ShelfButtonHost::Pointer pointer, 482 ShelfView::Pointer pointer,
491 int from_index, 483 int from_index,
492 int to_index, 484 int to_index,
493 bool progressively) { 485 bool progressively) {
494 views::View* to = test_api_->GetButton(to_index); 486 views::View* to = test_api_->GetButton(to_index);
495 views::View* from = test_api_->GetButton(from_index); 487 views::View* from = test_api_->GetButton(from_index);
496 int dist_x = to->x() - from->x(); 488 int dist_x = to->x() - from->x();
497 int dist_y = to->y() - from->y(); 489 int dist_y = to->y() - from->y();
498 if (progressively) { 490 if (progressively) {
499 int sgn = dist_x > 0 ? 1 : -1; 491 int sgn = dist_x > 0 ? 1 : -1;
500 dist_x = abs(dist_x); 492 dist_x = abs(dist_x);
501 for (; dist_x; dist_x -= std::min(10, dist_x)) 493 for (; dist_x; dist_x -= std::min(10, dist_x))
502 DoDrag(sgn * std::min(10, abs(dist_x)), 0, button, pointer, to); 494 DoDrag(sgn * std::min(10, abs(dist_x)), 0, button, pointer, to);
503 } else { 495 } else {
504 DoDrag(dist_x, dist_y, button, pointer, to); 496 DoDrag(dist_x, dist_y, button, pointer, to);
505 } 497 }
506 } 498 }
507 499
508 /* 500 /*
509 * Simulate drag operation. 501 * Simulate drag operation.
510 * Argument progressively means whether to simulate the drag progress (a 502 * Argument progressively means whether to simulate the drag progress (a
511 * series of changes of the posistion of dragged item) like the behavior of 503 * series of changes of the posistion of dragged item) like the behavior of
512 * user drags. 504 * user drags.
513 */ 505 */
514 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer, 506 views::View* SimulateDrag(ShelfView::Pointer pointer,
515 int button_index, 507 int button_index,
516 int destination_index, 508 int destination_index,
517 bool progressively) { 509 bool progressively) {
518 views::View* button = SimulateButtonPressed(pointer, button_index); 510 views::View* button = SimulateButtonPressed(pointer, button_index);
519 511
520 if (!progressively) { 512 if (!progressively) {
521 ContinueDrag(button, pointer, button_index, destination_index, false); 513 ContinueDrag(button, pointer, button_index, destination_index, false);
522 } else if (button_index < destination_index) { 514 } else if (button_index < destination_index) {
523 for (int cur_index = button_index + 1; cur_index <= destination_index; 515 for (int cur_index = button_index + 1; cur_index <= destination_index;
524 cur_index++) 516 cur_index++)
525 ContinueDrag(button, pointer, cur_index - 1, cur_index, true); 517 ContinueDrag(button, pointer, cur_index - 1, cur_index, true);
526 } else if (button_index > destination_index) { 518 } else if (button_index > destination_index) {
527 for (int cur_index = button_index - 1; cur_index >= destination_index; 519 for (int cur_index = button_index - 1; cur_index >= destination_index;
528 cur_index--) 520 cur_index--)
529 ContinueDrag(button, pointer, cur_index + 1, cur_index, true); 521 ContinueDrag(button, pointer, cur_index + 1, cur_index, true);
530 } 522 }
531 return button; 523 return button;
532 } 524 }
533 525
534 void DragAndVerify( 526 void DragAndVerify(
535 int from, 527 int from,
536 int to, 528 int to,
537 ShelfButtonHost* button_host, 529 ShelfView* shelf_view,
538 const std::vector<std::pair<int, views::View*>>& expected_id_map) { 530 const std::vector<std::pair<int, views::View*>>& expected_id_map) {
539 views::View* dragged_button = 531 views::View* dragged_button =
540 SimulateDrag(ShelfButtonHost::MOUSE, from, to, true); 532 SimulateDrag(ShelfView::MOUSE, from, to, true);
541 button_host->PointerReleasedOnButton(dragged_button, ShelfButtonHost::MOUSE, 533 shelf_view->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE,
542 false); 534 false);
543 test_api_->RunMessageLoopUntilAnimationsDone(); 535 test_api_->RunMessageLoopUntilAnimationsDone();
544 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(expected_id_map)); 536 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(expected_id_map));
545 } 537 }
546 538
547 void SetupForDragTest( 539 void SetupForDragTest(
548 std::vector<std::pair<ShelfID, views::View*> >* id_map) { 540 std::vector<std::pair<ShelfID, views::View*> >* id_map) {
549 // Initialize |id_map| with the automatically-created shelf buttons. 541 // Initialize |id_map| with the automatically-created shelf buttons.
550 for (size_t i = 0; i < model_->items().size(); ++i) { 542 for (size_t i = 0; i < model_->items().size(); ++i) {
551 ShelfButton* button = test_api_->GetButton(i); 543 ShelfButton* button = test_api_->GetButton(i);
552 id_map->push_back(std::make_pair(model_->items()[i].id, button)); 544 id_map->push_back(std::make_pair(model_->items()[i].id, button));
553 } 545 }
554 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); 546 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
555 547
556 // Add 5 app shelf buttons for testing. 548 // Add 5 app shelf buttons for testing.
557 for (int i = 0; i < 5; ++i) { 549 for (int i = 0; i < 5; ++i) {
558 ShelfID id = AddAppShortcut(); 550 ShelfID id = AddAppShortcut();
559 // App Icon is located at index 0, and browser shortcut is located at 551 // App Icon is located at index 0, and browser shortcut is located at
560 // index 1. So we should start to add app shortcut at index 2. 552 // index 1. So we should start to add app shortcut at index 2.
561 id_map->insert(id_map->begin() + (i + browser_index_ + 1), 553 id_map->insert(id_map->begin() + (i + browser_index_ + 1),
562 std::make_pair(id, GetButtonByID(id))); 554 std::make_pair(id, GetButtonByID(id)));
563 } 555 }
564 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); 556 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
565 } 557 }
566 558
567 views::View* GetTooltipAnchorView() {
568 return shelf_view_->tooltip_manager()->anchor_;
569 }
570
571 void AddButtonsUntilOverflow() { 559 void AddButtonsUntilOverflow() {
572 int items_added = 0; 560 int items_added = 0;
573 while (!test_api_->IsOverflowButtonVisible()) { 561 while (!test_api_->IsOverflowButtonVisible()) {
574 AddAppShortcut(); 562 AddAppShortcut();
575 ++items_added; 563 ++items_added;
576 ASSERT_LT(items_added, 10000); 564 ASSERT_LT(items_added, 10000);
577 } 565 }
578 } 566 }
579 567
580 void ShowTooltip() {
581 shelf_view_->tooltip_manager()->ShowInternal();
582 }
583
584 void TestDraggingAnItemFromOverflowToShelf(bool cancel) { 568 void TestDraggingAnItemFromOverflowToShelf(bool cancel) {
585 test_api_->ShowOverflowBubble(); 569 test_api_->ShowOverflowBubble();
586 ASSERT_TRUE(test_api_->overflow_bubble() && 570 ASSERT_TRUE(test_api_->overflow_bubble() &&
587 test_api_->overflow_bubble()->IsShowing()); 571 test_api_->overflow_bubble()->IsShowing());
588 572
589 ash::test::ShelfViewTestAPI test_api_for_overflow( 573 ash::test::ShelfViewTestAPI test_api_for_overflow(
590 test_api_->overflow_bubble()->shelf_view()); 574 test_api_->overflow_bubble()->shelf_view());
591 575
592 int total_item_count = model_->item_count(); 576 int total_item_count = model_->item_count();
593 577
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 if (button) { 1083 if (button) {
1100 EXPECT_TRUE(button->visible()) << "button index=" << i; 1084 EXPECT_TRUE(button->visible()) << "button index=" << i;
1101 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; 1085 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i;
1102 } 1086 }
1103 } 1087 }
1104 } 1088 }
1105 1089
1106 // Check that model changes are handled correctly while a shelf icon is being 1090 // Check that model changes are handled correctly while a shelf icon is being
1107 // dragged. 1091 // dragged.
1108 TEST_F(ShelfViewTest, ModelChangesWhileDragging) { 1092 TEST_F(ShelfViewTest, ModelChangesWhileDragging) {
1109 ShelfButtonHost* button_host = shelf_view_;
1110
1111 std::vector<std::pair<ShelfID, views::View*> > id_map; 1093 std::vector<std::pair<ShelfID, views::View*> > id_map;
1112 SetupForDragTest(&id_map); 1094 SetupForDragTest(&id_map);
1113 1095
1114 // Dragging browser shortcut at index 1. 1096 // Dragging browser shortcut at index 1.
1115 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); 1097 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
1116 views::View* dragged_button = 1098 views::View* dragged_button = SimulateDrag(ShelfView::MOUSE, 1, 3, false);
1117 SimulateDrag(ShelfButtonHost::MOUSE, 1, 3, false);
1118 std::rotate(id_map.begin() + 1, 1099 std::rotate(id_map.begin() + 1,
1119 id_map.begin() + 2, 1100 id_map.begin() + 2,
1120 id_map.begin() + 4); 1101 id_map.begin() + 4);
1121 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1102 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1122 button_host->PointerReleasedOnButton( 1103 shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false);
1123 dragged_button, ShelfButtonHost::MOUSE, false);
1124 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); 1104 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
1125 1105
1126 // Dragging changes model order. 1106 // Dragging changes model order.
1127 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3, false); 1107 dragged_button = SimulateDrag(ShelfView::MOUSE, 1, 3, false);
1128 std::rotate(id_map.begin() + 1, 1108 std::rotate(id_map.begin() + 1,
1129 id_map.begin() + 2, 1109 id_map.begin() + 2,
1130 id_map.begin() + 4); 1110 id_map.begin() + 4);
1131 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1111 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1132 1112
1133 // Cancelling the drag operation restores previous order. 1113 // Cancelling the drag operation restores previous order.
1134 button_host->PointerReleasedOnButton( 1114 shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, true);
1135 dragged_button, ShelfButtonHost::MOUSE, true);
1136 std::rotate(id_map.begin() + 1, 1115 std::rotate(id_map.begin() + 1,
1137 id_map.begin() + 3, 1116 id_map.begin() + 3,
1138 id_map.begin() + 4); 1117 id_map.begin() + 4);
1139 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1118 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1140 1119
1141 // Deleting an item keeps the remaining intact. 1120 // Deleting an item keeps the remaining intact.
1142 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3, false); 1121 dragged_button = SimulateDrag(ShelfView::MOUSE, 1, 3, false);
1143 model_->RemoveItemAt(1); 1122 model_->RemoveItemAt(1);
1144 id_map.erase(id_map.begin() + 1); 1123 id_map.erase(id_map.begin() + 1);
1145 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1124 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1146 button_host->PointerReleasedOnButton( 1125 shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false);
1147 dragged_button, ShelfButtonHost::MOUSE, false);
1148 1126
1149 // Adding a shelf item cancels the drag and respects the order. 1127 // Adding a shelf item cancels the drag and respects the order.
1150 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3, false); 1128 dragged_button = SimulateDrag(ShelfView::MOUSE, 1, 3, false);
1151 ShelfID new_id = AddAppShortcut(); 1129 ShelfID new_id = AddAppShortcut();
1152 id_map.insert(id_map.begin() + 6, 1130 id_map.insert(id_map.begin() + 6,
1153 std::make_pair(new_id, GetButtonByID(new_id))); 1131 std::make_pair(new_id, GetButtonByID(new_id)));
1154 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1132 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1155 button_host->PointerReleasedOnButton( 1133 shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false);
1156 dragged_button, ShelfButtonHost::MOUSE, false);
1157 1134
1158 // Adding a shelf item at the end (i.e. a panel) canels drag and respects 1135 // Adding a shelf item at the end (i.e. a panel) canels drag and respects
1159 // the order. 1136 // the order.
1160 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3, false); 1137 dragged_button = SimulateDrag(ShelfView::MOUSE, 1, 3, false);
1161 new_id = AddPanel(); 1138 new_id = AddPanel();
1162 id_map.insert(id_map.begin() + 7, 1139 id_map.insert(id_map.begin() + 7,
1163 std::make_pair(new_id, GetButtonByID(new_id))); 1140 std::make_pair(new_id, GetButtonByID(new_id)));
1164 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1141 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1165 button_host->PointerReleasedOnButton( 1142 shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false);
1166 dragged_button, ShelfButtonHost::MOUSE, false);
1167 } 1143 }
1168 1144
1169 // Check that 2nd drag from the other pointer would be ignored. 1145 // Check that 2nd drag from the other pointer would be ignored.
1170 TEST_F(ShelfViewTest, SimultaneousDrag) { 1146 TEST_F(ShelfViewTest, SimultaneousDrag) {
1171 ShelfButtonHost* button_host = shelf_view_;
1172
1173 std::vector<std::pair<ShelfID, views::View*> > id_map; 1147 std::vector<std::pair<ShelfID, views::View*> > id_map;
1174 SetupForDragTest(&id_map); 1148 SetupForDragTest(&id_map);
1175 1149
1176 // Start a mouse drag. 1150 // Start a mouse drag.
1177 views::View* dragged_button_mouse = 1151 views::View* dragged_button_mouse =
1178 SimulateDrag(ShelfButtonHost::MOUSE, 1, 3, false); 1152 SimulateDrag(ShelfView::MOUSE, 1, 3, false);
1179 std::rotate(id_map.begin() + 1, 1153 std::rotate(id_map.begin() + 1,
1180 id_map.begin() + 2, 1154 id_map.begin() + 2,
1181 id_map.begin() + 4); 1155 id_map.begin() + 4);
1182 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1156 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1183 // Attempt a touch drag before the mouse drag finishes. 1157 // Attempt a touch drag before the mouse drag finishes.
1184 views::View* dragged_button_touch = 1158 views::View* dragged_button_touch =
1185 SimulateDrag(ShelfButtonHost::TOUCH, 4, 2, false); 1159 SimulateDrag(ShelfView::TOUCH, 4, 2, false);
1186 1160
1187 // Nothing changes since 2nd drag is ignored. 1161 // Nothing changes since 2nd drag is ignored.
1188 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1162 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1189 1163
1190 // Finish the mouse drag. 1164 // Finish the mouse drag.
1191 button_host->PointerReleasedOnButton( 1165 shelf_view_->PointerReleasedOnButton(dragged_button_mouse, ShelfView::MOUSE,
1192 dragged_button_mouse, ShelfButtonHost::MOUSE, false); 1166 false);
1193 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1167 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1194 1168
1195 // Now start a touch drag. 1169 // Now start a touch drag.
1196 dragged_button_touch = SimulateDrag(ShelfButtonHost::TOUCH, 4, 2, false); 1170 dragged_button_touch = SimulateDrag(ShelfView::TOUCH, 4, 2, false);
1197 std::rotate(id_map.begin() + 3, 1171 std::rotate(id_map.begin() + 3,
1198 id_map.begin() + 4, 1172 id_map.begin() + 4,
1199 id_map.begin() + 5); 1173 id_map.begin() + 5);
1200 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1174 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1201 1175
1202 // And attempt a mouse drag before the touch drag finishes. 1176 // And attempt a mouse drag before the touch drag finishes.
1203 dragged_button_mouse = SimulateDrag(ShelfButtonHost::MOUSE, 1, 2, false); 1177 dragged_button_mouse = SimulateDrag(ShelfView::MOUSE, 1, 2, false);
1204 1178
1205 // Nothing changes since 2nd drag is ignored. 1179 // Nothing changes since 2nd drag is ignored.
1206 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1180 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1207 1181
1208 button_host->PointerReleasedOnButton( 1182 shelf_view_->PointerReleasedOnButton(dragged_button_touch, ShelfView::TOUCH,
1209 dragged_button_touch, ShelfButtonHost::TOUCH, false); 1183 false);
1210 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1184 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1211 } 1185 }
1212 1186
1213 // Check that whether the ash behaves correctly if not draggable 1187 // Check that whether the ash behaves correctly if not draggable
1214 // item are in front of the shelf. 1188 // item are in front of the shelf.
1215 TEST_F(ShelfViewTest, DragWithNotDraggableItemInFront) { 1189 TEST_F(ShelfViewTest, DragWithNotDraggableItemInFront) {
1216 std::vector<std::pair<ShelfID, views::View*>> id_map; 1190 std::vector<std::pair<ShelfID, views::View*>> id_map;
1217 SetupForDragTest(&id_map); 1191 SetupForDragTest(&id_map);
1218 1192
1219 (static_cast<TestShelfItemDelegate*>( 1193 (static_cast<TestShelfItemDelegate*>(
1220 item_manager_->GetShelfItemDelegate(id_map[1].first))) 1194 item_manager_->GetShelfItemDelegate(id_map[1].first)))
1221 ->set_is_draggable(false); 1195 ->set_is_draggable(false);
1222 (static_cast<TestShelfItemDelegate*>( 1196 (static_cast<TestShelfItemDelegate*>(
1223 item_manager_->GetShelfItemDelegate(id_map[2].first))) 1197 item_manager_->GetShelfItemDelegate(id_map[2].first)))
1224 ->set_is_draggable(false); 1198 ->set_is_draggable(false);
1225 1199
1226 ASSERT_NO_FATAL_FAILURE(DragAndVerify(3, 1, shelf_view_, id_map)); 1200 ASSERT_NO_FATAL_FAILURE(DragAndVerify(3, 1, shelf_view_, id_map));
1227 ASSERT_NO_FATAL_FAILURE(DragAndVerify(3, 2, shelf_view_, id_map)); 1201 ASSERT_NO_FATAL_FAILURE(DragAndVerify(3, 2, shelf_view_, id_map));
1228 1202
1229 std::rotate(id_map.begin() + 3, id_map.begin() + 4, id_map.begin() + 5); 1203 std::rotate(id_map.begin() + 3, id_map.begin() + 4, id_map.begin() + 5);
1230 ASSERT_NO_FATAL_FAILURE(DragAndVerify(4, 1, shelf_view_, id_map)); 1204 ASSERT_NO_FATAL_FAILURE(DragAndVerify(4, 1, shelf_view_, id_map));
1231 std::rotate(id_map.begin() + 3, id_map.begin() + 5, id_map.begin() + 6); 1205 std::rotate(id_map.begin() + 3, id_map.begin() + 5, id_map.begin() + 6);
1232 ASSERT_NO_FATAL_FAILURE(DragAndVerify(5, 1, shelf_view_, id_map)); 1206 ASSERT_NO_FATAL_FAILURE(DragAndVerify(5, 1, shelf_view_, id_map));
1233 } 1207 }
1234 1208
1235 // Check that clicking first on one item and then dragging another works as 1209 // Check that clicking first on one item and then dragging another works as
1236 // expected. 1210 // expected.
1237 TEST_F(ShelfViewTest, ClickOneDragAnother) { 1211 TEST_F(ShelfViewTest, ClickOneDragAnother) {
1238 ShelfButtonHost* button_host = shelf_view_;
1239
1240 std::vector<std::pair<ShelfID, views::View*> > id_map; 1212 std::vector<std::pair<ShelfID, views::View*> > id_map;
1241 SetupForDragTest(&id_map); 1213 SetupForDragTest(&id_map);
1242 1214
1243 // A click on item 1 is simulated. 1215 // A click on item 1 is simulated.
1244 SimulateClick(1); 1216 SimulateClick(1);
1245 1217
1246 // Dragging browser index at 0 should change the model order correctly. 1218 // Dragging browser index at 0 should change the model order correctly.
1247 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); 1219 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
1248 views::View* dragged_button = 1220 views::View* dragged_button = SimulateDrag(ShelfView::MOUSE, 1, 3, false);
1249 SimulateDrag(ShelfButtonHost::MOUSE, 1, 3, false); 1221 std::rotate(id_map.begin() + 1, id_map.begin() + 2, id_map.begin() + 4);
1250 std::rotate(id_map.begin() + 1,
1251 id_map.begin() + 2,
1252 id_map.begin() + 4);
1253 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1222 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1254 button_host->PointerReleasedOnButton( 1223 shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false);
1255 dragged_button, ShelfButtonHost::MOUSE, false);
1256 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); 1224 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
1257 } 1225 }
1258 1226
1259 // Tests that double-clicking an item does not activate it twice. 1227 // Tests that double-clicking an item does not activate it twice.
1260 TEST_F(ShelfViewTest, ClickingTwiceActivatesOnce) { 1228 TEST_F(ShelfViewTest, ClickingTwiceActivatesOnce) {
1261 // Watch for selection of the browser shortcut. 1229 // Watch for selection of the browser shortcut.
1262 ShelfID browser_shelf_id = model_->items()[browser_index_].id; 1230 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
1263 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; 1231 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1264 item_manager_->SetShelfItemDelegate( 1232 item_manager_->SetShelfItemDelegate(
1265 browser_shelf_id, scoped_ptr<ShelfItemDelegate>(selection_tracker)); 1233 browser_shelf_id, scoped_ptr<ShelfItemDelegate>(selection_tracker));
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1336 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1369 test_api_->RunMessageLoopUntilAnimationsDone(); 1337 test_api_->RunMessageLoopUntilAnimationsDone();
1370 VerifyShelfItemBoundsAreValid(); 1338 VerifyShelfItemBoundsAreValid();
1371 shelf_view_->shelf()->shelf_layout_manager()->SetAutoHideBehavior( 1339 shelf_view_->shelf()->shelf_layout_manager()->SetAutoHideBehavior(
1372 SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1340 SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1373 test_api_->RunMessageLoopUntilAnimationsDone(); 1341 test_api_->RunMessageLoopUntilAnimationsDone();
1374 VerifyShelfItemBoundsAreValid(); 1342 VerifyShelfItemBoundsAreValid();
1375 } 1343 }
1376 1344
1377 TEST_F(ShelfViewTest, ShelfTooltipTest) { 1345 TEST_F(ShelfViewTest, ShelfTooltipTest) {
1378 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1346 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, test_api_->GetButtonCount());
1379 test_api_->GetButtonCount());
1380 1347
1381 // Prepare some items to the shelf. 1348 // Prepare some items to the shelf.
1382 ShelfID app_button_id = AddAppShortcut(); 1349 ShelfID app_button_id = AddAppShortcut();
1383 ShelfID platform_button_id = AddPlatformApp(); 1350 ShelfID platform_button_id = AddPlatformApp();
1384 1351
1385 ShelfButton* app_button = GetButtonByID(app_button_id); 1352 ShelfButton* app_button = GetButtonByID(app_button_id);
1386 ShelfButton* platform_button = GetButtonByID(platform_button_id); 1353 ShelfButton* platform_button = GetButtonByID(platform_button_id);
1387 1354
1388 ShelfButtonHost* button_host = shelf_view_; 1355 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager();
1389 ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager(); 1356 EXPECT_TRUE(test_api_->shelf_view()->GetWidget()->GetNativeWindow());
1357 ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow());
1390 1358
1391 button_host->MouseEnteredButton(app_button); 1359 generator.MoveMouseTo(app_button->GetBoundsInScreen().CenterPoint());
1392 // There's a delay to show the tooltip, so it's not visible yet. 1360 // There's a delay to show the tooltip, so it's not visible yet.
1393 EXPECT_FALSE(tooltip_manager->IsVisible()); 1361 EXPECT_FALSE(tooltip_manager->IsVisible());
1394 EXPECT_EQ(app_button, GetTooltipAnchorView()); 1362 EXPECT_EQ(nullptr, tooltip_manager->GetCurrentAnchorView());
1395 1363
1396 ShowTooltip(); 1364 tooltip_manager->ShowTooltip(app_button);
1397 EXPECT_TRUE(tooltip_manager->IsVisible()); 1365 EXPECT_TRUE(tooltip_manager->IsVisible());
1366 EXPECT_EQ(app_button, tooltip_manager->GetCurrentAnchorView());
1398 1367
1399 // Once it's visible, it keeps visibility and is pointing to the same 1368 // The tooltip will continue showing while the cursor moves between buttons.
1400 // item. 1369 const gfx::Point midpoint =
1401 button_host->MouseExitedButton(app_button); 1370 gfx::UnionRects(app_button->GetBoundsInScreen(),
1371 platform_button->GetBoundsInScreen())
1372 .CenterPoint();
1373 generator.MoveMouseTo(midpoint);
1402 EXPECT_TRUE(tooltip_manager->IsVisible()); 1374 EXPECT_TRUE(tooltip_manager->IsVisible());
1403 EXPECT_EQ(app_button, GetTooltipAnchorView()); 1375 EXPECT_EQ(app_button, tooltip_manager->GetCurrentAnchorView());
1404 1376
1405 // When entered to another item, it switches to the new item. There is no 1377 // When the cursor moves over another item, its tooltip shows immediately.
1406 // delay for the visibility. 1378 generator.MoveMouseTo(platform_button->GetBoundsInScreen().CenterPoint());
1407 button_host->MouseEnteredButton(platform_button);
1408 EXPECT_TRUE(tooltip_manager->IsVisible()); 1379 EXPECT_TRUE(tooltip_manager->IsVisible());
1409 EXPECT_EQ(platform_button, GetTooltipAnchorView()); 1380 EXPECT_EQ(platform_button, tooltip_manager->GetCurrentAnchorView());
1410
1411 button_host->MouseExitedButton(platform_button);
1412 tooltip_manager->Close(); 1381 tooltip_manager->Close();
1413 1382
1414 // Next time: enter app_button -> move immediately to tab_button. 1383 // Now cursor over the app_button and move immediately to the platform_button.
1415 button_host->MouseEnteredButton(app_button); 1384 generator.MoveMouseTo(app_button->GetBoundsInScreen().CenterPoint());
1416 button_host->MouseExitedButton(app_button); 1385 generator.MoveMouseTo(midpoint);
1417 button_host->MouseEnteredButton(platform_button); 1386 generator.MoveMouseTo(platform_button->GetBoundsInScreen().CenterPoint());
1418 EXPECT_FALSE(tooltip_manager->IsVisible()); 1387 EXPECT_FALSE(tooltip_manager->IsVisible());
1419 EXPECT_EQ(platform_button, GetTooltipAnchorView()); 1388 EXPECT_EQ(nullptr, tooltip_manager->GetCurrentAnchorView());
1420 } 1389 }
1421 1390
1422 // Verify a fix for crash caused by a tooltip update for a deleted shelf 1391 // Verify a fix for crash caused by a tooltip update for a deleted shelf
1423 // button, see crbug.com/288838. 1392 // button, see crbug.com/288838.
1424 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) { 1393 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) {
1425 ShelfButtonHost* button_host = shelf_view_; 1394 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager();
1426 ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
1427 1395
1428 // Add an item to the shelf. 1396 // Add an item to the shelf.
1429 ShelfID app_button_id = AddAppShortcut(); 1397 ShelfID app_button_id = AddAppShortcut();
1430 ShelfButton* app_button = GetButtonByID(app_button_id); 1398 ShelfButton* app_button = GetButtonByID(app_button_id);
1431 1399
1432 // Spawn a tooltip on that item. 1400 // Spawn a tooltip on that item.
1433 button_host->MouseEnteredButton(app_button); 1401 tooltip_manager->ShowTooltip(app_button);
1434 ShowTooltip();
1435 EXPECT_TRUE(tooltip_manager->IsVisible()); 1402 EXPECT_TRUE(tooltip_manager->IsVisible());
1436 1403
1437 // Remove the app shortcut while the tooltip is open. The tooltip should be 1404 // Remove the app shortcut while the tooltip is open. The tooltip should be
1438 // closed. 1405 // closed.
1439 RemoveByID(app_button_id); 1406 RemoveByID(app_button_id);
1440 EXPECT_FALSE(tooltip_manager->IsVisible()); 1407 EXPECT_FALSE(tooltip_manager->IsVisible());
1441 1408
1442 // Change the shelf layout. This should not crash. 1409 // Change the shelf layout. This should not crash.
1443 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, 1410 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
1444 Shell::GetPrimaryRootWindow()); 1411 Shell::GetPrimaryRootWindow());
1445 } 1412 }
1446 1413
1447 // Changing the shelf alignment closes any open tooltip. 1414 // Changing the shelf alignment closes any open tooltip.
1448 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { 1415 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) {
1449 ShelfButtonHost* button_host = shelf_view_; 1416 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager();
1450 ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager();
1451 1417
1452 // Add an item to the shelf. 1418 // Add an item to the shelf.
1453 ShelfID app_button_id = AddAppShortcut(); 1419 ShelfID app_button_id = AddAppShortcut();
1454 ShelfButton* app_button = GetButtonByID(app_button_id); 1420 ShelfButton* app_button = GetButtonByID(app_button_id);
1455 1421
1456 // Spawn a tooltip on the item. 1422 // Spawn a tooltip on the item.
1457 button_host->MouseEnteredButton(app_button); 1423 tooltip_manager->ShowTooltip(app_button);
1458 ShowTooltip();
1459 EXPECT_TRUE(tooltip_manager->IsVisible()); 1424 EXPECT_TRUE(tooltip_manager->IsVisible());
1460 1425
1461 // Changing shelf alignment hides the tooltip. 1426 // Changing shelf alignment hides the tooltip.
1462 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, 1427 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
1463 Shell::GetPrimaryRootWindow()); 1428 Shell::GetPrimaryRootWindow());
1464 EXPECT_FALSE(tooltip_manager->IsVisible()); 1429 EXPECT_FALSE(tooltip_manager->IsVisible());
1465 } 1430 }
1466 1431
1467 TEST_F(ShelfViewTest, ShouldHideTooltipTest) { 1432 TEST_F(ShelfViewTest, ShouldHideTooltipTest) {
1468 ShelfID app_button_id = AddAppShortcut(); 1433 ShelfID app_button_id = AddAppShortcut();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 1497
1533 // The tooltip should hide on the app-list button. 1498 // The tooltip should hide on the app-list button.
1534 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1499 views::View* app_list_button = shelf_view_->GetAppListButtonView();
1535 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( 1500 EXPECT_TRUE(shelf_view_->ShouldHideTooltip(
1536 app_list_button->GetMirroredBounds().CenterPoint())); 1501 app_list_button->GetMirroredBounds().CenterPoint()));
1537 } 1502 }
1538 1503
1539 // Test that by moving the mouse cursor off the button onto the bubble it closes 1504 // Test that by moving the mouse cursor off the button onto the bubble it closes
1540 // the bubble. 1505 // the bubble.
1541 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) { 1506 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) {
1542 ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager(); 1507 ShelfTooltipManager* tooltip_manager = test_api_->tooltip_manager();
1543 tooltip_manager->CreateZeroDelayTimerForTest(); 1508 tooltip_manager->set_timer_delay_for_test(0);
1544 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1509 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1545 1510
1546 // Move the mouse off any item and check that no tooltip is shown. 1511 // Move the mouse off any item and check that no tooltip is shown.
1547 generator.MoveMouseTo(gfx::Point(0, 0)); 1512 generator.MoveMouseTo(gfx::Point(0, 0));
1548 EXPECT_FALSE(tooltip_manager->IsVisible()); 1513 EXPECT_FALSE(tooltip_manager->IsVisible());
1549 1514
1550 // Move the mouse over the button and check that it is visible. 1515 // Move the mouse over the button and check that it is visible.
1551 views::View* app_list_button = shelf_view_->GetAppListButtonView(); 1516 views::View* app_list_button = shelf_view_->GetAppListButtonView();
1552 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); 1517 gfx::Rect bounds = app_list_button->GetBoundsInScreen();
1553 generator.MoveMouseTo(bounds.CenterPoint()); 1518 generator.MoveMouseTo(bounds.CenterPoint());
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 test_api_->RunMessageLoopUntilAnimationsDone(); 1946 test_api_->RunMessageLoopUntilAnimationsDone();
1982 CheckAllItemsAreInBounds(); 1947 CheckAllItemsAreInBounds();
1983 } 1948 }
1984 1949
1985 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); 1950 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
1986 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, 1951 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
1987 testing::Bool()); 1952 testing::Bool());
1988 1953
1989 } // namespace test 1954 } // namespace test
1990 } // namespace ash 1955 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/test/shelf_test_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698