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 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 | 227 |
228 LauncherID id = model_->next_id(); | 228 LauncherID id = model_->next_id(); |
229 model_->AddAt(0, browser_shortcut); | 229 model_->AddAt(browser_index_, browser_shortcut); |
230 test_api_->RunMessageLoopUntilAnimationsDone(); | 230 test_api_->RunMessageLoopUntilAnimationsDone(); |
231 return id; | 231 return id; |
232 } | 232 } |
233 | 233 |
234 LauncherID AddAppShortcut() { | 234 LauncherID AddAppShortcut() { |
235 LauncherItem item; | 235 LauncherItem item; |
236 item.type = TYPE_APP_SHORTCUT; | 236 item.type = TYPE_APP_SHORTCUT; |
237 item.status = STATUS_CLOSED; | 237 item.status = STATUS_CLOSED; |
238 | 238 |
239 LauncherID id = model_->next_id(); | 239 LauncherID id = model_->next_id(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 // Initialize |id_map| with the automatically-created launcher buttons. | 359 // Initialize |id_map| with the automatically-created launcher buttons. |
360 for (size_t i = 0; i < model_->items().size(); ++i) { | 360 for (size_t i = 0; i < model_->items().size(); ++i) { |
361 internal::LauncherButton* button = test_api_->GetButton(i); | 361 internal::LauncherButton* button = test_api_->GetButton(i); |
362 id_map->push_back(std::make_pair(model_->items()[i].id, button)); | 362 id_map->push_back(std::make_pair(model_->items()[i].id, button)); |
363 } | 363 } |
364 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); | 364 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
365 | 365 |
366 // Add 5 app launcher buttons for testing. | 366 // Add 5 app launcher buttons for testing. |
367 for (int i = 0; i < 5; ++i) { | 367 for (int i = 0; i < 5; ++i) { |
368 LauncherID id = AddAppShortcut(); | 368 LauncherID id = AddAppShortcut(); |
369 // browser shortcut is located at index 0. So we should start to add app | 369 // App Icon is located at index 0, and browser shortcut is located at |
370 // shortcut at index 1. | 370 // index 1. So we should start to add app shortcut at index 2. |
371 id_map->insert(id_map->begin() + (i + 1), | 371 id_map->insert(id_map->begin() + (i + browser_index_ + 1), |
372 std::make_pair(id, GetButtonByID(id))); | 372 std::make_pair(id, GetButtonByID(id))); |
373 } | 373 } |
374 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); | 374 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
375 } | 375 } |
376 | 376 |
377 views::View* GetTooltipAnchorView() { | 377 views::View* GetTooltipAnchorView() { |
378 return launcher_view_->tooltip_manager()->anchor_; | 378 return launcher_view_->tooltip_manager()->anchor_; |
379 } | 379 } |
380 | 380 |
381 void ShowTooltip() { | 381 void ShowTooltip() { |
382 launcher_view_->tooltip_manager()->ShowInternal(); | 382 launcher_view_->tooltip_manager()->ShowInternal(); |
383 } | 383 } |
384 | 384 |
385 LauncherModel* model_; | 385 LauncherModel* model_; |
386 internal::LauncherView* launcher_view_; | 386 internal::LauncherView* launcher_view_; |
| 387 int browser_index_; |
387 | 388 |
388 scoped_ptr<LauncherViewTestAPI> test_api_; | 389 scoped_ptr<LauncherViewTestAPI> test_api_; |
389 | 390 |
390 private: | 391 private: |
391 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); | 392 DISALLOW_COPY_AND_ASSIGN(LauncherViewTest); |
392 }; | 393 }; |
393 | 394 |
| 395 class LauncherViewLegacyShelfLayoutTest : public LauncherViewTest { |
| 396 public: |
| 397 LauncherViewLegacyShelfLayoutTest() : LauncherViewTest() { |
| 398 browser_index_ = 0; |
| 399 } |
| 400 |
| 401 virtual ~LauncherViewLegacyShelfLayoutTest() {} |
| 402 |
| 403 virtual void SetUp() OVERRIDE { |
| 404 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 405 ash::switches::kAshDisableAlternateShelfLayout); |
| 406 LauncherViewTest::SetUp(); |
| 407 } |
| 408 |
| 409 private: |
| 410 DISALLOW_COPY_AND_ASSIGN(LauncherViewLegacyShelfLayoutTest); |
| 411 }; |
| 412 |
394 class LauncherViewTextDirectionTest | 413 class LauncherViewTextDirectionTest |
395 : public LauncherViewTest, | 414 : public LauncherViewTest, |
396 public testing::WithParamInterface<bool> { | 415 public testing::WithParamInterface<bool> { |
397 public: | 416 public: |
398 LauncherViewTextDirectionTest() : is_rtl_(GetParam()) {} | 417 LauncherViewTextDirectionTest() : is_rtl_(GetParam()) {} |
399 virtual ~LauncherViewTextDirectionTest() {} | 418 virtual ~LauncherViewTextDirectionTest() {} |
400 | 419 |
401 virtual void SetUp() OVERRIDE { | 420 virtual void SetUp() OVERRIDE { |
402 LauncherViewTest::SetUp(); | 421 LauncherViewTest::SetUp(); |
403 original_locale_ = l10n_util::GetApplicationLocale(std::string()); | 422 original_locale_ = l10n_util::GetApplicationLocale(std::string()); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 LauncherID last_added = AddAppShortcut(); | 527 LauncherID last_added = AddAppShortcut(); |
509 while (!test_api_->IsOverflowButtonVisible()) { | 528 while (!test_api_->IsOverflowButtonVisible()) { |
510 // Added button is visible after animation while in this loop. | 529 // Added button is visible after animation while in this loop. |
511 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | 530 EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
512 | 531 |
513 last_added = AddAppShortcut(); | 532 last_added = AddAppShortcut(); |
514 ++items_added; | 533 ++items_added; |
515 ASSERT_LT(items_added, 10000); | 534 ASSERT_LT(items_added, 10000); |
516 } | 535 } |
517 | 536 |
| 537 // And the platform app button is invisible. |
| 538 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); |
| 539 } |
| 540 |
| 541 TEST_F(LauncherViewLegacyShelfLayoutTest, |
| 542 AddAppShortcutWithBrowserButtonUntilOverflow) { |
| 543 // All buttons should be visible. |
| 544 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 545 test_api_->GetButtonCount()); |
| 546 |
| 547 LauncherID browser_button_id = AddPlatformApp(); |
| 548 |
| 549 // Add app shortcut until overflow. |
| 550 int items_added = 0; |
| 551 LauncherID last_added = AddAppShortcut(); |
| 552 while (!test_api_->IsOverflowButtonVisible()) { |
| 553 // Added button is visible after animation while in this loop. |
| 554 EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
| 555 |
| 556 last_added = AddAppShortcut(); |
| 557 ++items_added; |
| 558 ASSERT_LT(items_added, 10000); |
| 559 } |
| 560 |
518 // The last added app short button should be visible. | 561 // The last added app short button should be visible. |
519 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | 562 EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
520 // And the platform app button is invisible. | 563 // And the platform app button is invisible. |
521 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); | 564 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); |
522 } | 565 } |
523 | 566 |
524 TEST_F(LauncherViewTest, AddPanelHidesPlatformAppButton) { | 567 TEST_F(LauncherViewTest, AddPanelHidesPlatformAppButton) { |
525 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 568 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
526 test_api_->GetButtonCount()); | 569 test_api_->GetButtonCount()); |
527 | 570 |
528 // Add platform app button until overflow, remember last visible platform app | 571 // Add platform app button until overflow, remember last visible platform app |
529 // button. | 572 // button. |
530 int items_added = 0; | 573 int items_added = 0; |
531 LauncherID first_added = AddPlatformApp(); | 574 LauncherID first_added = AddPlatformApp(); |
532 EXPECT_TRUE(GetButtonByID(first_added)->visible()); | 575 EXPECT_TRUE(GetButtonByID(first_added)->visible()); |
| 576 while (true) { |
| 577 LauncherID added = AddPlatformApp(); |
| 578 if (test_api_->IsOverflowButtonVisible()) { |
| 579 EXPECT_FALSE(GetButtonByID(added)->visible()); |
| 580 RemoveByID(added); |
| 581 break; |
| 582 } |
| 583 ++items_added; |
| 584 ASSERT_LT(items_added, 10000); |
| 585 } |
| 586 |
| 587 LauncherID panel = AddPanel(); |
| 588 EXPECT_TRUE(test_api_->IsOverflowButtonVisible()); |
| 589 |
| 590 RemoveByID(panel); |
| 591 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); |
| 592 } |
| 593 |
| 594 TEST_F(LauncherViewLegacyShelfLayoutTest, AddPanelHidesPlatformAppButton) { |
| 595 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 596 test_api_->GetButtonCount()); |
| 597 |
| 598 // Add platform app button until overflow, remember last visible platform app |
| 599 // button. |
| 600 int items_added = 0; |
| 601 LauncherID first_added = AddPlatformApp(); |
| 602 EXPECT_TRUE(GetButtonByID(first_added)->visible()); |
533 LauncherID last_visible = first_added; | 603 LauncherID last_visible = first_added; |
534 while (true) { | 604 while (true) { |
535 LauncherID added = AddPlatformApp(); | 605 LauncherID added = AddPlatformApp(); |
536 if (test_api_->IsOverflowButtonVisible()) { | 606 if (test_api_->IsOverflowButtonVisible()) { |
537 EXPECT_FALSE(GetButtonByID(added)->visible()); | 607 EXPECT_FALSE(GetButtonByID(added)->visible()); |
538 break; | 608 break; |
539 } | 609 } |
540 last_visible = added; | 610 last_visible = added; |
541 ++items_added; | 611 ++items_added; |
542 ASSERT_LT(items_added, 10000); | 612 ASSERT_LT(items_added, 10000); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 } | 744 } |
675 | 745 |
676 // Check that model changes are handled correctly while a launcher icon is being | 746 // Check that model changes are handled correctly while a launcher icon is being |
677 // dragged. | 747 // dragged. |
678 TEST_F(LauncherViewTest, ModelChangesWhileDragging) { | 748 TEST_F(LauncherViewTest, ModelChangesWhileDragging) { |
679 internal::LauncherButtonHost* button_host = launcher_view_; | 749 internal::LauncherButtonHost* button_host = launcher_view_; |
680 | 750 |
681 std::vector<std::pair<LauncherID, views::View*> > id_map; | 751 std::vector<std::pair<LauncherID, views::View*> > id_map; |
682 SetupForDragTest(&id_map); | 752 SetupForDragTest(&id_map); |
683 | 753 |
| 754 // Dragging browser shortcut at index 1. |
| 755 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); |
| 756 views::View* dragged_button = SimulateDrag( |
| 757 internal::LauncherButtonHost::MOUSE, 1, 3); |
| 758 std::rotate(id_map.begin() + 1, |
| 759 id_map.begin() + 2, |
| 760 id_map.begin() + 4); |
| 761 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 762 button_host->PointerReleasedOnButton(dragged_button, |
| 763 internal::LauncherButtonHost::MOUSE, |
| 764 false); |
| 765 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
| 766 |
| 767 // Dragging changes model order. |
| 768 dragged_button = SimulateDrag( |
| 769 internal::LauncherButtonHost::MOUSE, 1, 3); |
| 770 std::rotate(id_map.begin() + 1, |
| 771 id_map.begin() + 2, |
| 772 id_map.begin() + 4); |
| 773 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 774 |
| 775 // Cancelling the drag operation restores previous order. |
| 776 button_host->PointerReleasedOnButton(dragged_button, |
| 777 internal::LauncherButtonHost::MOUSE, |
| 778 true); |
| 779 std::rotate(id_map.begin() + 1, |
| 780 id_map.begin() + 3, |
| 781 id_map.begin() + 4); |
| 782 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 783 |
| 784 // Deleting an item keeps the remaining intact. |
| 785 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); |
| 786 model_->RemoveItemAt(1); |
| 787 id_map.erase(id_map.begin() + 1); |
| 788 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 789 button_host->PointerReleasedOnButton(dragged_button, |
| 790 internal::LauncherButtonHost::MOUSE, |
| 791 false); |
| 792 |
| 793 // Adding a launcher item cancels the drag and respects the order. |
| 794 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); |
| 795 LauncherID new_id = AddAppShortcut(); |
| 796 id_map.insert(id_map.begin() + 6, |
| 797 std::make_pair(new_id, GetButtonByID(new_id))); |
| 798 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 799 button_host->PointerReleasedOnButton(dragged_button, |
| 800 internal::LauncherButtonHost::MOUSE, |
| 801 false); |
| 802 |
| 803 // Adding a launcher item at the end (i.e. a panel) canels drag and respects |
| 804 // the order. |
| 805 dragged_button = SimulateDrag(internal::LauncherButtonHost::MOUSE, 1, 3); |
| 806 new_id = AddPanel(); |
| 807 id_map.insert(id_map.begin() + 7, |
| 808 std::make_pair(new_id, GetButtonByID(new_id))); |
| 809 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 810 button_host->PointerReleasedOnButton(dragged_button, |
| 811 internal::LauncherButtonHost::MOUSE, |
| 812 false); |
| 813 } |
| 814 |
| 815 TEST_F(LauncherViewLegacyShelfLayoutTest, ModelChangesWhileDragging) { |
| 816 internal::LauncherButtonHost* button_host = launcher_view_; |
| 817 |
| 818 std::vector<std::pair<LauncherID, views::View*> > id_map; |
| 819 SetupForDragTest(&id_map); |
| 820 |
684 // Dragging browser shortcut at index 0. | 821 // Dragging browser shortcut at index 0. |
685 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); | 822 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); |
686 views::View* dragged_button = SimulateDrag( | 823 views::View* dragged_button = SimulateDrag( |
687 internal::LauncherButtonHost::MOUSE, 0, 2); | 824 internal::LauncherButtonHost::MOUSE, 0, 2); |
688 std::rotate(id_map.begin(), | 825 std::rotate(id_map.begin(), |
689 id_map.begin() + 1, | 826 id_map.begin() + 1, |
690 id_map.begin() + 3); | 827 id_map.begin() + 3); |
691 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 828 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
692 button_host->PointerReleasedOnButton(dragged_button, | 829 button_host->PointerReleasedOnButton(dragged_button, |
693 internal::LauncherButtonHost::MOUSE, | 830 internal::LauncherButtonHost::MOUSE, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 | 881 |
745 // Check that 2nd drag from the other pointer would be ignored. | 882 // Check that 2nd drag from the other pointer would be ignored. |
746 TEST_F(LauncherViewTest, SimultaneousDrag) { | 883 TEST_F(LauncherViewTest, SimultaneousDrag) { |
747 internal::LauncherButtonHost* button_host = launcher_view_; | 884 internal::LauncherButtonHost* button_host = launcher_view_; |
748 | 885 |
749 std::vector<std::pair<LauncherID, views::View*> > id_map; | 886 std::vector<std::pair<LauncherID, views::View*> > id_map; |
750 SetupForDragTest(&id_map); | 887 SetupForDragTest(&id_map); |
751 | 888 |
752 // Start a mouse drag. | 889 // Start a mouse drag. |
753 views::View* dragged_button_mouse = SimulateDrag( | 890 views::View* dragged_button_mouse = SimulateDrag( |
754 internal::LauncherButtonHost::MOUSE, 0, 2); | 891 internal::LauncherButtonHost::MOUSE, 1, 3); |
755 std::rotate(id_map.begin(), | 892 std::rotate(id_map.begin() + 1, |
756 id_map.begin() + 1, | 893 id_map.begin() + 2, |
757 id_map.begin() + 3); | 894 id_map.begin() + 4); |
758 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 895 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
759 // Attempt a touch drag before the mouse drag finishes. | 896 // Attempt a touch drag before the mouse drag finishes. |
760 views::View* dragged_button_touch = SimulateDrag( | 897 views::View* dragged_button_touch = SimulateDrag( |
761 internal::LauncherButtonHost::TOUCH, 3, 1); | 898 internal::LauncherButtonHost::TOUCH, 4, 2); |
762 | 899 |
763 // Nothing changes since 2nd drag is ignored. | 900 // Nothing changes since 2nd drag is ignored. |
764 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 901 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
765 | 902 |
766 // Finish the mouse drag. | 903 // Finish the mouse drag. |
767 button_host->PointerReleasedOnButton(dragged_button_mouse, | 904 button_host->PointerReleasedOnButton(dragged_button_mouse, |
768 internal::LauncherButtonHost::MOUSE, | 905 internal::LauncherButtonHost::MOUSE, |
769 false); | 906 false); |
770 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 907 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
771 | 908 |
772 // Now start a touch drag. | 909 // Now start a touch drag. |
773 dragged_button_touch = SimulateDrag( | 910 dragged_button_touch = SimulateDrag( |
774 internal::LauncherButtonHost::TOUCH, 3, 1); | 911 internal::LauncherButtonHost::TOUCH, 4, 2); |
775 std::rotate(id_map.begin() + 2, | 912 std::rotate(id_map.begin() + 3, |
776 id_map.begin() + 3, | 913 id_map.begin() + 4, |
777 id_map.begin() + 4); | 914 id_map.begin() + 5); |
778 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 915 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
779 | 916 |
780 // And attempt a mouse drag before the touch drag finishes. | 917 // And attempt a mouse drag before the touch drag finishes. |
781 dragged_button_mouse = SimulateDrag( | 918 dragged_button_mouse = SimulateDrag( |
782 internal::LauncherButtonHost::MOUSE, 0, 1); | 919 internal::LauncherButtonHost::MOUSE, 1, 2); |
783 | 920 |
784 // Nothing changes since 2nd drag is ignored. | 921 // Nothing changes since 2nd drag is ignored. |
785 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 922 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
786 | 923 |
787 button_host->PointerReleasedOnButton(dragged_button_touch, | 924 button_host->PointerReleasedOnButton(dragged_button_touch, |
788 internal::LauncherButtonHost::TOUCH, | 925 internal::LauncherButtonHost::TOUCH, |
789 false); | 926 false); |
790 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 927 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
791 } | 928 } |
792 | 929 |
793 // Check that clicking first on one item and then dragging another works as | 930 // Check that clicking first on one item and then dragging another works as |
794 // expected. | 931 // expected. |
795 TEST_F(LauncherViewTest, ClickOneDragAnother) { | 932 TEST_F(LauncherViewTest, ClickOneDragAnother) { |
796 internal::LauncherButtonHost* button_host = launcher_view_; | 933 internal::LauncherButtonHost* button_host = launcher_view_; |
797 | 934 |
798 std::vector<std::pair<LauncherID, views::View*> > id_map; | 935 std::vector<std::pair<LauncherID, views::View*> > id_map; |
799 SetupForDragTest(&id_map); | 936 SetupForDragTest(&id_map); |
800 | 937 |
801 // A click on item 1 is simulated. | 938 // A click on item 1 is simulated. |
802 SimulateClick(internal::LauncherButtonHost::MOUSE, 1); | 939 SimulateClick(internal::LauncherButtonHost::MOUSE, 1); |
803 | 940 |
804 // Dragging browser index at 0 should change the model order correctly. | 941 // Dragging browser index at 0 should change the model order correctly. |
805 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); | 942 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); |
806 views::View* dragged_button = SimulateDrag( | 943 views::View* dragged_button = SimulateDrag( |
807 internal::LauncherButtonHost::MOUSE, 0, 2); | 944 internal::LauncherButtonHost::MOUSE, 1, 3); |
808 std::rotate(id_map.begin(), | 945 std::rotate(id_map.begin() + 1, |
809 id_map.begin() + 1, | 946 id_map.begin() + 2, |
810 id_map.begin() + 3); | 947 id_map.begin() + 4); |
811 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 948 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
812 button_host->PointerReleasedOnButton(dragged_button, | 949 button_host->PointerReleasedOnButton(dragged_button, |
813 internal::LauncherButtonHost::MOUSE, | 950 internal::LauncherButtonHost::MOUSE, |
814 false); | 951 false); |
815 EXPECT_TRUE(model_->items()[2].type == TYPE_BROWSER_SHORTCUT); | 952 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
816 } | 953 } |
817 | 954 |
818 // Confirm that item status changes are reflected in the buttons. | 955 // Confirm that item status changes are reflected in the buttons. |
819 TEST_F(LauncherViewTest, LauncherItemStatus) { | 956 TEST_F(LauncherViewTest, LauncherItemStatus) { |
820 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 957 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
821 test_api_->GetButtonCount()); | 958 test_api_->GetButtonCount()); |
822 | 959 |
823 // Add platform app button. | 960 // Add platform app button. |
824 LauncherID last_added = AddPlatformApp(); | 961 LauncherID last_added = AddPlatformApp(); |
825 LauncherItem item = GetItemByID(last_added); | 962 LauncherItem item = GetItemByID(last_added); |
826 int index = model_->ItemIndexByID(last_added); | 963 int index = model_->ItemIndexByID(last_added); |
827 internal::LauncherButton* button = GetButtonByID(last_added); | 964 internal::LauncherButton* button = GetButtonByID(last_added); |
828 ASSERT_EQ(internal::LauncherButton::STATE_RUNNING, button->state()); | 965 ASSERT_EQ(internal::LauncherButton::STATE_RUNNING, button->state()); |
829 item.status = ash::STATUS_ACTIVE; | 966 item.status = ash::STATUS_ACTIVE; |
830 model_->Set(index, item); | 967 model_->Set(index, item); |
831 ASSERT_EQ(internal::LauncherButton::STATE_ACTIVE, button->state()); | 968 ASSERT_EQ(internal::LauncherButton::STATE_ACTIVE, button->state()); |
832 item.status = ash::STATUS_ATTENTION; | 969 item.status = ash::STATUS_ATTENTION; |
833 model_->Set(index, item); | 970 model_->Set(index, item); |
834 ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state()); | 971 ASSERT_EQ(internal::LauncherButton::STATE_ATTENTION, button->state()); |
835 } | 972 } |
836 | 973 |
837 TEST_F(LauncherViewTest, LauncherItemPositionReflectedOnStateChanged) { | 974 TEST_F(LauncherViewLegacyShelfLayoutTest, |
| 975 LauncherItemPositionReflectedOnStateChanged) { |
838 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 976 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
839 test_api_->GetButtonCount()); | 977 test_api_->GetButtonCount()); |
840 | 978 |
841 // Add 2 items to the launcher. | 979 // Add 2 items to the launcher. |
842 LauncherID item1_id = AddPlatformApp(); | 980 LauncherID item1_id = AddPlatformApp(); |
843 LauncherID item2_id = AddPlatformAppNoWait(); | 981 LauncherID item2_id = AddPlatformAppNoWait(); |
844 internal::LauncherButton* item1_button = GetButtonByID(item1_id); | 982 internal::LauncherButton* item1_button = GetButtonByID(item1_id); |
845 internal::LauncherButton* item2_button = GetButtonByID(item2_id); | 983 internal::LauncherButton* item2_button = GetButtonByID(item2_id); |
846 | 984 |
847 internal::LauncherButton::State state_mask = | 985 internal::LauncherButton::State state_mask = |
848 static_cast<internal::LauncherButton::State> | 986 static_cast<internal::LauncherButton::State> |
849 (internal::LauncherButton::STATE_NORMAL | | 987 (internal::LauncherButton::STATE_NORMAL | |
850 internal::LauncherButton::STATE_HOVERED | | 988 internal::LauncherButton::STATE_HOVERED | |
851 internal::LauncherButton::STATE_RUNNING | | 989 internal::LauncherButton::STATE_RUNNING | |
852 internal::LauncherButton::STATE_ACTIVE | | 990 internal::LauncherButton::STATE_ACTIVE | |
853 internal::LauncherButton::STATE_ATTENTION | | 991 internal::LauncherButton::STATE_ATTENTION | |
854 internal::LauncherButton::STATE_FOCUSED); | 992 internal::LauncherButton::STATE_FOCUSED); |
855 | 993 |
856 // Clear the button states. | 994 // Clear the button states. |
857 item1_button->ClearState(state_mask); | 995 item1_button->ClearState(state_mask); |
858 item2_button->ClearState(state_mask); | 996 item2_button->ClearState(state_mask); |
859 | 997 |
860 // Since default alignment in tests is bottom, state is reflected in y-axis. | 998 // Since default alignment in tests is bottom, state is reflected in y-axis. |
861 ASSERT_EQ(item1_button->GetIconBounds().y(), | 999 ASSERT_EQ(item1_button->GetIconBounds().y(), |
862 item2_button->GetIconBounds().y()); | 1000 item2_button->GetIconBounds().y()); |
863 item1_button->AddState(internal::LauncherButton::STATE_HOVERED); | 1001 item1_button->AddState(internal::LauncherButton::STATE_HOVERED); |
864 ASSERT_NE(item1_button->GetIconBounds().y(), | 1002 ASSERT_NE(item1_button->GetIconBounds().y(), |
865 item2_button->GetIconBounds().y()); | 1003 item2_button->GetIconBounds().y()); |
866 item1_button->ClearState(internal::LauncherButton::STATE_HOVERED); | 1004 item1_button->ClearState(internal::LauncherButton::STATE_HOVERED); |
867 | |
868 // Enable the alternate shelf layout. | |
869 CommandLine::ForCurrentProcess()->AppendSwitch( | |
870 ash::switches::kAshUseAlternateShelfLayout); | |
871 launcher_view_->Layout(); | |
872 | |
873 // Since default alignment in tests is bottom, state is reflected in y-axis. | |
874 // In alternate shelf layout there is no visible hovered state. | |
875 ASSERT_EQ(item1_button->GetIconBounds().y(), | |
876 item2_button->GetIconBounds().y()); | |
877 item1_button->AddState(internal::LauncherButton::STATE_HOVERED); | |
878 ASSERT_EQ(item1_button->GetIconBounds().y(), | |
879 item2_button->GetIconBounds().y()); | |
880 } | 1005 } |
881 | 1006 |
882 // Confirm that item status changes are reflected in the buttons | 1007 // Confirm that item status changes are reflected in the buttons |
883 // for platform apps. | 1008 // for platform apps. |
884 TEST_F(LauncherViewTest, LauncherItemStatusPlatformApp) { | 1009 TEST_F(LauncherViewTest, LauncherItemStatusPlatformApp) { |
885 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 1010 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
886 test_api_->GetButtonCount()); | 1011 test_api_->GetButtonCount()); |
887 | 1012 |
888 // Add platform app button. | 1013 // Add platform app button. |
889 LauncherID last_added = AddPlatformApp(); | 1014 LauncherID last_added = AddPlatformApp(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 // Move the mouse over the button and check that it is visible. | 1170 // Move the mouse over the button and check that it is visible. |
1046 views::View* app_list_button = launcher_view_->GetAppListButtonView(); | 1171 views::View* app_list_button = launcher_view_->GetAppListButtonView(); |
1047 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); | 1172 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); |
1048 generator.MoveMouseTo(bounds.CenterPoint()); | 1173 generator.MoveMouseTo(bounds.CenterPoint()); |
1049 // Wait for the timer to go off. | 1174 // Wait for the timer to go off. |
1050 RunAllPendingInMessageLoop(); | 1175 RunAllPendingInMessageLoop(); |
1051 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1176 EXPECT_TRUE(tooltip_manager->IsVisible()); |
1052 | 1177 |
1053 // Move the mouse cursor slightly to the right of the item. The tooltip should | 1178 // Move the mouse cursor slightly to the right of the item. The tooltip should |
1054 // stay open. | 1179 // stay open. |
1055 generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0); | 1180 generator.MoveMouseBy(bounds.width() / 2 + 5, 0); |
1056 // Make sure there is no delayed close. | 1181 // Make sure there is no delayed close. |
1057 RunAllPendingInMessageLoop(); | 1182 RunAllPendingInMessageLoop(); |
1058 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1183 EXPECT_TRUE(tooltip_manager->IsVisible()); |
1059 | 1184 |
1060 // Move back - it should still stay open. | 1185 // Move back - it should still stay open. |
1061 generator.MoveMouseBy(bounds.width() / 2 + 5, 0); | 1186 generator.MoveMouseBy(-(bounds.width() / 2 + 5), 0); |
1062 // Make sure there is no delayed close. | 1187 // Make sure there is no delayed close. |
1063 RunAllPendingInMessageLoop(); | 1188 RunAllPendingInMessageLoop(); |
1064 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1189 EXPECT_TRUE(tooltip_manager->IsVisible()); |
1065 | 1190 |
1066 // Now move the mouse cursor slightly above the item - so that it is over the | 1191 // Now move the mouse cursor slightly above the item - so that it is over the |
1067 // tooltip bubble. Now it should disappear. | 1192 // tooltip bubble. Now it should disappear. |
1068 generator.MoveMouseBy(0, -(bounds.height() / 2 + 5)); | 1193 generator.MoveMouseBy(0, -(bounds.height() / 2 + 5)); |
1069 // Wait until the delayed close kicked in. | 1194 // Wait until the delayed close kicked in. |
1070 RunAllPendingInMessageLoop(); | 1195 RunAllPendingInMessageLoop(); |
1071 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1196 EXPECT_FALSE(tooltip_manager->IsVisible()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 const int app_list_button_index = test_api_->GetButtonCount() - 1; | 1228 const int app_list_button_index = test_api_->GetButtonCount() - 1; |
1104 const gfx::Rect& app_list_ideal_bounds = | 1229 const gfx::Rect& app_list_ideal_bounds = |
1105 test_api_->GetIdealBoundsByIndex(app_list_button_index); | 1230 test_api_->GetIdealBoundsByIndex(app_list_button_index); |
1106 const gfx::Rect& app_list_bounds = | 1231 const gfx::Rect& app_list_bounds = |
1107 test_api_->GetBoundsByIndex(app_list_button_index); | 1232 test_api_->GetBoundsByIndex(app_list_button_index); |
1108 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); | 1233 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); |
1109 } | 1234 } |
1110 | 1235 |
1111 // Check that the first item in the list follows Fitt's law by including the | 1236 // Check that the first item in the list follows Fitt's law by including the |
1112 // first pixel and being therefore bigger then the others. | 1237 // first pixel and being therefore bigger then the others. |
1113 TEST_F(LauncherViewTest, CheckFittsLaw) { | 1238 TEST_F(LauncherViewLegacyShelfLayoutTest, CheckFittsLaw) { |
1114 // All buttons should be visible. | 1239 // All buttons should be visible. |
1115 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 1240 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
1116 test_api_->GetButtonCount()); | 1241 test_api_->GetButtonCount()); |
1117 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); | 1242 gfx::Rect ideal_bounds_0 = test_api_->GetIdealBoundsByIndex(0); |
1118 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); | 1243 gfx::Rect ideal_bounds_1 = test_api_->GetIdealBoundsByIndex(1); |
1119 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); | 1244 EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width()); |
1120 } | 1245 } |
1121 | 1246 |
1122 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool()); | 1247 INSTANTIATE_TEST_CASE_P(LtrRtl, LauncherViewTextDirectionTest, testing::Bool()); |
1123 | 1248 |
1124 } // namespace test | 1249 } // namespace test |
1125 } // namespace ash | 1250 } // namespace ash |
OLD | NEW |