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

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: nits + extra test case Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/launcher/launcher_view.cc ('k') | ash/root_window_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // No animation happens for LauncherView bounds change. 188 // No animation happens for LauncherView bounds change.
189 EXPECT_TRUE(observer()->change_notified()); 189 EXPECT_TRUE(observer()->change_notified());
190 observer()->Reset(); 190 observer()->Reset();
191 } 191 }
192 192
193 //////////////////////////////////////////////////////////////////////////////// 193 ////////////////////////////////////////////////////////////////////////////////
194 // LauncherView tests. 194 // LauncherView tests.
195 195
196 class LauncherViewTest : public AshTestBase { 196 class LauncherViewTest : public AshTestBase {
197 public: 197 public:
198 LauncherViewTest() : model_(NULL), launcher_view_(NULL) {} 198 LauncherViewTest() : model_(NULL), launcher_view_(NULL), browser_index_(1) {}
199 virtual ~LauncherViewTest() {} 199 virtual ~LauncherViewTest() {}
200 200
201 virtual void SetUp() OVERRIDE { 201 virtual void SetUp() OVERRIDE {
202 AshTestBase::SetUp(); 202 AshTestBase::SetUp();
203 test::ShellTestApi test_api(Shell::GetInstance()); 203 test::ShellTestApi test_api(Shell::GetInstance());
204 model_ = test_api.launcher_model(); 204 model_ = test_api.launcher_model();
205 Launcher* launcher = Launcher::ForPrimaryDisplay(); 205 Launcher* launcher = Launcher::ForPrimaryDisplay();
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(browser_index_, 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 + browser_index_ + 1),
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 int browser_index_;
404 405
405 scoped_ptr<LauncherViewTestAPI> test_api_; 406 scoped_ptr<LauncherViewTestAPI> test_api_;
406 407
407 private: 408 private:
408 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); 409 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest);
409 }; 410 };
410 411
412 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest {
413 public:
414 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() {
415 browser_index_ = 0;
416 }
417
418 virtual ~LauncherViewLegacyShelfLayoutTest() {}
419
420 virtual void SetUp() OVERRIDE {
421 CommandLine::ForCurrentProcess()->AppendSwitch(
422 ash::switches::kAshDisableAlternateShelfLayout);
423 LauncherViewTest::SetUp();
424 }
425
426 private:
427 DISALLOW_COPY_AND_ASSIGN(LauncherViewLegacyShelfLayoutTest);
428 };
429
411 class LauncherViewTextDirectionTest 430 class LauncherViewTextDirectionTest
412 : public LauncherViewTest, 431 : public LauncherViewTest,
413 public testing::WithParamInterface<bool> { 432 public testing::WithParamInterface<bool> {
414 public: 433 public:
415 LauncherViewTextDirectionTest() : is_rtl_(GetParam()) {} 434 LauncherViewTextDirectionTest() : is_rtl_(GetParam()) {}
416 virtual ~LauncherViewTextDirectionTest() {} 435 virtual ~LauncherViewTextDirectionTest() {}
417 436
418 virtual void SetUp() OVERRIDE { 437 virtual void SetUp() OVERRIDE {
419 LauncherViewTest::SetUp(); 438 LauncherViewTest::SetUp();
420 original_locale_ = l10n_util::GetApplicationLocale(std::string()); 439 original_locale_ = l10n_util::GetApplicationLocale(std::string());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 LauncherID last_added = AddAppShortcut(); 552 LauncherID last_added = AddAppShortcut();
534 while (!test_api_->IsOverflowButtonVisible()) { 553 while (!test_api_->IsOverflowButtonVisible()) {
535 // Added button is visible after animation while in this loop. 554 // Added button is visible after animation while in this loop.
536 EXPECT_TRUE(GetButtonByID(last_added)->visible()); 555 EXPECT_TRUE(GetButtonByID(last_added)->visible());
537 556
538 last_added = AddAppShortcut(); 557 last_added = AddAppShortcut();
539 ++items_added; 558 ++items_added;
540 ASSERT_LT(items_added, 10000); 559 ASSERT_LT(items_added, 10000);
541 } 560 }
542 561
562 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
563 }
564
565 TEST_F(LauncherViewLegacyShelfLayoutTest,
566 AddAppShortcutWithBrowserButtonUntilOverflow) {
567 // All buttons should be visible.
568 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
569 test_api_->GetButtonCount());
570
571 LauncherID browser_button_id = AddTabbedBrowser();
572
573 // Add app shortcut until overflow.
574 int items_added = 0;
575 LauncherID last_added = AddAppShortcut();
576 while (!test_api_->IsOverflowButtonVisible()) {
577 // Added button is visible after animation while in this loop.
578 EXPECT_TRUE(GetButtonByID(last_added)->visible());
579
580 last_added = AddAppShortcut();
581 ++items_added;
582 ASSERT_LT(items_added, 10000);
583 }
584
543 // The last added app short button should be visible. 585 // The last added app short button should be visible.
544 EXPECT_TRUE(GetButtonByID(last_added)->visible()); 586 EXPECT_TRUE(GetButtonByID(last_added)->visible());
545 // And the browser button is invisible. 587 // And the browser button is invisible.
546 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); 588 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
547 } 589 }
548 590
549 TEST_F(LauncherViewTest, AddPanelHidesTabbedBrowser) { 591 TEST_F(LauncherViewTest, AddPanelHidesTabbedBrowser) {
550 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 592 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
551 test_api_->GetButtonCount()); 593 test_api_->GetButtonCount());
552 594
553 // Add tabbed browser until overflow, remember last visible tabbed browser. 595 // Add tabbed browser until overflow, remember last visible tabbed browser.
554 int items_added = 0; 596 int items_added = 0;
555 LauncherID first_added = AddTabbedBrowser(); 597 LauncherID first_added = AddTabbedBrowser();
556 EXPECT_TRUE(GetButtonByID(first_added)->visible()); 598 EXPECT_TRUE(GetButtonByID(first_added)->visible());
599 while (true) {
600 LauncherID added = AddTabbedBrowser();
601 if (test_api_->IsOverflowButtonVisible()) {
602 EXPECT_FALSE(GetButtonByID(added)->visible());
603 RemoveByID(added);
604 break;
605 }
606 ++items_added;
607 ASSERT_LT(items_added, 10000);
608 }
609
610 EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
611 LauncherID panel = AddPanel();
612 EXPECT_TRUE(GetButtonByID(panel)->visible());
613 EXPECT_TRUE(test_api_->IsOverflowButtonVisible());
614 RemoveByID(panel);
615 EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
616 }
617
618 TEST_F(LauncherViewLegacyShelfLayoutTest, AddPanelHidesTabbedBrowser) {
619 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
620 test_api_->GetButtonCount());
621
622 // Add tabbed browser items until an overflow, remembering the last visible
623 // tabbed browser item.
624 int items_added = 0;
625 LauncherID first_added = AddTabbedBrowser();
626 EXPECT_TRUE(GetButtonByID(first_added)->visible());
557 LauncherID last_visible = first_added; 627 LauncherID last_visible = first_added;
558 while (true) { 628 while (true) {
559 LauncherID added = AddTabbedBrowser(); 629 LauncherID added = AddTabbedBrowser();
560 if (test_api_->IsOverflowButtonVisible()) { 630 if (test_api_->IsOverflowButtonVisible()) {
561 EXPECT_FALSE(GetButtonByID(added)->visible()); 631 EXPECT_FALSE(GetButtonByID(added)->visible());
562 break; 632 break;
563 } 633 }
564 last_visible = added; 634 last_visible = added;
565 ++items_added; 635 ++items_added;
566 ASSERT_LT(items_added, 10000); 636 ASSERT_LT(items_added, 10000);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 while (GetButtonByID(browser)->visible() && 677 while (GetButtonByID(browser)->visible() &&
608 GetButtonByID(last_panel)->visible()) { 678 GetButtonByID(last_panel)->visible()) {
609 browser = AddTabbedBrowser(); 679 browser = AddTabbedBrowser();
610 ++items_added; 680 ++items_added;
611 ASSERT_LT(items_added, 10000); 681 ASSERT_LT(items_added, 10000);
612 } 682 }
613 EXPECT_TRUE(GetButtonByID(last_panel)->visible()); 683 EXPECT_TRUE(GetButtonByID(last_panel)->visible());
614 EXPECT_FALSE(GetButtonByID(browser)->visible()); 684 EXPECT_FALSE(GetButtonByID(browser)->visible());
615 } 685 }
616 686
687 TEST_F(LauncherViewLegacyShelfLayoutTest, BrowserHidesExcessPanels) {
688 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
689 test_api_->GetButtonCount());
690
691 // Add tabbed browser.
692 LauncherID browser = AddTabbedBrowser();
693 LauncherID first_panel = AddPanel();
694
695 EXPECT_TRUE(GetButtonByID(browser)->visible());
696 EXPECT_TRUE(GetButtonByID(first_panel)->visible());
697
698 // Add panels until there is an overflow.
699 LauncherID last_panel = first_panel;
700 int items_added = 0;
701 while (!test_api_->IsOverflowButtonVisible()) {
702 last_panel = AddPanel();
703 ++items_added;
704 ASSERT_LT(items_added, 10000);
705 }
706
707 // The first panel should now be hidden by the new browsers needing space.
708 EXPECT_FALSE(GetButtonByID(first_panel)->visible());
709 EXPECT_TRUE(GetButtonByID(last_panel)->visible());
710 EXPECT_TRUE(GetButtonByID(browser)->visible());
711
712 // Adding browsers should eventually begin to hide browsers. We will add
713 // browsers until either the last panel or browser is hidden.
714 items_added = 0;
715 while (GetButtonByID(browser)->visible() &&
716 GetButtonByID(last_panel)->visible()) {
717 browser = AddTabbedBrowser();
718 ++items_added;
719 ASSERT_LT(items_added, 10000);
720 }
721 EXPECT_TRUE(GetButtonByID(last_panel)->visible());
722 EXPECT_FALSE(GetButtonByID(browser)->visible());
723 }
724
617 // Adds button until overflow then removes first added one. Verifies that 725 // Adds button until overflow then removes first added one. Verifies that
618 // the last added one changes from invisible to visible and overflow 726 // the last added one changes from invisible to visible and overflow
619 // chevron is gone. 727 // chevron is gone.
620 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) { 728 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) {
621 // All buttons should be visible. 729 // All buttons should be visible.
622 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 730 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
623 test_api_->GetButtonCount()); 731 test_api_->GetButtonCount());
624 732
625 // Add tabbed browser until overflow. 733 // Add tabbed browser until overflow.
626 int items_added = 0; 734 int items_added = 0;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 806
699 // Check that model changes are handled correctly while a launcher icon is being 807 // Check that model changes are handled correctly while a launcher icon is being
700 // dragged. 808 // dragged.
701 TEST_F(LauncherViewTest, ModelChangesWhileDragging) { 809 TEST_F(LauncherViewTest, ModelChangesWhileDragging) {
702 internal::LauncherButtonHost* button_host = launcher_view_; 810 internal::LauncherButtonHost* button_host = launcher_view_;
703 811
704 std::vector<std::pair<LauncherID, views::View*> > id_map; 812 std::vector<std::pair<LauncherID, views::View*> > id_map;
705 SetupForDragTest(&id_map); 813 SetupForDragTest(&id_map);
706 814
707 // Dragging browser shortcut at index 0. 815 // Dragging browser shortcut at index 0.
816 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
817 views::View* dragged_button = SimulateDrag(
818 internal::LauncherButtonHost::MOUSE, 1, 3);
819 std::rotate(id_map.begin() + 1,
820 id_map.begin() + 2,
821 id_map.begin() + 4);
822 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
823 button_host->PointerReleasedOnButton(dragged_button,
824 internal::LauncherButtonHost::MOUSE,
825 false);
826 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
827
828 // Dragging changes model order.
829 dragged_button = SimulateDrag(
830 internal::LauncherButtonHost::MOUSE, 1, 3);
831 std::rotate(id_map.begin() + 1,
832 id_map.begin() + 2,
833 id_map.begin() + 4);
834 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
835
836 // Cancelling the drag operation restores previous order.
837 button_host->PointerReleasedOnButton(dragged_button,
838 internal::LauncherButtonHost::MOUSE,
839 true);
840 std::rotate(id_map.begin() + 1,
841 id_map.begin() + 3,
842 id_map.begin() + 4);
843 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
844
845 // Deleting an item keeps the remaining intact.
846 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
847 model_->RemoveItemAt(1);
848 id_map.erase(id_map.begin() + 1);
849 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
850 button_host->PointerReleasedOnButton(dragged_button,
851 internal::LauncherButtonHost::MOUSE,
852 false);
853
854 // Adding a launcher item cancels the drag and respects the order.
855 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
856 LauncherID new_id = AddAppShortcut();
857 id_map.insert(id_map.begin() + 6,
858 std::make_pair(new_id, GetButtonByID(new_id)));
859 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
860 button_host->PointerReleasedOnButton(dragged_button,
861 internal::LauncherButtonHost::MOUSE,
862 false);
863
864 // Adding a launcher item at the end (i.e. a panel) cancels drag and respects
James Cook 2013/08/27 17:08:52 nit: one space before "cancels"
865 // the order.
866 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3);
867 new_id = AddPanel();
868 id_map.insert(id_map.begin() + 7,
869 std::make_pair(new_id, GetButtonByID(new_id)));
870 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
871 button_host->PointerReleasedOnButton(dragged_button,
872 internal::LauncherButtonHost::MOUSE,
873 false);
874 }
875
876 TEST_F(LauncherViewLegacyShelfLayoutTest, ModelChangesWhileDragging) {
877 internal::LauncherButtonHost* button_host = launcher_view_;
878
879 std::vector<std::pair<LauncherID, views::View*> > id_map;
880 SetupForDragTest(&id_map);
881
882 // Dragging browser shortcut at index 0.
708 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); 883 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT);
709 views::View* dragged_button = SimulateDrag( 884 views::View* dragged_button = SimulateDrag(
710 internal::LauncherButtonHost::MOUSE, 0, 2); 885 internal::LauncherButtonHost::MOUSE, 0, 2);
711 std::rotate(id_map.begin(), 886 std::rotate(id_map.begin(),
712 id_map.begin() + 1, 887 id_map.begin() + 1,
713 id_map.begin() + 3); 888 id_map.begin() + 3);
714 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 889 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
715 button_host->PointerReleasedOnButton(dragged_button, 890 button_host->PointerReleasedOnButton(dragged_button,
716 internal::LauncherButtonHost::MOUSE, 891 internal::LauncherButtonHost::MOUSE,
717 false); 892 false);
(...skipping 28 matching lines...) Expand all
746 // Adding a launcher item cancels the drag and respects the order. 921 // Adding a launcher item cancels the drag and respects the order.
747 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 0, 2); 922 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 0, 2);
748 LauncherID new_id = AddAppShortcut(); 923 LauncherID new_id = AddAppShortcut();
749 id_map.insert(id_map.begin() + 5, 924 id_map.insert(id_map.begin() + 5,
750 std::make_pair(new_id, GetButtonByID(new_id))); 925 std::make_pair(new_id, GetButtonByID(new_id)));
751 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 926 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
752 button_host->PointerReleasedOnButton(dragged_button, 927 button_host->PointerReleasedOnButton(dragged_button,
753 internal::LauncherButtonHost::MOUSE, 928 internal::LauncherButtonHost::MOUSE,
754 false); 929 false);
755 930
756 // Adding a launcher item at the end (i.e. a panel) canels drag and respects 931 // Adding a launcher item at the end (i.e. a panel) cancels drag and respects
James Cook 2013/08/27 17:08:52 nit: one space before "cancels"
757 // the order. 932 // the order.
758 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 0, 2); 933 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 0, 2);
759 new_id = AddPanel(); 934 new_id = AddPanel();
760 id_map.insert(id_map.begin() + 7, 935 id_map.insert(id_map.begin() + 7,
761 std::make_pair(new_id, GetButtonByID(new_id))); 936 std::make_pair(new_id, GetButtonByID(new_id)));
762 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 937 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
763 button_host->PointerReleasedOnButton(dragged_button, 938 button_host->PointerReleasedOnButton(dragged_button,
764 internal::LauncherButtonHost::MOUSE, 939 internal::LauncherButtonHost::MOUSE,
765 false); 940 false);
766 } 941 }
767 942
768 // Check that 2nd drag from the other pointer would be ignored. 943 // Check that 2nd drag from the other pointer would be ignored.
769 TEST_F(LauncherViewTest, SimultaneousDrag) { 944 TEST_F(LauncherViewTest, SimultaneousDrag) {
770 internal::LauncherButtonHost* button_host = launcher_view_; 945 internal::LauncherButtonHost* button_host = launcher_view_;
771 946
772 std::vector<std::pair<LauncherID, views::View*> > id_map; 947 std::vector<std::pair<LauncherID, views::View*> > id_map;
773 SetupForDragTest(&id_map); 948 SetupForDragTest(&id_map);
774 949
775 // Start a mouse drag. 950 // Start a mouse drag.
776 views::View* dragged_button_mouse = SimulateDrag( 951 views::View* dragged_button_mouse = SimulateDrag(
952 internal::LauncherButtonHost::MOUSE, 1, 3);
953 std::rotate(id_map.begin() + 1,
954 id_map.begin() + 2,
955 id_map.begin() + 4);
956
957 // Attempt a touch drag before the mouse drag finishes.
958 views::View* dragged_button_touch = SimulateDrag(
959 internal::LauncherButtonHost::TOUCH, 4, 2);
960 // Nothing changes since 2nd drag is ignored.
961 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
962
963 // Finish the mouse drag.
964 button_host->PointerReleasedOnButton(dragged_button_mouse,
965 internal::LauncherButtonHost::MOUSE,
966 false);
967 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
968
969 // Now start a touch drag.
970 dragged_button_touch = SimulateDrag(
971 internal::LauncherButtonHost::TOUCH, 4, 2);
972 std::rotate(id_map.begin() + 3,
973 id_map.begin() + 4,
974 id_map.begin() + 5);
975 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
976
977 // And attempt a mouse drag before the touch drag finishes.
978 dragged_button_mouse = SimulateDrag(
979 internal::LauncherButtonHost::MOUSE, 1, 2);
980
981 // Nothing changes since 2nd drag is ignored.
982 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
983
984 button_host->PointerReleasedOnButton(dragged_button_touch,
985 internal::LauncherButtonHost::TOUCH,
986 false);
987 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
988 }
989
990 TEST_F(LauncherViewLegacyShelfLayoutTest, SimultaneousDrag) {
991 internal::LauncherButtonHost* button_host = launcher_view_;
992
993 std::vector<std::pair<LauncherID, views::View*> > id_map;
994 SetupForDragTest(&id_map);
995
996 // Start a mouse drag.
997 views::View* dragged_button_mouse = SimulateDrag(
777 internal::LauncherButtonHost::MOUSE, 0, 2); 998 internal::LauncherButtonHost::MOUSE, 0, 2);
778 std::rotate(id_map.begin(), 999 std::rotate(id_map.begin(),
779 id_map.begin() + 1, 1000 id_map.begin() + 1,
780 id_map.begin() + 3); 1001 id_map.begin() + 3);
781 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1002 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
782 // Attempt a touch drag before the mouse drag finishes. 1003 // Attempt a touch drag before the mouse drag finishes.
783 views::View* dragged_button_touch = SimulateDrag( 1004 views::View* dragged_button_touch = SimulateDrag(
784 internal::LauncherButtonHost::TOUCH, 3, 1); 1005 internal::LauncherButtonHost::TOUCH, 3, 1);
785 1006
786 // Nothing changes since 2nd drag is ignored. 1007 // Nothing changes since 2nd drag is ignored.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 TEST_F(LauncherViewTest, ClickOneDragAnother) { 1039 TEST_F(LauncherViewTest, ClickOneDragAnother) {
819 internal::LauncherButtonHost* button_host = launcher_view_; 1040 internal::LauncherButtonHost* button_host = launcher_view_;
820 1041
821 std::vector<std::pair<LauncherID, views::View*> > id_map; 1042 std::vector<std::pair<LauncherID, views::View*> > id_map;
822 SetupForDragTest(&id_map); 1043 SetupForDragTest(&id_map);
823 1044
824 // A click on item 1 is simulated. 1045 // A click on item 1 is simulated.
825 SimulateClick(internal::LauncherButtonHost::MOUSE, 1); 1046 SimulateClick(internal::LauncherButtonHost::MOUSE, 1);
826 1047
827 // Dragging browser index at 0 should change the model order correctly. 1048 // Dragging browser index at 0 should change the model order correctly.
1049 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
1050 views::View* dragged_button = SimulateDrag(
1051 internal::LauncherButtonHost::MOUSE, 1, 3);
1052 std::rotate(id_map.begin() + 1,
1053 id_map.begin() + 2,
1054 id_map.begin() + 4);
1055 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1056 button_host->PointerReleasedOnButton(dragged_button,
1057 internal::LauncherButtonHost::MOUSE,
1058 false);
1059 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
1060 }
1061
1062 TEST_F(LauncherViewLegacyShelfLayoutTest, ClickOneDragAnother) {
1063 internal::LauncherButtonHost* button_host = launcher_view_;
1064
1065 std::vector<std::pair<LauncherID, views::View*> > id_map;
1066 SetupForDragTest(&id_map);
1067
1068 // A click on item 1 is simulated.
1069 SimulateClick(internal::LauncherButtonHost::MOUSE, 1);
1070
1071 // Dragging browser index at 0 should change the model order correctly.
828 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); 1072 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT);
829 views::View* dragged_button = SimulateDrag( 1073 views::View* dragged_button = SimulateDrag(
830 internal::LauncherButtonHost::MOUSE, 0, 2); 1074 internal::LauncherButtonHost::MOUSE, 0, 2);
831 std::rotate(id_map.begin(), 1075 std::rotate(id_map.begin(),
832 id_map.begin() + 1, 1076 id_map.begin() + 1,
833 id_map.begin() + 3); 1077 id_map.begin() + 3);
834 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1078 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
835 button_host->PointerReleasedOnButton(dragged_button, 1079 button_host->PointerReleasedOnButton(dragged_button,
836 internal::LauncherButtonHost::MOUSE, 1080 internal::LauncherButtonHost::MOUSE,
837 false); 1081 false);
(...skipping 12 matching lines...) Expand all
850 internal::LauncherButton* button = GetButtonByID(last_added); 1094 internal::LauncherButton* button = GetButtonByID(last_added);
851 ASSERT_EQ(internal::LauncherButton::STATE_RUNNING, button->state()); 1095 ASSERT_EQ(internal::LauncherButton::STATE_RUNNING, button->state());
852 item.status = ash::STATUS_ACTIVE; 1096 item.status = ash::STATUS_ACTIVE;
853 model_->Set(index, item); 1097 model_->Set(index, item);
854 ASSERT_EQ(internal::LauncherButton::STATE_ACTIVE, button->state()); 1098 ASSERT_EQ(internal::LauncherButton::STATE_ACTIVE, button->state());
855 item.status = ash::STATUS_ATTENTION; 1099 item.status = ash::STATUS_ATTENTION;
856 model_->Set(index, item); 1100 model_->Set(index, item);
857 ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state()); 1101 ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state());
858 } 1102 }
859 1103
860 TEST_F(LauncherViewTest, LauncherItemPositionReflectedOnStateChanged) { 1104 TEST_F(LauncherViewLegacyShelfLayoutTest,
1105 LauncherItemPositionReflectedOnStateChanged) {
861 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1106 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
862 test_api_->GetButtonCount()); 1107 test_api_->GetButtonCount());
863 1108
864 // Add 2 items to the launcher. 1109 // Add 2 items to the launcher.
865 LauncherID item1_id = AddTabbedBrowser(); 1110 LauncherID item1_id = AddTabbedBrowser();
866 LauncherID item2_id = AddPlatformAppNoWait(); 1111 LauncherID item2_id = AddPlatformAppNoWait();
867 internal::LauncherButton* item1_button = GetButtonByID(item1_id); 1112 internal::LauncherButton* item1_button = GetButtonByID(item1_id);
868 internal::LauncherButton* item2_button = GetButtonByID(item2_id); 1113 internal::LauncherButton* item2_button = GetButtonByID(item2_id);
869 1114
870 internal::LauncherButton::State state_mask = 1115 internal::LauncherButton::State state_mask =
871 static_cast<internal::LauncherButton::State> 1116 static_cast<internal::LauncherButton::State>
872 (internal::LauncherButton::STATE_NORMAL | 1117 (internal::LauncherButton::STATE_NORMAL |
873 internal::LauncherButton::STATE_HOVERED | 1118 internal::LauncherButton::STATE_HOVERED |
874 internal::LauncherButton::STATE_RUNNING | 1119 internal::LauncherButton::STATE_RUNNING |
875 internal::LauncherButton::STATE_ACTIVE | 1120 internal::LauncherButton::STATE_ACTIVE |
876 internal::LauncherButton::STATE_ATTENTION | 1121 internal::LauncherButton::STATE_ATTENTION |
877 internal::LauncherButton::STATE_FOCUSED); 1122 internal::LauncherButton::STATE_FOCUSED);
878 1123
879 // Clear the button states. 1124 // Clear the button states.
880 item1_button->ClearState(state_mask); 1125 item1_button->ClearState(state_mask);
881 item2_button->ClearState(state_mask); 1126 item2_button->ClearState(state_mask);
882 1127
883 // Since default alignment in tests is bottom, state is reflected in y-axis. 1128 // Since default alignment in tests is bottom, state is reflected in y-axis.
884 ASSERT_EQ(item1_button->GetIconBounds().y(), 1129 ASSERT_EQ(item1_button->GetIconBounds().y(),
885 item2_button->GetIconBounds().y()); 1130 item2_button->GetIconBounds().y());
886 item1_button->AddState(internal::LauncherButton::STATE_HOVERED); 1131 item1_button->AddState(internal::LauncherButton::STATE_HOVERED);
887 ASSERT_NE(item1_button->GetIconBounds().y(), 1132 ASSERT_NE(item1_button->GetIconBounds().y(),
888 item2_button->GetIconBounds().y()); 1133 item2_button->GetIconBounds().y());
889 item1_button->ClearState(internal::LauncherButton::STATE_HOVERED); 1134 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 } 1135 }
904 1136
905 // Confirm that item status changes are reflected in the buttons 1137 // Confirm that item status changes are reflected in the buttons
906 // for platform apps. 1138 // for platform apps.
907 TEST_F(LauncherViewTest, LauncherItemStatusPlatformApp) { 1139 TEST_F(LauncherViewTest, LauncherItemStatusPlatformApp) {
908 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1140 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
909 test_api_->GetButtonCount()); 1141 test_api_->GetButtonCount());
910 1142
911 // Add tabbed browser. 1143 // Add tabbed browser.
912 LauncherID last_added = AddPlatformApp(); 1144 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. 1299 // Move the mouse over the button and check that it is visible.
1068 views::View* app_list_button = launcher_view_->GetAppListButtonView(); 1300 views::View* app_list_button = launcher_view_->GetAppListButtonView();
1069 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); 1301 gfx::Rect bounds = app_list_button->GetBoundsInScreen();
1070 generator.MoveMouseTo(bounds.CenterPoint()); 1302 generator.MoveMouseTo(bounds.CenterPoint());
1071 // Wait for the timer to go off. 1303 // Wait for the timer to go off.
1072 RunAllPendingInMessageLoop(); 1304 RunAllPendingInMessageLoop();
1073 EXPECT_TRUE(tooltip_manager->IsVisible()); 1305 EXPECT_TRUE(tooltip_manager->IsVisible());
1074 1306
1075 // Move the mouse cursor slightly to the right of the item. The tooltip should 1307 // Move the mouse cursor slightly to the right of the item. The tooltip should
1076 // stay open. 1308 // stay open.
1077 generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0); 1309 generator.MoveMouseBy(bounds.width() / 2 + 5, 0);
1078 // Make sure there is no delayed close. 1310 // Make sure there is no delayed close.
1079 RunAllPendingInMessageLoop(); 1311 RunAllPendingInMessageLoop();
1080 EXPECT_TRUE(tooltip_manager->IsVisible()); 1312 EXPECT_TRUE(tooltip_manager->IsVisible());
1081 1313
1082 // Move back - it should still stay open. 1314 // Move back - it should still stay open.
1083 generator.MoveMouseBy(bounds.width() / 2 + 5, 0); 1315 generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0);
1084 // Make sure there is no delayed close. 1316 // Make sure there is no delayed close.
1085 RunAllPendingInMessageLoop(); 1317 RunAllPendingInMessageLoop();
1086 EXPECT_TRUE(tooltip_manager->IsVisible()); 1318 EXPECT_TRUE(tooltip_manager->IsVisible());
1087 1319
1088 // Now move the mouse cursor slightly above the item - so that it is over the 1320 // Now move the mouse cursor slightly above the item - so that it is over the
1089 // tooltip bubble. Now it should disappear. 1321 // tooltip bubble. Now it should disappear.
1090 generator.MoveMouseBy(0, -(bounds.height() / 2 + 5)); 1322 generator.MoveMouseBy(0, -(bounds.height() / 2 + 5));
1091 // Wait until the delayed close kicked in. 1323 // Wait until the delayed close kicked in.
1092 RunAllPendingInMessageLoop(); 1324 RunAllPendingInMessageLoop();
1093 EXPECT_FALSE(tooltip_manager->IsVisible()); 1325 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; 1357 const int app_list_button_index = test_api_->GetButtonCount() - 1;
1126 const gfx::Rect& app_list_ideal_bounds = 1358 const gfx::Rect& app_list_ideal_bounds =
1127 test_api_->GetIdealBoundsByIndex(app_list_button_index); 1359 test_api_->GetIdealBoundsByIndex(app_list_button_index);
1128 const gfx::Rect& app_list_bounds = 1360 const gfx::Rect& app_list_bounds =
1129 test_api_->GetBoundsByIndex(app_list_button_index); 1361 test_api_->GetBoundsByIndex(app_list_button_index);
1130 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); 1362 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds);
1131 } 1363 }
1132 1364
1133 // Check that the first item in the list follows Fitt's law by including the 1365 // 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. 1366 // first pixel and being therefore bigger then the others.
1135 TEST_F(LauncherViewTest, CheckFittsLaw) { 1367 TEST_F(LauncherViewLegacyShelfLayoutTest, CheckFittsLaw) {
1136 // All buttons should be visible. 1368 // All buttons should be visible.
1137 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, 1369 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1,
1138 test_api_->GetButtonCount()); 1370 test_api_->GetButtonCount());
1139 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); 1371 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0);
1140 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); 1372 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1);
1141 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); 1373 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width());
1142 } 1374 }
1143 1375
1144 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool()); 1376 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool());
1145 1377
1146 } // namespace test 1378 } // namespace test
1147 } // namespace ash 1379 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_view.cc ('k') | ash/root_window_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698