OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 until overflow, remember last visible tabbed browser. | |
Mr4D (OOO till 08-26)
2013/08/27 02:35:14
Somehow this isn't really a sentence.
Harry McCleave
2013/08/27 03:25:45
Done.
| |
623 int items_added = 0; | |
624 LauncherID first_added = AddTabbedBrowser(); | |
625 EXPECT_TRUE(GetButtonByID(first_added)->visible()); | |
557 LauncherID last_visible = first_added; | 626 LauncherID last_visible = first_added; |
558 while (true) { | 627 while (true) { |
559 LauncherID added = AddTabbedBrowser(); | 628 LauncherID added = AddTabbedBrowser(); |
560 if (test_api_->IsOverflowButtonVisible()) { | 629 if (test_api_->IsOverflowButtonVisible()) { |
561 EXPECT_FALSE(GetButtonByID(added)->visible()); | 630 EXPECT_FALSE(GetButtonByID(added)->visible()); |
562 break; | 631 break; |
563 } | 632 } |
564 last_visible = added; | 633 last_visible = added; |
565 ++items_added; | 634 ++items_added; |
566 ASSERT_LT(items_added, 10000); | 635 ASSERT_LT(items_added, 10000); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 while (GetButtonByID(browser)->visible() && | 676 while (GetButtonByID(browser)->visible() && |
608 GetButtonByID(last_panel)->visible()) { | 677 GetButtonByID(last_panel)->visible()) { |
609 browser = AddTabbedBrowser(); | 678 browser = AddTabbedBrowser(); |
610 ++items_added; | 679 ++items_added; |
611 ASSERT_LT(items_added, 10000); | 680 ASSERT_LT(items_added, 10000); |
612 } | 681 } |
613 EXPECT_TRUE(GetButtonByID(last_panel)->visible()); | 682 EXPECT_TRUE(GetButtonByID(last_panel)->visible()); |
614 EXPECT_FALSE(GetButtonByID(browser)->visible()); | 683 EXPECT_FALSE(GetButtonByID(browser)->visible()); |
615 } | 684 } |
616 | 685 |
686 TEST_F(LauncherViewLegacyShelfLayoutTest, BrowserHidesExcessPanels) { | |
687 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | |
688 test_api_->GetButtonCount()); | |
689 | |
690 // Add tabbed browser. | |
691 LauncherID browser = AddTabbedBrowser(); | |
692 LauncherID first_panel = AddPanel(); | |
693 | |
694 EXPECT_TRUE(GetButtonByID(browser)->visible()); | |
695 EXPECT_TRUE(GetButtonByID(first_panel)->visible()); | |
696 | |
697 // Add panels until there is an overflow. | |
698 LauncherID last_panel = first_panel; | |
699 int items_added = 0; | |
700 while (!test_api_->IsOverflowButtonVisible()) { | |
701 last_panel = AddPanel(); | |
702 ++items_added; | |
703 ASSERT_LT(items_added, 10000); | |
704 } | |
705 | |
706 // The first panel should now be hidden by the new browsers needing space. | |
707 EXPECT_FALSE(GetButtonByID(first_panel)->visible()); | |
708 EXPECT_TRUE(GetButtonByID(last_panel)->visible()); | |
709 EXPECT_TRUE(GetButtonByID(browser)->visible()); | |
710 | |
711 // Adding browsers should eventually begin to hide browsers. We will add | |
712 // browsers until either the last panel or browser is hidden. | |
713 items_added = 0; | |
714 while (GetButtonByID(browser)->visible() && | |
715 GetButtonByID(last_panel)->visible()) { | |
716 browser = AddTabbedBrowser(); | |
717 ++items_added; | |
718 ASSERT_LT(items_added, 10000); | |
719 } | |
720 EXPECT_TRUE(GetButtonByID(last_panel)->visible()); | |
721 EXPECT_FALSE(GetButtonByID(browser)->visible()); | |
722 } | |
723 | |
617 // Adds button until overflow then removes first added one. Verifies that | 724 // Adds button until overflow then removes first added one. Verifies that |
618 // the last added one changes from invisible to visible and overflow | 725 // the last added one changes from invisible to visible and overflow |
619 // chevron is gone. | 726 // chevron is gone. |
620 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) { | 727 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) { |
621 // All buttons should be visible. | 728 // All buttons should be visible. |
622 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 729 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
623 test_api_->GetButtonCount()); | 730 test_api_->GetButtonCount()); |
624 | 731 |
625 // Add tabbed browser until overflow. | 732 // Add tabbed browser until overflow. |
626 int items_added = 0; | 733 int items_added = 0; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 | 805 |
699 // Check that model changes are handled correctly while a launcher icon is being | 806 // Check that model changes are handled correctly while a launcher icon is being |
700 // dragged. | 807 // dragged. |
701 TEST_F(LauncherViewTest, ModelChangesWhileDragging) { | 808 TEST_F(LauncherViewTest, ModelChangesWhileDragging) { |
702 internal::LauncherButtonHost* button_host = launcher_view_; | 809 internal::LauncherButtonHost* button_host = launcher_view_; |
703 | 810 |
704 std::vector<std::pair<LauncherID, views::View*> > id_map; | 811 std::vector<std::pair<LauncherID, views::View*> > id_map; |
705 SetupForDragTest(&id_map); | 812 SetupForDragTest(&id_map); |
706 | 813 |
707 // Dragging browser shortcut at index 0. | 814 // Dragging browser shortcut at index 0. |
815 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); | |
816 views::View* dragged_button = SimulateDrag( | |
817 internal::LauncherButtonHost::MOUSE, 1, 3); | |
818 std::rotate(id_map.begin() + 1, | |
819 id_map.begin() + 2, | |
820 id_map.begin() + 4); | |
821 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
822 button_host->PointerReleasedOnButton(dragged_button, | |
823 internal::LauncherButtonHost::MOUSE, | |
824 false); | |
825 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); | |
826 | |
827 // Dragging changes model order. | |
828 dragged_button = SimulateDrag( | |
829 internal::LauncherButtonHost::MOUSE, 1, 3); | |
830 std::rotate(id_map.begin() + 1, | |
831 id_map.begin() + 2, | |
832 id_map.begin() + 4); | |
833 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
834 | |
835 // Cancelling the drag operation restores previous order. | |
836 button_host->PointerReleasedOnButton(dragged_button, | |
837 internal::LauncherButtonHost::MOUSE, | |
838 true); | |
839 std::rotate(id_map.begin() + 1, | |
840 id_map.begin() + 3, | |
841 id_map.begin() + 4); | |
842 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
843 | |
844 // Deleting an item keeps the remaining intact. | |
845 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); | |
846 model_->RemoveItemAt(1); | |
847 id_map.erase(id_map.begin() + 1); | |
848 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
849 button_host->PointerReleasedOnButton(dragged_button, | |
850 internal::LauncherButtonHost::MOUSE, | |
851 false); | |
852 | |
853 // Adding a launcher item cancels the drag and respects the order. | |
854 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); | |
855 LauncherID new_id = AddAppShortcut(); | |
856 id_map.insert(id_map.begin() + 6, | |
857 std::make_pair(new_id, GetButtonByID(new_id))); | |
858 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
859 button_host->PointerReleasedOnButton(dragged_button, | |
860 internal::LauncherButtonHost::MOUSE, | |
861 false); | |
862 | |
863 // Adding a launcher item at the end (i.e. a panel) canels drag and respects | |
Mr4D (OOO till 08-26)
2013/08/27 02:35:14
cancels I suppose?
| |
864 // the order. | |
865 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); | |
866 new_id = AddPanel(); | |
867 id_map.insert(id_map.begin() + 7, | |
868 std::make_pair(new_id, GetButtonByID(new_id))); | |
869 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | |
870 button_host->PointerReleasedOnButton(dragged_button, | |
871 internal::LauncherButtonHost::MOUSE, | |
872 false); | |
873 } | |
874 | |
875 TEST_F(LauncherViewLegacyShelfLayoutTest, ModelChangesWhileDragging) { | |
876 internal::LauncherButtonHost* button_host = launcher_view_; | |
877 | |
878 std::vector<std::pair<LauncherID, views::View*> > id_map; | |
879 SetupForDragTest(&id_map); | |
880 | |
881 // Dragging browser shortcut at index 0. | |
708 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); | 882 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); |
709 views::View* dragged_button = SimulateDrag( | 883 views::View* dragged_button = SimulateDrag( |
710 internal::LauncherButtonHost::MOUSE, 0, 2); | 884 internal::LauncherButtonHost::MOUSE, 0, 2); |
711 std::rotate(id_map.begin(), | 885 std::rotate(id_map.begin(), |
712 id_map.begin() + 1, | 886 id_map.begin() + 1, |
713 id_map.begin() + 3); | 887 id_map.begin() + 3); |
714 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 888 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
715 button_host->PointerReleasedOnButton(dragged_button, | 889 button_host->PointerReleasedOnButton(dragged_button, |
716 internal::LauncherButtonHost::MOUSE, | 890 internal::LauncherButtonHost::MOUSE, |
717 false); | 891 false); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 | 941 |
768 // Check that 2nd drag from the other pointer would be ignored. | 942 // Check that 2nd drag from the other pointer would be ignored. |
769 TEST_F(LauncherViewTest, SimultaneousDrag) { | 943 TEST_F(LauncherViewTest, SimultaneousDrag) { |
770 internal::LauncherButtonHost* button_host = launcher_view_; | 944 internal::LauncherButtonHost* button_host = launcher_view_; |
771 | 945 |
772 std::vector<std::pair<LauncherID, views::View*> > id_map; | 946 std::vector<std::pair<LauncherID, views::View*> > id_map; |
773 SetupForDragTest(&id_map); | 947 SetupForDragTest(&id_map); |
774 | 948 |
775 // Start a mouse drag. | 949 // Start a mouse drag. |
776 views::View* dragged_button_mouse = SimulateDrag( | 950 views::View* dragged_button_mouse = SimulateDrag( |
951 internal::LauncherButtonHost::MOUSE, 1, 3); | |
952 std::rotate(id_map.begin() + 1, | |
953 id_map.begin() + 2, | |
954 id_map.begin() + 4); | |
955 | |
956 // Attempt a touch drag before the mouse drag finishes. | |
957 views::View* dragged_button_touch = SimulateDrag( | |
958 internal::LauncherButtonHost::TOUCH, 4, 2); | |
959 (void)button_host;(void)dragged_button_mouse;(void)dragged_button_touch; | |
Mr4D (OOO till 08-26)
2013/08/27 02:35:14
?
Harry McCleave
2013/08/27 03:25:45
Done.
| |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 |
OLD | NEW |