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

Side by Side Diff: ash/launcher/launcher_view_unittest.cc

Issue 22793011: ash:Shelf - Enable Alternate Shelf and Side Shelf by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
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/launcher/launcher_view.h" 5 #include "ash/launcher/launcher_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 launcher_view_ = launcher->GetLauncherViewForTest(); 206 launcher_view_ = launcher->GetLauncherViewForTest();
207 207
208 // The bounds should be big enough for 4 buttons + overflow chevron. 208 // The bounds should be big enough for 4 buttons + overflow chevron.
209 launcher_view_->SetBounds(0, 0, 500, 50); 209 launcher_view_->SetBounds(0, 0, 500, 50);
210 210
211 test_api_.reset(new LauncherViewTestAPI(launcher_view_)); 211 test_api_.reset(new LauncherViewTestAPI(launcher_view_));
212 test_api_->SetAnimationDuration(1); // Speeds up animation for test. 212 test_api_->SetAnimationDuration(1); // Speeds up animation for test.
213 213
214 // Add browser shortcut launcher item at index 0 for test. 214 // Add browser shortcut launcher item at index 0 for test.
215 AddBrowserShortcut(); 215 AddBrowserShortcut();
216 } 216 }
217 217
218 virtual void TearDown() OVERRIDE { 218 virtual void TearDown() OVERRIDE {
219 test_api_.reset(); 219 test_api_.reset();
220 AshTestBase::TearDown(); 220 AshTestBase::TearDown();
221 } 221 }
222 222
223 protected: 223 protected:
224 LauncherID AddBrowserShortcut() { 224 virtual LauncherID AddBrowserShortcut() {
225 LauncherItem browser_shortcut; 225 LauncherItem browser_shortcut;
226 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 226 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
227 browser_shortcut.is_incognito = false; 227 browser_shortcut.is_incognito = false;
228 228
229 LauncherID id = model_->next_id(); 229 LauncherID id = model_->next_id();
230 model_->AddAt(0, browser_shortcut); 230 model_->AddAt(1, browser_shortcut);
231 test_api_->RunMessageLoopUntilAnimationsDone(); 231 test_api_->RunMessageLoopUntilAnimationsDone();
232 return id; 232 return id;
233 } 233 }
234 234
235 LauncherID AddAppShortcut() { 235 LauncherID AddAppShortcut() {
236 LauncherItem item; 236 LauncherItem item;
237 item.type = TYPE_APP_SHORTCUT; 237 item.type = TYPE_APP_SHORTCUT;
238 item.status = STATUS_CLOSED; 238 item.status = STATUS_CLOSED;
239 239
240 LauncherID id = model_->next_id(); 240 LauncherID id = model_->next_id();
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 364
365 // Drag. 365 // Drag.
366 views::View* destination = test_api_->GetButton(destination_index); 366 views::View* destination = test_api_->GetButton(destination_index);
367 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 367 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
368 destination->bounds().origin(), 368 destination->bounds().origin(),
369 destination->bounds().origin(), 0); 369 destination->bounds().origin(), 0);
370 button_host->PointerDraggedOnButton(button, pointer, drag_event); 370 button_host->PointerDraggedOnButton(button, pointer, drag_event);
371 return button; 371 return button;
372 } 372 }
373 373
374 void SetupForDragTest( 374 virtual void SetupForDragTest(
375 std::vector<std::pair<LauncherID, views::View*> >* id_map) { 375 std::vector<std::pair<LauncherID, views::View*> >* id_map) {
376 // Initialize |id_map| with the automatically-created launcher buttons. 376 // Initialize |id_map| with the automatically-created launcher buttons.
377 for (size_t i = 0; i < model_->items().size(); ++i) { 377 for (size_t i = 0; i < model_->items().size(); ++i) {
378 internal::LauncherButton* button = test_api_->GetButton(i); 378 internal::LauncherButton* button = test_api_->GetButton(i);
379 id_map->push_back(std::make_pair(model_->items()[i].id, button)); 379 id_map->push_back(std::make_pair(model_->items()[i].id, button));
380 } 380 }
381 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); 381 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
382 382
383 // Add 5 app launcher buttons for testing. 383 // Add 5 app launcher buttons for testing.
384 for (int i = 0; i < 5; ++i) { 384 for (int i = 0; i < 5; ++i) {
385 LauncherID id = AddAppShortcut(); 385 LauncherID id = AddAppShortcut();
386 // browser shortcut is located at index 0. So we should start to add app 386 // App Icon is located at index 0, and browser shortcut is located at
387 // shortcut at index 1. 387 // index 1. So we should start to add app shortcuts at index 2.
388 id_map->insert(id_map->begin() + (i + 1), 388 id_map->insert(id_map->begin() + (i + 2),
389 std::make_pair(id, GetButtonByID(id))); 389 std::make_pair(id, GetButtonByID(id)));
390 } 390 }
391 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); 391 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
392 } 392 }
393 393
394 views::View* GetTooltipAnchorView() { 394 views::View* GetTooltipAnchorView() {
395 return launcher_view_->tooltip_manager()->anchor_; 395 return launcher_view_->tooltip_manager()->anchor_;
396 } 396 }
397 397
398 void ShowTooltip() { 398 void ShowTooltip() {
399 launcher_view_->tooltip_manager()->ShowInternal(); 399 launcher_view_->tooltip_manager()->ShowInternal();
400 } 400 }
401 401
402 LauncherModel* model_; 402 LauncherModel* model_;
403 internal::LauncherView* launcher_view_; 403 internal::LauncherView* launcher_view_;
404 404
405 scoped_ptr<LauncherViewTestAPI> test_api_; 405 scoped_ptr<LauncherViewTestAPI> test_api_;
406 406
407 private: 407 private:
408 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); 408 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest);
409 }; 409 };
410 410
411 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest {
412 public:
413 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() {}
James Cook 2013/08/22 00:19:12 see below, but this could do something like: {
Harry McCleave 2013/08/27 00:37:00 Done.
414
415 virtual void SetUp() OVERRIDE {
416 CommandLine::ForCurrentProcess()->AppendSwitch(
417 ash::switches::kAshDisableAlternateShelfLayout);
418 LauncherViewTest::SetUp();
419 }
420
421 protected:
422 virtual LauncherID AddBrowserShortcut() OVERRIDE {
423 LauncherItem browser_shortcut;
424 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
425 browser_shortcut.is_incognito = false;
426
427 LauncherID id = model_->next_id();
428 model_->AddAt(0, browser_shortcut);
429 test_api_->RunMessageLoopUntilAnimationsDone();
430 return id;
431 }
432
433 virtual void SetupForDragTest(
James Cook 2013/08/22 00:19:12 This feels to me like it doesn't need to be duplic
Harry McCleave 2013/08/27 00:37:00 Done.
434 std::vector<std::pair<LauncherID, views::View*> >* id_map) OVERRIDE {
435 // Initialize |id_map| with the automatically-created launcher buttons.
436 for (size_t i = 0; i < model_->items().size(); ++i) {
437 internal::LauncherButton* button = test_api_->GetButton(i);
438 id_map->push_back(std::make_pair(model_->items()[i].id, button));
439 }
440 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
441
442 // Add 5 app launcher buttons for testing.
443 for (int i = 0; i < 5; ++i) {
444 LauncherID id = AddAppShortcut();
445 // browser shortcut is located at index 0. So we should start to add app
446 // shortcut at index 1.
447 id_map->insert(id_map->begin() + (i + 1),
448 std::make_pair(id, GetButtonByID(id)));
449 }
450 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map));
451 }
452
453 private:
454 DISALLOW_COPY_AND_ASSIGN(LauncherViewLegacyShelfLayoutTest);
455 };
456
411 class LauncherViewTextDirectionTest 457 class LauncherViewTextDirectionTest
412 : public LauncherViewTest, 458 : public LauncherViewTest,
413 public testing::WithParamInterface<bool> { 459 public testing::WithParamInterface<bool> {
414 public: 460 public:
415 LauncherViewTextDirectionTest() : is_rtl_(GetParam()) {} 461 LauncherViewTextDirectionTest() : is_rtl_(GetParam()) {}
416 virtual ~LauncherViewTextDirectionTest() {} 462 virtual ~LauncherViewTextDirectionTest() {}
417 463
418 virtual void SetUp() OVERRIDE { 464 virtual void SetUp() OVERRIDE {
419 LauncherViewTest::SetUp(); 465 LauncherViewTest::SetUp();
420 original_locale_ = l10n_util::GetApplicationLocale(std::string()); 466 original_locale_ = l10n_util::GetApplicationLocale(std::string());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 LauncherID last_added = AddAppShortcut(); 579 LauncherID last_added = AddAppShortcut();
534 while (!test_api_->IsOverflowButtonVisible()) { 580 while (!test_api_->IsOverflowButtonVisible()) {
535 // Added button is visible after animation while in this loop. 581 // Added button is visible after animation while in this loop.
536 EXPECT_TRUE(GetButtonByID(last_added)->visible()); 582 EXPECT_TRUE(GetButtonByID(last_added)->visible());
537 583
538 last_added = AddAppShortcut(); 584 last_added = AddAppShortcut();
539 ++items_added; 585 ++items_added;
540 ASSERT_LT(items_added, 10000); 586 ASSERT_LT(items_added, 10000);
541 } 587 }
542 588
589 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
590 }
591
592 TEST_F(LauncherViewLegacyShelfLayoutTest,
593 AddAppShortcutWithBrowserButtonUntilOverflow) {
594 // All buttons should be visible.
595 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
596 test_api_->GetButtonCount());
597
598 LauncherID browser_button_id = AddTabbedBrowser();
599
600 // Add app shortcut until overflow.
601 int items_added = 0;
602 LauncherID last_added = AddAppShortcut();
603 while (!test_api_->IsOverflowButtonVisible()) {
604 // Added button is visible after animation while in this loop.
605 EXPECT_TRUE(GetButtonByID(last_added)->visible());
606
607 last_added = AddAppShortcut();
608 ++items_added;
609 ASSERT_LT(items_added, 10000);
610 }
611
543 // The last added app short button should be visible. 612 // The last added app short button should be visible.
544 EXPECT_TRUE(GetButtonByID(last_added)->visible()); 613 EXPECT_TRUE(GetButtonByID(last_added)->visible());
545 // And the browser button is invisible. 614 // And the browser button is invisible.
546 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); 615 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
547 } 616 }
548 617
549 TEST_F(LauncherViewTest, AddPanelHidesTabbedBrowser) { 618 TEST_F(LauncherViewTest, AddPanelHidesTabbedBrowser) {
550 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 619 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
551 test_api_->GetButtonCount()); 620 test_api_->GetButtonCount());
552 621
553 // Add tabbed browser until overflow, remember last visible tabbed browser. 622 // Add tabbed browser until overflow, remember last visible tabbed browser.
554 int items_added = 0; 623 int items_added = 0;
555 LauncherID first_added = AddTabbedBrowser(); 624 LauncherID first_added = AddTabbedBrowser();
556 EXPECT_TRUE(GetButtonByID(first_added)->visible()); 625 EXPECT_TRUE(GetButtonByID(first_added)->visible());
626 while (true) {
627 LauncherID added = AddTabbedBrowser();
628 if (test_api_->IsOverflowButtonVisible()) {
629 EXPECT_FALSE(GetButtonByID(added)->visible());
630 RemoveByID(added);
631 break;
632 }
633 ++items_added;
634 ASSERT_LT(items_added, 10000);
635 }
636
637 EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
638 LauncherID panel = AddPanel();
639 EXPECT_TRUE(GetButtonByID(panel)->visible());
640 EXPECT_TRUE(test_api_->IsOverflowButtonVisible());
641 RemoveByID(panel);
642 EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
643 }
644
645 TEST_F(LauncherViewLegacyShelfLayoutTest, AddPanelHidesTabbedBrowser) {
646 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
647 test_api_->GetButtonCount());
648
649 // Add tabbed browser until overflow, remember last visible tabbed browser.
650 int items_added = 0;
651 LauncherID first_added = AddTabbedBrowser();
652 EXPECT_TRUE(GetButtonByID(first_added)->visible());
557 LauncherID last_visible = first_added; 653 LauncherID last_visible = first_added;
558 while (true) { 654 while (true) {
559 LauncherID added = AddTabbedBrowser(); 655 LauncherID added = AddTabbedBrowser();
560 if (test_api_->IsOverflowButtonVisible()) { 656 if (test_api_->IsOverflowButtonVisible()) {
561 EXPECT_FALSE(GetButtonByID(added)->visible()); 657 EXPECT_FALSE(GetButtonByID(added)->visible());
562 break; 658 break;
563 } 659 }
564 last_visible = added; 660 last_visible = added;
565 ++items_added; 661 ++items_added;
566 ASSERT_LT(items_added, 10000); 662 ASSERT_LT(items_added, 10000);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 while (GetButtonByID(browser)->visible() && 703 while (GetButtonByID(browser)->visible() &&
608 GetButtonByID(last_panel)->visible()) { 704 GetButtonByID(last_panel)->visible()) {
609 browser = AddTabbedBrowser(); 705 browser = AddTabbedBrowser();
610 ++items_added; 706 ++items_added;
611 ASSERT_LT(items_added, 10000); 707 ASSERT_LT(items_added, 10000);
612 } 708 }
613 EXPECT_TRUE(GetButtonByID(last_panel)->visible()); 709 EXPECT_TRUE(GetButtonByID(last_panel)->visible());
614 EXPECT_FALSE(GetButtonByID(browser)->visible()); 710 EXPECT_FALSE(GetButtonByID(browser)->visible());
615 } 711 }
616 712
713 TEST_F(LauncherViewLegacyShelfLayoutTest, BrowserHidesExcessPanels) {
714 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
715 test_api_->GetButtonCount());
716
717 // Add tabbed browser.
718 LauncherID browser = AddTabbedBrowser();
719 LauncherID first_panel = AddPanel();
720
721 EXPECT_TRUE(GetButtonByID(browser)->visible());
722 EXPECT_TRUE(GetButtonByID(first_panel)->visible());
723
724 // Add panels until there is an overflow.
725 LauncherID last_panel = first_panel;
726 int items_added = 0;
727 while (!test_api_->IsOverflowButtonVisible()) {
728 last_panel = AddPanel();
729 ++items_added;
730 ASSERT_LT(items_added, 10000);
731 }
732
733 // The first panel should now be hidden by the new browsers needing space.
734 EXPECT_FALSE(GetButtonByID(first_panel)->visible());
735 EXPECT_TRUE(GetButtonByID(last_panel)->visible());
736 EXPECT_TRUE(GetButtonByID(browser)->visible());
737
738 // Adding browsers should eventually begin to hide browsers. We will add
739 // browsers until either the last panel or browser is hidden.
740 items_added = 0;
741 while (GetButtonByID(browser)->visible() &&
742 GetButtonByID(last_panel)->visible()) {
743 browser = AddTabbedBrowser();
744 ++items_added;
745 ASSERT_LT(items_added, 10000);
746 }
747 EXPECT_TRUE(GetButtonByID(last_panel)->visible());
748 EXPECT_FALSE(GetButtonByID(browser)->visible());
749 }
750
617 // Adds button until overflow then removes first added one. Verifies that 751 // Adds button until overflow then removes first added one. Verifies that
618 // the last added one changes from invisible to visible and overflow 752 // the last added one changes from invisible to visible and overflow
619 // chevron is gone. 753 // chevron is gone.
620 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) { 754 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) {
621 // All buttons should be visible. 755 // All buttons should be visible.
622 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 756 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
623 test_api_->GetButtonCount()); 757 test_api_->GetButtonCount());
624 758
625 // Add tabbed browser until overflow. 759 // Add tabbed browser until overflow.
626 int items_added = 0; 760 int items_added = 0;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 832
699 // Check that model changes are handled correctly while a launcher icon is being 833 // Check that model changes are handled correctly while a launcher icon is being
700 // dragged. 834 // dragged.
701 TEST_F(LauncherViewTest, ModelChangesWhileDragging) { 835 TEST_F(LauncherViewTest, ModelChangesWhileDragging) {
702 internal::LauncherButtonHost* button_host = launcher_view_; 836 internal::LauncherButtonHost* button_host = launcher_view_;
703 837
704 std::vector<std::pair<LauncherID, views::View*> > id_map; 838 std::vector<std::pair<LauncherID, views::View*> > id_map;
705 SetupForDragTest(&id_map); 839 SetupForDragTest(&id_map);
706 840
707 // Dragging browser shortcut at index 0. 841 // Dragging browser shortcut at index 0.
842 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
843 views::View* dragged_button = SimulateDrag(
844 internal::LauncherButtonHost::MOUSE, 1, 3);
845 std::rotate(id_map.begin() + 1,
846 id_map.begin() + 2,
847 id_map.begin() + 4);
848 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
849 button_host->PointerReleasedOnButton(dragged_button,
850 internal::LauncherButtonHost::MOUSE,
851 false);
852 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
853
854 // Dragging changes model order.
855 dragged_button = SimulateDrag(
856 internal::LauncherButtonHost::MOUSE, 1, 3);
857 std::rotate(id_map.begin() + 1,
858 id_map.begin() + 2,
859 id_map.begin() + 4);
860 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
861
862 // Cancelling the drag operation restores previous order.
863 button_host->PointerReleasedOnButton(dragged_button,
864 internal::LauncherButtonHost::MOUSE,
865 true);
866 std::rotate(id_map.begin() + 1,
867 id_map.begin() + 3,
868 id_map.begin() + 4);
869 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
870
871 // Deleting an item keeps the remaining intact.
872 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
873 model_->RemoveItemAt(1);
874 id_map.erase(id_map.begin() + 1);
875 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
876 button_host->PointerReleasedOnButton(dragged_button,
877 internal::LauncherButtonHost::MOUSE,
878 false);
879
880 // Adding a launcher item cancels the drag and respects the order.
881 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
882 LauncherID new_id = AddAppShortcut();
883 id_map.insert(id_map.begin() + 6,
884 std::make_pair(new_id, GetButtonByID(new_id)));
885 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
886 button_host->PointerReleasedOnButton(dragged_button,
887 internal::LauncherButtonHost::MOUSE,
888 false);
889
890 // Adding a launcher item at the end (i.e. a panel) canels drag and respects
891 // the order.
892 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
893 new_id = AddPanel();
894 id_map.insert(id_map.begin() + 7,
895 std::make_pair(new_id, GetButtonByID(new_id)));
896 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
897 button_host->PointerReleasedOnButton(dragged_button,
898 internal::LauncherButtonHost::MOUSE,
899 false);
900 }
901
902 TEST_F(LauncherViewLegacyShelfLayoutTest, ModelChangesWhileDragging) {
903 internal::LauncherButtonHost* button_host = launcher_view_;
904
905 std::vector<std::pair<LauncherID, views::View*> > id_map;
906 SetupForDragTest(&id_map);
907
908 // Dragging browser shortcut at index 0.
708 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); 909 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT);
709 views::View* dragged_button = SimulateDrag( 910 views::View* dragged_button = SimulateDrag(
710 internal::LauncherButtonHost::MOUSE, 0, 2); 911 internal::LauncherButtonHost::MOUSE, 0, 2);
711 std::rotate(id_map.begin(), 912 std::rotate(id_map.begin(),
712 id_map.begin() + 1, 913 id_map.begin() + 1,
713 id_map.begin() + 3); 914 id_map.begin() + 3);
714 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 915 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
715 button_host->PointerReleasedOnButton(dragged_button, 916 button_host->PointerReleasedOnButton(dragged_button,
716 internal::LauncherButtonHost::MOUSE, 917 internal::LauncherButtonHost::MOUSE,
717 false); 918 false);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 968
768 // Check that 2nd drag from the other pointer would be ignored. 969 // Check that 2nd drag from the other pointer would be ignored.
769 TEST_F(LauncherViewTest, SimultaneousDrag) { 970 TEST_F(LauncherViewTest, SimultaneousDrag) {
770 internal::LauncherButtonHost* button_host = launcher_view_; 971 internal::LauncherButtonHost* button_host = launcher_view_;
771 972
772 std::vector<std::pair<LauncherID, views::View*> > id_map; 973 std::vector<std::pair<LauncherID, views::View*> > id_map;
773 SetupForDragTest(&id_map); 974 SetupForDragTest(&id_map);
774 975
775 // Start a mouse drag. 976 // Start a mouse drag.
776 views::View* dragged_button_mouse = SimulateDrag( 977 views::View* dragged_button_mouse = SimulateDrag(
978 internal::LauncherButtonHost::MOUSE, 1, 3);
979 std::rotate(id_map.begin() + 1,
980 id_map.begin() + 2,
981 id_map.begin() + 4);
982
983 // Attempt a touch drag before the mouse drag finishes.
984 views::View* dragged_button_touch = SimulateDrag(
985 internal::LauncherButtonHost::TOUCH, 4, 2);
986 (void)button_host;(void)dragged_button_mouse;(void)dragged_button_touch;
987 // Nothing changes since 2nd drag is ignored.
988 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
989
990 // Finish the mouse drag.
991 button_host->PointerReleasedOnButton(dragged_button_mouse,
992 internal::LauncherButtonHost::MOUSE,
993 false);
994 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
995
996 // Now start a touch drag.
997 dragged_button_touch = SimulateDrag(
998 internal::LauncherButtonHost::TOUCH, 4, 2);
999 std::rotate(id_map.begin() + 3,
1000 id_map.begin() + 4,
1001 id_map.begin() + 5);
1002 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1003
1004 // And attempt a mouse drag before the touch drag finishes.
1005 dragged_button_mouse = SimulateDrag(
1006 internal::LauncherButtonHost::MOUSE, 1, 2);
1007
1008 // Nothing changes since 2nd drag is ignored.
1009 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1010
1011 button_host->PointerReleasedOnButton(dragged_button_touch,
1012 internal::LauncherButtonHost::TOUCH,
1013 false);
1014 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1015 }
1016
1017 TEST_F(LauncherViewLegacyShelfLayoutTest, SimultaneousDrag) {
1018 internal::LauncherButtonHost* button_host = launcher_view_;
1019
1020 std::vector<std::pair<LauncherID, views::View*> > id_map;
1021 SetupForDragTest(&id_map);
1022
1023 // Start a mouse drag.
1024 views::View* dragged_button_mouse = SimulateDrag(
777 internal::LauncherButtonHost::MOUSE, 0, 2); 1025 internal::LauncherButtonHost::MOUSE, 0, 2);
778 std::rotate(id_map.begin(), 1026 std::rotate(id_map.begin(),
779 id_map.begin() + 1, 1027 id_map.begin() + 1,
780 id_map.begin() + 3); 1028 id_map.begin() + 3);
781 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1029 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
782 // Attempt a touch drag before the mouse drag finishes. 1030 // Attempt a touch drag before the mouse drag finishes.
783 views::View* dragged_button_touch = SimulateDrag( 1031 views::View* dragged_button_touch = SimulateDrag(
784 internal::LauncherButtonHost::TOUCH, 3, 1); 1032 internal::LauncherButtonHost::TOUCH, 3, 1);
785 1033
786 // Nothing changes since 2nd drag is ignored. 1034 // Nothing changes since 2nd drag is ignored.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 TEST_F(LauncherViewTest, ClickOneDragAnother) { 1066 TEST_F(LauncherViewTest, ClickOneDragAnother) {
819 internal::LauncherButtonHost* button_host = launcher_view_; 1067 internal::LauncherButtonHost* button_host = launcher_view_;
820 1068
821 std::vector<std::pair<LauncherID, views::View*> > id_map; 1069 std::vector<std::pair<LauncherID, views::View*> > id_map;
822 SetupForDragTest(&id_map); 1070 SetupForDragTest(&id_map);
823 1071
824 // A click on item 1 is simulated. 1072 // A click on item 1 is simulated.
825 SimulateClick(internal::LauncherButtonHost::MOUSE, 1); 1073 SimulateClick(internal::LauncherButtonHost::MOUSE, 1);
826 1074
827 // Dragging browser index at 0 should change the model order correctly. 1075 // Dragging browser index at 0 should change the model order correctly.
1076 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
1077 views::View* dragged_button = SimulateDrag(
1078 internal::LauncherButtonHost::MOUSE, 1, 3);
1079 std::rotate(id_map.begin() + 1,
1080 id_map.begin() + 2,
1081 id_map.begin() + 4);
1082 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1083 button_host->PointerReleasedOnButton(dragged_button,
1084 internal::LauncherButtonHost::MOUSE,
1085 false);
1086 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
1087 }
1088
1089 TEST_F(LauncherViewLegacyShelfLayoutTest, ClickOneDragAnother) {
1090 internal::LauncherButtonHost* button_host = launcher_view_;
1091
1092 std::vector<std::pair<LauncherID, views::View*> > id_map;
1093 SetupForDragTest(&id_map);
1094
1095 // A click on item 1 is simulated.
1096 SimulateClick(internal::LauncherButtonHost::MOUSE, 1);
1097
1098 // Dragging browser index at 0 should change the model order correctly.
828 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); 1099 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT);
829 views::View* dragged_button = SimulateDrag( 1100 views::View* dragged_button = SimulateDrag(
830 internal::LauncherButtonHost::MOUSE, 0, 2); 1101 internal::LauncherButtonHost::MOUSE, 0, 2);
831 std::rotate(id_map.begin(), 1102 std::rotate(id_map.begin(),
832 id_map.begin() + 1, 1103 id_map.begin() + 1,
833 id_map.begin() + 3); 1104 id_map.begin() + 3);
834 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1105 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
835 button_host->PointerReleasedOnButton(dragged_button, 1106 button_host->PointerReleasedOnButton(dragged_button,
836 internal::LauncherButtonHost::MOUSE, 1107 internal::LauncherButtonHost::MOUSE,
837 false); 1108 false);
(...skipping 12 matching lines...) Expand all
850 internal::LauncherButton* button = GetButtonByID(last_added); 1121 internal::LauncherButton* button = GetButtonByID(last_added);
851 ASSERT_EQ(internal::LauncherButton::STATE_RUNNING, button->state()); 1122 ASSERT_EQ(internal::LauncherButton::STATE_RUNNING, button->state());
852 item.status = ash::STATUS_ACTIVE; 1123 item.status = ash::STATUS_ACTIVE;
853 model_->Set(index, item); 1124 model_->Set(index, item);
854 ASSERT_EQ(internal::LauncherButton::STATE_ACTIVE, button->state()); 1125 ASSERT_EQ(internal::LauncherButton::STATE_ACTIVE, button->state());
855 item.status = ash::STATUS_ATTENTION; 1126 item.status = ash::STATUS_ATTENTION;
856 model_->Set(index, item); 1127 model_->Set(index, item);
857 ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state()); 1128 ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state());
858 } 1129 }
859 1130
860 TEST_F(LauncherViewTest, LauncherItemPositionReflectedOnStateChanged) { 1131 TEST_F(LauncherViewLegacyShelfLayoutTest,
1132 LauncherItemPositionReflectedOnStateChanged) {
861 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1133 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
862 test_api_->GetButtonCount()); 1134 test_api_->GetButtonCount());
863 1135
864 // Add 2 items to the launcher. 1136 // Add 2 items to the launcher.
865 LauncherID item1_id = AddTabbedBrowser(); 1137 LauncherID item1_id = AddTabbedBrowser();
866 LauncherID item2_id = AddPlatformAppNoWait(); 1138 LauncherID item2_id = AddPlatformAppNoWait();
867 internal::LauncherButton* item1_button = GetButtonByID(item1_id); 1139 internal::LauncherButton* item1_button = GetButtonByID(item1_id);
868 internal::LauncherButton* item2_button = GetButtonByID(item2_id); 1140 internal::LauncherButton* item2_button = GetButtonByID(item2_id);
869 1141
870 internal::LauncherButton::State state_mask = 1142 internal::LauncherButton::State state_mask =
871 static_cast<internal::LauncherButton::State> 1143 static_cast<internal::LauncherButton::State>
872 (internal::LauncherButton::STATE_NORMAL | 1144 (internal::LauncherButton::STATE_NORMAL |
873 internal::LauncherButton::STATE_HOVERED | 1145 internal::LauncherButton::STATE_HOVERED |
874 internal::LauncherButton::STATE_RUNNING | 1146 internal::LauncherButton::STATE_RUNNING |
875 internal::LauncherButton::STATE_ACTIVE | 1147 internal::LauncherButton::STATE_ACTIVE |
876 internal::LauncherButton::STATE_ATTENTION | 1148 internal::LauncherButton::STATE_ATTENTION |
877 internal::LauncherButton::STATE_FOCUSED); 1149 internal::LauncherButton::STATE_FOCUSED);
878 1150
879 // Clear the button states. 1151 // Clear the button states.
880 item1_button->ClearState(state_mask); 1152 item1_button->ClearState(state_mask);
881 item2_button->ClearState(state_mask); 1153 item2_button->ClearState(state_mask);
882 1154
883 // Since default alignment in tests is bottom, state is reflected in y-axis. 1155 // Since default alignment in tests is bottom, state is reflected in y-axis.
884 ASSERT_EQ(item1_button->GetIconBounds().y(), 1156 ASSERT_EQ(item1_button->GetIconBounds().y(),
885 item2_button->GetIconBounds().y()); 1157 item2_button->GetIconBounds().y());
886 item1_button->AddState(internal::LauncherButton::STATE_HOVERED); 1158 item1_button->AddState(internal::LauncherButton::STATE_HOVERED);
887 ASSERT_NE(item1_button->GetIconBounds().y(), 1159 ASSERT_NE(item1_button->GetIconBounds().y(),
888 item2_button->GetIconBounds().y()); 1160 item2_button->GetIconBounds().y());
889 item1_button->ClearState(internal::LauncherButton::STATE_HOVERED); 1161 item1_button->ClearState(internal::LauncherButton::STATE_HOVERED);
890
891 // Enable the alternate shelf layout.
892 CommandLine::ForCurrentProcess()->AppendSwitch(
893 ash::switches::kAshUseAlternateShelfLayout);
894 launcher_view_->Layout();
895
896 // Since default alignment in tests is bottom, state is reflected in y-axis.
897 // In alternate shelf layout there is no visible hovered state.
898 ASSERT_EQ(item1_button->GetIconBounds().y(),
899 item2_button->GetIconBounds().y());
900 item1_button->AddState(internal::LauncherButton::STATE_HOVERED);
901 ASSERT_EQ(item1_button->GetIconBounds().y(),
902 item2_button->GetIconBounds().y());
903 } 1162 }
904 1163
905 // Confirm that item status changes are reflected in the buttons 1164 // Confirm that item status changes are reflected in the buttons
906 // for platform apps. 1165 // for platform apps.
907 TEST_F(LauncherViewTest, LauncherItemStatusPlatformApp) { 1166 TEST_F(LauncherViewTest, LauncherItemStatusPlatformApp) {
908 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1167 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
909 test_api_->GetButtonCount()); 1168 test_api_->GetButtonCount());
910 1169
911 // Add tabbed browser. 1170 // Add tabbed browser.
912 LauncherID last_added = AddPlatformApp(); 1171 LauncherID last_added = AddPlatformApp();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 // Move the mouse over the button and check that it is visible. 1326 // Move the mouse over the button and check that it is visible.
1068 views::View* app_list_button = launcher_view_->GetAppListButtonView(); 1327 views::View* app_list_button = launcher_view_->GetAppListButtonView();
1069 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); 1328 gfx::Rect bounds = app_list_button->GetBoundsInScreen();
1070 generator.MoveMouseTo(bounds.CenterPoint()); 1329 generator.MoveMouseTo(bounds.CenterPoint());
1071 // Wait for the timer to go off. 1330 // Wait for the timer to go off.
1072 RunAllPendingInMessageLoop(); 1331 RunAllPendingInMessageLoop();
1073 EXPECT_TRUE(tooltip_manager->IsVisible()); 1332 EXPECT_TRUE(tooltip_manager->IsVisible());
1074 1333
1075 // Move the mouse cursor slightly to the right of the item. The tooltip should 1334 // Move the mouse cursor slightly to the right of the item. The tooltip should
1076 // stay open. 1335 // stay open.
1077 generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0); 1336 generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
1078 // Make sure there is no delayed close. 1337 // Make sure there is no delayed close.
1079 RunAllPendingInMessageLoop(); 1338 RunAllPendingInMessageLoop();
1080 EXPECT_TRUE(tooltip_manager->IsVisible()); 1339 EXPECT_TRUE(tooltip_manager->IsVisible());
1081 1340
1082 // Move back - it should still stay open. 1341 // Move back - it should still stay open.
1083 generator.MoveMouseBy(bounds.width() / 2 + 5, 0); 1342 generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0);
1084 // Make sure there is no delayed close. 1343 // Make sure there is no delayed close.
1085 RunAllPendingInMessageLoop(); 1344 RunAllPendingInMessageLoop();
1086 EXPECT_TRUE(tooltip_manager->IsVisible()); 1345 EXPECT_TRUE(tooltip_manager->IsVisible());
1087 1346
1088 // Now move the mouse cursor slightly above the item - so that it is over the 1347 // Now move the mouse cursor slightly above the item - so that it is over the
1089 // tooltip bubble. Now it should disappear. 1348 // tooltip bubble. Now it should disappear.
1090 generator.MoveMouseBy(0, -(bounds.height() / 2 + 5)); 1349 generator.MoveMouseBy(0, -(bounds.height() / 2 + 5));
1091 // Wait until the delayed close kicked in. 1350 // Wait until the delayed close kicked in.
1092 RunAllPendingInMessageLoop(); 1351 RunAllPendingInMessageLoop();
1093 EXPECT_FALSE(tooltip_manager->IsVisible()); 1352 EXPECT_FALSE(tooltip_manager->IsVisible());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 const int app_list_button_index = test_api_->GetButtonCount() - 1; 1384 const int app_list_button_index = test_api_->GetButtonCount() - 1;
1126 const gfx::Rect& app_list_ideal_bounds = 1385 const gfx::Rect& app_list_ideal_bounds =
1127 test_api_->GetIdealBoundsByIndex(app_list_button_index); 1386 test_api_->GetIdealBoundsByIndex(app_list_button_index);
1128 const gfx::Rect& app_list_bounds = 1387 const gfx::Rect& app_list_bounds =
1129 test_api_->GetBoundsByIndex(app_list_button_index); 1388 test_api_->GetBoundsByIndex(app_list_button_index);
1130 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); 1389 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds);
1131 } 1390 }
1132 1391
1133 // Check that the first item in the list follows Fitt's law by including the 1392 // Check that the first item in the list follows Fitt's law by including the
1134 // first pixel and being therefore bigger then the others. 1393 // first pixel and being therefore bigger then the others.
1135 TEST_F(LauncherViewTest, CheckFittsLaw) { 1394 TEST_F(LauncherViewLegacyShelfLayoutTest, CheckFittsLaw) {
1136 // All buttons should be visible. 1395 // All buttons should be visible.
1137 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1396 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
1138 test_api_->GetButtonCount()); 1397 test_api_->GetButtonCount());
1139 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); 1398 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0);
1140 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); 1399 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1);
1141 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); 1400 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width());
1142 } 1401 }
1143 1402
1144 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool()); 1403 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool());
1145 1404
1146 } // namespace test 1405 } // namespace test
1147 } // namespace ash 1406 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698