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/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 virtual ~ShelfViewTest() {} | 263 virtual ~ShelfViewTest() {} |
264 | 264 |
265 virtual void SetUp() OVERRIDE { | 265 virtual void SetUp() OVERRIDE { |
266 AshTestBase::SetUp(); | 266 AshTestBase::SetUp(); |
267 test::ShellTestApi test_api(Shell::GetInstance()); | 267 test::ShellTestApi test_api(Shell::GetInstance()); |
268 model_ = test_api.shelf_model(); | 268 model_ = test_api.shelf_model(); |
269 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 269 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
270 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); | 270 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); |
271 | 271 |
272 // The bounds should be big enough for 4 buttons + overflow chevron. | 272 // The bounds should be big enough for 4 buttons + overflow chevron. |
273 shelf_view_->SetBounds(0, 0, 500, | 273 shelf_view_->SetBounds( |
274 internal::ShelfLayoutManager::GetPreferredShelfSize()); | 274 0, 0, 500, ShelfLayoutManager::GetPreferredShelfSize()); |
275 | 275 |
276 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); | 276 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); |
277 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | 277 test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
278 | 278 |
279 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); | 279 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); |
280 DCHECK(item_manager_); | 280 DCHECK(item_manager_); |
281 | 281 |
282 // Add browser shortcut shelf item at index 0 for test. | 282 // Add browser shortcut shelf item at index 0 for test. |
283 AddBrowserShortcut(); | 283 AddBrowserShortcut(); |
284 } | 284 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 ShelfID id = AddPlatformAppNoWait(); | 349 ShelfID id = AddPlatformAppNoWait(); |
350 test_api_->RunMessageLoopUntilAnimationsDone(); | 350 test_api_->RunMessageLoopUntilAnimationsDone(); |
351 return id; | 351 return id; |
352 } | 352 } |
353 | 353 |
354 void RemoveByID(ShelfID id) { | 354 void RemoveByID(ShelfID id) { |
355 model_->RemoveItemAt(model_->ItemIndexByID(id)); | 355 model_->RemoveItemAt(model_->ItemIndexByID(id)); |
356 test_api_->RunMessageLoopUntilAnimationsDone(); | 356 test_api_->RunMessageLoopUntilAnimationsDone(); |
357 } | 357 } |
358 | 358 |
359 internal::ShelfButton* GetButtonByID(ShelfID id) { | 359 ShelfButton* GetButtonByID(ShelfID id) { |
360 int index = model_->ItemIndexByID(id); | 360 int index = model_->ItemIndexByID(id); |
361 return test_api_->GetButton(index); | 361 return test_api_->GetButton(index); |
362 } | 362 } |
363 | 363 |
364 ShelfItem GetItemByID(ShelfID id) { | 364 ShelfItem GetItemByID(ShelfID id) { |
365 ShelfItems::const_iterator items = model_->ItemByID(id); | 365 ShelfItems::const_iterator items = model_->ItemByID(id); |
366 return *items; | 366 return *items; |
367 } | 367 } |
368 | 368 |
369 void CheckModelIDs( | 369 void CheckModelIDs( |
(...skipping 17 matching lines...) Expand all Loading... |
387 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); | 387 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); |
388 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); | 388 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); |
389 EXPECT_GE(item_bounds.x(), 0); | 389 EXPECT_GE(item_bounds.x(), 0); |
390 EXPECT_GE(item_bounds.y(), 0); | 390 EXPECT_GE(item_bounds.y(), 0); |
391 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); | 391 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); |
392 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); | 392 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); |
393 } | 393 } |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 views::View* SimulateButtonPressed( | 397 views::View* SimulateButtonPressed(ShelfButtonHost::Pointer pointer, |
398 internal::ShelfButtonHost::Pointer pointer, | 398 int button_index) { |
399 int button_index) { | 399 ShelfButtonHost* button_host = shelf_view_; |
400 internal::ShelfButtonHost* button_host = shelf_view_; | |
401 views::View* button = test_api_->GetButton(button_index); | 400 views::View* button = test_api_->GetButton(button_index); |
402 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, | 401 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, |
403 button->bounds().origin(), | 402 button->bounds().origin(), |
404 button->GetBoundsInScreen().origin(), 0, 0); | 403 button->GetBoundsInScreen().origin(), 0, 0); |
405 button_host->PointerPressedOnButton(button, pointer, click_event); | 404 button_host->PointerPressedOnButton(button, pointer, click_event); |
406 return button; | 405 return button; |
407 } | 406 } |
408 | 407 |
409 views::View* SimulateClick(internal::ShelfButtonHost::Pointer pointer, | 408 views::View* SimulateClick(ShelfButtonHost::Pointer pointer, |
410 int button_index) { | 409 int button_index) { |
411 internal::ShelfButtonHost* button_host = shelf_view_; | 410 ShelfButtonHost* button_host = shelf_view_; |
412 views::View* button = SimulateButtonPressed(pointer, button_index); | 411 views::View* button = SimulateButtonPressed(pointer, button_index); |
413 button_host->PointerReleasedOnButton(button, | 412 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); |
414 internal::ShelfButtonHost::MOUSE, | |
415 false); | |
416 return button; | 413 return button; |
417 } | 414 } |
418 | 415 |
419 views::View* SimulateDrag(internal::ShelfButtonHost::Pointer pointer, | 416 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer, |
420 int button_index, | 417 int button_index, |
421 int destination_index) { | 418 int destination_index) { |
422 internal::ShelfButtonHost* button_host = shelf_view_; | 419 ShelfButtonHost* button_host = shelf_view_; |
423 views::View* button = SimulateButtonPressed(pointer, button_index); | 420 views::View* button = SimulateButtonPressed(pointer, button_index); |
424 | 421 |
425 // Drag. | 422 // Drag. |
426 views::View* destination = test_api_->GetButton(destination_index); | 423 views::View* destination = test_api_->GetButton(destination_index); |
427 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, | 424 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, |
428 destination->bounds().origin(), | 425 destination->bounds().origin(), |
429 destination->GetBoundsInScreen().origin(), 0, 0); | 426 destination->GetBoundsInScreen().origin(), 0, 0); |
430 button_host->PointerDraggedOnButton(button, pointer, drag_event); | 427 button_host->PointerDraggedOnButton(button, pointer, drag_event); |
431 return button; | 428 return button; |
432 } | 429 } |
433 | 430 |
434 void SetupForDragTest( | 431 void SetupForDragTest( |
435 std::vector<std::pair<ShelfID, views::View*> >* id_map) { | 432 std::vector<std::pair<ShelfID, views::View*> >* id_map) { |
436 // Initialize |id_map| with the automatically-created shelf buttons. | 433 // Initialize |id_map| with the automatically-created shelf buttons. |
437 for (size_t i = 0; i < model_->items().size(); ++i) { | 434 for (size_t i = 0; i < model_->items().size(); ++i) { |
438 internal::ShelfButton* button = test_api_->GetButton(i); | 435 ShelfButton* button = test_api_->GetButton(i); |
439 id_map->push_back(std::make_pair(model_->items()[i].id, button)); | 436 id_map->push_back(std::make_pair(model_->items()[i].id, button)); |
440 } | 437 } |
441 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); | 438 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
442 | 439 |
443 // Add 5 app shelf buttons for testing. | 440 // Add 5 app shelf buttons for testing. |
444 for (int i = 0; i < 5; ++i) { | 441 for (int i = 0; i < 5; ++i) { |
445 ShelfID id = AddAppShortcut(); | 442 ShelfID id = AddAppShortcut(); |
446 // App Icon is located at index 0, and browser shortcut is located at | 443 // App Icon is located at index 0, and browser shortcut is located at |
447 // index 1. So we should start to add app shortcut at index 2. | 444 // index 1. So we should start to add app shortcut at index 2. |
448 id_map->insert(id_map->begin() + (i + browser_index_ + 1), | 445 id_map->insert(id_map->begin() + (i + browser_index_ + 1), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 int second_last_visible_item_id_in_shelf = | 480 int second_last_visible_item_id_in_shelf = |
484 GetItemId(test_api_->GetLastVisibleIndex() - 1); | 481 GetItemId(test_api_->GetLastVisibleIndex() - 1); |
485 int first_visible_item_id_in_overflow = | 482 int first_visible_item_id_in_overflow = |
486 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); | 483 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); |
487 int second_last_visible_item_id_in_overflow = | 484 int second_last_visible_item_id_in_overflow = |
488 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1); | 485 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1); |
489 | 486 |
490 int drag_item_index = | 487 int drag_item_index = |
491 test_api_for_overflow.GetLastVisibleIndex(); | 488 test_api_for_overflow.GetLastVisibleIndex(); |
492 ShelfID drag_item_id = GetItemId(drag_item_index); | 489 ShelfID drag_item_id = GetItemId(drag_item_index); |
493 internal::ShelfButton* drag_button = | 490 ShelfButton* drag_button = test_api_for_overflow.GetButton(drag_item_index); |
494 test_api_for_overflow.GetButton(drag_item_index); | |
495 gfx::Point center_point_of_drag_item = | 491 gfx::Point center_point_of_drag_item = |
496 drag_button->GetBoundsInScreen().CenterPoint(); | 492 drag_button->GetBoundsInScreen().CenterPoint(); |
497 | 493 |
498 aura::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(), | 494 aura::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow(), |
499 center_point_of_drag_item); | 495 center_point_of_drag_item); |
500 // Rip an item off to OverflowBubble. | 496 // Rip an item off to OverflowBubble. |
501 generator.PressLeftButton(); | 497 generator.PressLeftButton(); |
502 gfx::Point rip_off_point(center_point_of_drag_item.x(), 0); | 498 gfx::Point rip_off_point(center_point_of_drag_item.x(), 0); |
503 generator.MoveMouseTo(rip_off_point); | 499 generator.MoveMouseTo(rip_off_point); |
504 test_api_for_overflow.RunMessageLoopUntilAnimationsDone(); | 500 test_api_for_overflow.RunMessageLoopUntilAnimationsDone(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 // Replace ShelfDelegate. | 561 // Replace ShelfDelegate. |
566 test::ShellTestApi test_api(Shell::GetInstance()); | 562 test::ShellTestApi test_api(Shell::GetInstance()); |
567 test_api.SetShelfDelegate(NULL); | 563 test_api.SetShelfDelegate(NULL); |
568 ShelfDelegate* delegate = new TestShelfDelegateForShelfView(model_); | 564 ShelfDelegate* delegate = new TestShelfDelegateForShelfView(model_); |
569 test_api.SetShelfDelegate(delegate); | 565 test_api.SetShelfDelegate(delegate); |
570 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).SetShelfDelegate(delegate); | 566 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).SetShelfDelegate(delegate); |
571 test_api_->SetShelfDelegate(delegate); | 567 test_api_->SetShelfDelegate(delegate); |
572 } | 568 } |
573 | 569 |
574 ShelfModel* model_; | 570 ShelfModel* model_; |
575 internal::ShelfView* shelf_view_; | 571 ShelfView* shelf_view_; |
576 int browser_index_; | 572 int browser_index_; |
577 ShelfItemDelegateManager* item_manager_; | 573 ShelfItemDelegateManager* item_manager_; |
578 | 574 |
579 scoped_ptr<ShelfViewTestAPI> test_api_; | 575 scoped_ptr<ShelfViewTestAPI> test_api_; |
580 | 576 |
581 private: | 577 private: |
582 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest); | 578 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest); |
583 }; | 579 }; |
584 | 580 |
585 class ShelfViewLegacyShelfLayoutTest : public ShelfViewTest { | 581 class ShelfViewLegacyShelfLayoutTest : public ShelfViewTest { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 private: | 638 private: |
643 ScopedTextDirectionChange text_direction_change_; | 639 ScopedTextDirectionChange text_direction_change_; |
644 | 640 |
645 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); | 641 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); |
646 }; | 642 }; |
647 | 643 |
648 // Checks that the ideal item icon bounds match the view's bounds in the screen | 644 // Checks that the ideal item icon bounds match the view's bounds in the screen |
649 // in both LTR and RTL. | 645 // in both LTR and RTL. |
650 TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) { | 646 TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) { |
651 ShelfID id = AddPlatformApp(); | 647 ShelfID id = AddPlatformApp(); |
652 internal::ShelfButton* button = GetButtonByID(id); | 648 ShelfButton* button = GetButtonByID(id); |
653 gfx::Rect item_bounds = button->GetBoundsInScreen(); | 649 gfx::Rect item_bounds = button->GetBoundsInScreen(); |
654 gfx::Point icon_offset = button->GetIconBounds().origin(); | 650 gfx::Point icon_offset = button->GetIconBounds().origin(); |
655 item_bounds.Offset(icon_offset.OffsetFromOrigin()); | 651 item_bounds.Offset(icon_offset.OffsetFromOrigin()); |
656 gfx::Rect ideal_bounds = shelf_view_->GetIdealBoundsOfItemIcon(id); | 652 gfx::Rect ideal_bounds = shelf_view_->GetIdealBoundsOfItemIcon(id); |
657 gfx::Point screen_origin; | 653 gfx::Point screen_origin; |
658 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); | 654 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); |
659 ideal_bounds.Offset(screen_origin.x(), screen_origin.y()); | 655 ideal_bounds.Offset(screen_origin.x(), screen_origin.y()); |
660 EXPECT_EQ(item_bounds.x(), ideal_bounds.x()); | 656 EXPECT_EQ(item_bounds.x(), ideal_bounds.x()); |
661 EXPECT_EQ(item_bounds.y(), ideal_bounds.y()); | 657 EXPECT_EQ(item_bounds.y(), ideal_bounds.y()); |
662 } | 658 } |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 } | 935 } |
940 | 936 |
941 // ShelfView should be big enough to hold at least 3 new buttons. | 937 // ShelfView should be big enough to hold at least 3 new buttons. |
942 ASSERT_GE(added_count, 3); | 938 ASSERT_GE(added_count, 3); |
943 | 939 |
944 // Wait for the last animation to finish. | 940 // Wait for the last animation to finish. |
945 test_api_->RunMessageLoopUntilAnimationsDone(); | 941 test_api_->RunMessageLoopUntilAnimationsDone(); |
946 | 942 |
947 // Verifies non-overflow buttons are visible. | 943 // Verifies non-overflow buttons are visible. |
948 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { | 944 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { |
949 internal::ShelfButton* button = test_api_->GetButton(i); | 945 ShelfButton* button = test_api_->GetButton(i); |
950 if (button) { | 946 if (button) { |
951 EXPECT_TRUE(button->visible()) << "button index=" << i; | 947 EXPECT_TRUE(button->visible()) << "button index=" << i; |
952 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; | 948 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; |
953 } | 949 } |
954 } | 950 } |
955 } | 951 } |
956 | 952 |
957 // Check that model changes are handled correctly while a shelf icon is being | 953 // Check that model changes are handled correctly while a shelf icon is being |
958 // dragged. | 954 // dragged. |
959 TEST_F(ShelfViewTest, ModelChangesWhileDragging) { | 955 TEST_F(ShelfViewTest, ModelChangesWhileDragging) { |
960 internal::ShelfButtonHost* button_host = shelf_view_; | 956 ShelfButtonHost* button_host = shelf_view_; |
961 | 957 |
962 std::vector<std::pair<ShelfID, views::View*> > id_map; | 958 std::vector<std::pair<ShelfID, views::View*> > id_map; |
963 SetupForDragTest(&id_map); | 959 SetupForDragTest(&id_map); |
964 | 960 |
965 // Dragging browser shortcut at index 1. | 961 // Dragging browser shortcut at index 1. |
966 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); | 962 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); |
967 views::View* dragged_button = SimulateDrag( | 963 views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); |
968 internal::ShelfButtonHost::MOUSE, 1, 3); | |
969 std::rotate(id_map.begin() + 1, | 964 std::rotate(id_map.begin() + 1, |
970 id_map.begin() + 2, | 965 id_map.begin() + 2, |
971 id_map.begin() + 4); | 966 id_map.begin() + 4); |
972 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 967 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
973 button_host->PointerReleasedOnButton(dragged_button, | 968 button_host->PointerReleasedOnButton( |
974 internal::ShelfButtonHost::MOUSE, | 969 dragged_button, ShelfButtonHost::MOUSE, false); |
975 false); | |
976 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); | 970 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
977 | 971 |
978 // Dragging changes model order. | 972 // Dragging changes model order. |
979 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); | 973 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); |
980 std::rotate(id_map.begin() + 1, | 974 std::rotate(id_map.begin() + 1, |
981 id_map.begin() + 2, | 975 id_map.begin() + 2, |
982 id_map.begin() + 4); | 976 id_map.begin() + 4); |
983 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 977 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
984 | 978 |
985 // Cancelling the drag operation restores previous order. | 979 // Cancelling the drag operation restores previous order. |
986 button_host->PointerReleasedOnButton(dragged_button, | 980 button_host->PointerReleasedOnButton( |
987 internal::ShelfButtonHost::MOUSE, | 981 dragged_button, ShelfButtonHost::MOUSE, true); |
988 true); | |
989 std::rotate(id_map.begin() + 1, | 982 std::rotate(id_map.begin() + 1, |
990 id_map.begin() + 3, | 983 id_map.begin() + 3, |
991 id_map.begin() + 4); | 984 id_map.begin() + 4); |
992 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 985 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
993 | 986 |
994 // Deleting an item keeps the remaining intact. | 987 // Deleting an item keeps the remaining intact. |
995 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); | 988 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); |
996 model_->RemoveItemAt(1); | 989 model_->RemoveItemAt(1); |
997 id_map.erase(id_map.begin() + 1); | 990 id_map.erase(id_map.begin() + 1); |
998 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 991 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
999 button_host->PointerReleasedOnButton(dragged_button, | 992 button_host->PointerReleasedOnButton( |
1000 internal::ShelfButtonHost::MOUSE, | 993 dragged_button, ShelfButtonHost::MOUSE, false); |
1001 false); | |
1002 | 994 |
1003 // Adding a shelf item cancels the drag and respects the order. | 995 // Adding a shelf item cancels the drag and respects the order. |
1004 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); | 996 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); |
1005 ShelfID new_id = AddAppShortcut(); | 997 ShelfID new_id = AddAppShortcut(); |
1006 id_map.insert(id_map.begin() + 6, | 998 id_map.insert(id_map.begin() + 6, |
1007 std::make_pair(new_id, GetButtonByID(new_id))); | 999 std::make_pair(new_id, GetButtonByID(new_id))); |
1008 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1000 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1009 button_host->PointerReleasedOnButton(dragged_button, | 1001 button_host->PointerReleasedOnButton( |
1010 internal::ShelfButtonHost::MOUSE, | 1002 dragged_button, ShelfButtonHost::MOUSE, false); |
1011 false); | |
1012 | 1003 |
1013 // Adding a shelf item at the end (i.e. a panel) canels drag and respects | 1004 // Adding a shelf item at the end (i.e. a panel) canels drag and respects |
1014 // the order. | 1005 // the order. |
1015 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); | 1006 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); |
1016 new_id = AddPanel(); | 1007 new_id = AddPanel(); |
1017 id_map.insert(id_map.begin() + 7, | 1008 id_map.insert(id_map.begin() + 7, |
1018 std::make_pair(new_id, GetButtonByID(new_id))); | 1009 std::make_pair(new_id, GetButtonByID(new_id))); |
1019 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1010 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1020 button_host->PointerReleasedOnButton(dragged_button, | 1011 button_host->PointerReleasedOnButton( |
1021 internal::ShelfButtonHost::MOUSE, | 1012 dragged_button, ShelfButtonHost::MOUSE, false); |
1022 false); | |
1023 } | 1013 } |
1024 | 1014 |
1025 TEST_F(ShelfViewLegacyShelfLayoutTest, ModelChangesWhileDragging) { | 1015 TEST_F(ShelfViewLegacyShelfLayoutTest, ModelChangesWhileDragging) { |
1026 internal::ShelfButtonHost* button_host = shelf_view_; | 1016 ShelfButtonHost* button_host = shelf_view_; |
1027 | 1017 |
1028 std::vector<std::pair<ShelfID, views::View*> > id_map; | 1018 std::vector<std::pair<ShelfID, views::View*> > id_map; |
1029 SetupForDragTest(&id_map); | 1019 SetupForDragTest(&id_map); |
1030 | 1020 |
1031 // Dragging browser shortcut at index 0. | 1021 // Dragging browser shortcut at index 0. |
1032 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); | 1022 EXPECT_TRUE(model_->items()[0].type == TYPE_BROWSER_SHORTCUT); |
1033 views::View* dragged_button = SimulateDrag( | 1023 views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2); |
1034 internal::ShelfButtonHost::MOUSE, 0, 2); | |
1035 std::rotate(id_map.begin(), | 1024 std::rotate(id_map.begin(), |
1036 id_map.begin() + 1, | 1025 id_map.begin() + 1, |
1037 id_map.begin() + 3); | 1026 id_map.begin() + 3); |
1038 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1027 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1039 button_host->PointerReleasedOnButton(dragged_button, | 1028 button_host->PointerReleasedOnButton( |
1040 internal::ShelfButtonHost::MOUSE, | 1029 dragged_button, ShelfButtonHost::MOUSE, false); |
1041 false); | |
1042 EXPECT_TRUE(model_->items()[2].type == TYPE_BROWSER_SHORTCUT); | 1030 EXPECT_TRUE(model_->items()[2].type == TYPE_BROWSER_SHORTCUT); |
1043 | 1031 |
1044 // Dragging changes model order. | 1032 // Dragging changes model order. |
1045 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | 1033 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2); |
1046 std::rotate(id_map.begin(), | 1034 std::rotate(id_map.begin(), |
1047 id_map.begin() + 1, | 1035 id_map.begin() + 1, |
1048 id_map.begin() + 3); | 1036 id_map.begin() + 3); |
1049 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1037 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1050 | 1038 |
1051 // Cancelling the drag operation restores previous order. | 1039 // Cancelling the drag operation restores previous order. |
1052 button_host->PointerReleasedOnButton(dragged_button, | 1040 button_host->PointerReleasedOnButton( |
1053 internal::ShelfButtonHost::MOUSE, | 1041 dragged_button, ShelfButtonHost::MOUSE, true); |
1054 true); | |
1055 std::rotate(id_map.begin(), | 1042 std::rotate(id_map.begin(), |
1056 id_map.begin() + 2, | 1043 id_map.begin() + 2, |
1057 id_map.begin() + 3); | 1044 id_map.begin() + 3); |
1058 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1045 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1059 | 1046 |
1060 // Deleting an item keeps the remaining intact. | 1047 // Deleting an item keeps the remaining intact. |
1061 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | 1048 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2); |
1062 model_->RemoveItemAt(1); | 1049 model_->RemoveItemAt(1); |
1063 id_map.erase(id_map.begin() + 1); | 1050 id_map.erase(id_map.begin() + 1); |
1064 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1051 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1065 button_host->PointerReleasedOnButton(dragged_button, | 1052 button_host->PointerReleasedOnButton( |
1066 internal::ShelfButtonHost::MOUSE, | 1053 dragged_button, ShelfButtonHost::MOUSE, false); |
1067 false); | |
1068 | 1054 |
1069 // Adding a shelf item cancels the drag and respects the order. | 1055 // Adding a shelf item cancels the drag and respects the order. |
1070 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | 1056 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2); |
1071 ShelfID new_id = AddAppShortcut(); | 1057 ShelfID new_id = AddAppShortcut(); |
1072 id_map.insert(id_map.begin() + 5, | 1058 id_map.insert(id_map.begin() + 5, |
1073 std::make_pair(new_id, GetButtonByID(new_id))); | 1059 std::make_pair(new_id, GetButtonByID(new_id))); |
1074 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1060 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1075 button_host->PointerReleasedOnButton(dragged_button, | 1061 button_host->PointerReleasedOnButton( |
1076 internal::ShelfButtonHost::MOUSE, | 1062 dragged_button, ShelfButtonHost::MOUSE, false); |
1077 false); | |
1078 | 1063 |
1079 // Adding a shelf item at the end (i.e. a panel) canels drag and respects | 1064 // Adding a shelf item at the end (i.e. a panel) canels drag and respects |
1080 // the order. | 1065 // the order. |
1081 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | 1066 dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 0, 2); |
1082 new_id = AddPanel(); | 1067 new_id = AddPanel(); |
1083 id_map.insert(id_map.begin() + 7, | 1068 id_map.insert(id_map.begin() + 7, |
1084 std::make_pair(new_id, GetButtonByID(new_id))); | 1069 std::make_pair(new_id, GetButtonByID(new_id))); |
1085 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1070 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1086 button_host->PointerReleasedOnButton(dragged_button, | 1071 button_host->PointerReleasedOnButton( |
1087 internal::ShelfButtonHost::MOUSE, | 1072 dragged_button, ShelfButtonHost::MOUSE, false); |
1088 false); | |
1089 } | 1073 } |
1090 | 1074 |
1091 // Check that 2nd drag from the other pointer would be ignored. | 1075 // Check that 2nd drag from the other pointer would be ignored. |
1092 TEST_F(ShelfViewTest, SimultaneousDrag) { | 1076 TEST_F(ShelfViewTest, SimultaneousDrag) { |
1093 internal::ShelfButtonHost* button_host = shelf_view_; | 1077 ShelfButtonHost* button_host = shelf_view_; |
1094 | 1078 |
1095 std::vector<std::pair<ShelfID, views::View*> > id_map; | 1079 std::vector<std::pair<ShelfID, views::View*> > id_map; |
1096 SetupForDragTest(&id_map); | 1080 SetupForDragTest(&id_map); |
1097 | 1081 |
1098 // Start a mouse drag. | 1082 // Start a mouse drag. |
1099 views::View* dragged_button_mouse = SimulateDrag( | 1083 views::View* dragged_button_mouse = |
1100 internal::ShelfButtonHost::MOUSE, 1, 3); | 1084 SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); |
1101 std::rotate(id_map.begin() + 1, | 1085 std::rotate(id_map.begin() + 1, |
1102 id_map.begin() + 2, | 1086 id_map.begin() + 2, |
1103 id_map.begin() + 4); | 1087 id_map.begin() + 4); |
1104 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1088 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1105 // Attempt a touch drag before the mouse drag finishes. | 1089 // Attempt a touch drag before the mouse drag finishes. |
1106 views::View* dragged_button_touch = SimulateDrag( | 1090 views::View* dragged_button_touch = |
1107 internal::ShelfButtonHost::TOUCH, 4, 2); | 1091 SimulateDrag(ShelfButtonHost::TOUCH, 4, 2); |
1108 | 1092 |
1109 // Nothing changes since 2nd drag is ignored. | 1093 // Nothing changes since 2nd drag is ignored. |
1110 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1094 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1111 | 1095 |
1112 // Finish the mouse drag. | 1096 // Finish the mouse drag. |
1113 button_host->PointerReleasedOnButton(dragged_button_mouse, | 1097 button_host->PointerReleasedOnButton( |
1114 internal::ShelfButtonHost::MOUSE, | 1098 dragged_button_mouse, ShelfButtonHost::MOUSE, false); |
1115 false); | |
1116 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1099 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1117 | 1100 |
1118 // Now start a touch drag. | 1101 // Now start a touch drag. |
1119 dragged_button_touch = SimulateDrag(internal::ShelfButtonHost::TOUCH, 4, 2); | 1102 dragged_button_touch = SimulateDrag(ShelfButtonHost::TOUCH, 4, 2); |
1120 std::rotate(id_map.begin() + 3, | 1103 std::rotate(id_map.begin() + 3, |
1121 id_map.begin() + 4, | 1104 id_map.begin() + 4, |
1122 id_map.begin() + 5); | 1105 id_map.begin() + 5); |
1123 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1106 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1124 | 1107 |
1125 // And attempt a mouse drag before the touch drag finishes. | 1108 // And attempt a mouse drag before the touch drag finishes. |
1126 dragged_button_mouse = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 2); | 1109 dragged_button_mouse = SimulateDrag(ShelfButtonHost::MOUSE, 1, 2); |
1127 | 1110 |
1128 // Nothing changes since 2nd drag is ignored. | 1111 // Nothing changes since 2nd drag is ignored. |
1129 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1112 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1130 | 1113 |
1131 button_host->PointerReleasedOnButton(dragged_button_touch, | 1114 button_host->PointerReleasedOnButton( |
1132 internal::ShelfButtonHost::TOUCH, | 1115 dragged_button_touch, ShelfButtonHost::TOUCH, false); |
1133 false); | |
1134 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1116 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1135 } | 1117 } |
1136 | 1118 |
1137 // Check that clicking first on one item and then dragging another works as | 1119 // Check that clicking first on one item and then dragging another works as |
1138 // expected. | 1120 // expected. |
1139 TEST_F(ShelfViewTest, ClickOneDragAnother) { | 1121 TEST_F(ShelfViewTest, ClickOneDragAnother) { |
1140 internal::ShelfButtonHost* button_host = shelf_view_; | 1122 ShelfButtonHost* button_host = shelf_view_; |
1141 | 1123 |
1142 std::vector<std::pair<ShelfID, views::View*> > id_map; | 1124 std::vector<std::pair<ShelfID, views::View*> > id_map; |
1143 SetupForDragTest(&id_map); | 1125 SetupForDragTest(&id_map); |
1144 | 1126 |
1145 // A click on item 1 is simulated. | 1127 // A click on item 1 is simulated. |
1146 SimulateClick(internal::ShelfButtonHost::MOUSE, 1); | 1128 SimulateClick(ShelfButtonHost::MOUSE, 1); |
1147 | 1129 |
1148 // Dragging browser index at 0 should change the model order correctly. | 1130 // Dragging browser index at 0 should change the model order correctly. |
1149 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); | 1131 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); |
1150 views::View* dragged_button = SimulateDrag( | 1132 views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); |
1151 internal::ShelfButtonHost::MOUSE, 1, 3); | |
1152 std::rotate(id_map.begin() + 1, | 1133 std::rotate(id_map.begin() + 1, |
1153 id_map.begin() + 2, | 1134 id_map.begin() + 2, |
1154 id_map.begin() + 4); | 1135 id_map.begin() + 4); |
1155 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1136 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
1156 button_host->PointerReleasedOnButton(dragged_button, | 1137 button_host->PointerReleasedOnButton( |
1157 internal::ShelfButtonHost::MOUSE, | 1138 dragged_button, ShelfButtonHost::MOUSE, false); |
1158 false); | |
1159 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); | 1139 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
1160 } | 1140 } |
1161 | 1141 |
1162 // Confirm that item status changes are reflected in the buttons. | 1142 // Confirm that item status changes are reflected in the buttons. |
1163 TEST_F(ShelfViewTest, ShelfItemStatus) { | 1143 TEST_F(ShelfViewTest, ShelfItemStatus) { |
1164 // All buttons should be visible. | 1144 // All buttons should be visible. |
1165 ASSERT_EQ(test_api_->GetButtonCount(), | 1145 ASSERT_EQ(test_api_->GetButtonCount(), |
1166 test_api_->GetLastVisibleIndex() + 1); | 1146 test_api_->GetLastVisibleIndex() + 1); |
1167 | 1147 |
1168 // Add platform app button. | 1148 // Add platform app button. |
1169 ShelfID last_added = AddPlatformApp(); | 1149 ShelfID last_added = AddPlatformApp(); |
1170 ShelfItem item = GetItemByID(last_added); | 1150 ShelfItem item = GetItemByID(last_added); |
1171 int index = model_->ItemIndexByID(last_added); | 1151 int index = model_->ItemIndexByID(last_added); |
1172 internal::ShelfButton* button = GetButtonByID(last_added); | 1152 ShelfButton* button = GetButtonByID(last_added); |
1173 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); | 1153 ASSERT_EQ(ShelfButton::STATE_RUNNING, button->state()); |
1174 item.status = STATUS_ACTIVE; | 1154 item.status = STATUS_ACTIVE; |
1175 model_->Set(index, item); | 1155 model_->Set(index, item); |
1176 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); | 1156 ASSERT_EQ(ShelfButton::STATE_ACTIVE, button->state()); |
1177 item.status = STATUS_ATTENTION; | 1157 item.status = STATUS_ATTENTION; |
1178 model_->Set(index, item); | 1158 model_->Set(index, item); |
1179 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); | 1159 ASSERT_EQ(ShelfButton::STATE_ATTENTION, button->state()); |
1180 } | 1160 } |
1181 | 1161 |
1182 TEST_F(ShelfViewLegacyShelfLayoutTest, | 1162 TEST_F(ShelfViewLegacyShelfLayoutTest, |
1183 ShelfItemPositionReflectedOnStateChanged) { | 1163 ShelfItemPositionReflectedOnStateChanged) { |
1184 // All buttons should be visible. | 1164 // All buttons should be visible. |
1185 ASSERT_EQ(test_api_->GetButtonCount(), | 1165 ASSERT_EQ(test_api_->GetButtonCount(), |
1186 test_api_->GetLastVisibleIndex() + 1); | 1166 test_api_->GetLastVisibleIndex() + 1); |
1187 | 1167 |
1188 // Add 2 items to the shelf. | 1168 // Add 2 items to the shelf. |
1189 ShelfID item1_id = AddPlatformApp(); | 1169 ShelfID item1_id = AddPlatformApp(); |
1190 ShelfID item2_id = AddPlatformAppNoWait(); | 1170 ShelfID item2_id = AddPlatformAppNoWait(); |
1191 internal::ShelfButton* item1_button = GetButtonByID(item1_id); | 1171 ShelfButton* item1_button = GetButtonByID(item1_id); |
1192 internal::ShelfButton* item2_button = GetButtonByID(item2_id); | 1172 ShelfButton* item2_button = GetButtonByID(item2_id); |
1193 | 1173 |
1194 internal::ShelfButton::State state_mask = | 1174 ShelfButton::State state_mask = static_cast<ShelfButton::State>( |
1195 static_cast<internal::ShelfButton::State>( | 1175 ShelfButton::STATE_NORMAL | ShelfButton::STATE_HOVERED | |
1196 internal::ShelfButton::STATE_NORMAL | | 1176 ShelfButton::STATE_RUNNING | ShelfButton::STATE_ACTIVE | |
1197 internal::ShelfButton::STATE_HOVERED | | 1177 ShelfButton::STATE_ATTENTION | ShelfButton::STATE_FOCUSED); |
1198 internal::ShelfButton::STATE_RUNNING | | |
1199 internal::ShelfButton::STATE_ACTIVE | | |
1200 internal::ShelfButton::STATE_ATTENTION | | |
1201 internal::ShelfButton::STATE_FOCUSED); | |
1202 | 1178 |
1203 // Clear the button states. | 1179 // Clear the button states. |
1204 item1_button->ClearState(state_mask); | 1180 item1_button->ClearState(state_mask); |
1205 item2_button->ClearState(state_mask); | 1181 item2_button->ClearState(state_mask); |
1206 | 1182 |
1207 // Since default alignment in tests is bottom, state is reflected in y-axis. | 1183 // Since default alignment in tests is bottom, state is reflected in y-axis. |
1208 ASSERT_EQ(item1_button->GetIconBounds().y(), | 1184 ASSERT_EQ(item1_button->GetIconBounds().y(), |
1209 item2_button->GetIconBounds().y()); | 1185 item2_button->GetIconBounds().y()); |
1210 item1_button->AddState(internal::ShelfButton::STATE_HOVERED); | 1186 item1_button->AddState(ShelfButton::STATE_HOVERED); |
1211 ASSERT_NE(item1_button->GetIconBounds().y(), | 1187 ASSERT_NE(item1_button->GetIconBounds().y(), |
1212 item2_button->GetIconBounds().y()); | 1188 item2_button->GetIconBounds().y()); |
1213 item1_button->ClearState(internal::ShelfButton::STATE_HOVERED); | 1189 item1_button->ClearState(ShelfButton::STATE_HOVERED); |
1214 } | 1190 } |
1215 | 1191 |
1216 // Confirm that item status changes are reflected in the buttons | 1192 // Confirm that item status changes are reflected in the buttons |
1217 // for platform apps. | 1193 // for platform apps. |
1218 TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) { | 1194 TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) { |
1219 // All buttons should be visible. | 1195 // All buttons should be visible. |
1220 ASSERT_EQ(test_api_->GetButtonCount(), | 1196 ASSERT_EQ(test_api_->GetButtonCount(), |
1221 test_api_->GetLastVisibleIndex() + 1); | 1197 test_api_->GetLastVisibleIndex() + 1); |
1222 | 1198 |
1223 // Add platform app button. | 1199 // Add platform app button. |
1224 ShelfID last_added = AddPlatformApp(); | 1200 ShelfID last_added = AddPlatformApp(); |
1225 ShelfItem item = GetItemByID(last_added); | 1201 ShelfItem item = GetItemByID(last_added); |
1226 int index = model_->ItemIndexByID(last_added); | 1202 int index = model_->ItemIndexByID(last_added); |
1227 internal::ShelfButton* button = GetButtonByID(last_added); | 1203 ShelfButton* button = GetButtonByID(last_added); |
1228 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); | 1204 ASSERT_EQ(ShelfButton::STATE_RUNNING, button->state()); |
1229 item.status = STATUS_ACTIVE; | 1205 item.status = STATUS_ACTIVE; |
1230 model_->Set(index, item); | 1206 model_->Set(index, item); |
1231 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); | 1207 ASSERT_EQ(ShelfButton::STATE_ACTIVE, button->state()); |
1232 item.status = STATUS_ATTENTION; | 1208 item.status = STATUS_ATTENTION; |
1233 model_->Set(index, item); | 1209 model_->Set(index, item); |
1234 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); | 1210 ASSERT_EQ(ShelfButton::STATE_ATTENTION, button->state()); |
1235 } | 1211 } |
1236 | 1212 |
1237 // Confirm that shelf item bounds are correctly updated on shelf changes. | 1213 // Confirm that shelf item bounds are correctly updated on shelf changes. |
1238 TEST_F(ShelfViewTest, ShelfItemBoundsCheck) { | 1214 TEST_F(ShelfViewTest, ShelfItemBoundsCheck) { |
1239 VerifyShelfItemBoundsAreValid(); | 1215 VerifyShelfItemBoundsAreValid(); |
1240 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( | 1216 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( |
1241 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1217 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
1242 test_api_->RunMessageLoopUntilAnimationsDone(); | 1218 test_api_->RunMessageLoopUntilAnimationsDone(); |
1243 VerifyShelfItemBoundsAreValid(); | 1219 VerifyShelfItemBoundsAreValid(); |
1244 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( | 1220 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( |
1245 SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1221 SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
1246 test_api_->RunMessageLoopUntilAnimationsDone(); | 1222 test_api_->RunMessageLoopUntilAnimationsDone(); |
1247 VerifyShelfItemBoundsAreValid(); | 1223 VerifyShelfItemBoundsAreValid(); |
1248 } | 1224 } |
1249 | 1225 |
1250 TEST_F(ShelfViewTest, ShelfTooltipTest) { | 1226 TEST_F(ShelfViewTest, ShelfTooltipTest) { |
1251 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 1227 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
1252 test_api_->GetButtonCount()); | 1228 test_api_->GetButtonCount()); |
1253 | 1229 |
1254 // Prepare some items to the shelf. | 1230 // Prepare some items to the shelf. |
1255 ShelfID app_button_id = AddAppShortcut(); | 1231 ShelfID app_button_id = AddAppShortcut(); |
1256 ShelfID platform_button_id = AddPlatformApp(); | 1232 ShelfID platform_button_id = AddPlatformApp(); |
1257 | 1233 |
1258 internal::ShelfButton* app_button = GetButtonByID(app_button_id); | 1234 ShelfButton* app_button = GetButtonByID(app_button_id); |
1259 internal::ShelfButton* platform_button = GetButtonByID(platform_button_id); | 1235 ShelfButton* platform_button = GetButtonByID(platform_button_id); |
1260 | 1236 |
1261 internal::ShelfButtonHost* button_host = shelf_view_; | 1237 ShelfButtonHost* button_host = shelf_view_; |
1262 internal::ShelfTooltipManager* tooltip_manager = | 1238 ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager(); |
1263 shelf_view_->tooltip_manager(); | |
1264 | 1239 |
1265 button_host->MouseEnteredButton(app_button); | 1240 button_host->MouseEnteredButton(app_button); |
1266 // There's a delay to show the tooltip, so it's not visible yet. | 1241 // There's a delay to show the tooltip, so it's not visible yet. |
1267 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1242 EXPECT_FALSE(tooltip_manager->IsVisible()); |
1268 EXPECT_EQ(app_button, GetTooltipAnchorView()); | 1243 EXPECT_EQ(app_button, GetTooltipAnchorView()); |
1269 | 1244 |
1270 ShowTooltip(); | 1245 ShowTooltip(); |
1271 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1246 EXPECT_TRUE(tooltip_manager->IsVisible()); |
1272 | 1247 |
1273 // Once it's visible, it keeps visibility and is pointing to the same | 1248 // Once it's visible, it keeps visibility and is pointing to the same |
(...skipping 15 matching lines...) Expand all Loading... |
1289 button_host->MouseEnteredButton(app_button); | 1264 button_host->MouseEnteredButton(app_button); |
1290 button_host->MouseExitedButton(app_button); | 1265 button_host->MouseExitedButton(app_button); |
1291 button_host->MouseEnteredButton(platform_button); | 1266 button_host->MouseEnteredButton(platform_button); |
1292 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1267 EXPECT_FALSE(tooltip_manager->IsVisible()); |
1293 EXPECT_EQ(platform_button, GetTooltipAnchorView()); | 1268 EXPECT_EQ(platform_button, GetTooltipAnchorView()); |
1294 } | 1269 } |
1295 | 1270 |
1296 // Verify a fix for crash caused by a tooltip update for a deletedshelf | 1271 // Verify a fix for crash caused by a tooltip update for a deletedshelf |
1297 // button, see crbug.com/288838. | 1272 // button, see crbug.com/288838. |
1298 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) { | 1273 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) { |
1299 internal::ShelfButtonHost* button_host = shelf_view_; | 1274 ShelfButtonHost* button_host = shelf_view_; |
1300 internal::ShelfTooltipManager* tooltip_manager = | 1275 ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager(); |
1301 shelf_view_->tooltip_manager(); | |
1302 | 1276 |
1303 // Add an item to the shelf. | 1277 // Add an item to the shelf. |
1304 ShelfID app_button_id = AddAppShortcut(); | 1278 ShelfID app_button_id = AddAppShortcut(); |
1305 internal::ShelfButton* app_button = GetButtonByID(app_button_id); | 1279 ShelfButton* app_button = GetButtonByID(app_button_id); |
1306 | 1280 |
1307 // Spawn a tooltip on that item. | 1281 // Spawn a tooltip on that item. |
1308 button_host->MouseEnteredButton(app_button); | 1282 button_host->MouseEnteredButton(app_button); |
1309 ShowTooltip(); | 1283 ShowTooltip(); |
1310 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1284 EXPECT_TRUE(tooltip_manager->IsVisible()); |
1311 | 1285 |
1312 // Remove the app shortcut while the tooltip is open. The tooltip should be | 1286 // Remove the app shortcut while the tooltip is open. The tooltip should be |
1313 // closed. | 1287 // closed. |
1314 RemoveByID(app_button_id); | 1288 RemoveByID(app_button_id); |
1315 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1289 EXPECT_FALSE(tooltip_manager->IsVisible()); |
1316 | 1290 |
1317 // Change the shelf layout. This should not crash. | 1291 // Change the shelf layout. This should not crash. |
1318 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, | 1292 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, |
1319 Shell::GetPrimaryRootWindow()); | 1293 Shell::GetPrimaryRootWindow()); |
1320 } | 1294 } |
1321 | 1295 |
1322 // Changing the shelf alignment closes any open tooltip. | 1296 // Changing the shelf alignment closes any open tooltip. |
1323 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { | 1297 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { |
1324 internal::ShelfButtonHost* button_host = shelf_view_; | 1298 ShelfButtonHost* button_host = shelf_view_; |
1325 internal::ShelfTooltipManager* tooltip_manager = | 1299 ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager(); |
1326 shelf_view_->tooltip_manager(); | |
1327 | 1300 |
1328 // Add an item to the shelf. | 1301 // Add an item to the shelf. |
1329 ShelfID app_button_id = AddAppShortcut(); | 1302 ShelfID app_button_id = AddAppShortcut(); |
1330 internal::ShelfButton* app_button = GetButtonByID(app_button_id); | 1303 ShelfButton* app_button = GetButtonByID(app_button_id); |
1331 | 1304 |
1332 // Spawn a tooltip on the item. | 1305 // Spawn a tooltip on the item. |
1333 button_host->MouseEnteredButton(app_button); | 1306 button_host->MouseEnteredButton(app_button); |
1334 ShowTooltip(); | 1307 ShowTooltip(); |
1335 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1308 EXPECT_TRUE(tooltip_manager->IsVisible()); |
1336 | 1309 |
1337 // Changing shelf alignment hides the tooltip. | 1310 // Changing shelf alignment hides the tooltip. |
1338 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, | 1311 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, |
1339 Shell::GetPrimaryRootWindow()); | 1312 Shell::GetPrimaryRootWindow()); |
1340 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1313 EXPECT_FALSE(tooltip_manager->IsVisible()); |
1341 } | 1314 } |
1342 | 1315 |
1343 TEST_F(ShelfViewTest, ShouldHideTooltipTest) { | 1316 TEST_F(ShelfViewTest, ShouldHideTooltipTest) { |
1344 ShelfID app_button_id = AddAppShortcut(); | 1317 ShelfID app_button_id = AddAppShortcut(); |
1345 ShelfID platform_button_id = AddPlatformApp(); | 1318 ShelfID platform_button_id = AddPlatformApp(); |
1346 | 1319 |
1347 // The tooltip shouldn't hide if the mouse is on normal buttons. | 1320 // The tooltip shouldn't hide if the mouse is on normal buttons. |
1348 for (int i = 0; i < test_api_->GetButtonCount(); i++) { | 1321 for (int i = 0; i < test_api_->GetButtonCount(); i++) { |
1349 internal::ShelfButton* button = test_api_->GetButton(i); | 1322 ShelfButton* button = test_api_->GetButton(i); |
1350 if (!button) | 1323 if (!button) |
1351 continue; | 1324 continue; |
1352 | 1325 |
1353 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( | 1326 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( |
1354 button->GetMirroredBounds().CenterPoint())) | 1327 button->GetMirroredBounds().CenterPoint())) |
1355 << "ShelfView tries to hide on button " << i; | 1328 << "ShelfView tries to hide on button " << i; |
1356 } | 1329 } |
1357 | 1330 |
1358 // The tooltip should not hide on the app-list button. | 1331 // The tooltip should not hide on the app-list button. |
1359 views::View* app_list_button = shelf_view_->GetAppListButtonView(); | 1332 views::View* app_list_button = shelf_view_->GetAppListButtonView(); |
1360 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( | 1333 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( |
1361 app_list_button->GetMirroredBounds().CenterPoint())); | 1334 app_list_button->GetMirroredBounds().CenterPoint())); |
1362 | 1335 |
1363 // The tooltip shouldn't hide if the mouse is in the gap between two buttons. | 1336 // The tooltip shouldn't hide if the mouse is in the gap between two buttons. |
1364 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds(); | 1337 gfx::Rect app_button_rect = GetButtonByID(app_button_id)->GetMirroredBounds(); |
1365 gfx::Rect platform_button_rect = | 1338 gfx::Rect platform_button_rect = |
1366 GetButtonByID(platform_button_id)->GetMirroredBounds(); | 1339 GetButtonByID(platform_button_id)->GetMirroredBounds(); |
1367 ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect)); | 1340 ASSERT_FALSE(app_button_rect.Intersects(platform_button_rect)); |
1368 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( | 1341 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( |
1369 gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint())); | 1342 gfx::UnionRects(app_button_rect, platform_button_rect).CenterPoint())); |
1370 | 1343 |
1371 // The tooltip should hide if it's outside of all buttons. | 1344 // The tooltip should hide if it's outside of all buttons. |
1372 gfx::Rect all_area; | 1345 gfx::Rect all_area; |
1373 for (int i = 0; i < test_api_->GetButtonCount(); i++) { | 1346 for (int i = 0; i < test_api_->GetButtonCount(); i++) { |
1374 internal::ShelfButton* button = test_api_->GetButton(i); | 1347 ShelfButton* button = test_api_->GetButton(i); |
1375 if (!button) | 1348 if (!button) |
1376 continue; | 1349 continue; |
1377 | 1350 |
1378 all_area.Union(button->GetMirroredBounds()); | 1351 all_area.Union(button->GetMirroredBounds()); |
1379 } | 1352 } |
1380 all_area.Union(shelf_view_->GetAppListButtonView()->GetMirroredBounds()); | 1353 all_area.Union(shelf_view_->GetAppListButtonView()->GetMirroredBounds()); |
1381 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin())); | 1354 EXPECT_FALSE(shelf_view_->ShouldHideTooltip(all_area.origin())); |
1382 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( | 1355 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( |
1383 gfx::Point(all_area.right() - 1, all_area.bottom() - 1))); | 1356 gfx::Point(all_area.right() - 1, all_area.bottom() - 1))); |
1384 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( | 1357 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( |
1385 gfx::Point(all_area.right(), all_area.y()))); | 1358 gfx::Point(all_area.right(), all_area.y()))); |
1386 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( | 1359 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( |
1387 gfx::Point(all_area.x() - 1, all_area.y()))); | 1360 gfx::Point(all_area.x() - 1, all_area.y()))); |
1388 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( | 1361 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( |
1389 gfx::Point(all_area.x(), all_area.y() - 1))); | 1362 gfx::Point(all_area.x(), all_area.y() - 1))); |
1390 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( | 1363 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( |
1391 gfx::Point(all_area.x(), all_area.bottom()))); | 1364 gfx::Point(all_area.x(), all_area.bottom()))); |
1392 } | 1365 } |
1393 | 1366 |
1394 TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) { | 1367 TEST_F(ShelfViewTest, ShouldHideTooltipWithAppListWindowTest) { |
1395 Shell::GetInstance()->ToggleAppList(NULL); | 1368 Shell::GetInstance()->ToggleAppList(NULL); |
1396 ASSERT_TRUE(Shell::GetInstance()->GetAppListWindow()); | 1369 ASSERT_TRUE(Shell::GetInstance()->GetAppListWindow()); |
1397 | 1370 |
1398 // The tooltip shouldn't hide if the mouse is on normal buttons. | 1371 // The tooltip shouldn't hide if the mouse is on normal buttons. |
1399 for (int i = 1; i < test_api_->GetButtonCount(); i++) { | 1372 for (int i = 1; i < test_api_->GetButtonCount(); i++) { |
1400 internal::ShelfButton* button = test_api_->GetButton(i); | 1373 ShelfButton* button = test_api_->GetButton(i); |
1401 if (!button) | 1374 if (!button) |
1402 continue; | 1375 continue; |
1403 | 1376 |
1404 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( | 1377 EXPECT_FALSE(shelf_view_->ShouldHideTooltip( |
1405 button->GetMirroredBounds().CenterPoint())) | 1378 button->GetMirroredBounds().CenterPoint())) |
1406 << "ShelfView tries to hide on button " << i; | 1379 << "ShelfView tries to hide on button " << i; |
1407 } | 1380 } |
1408 | 1381 |
1409 // The tooltip should hide on the app-list button. | 1382 // The tooltip should hide on the app-list button. |
1410 views::View* app_list_button = shelf_view_->GetAppListButtonView(); | 1383 views::View* app_list_button = shelf_view_->GetAppListButtonView(); |
1411 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( | 1384 EXPECT_TRUE(shelf_view_->ShouldHideTooltip( |
1412 app_list_button->GetMirroredBounds().CenterPoint())); | 1385 app_list_button->GetMirroredBounds().CenterPoint())); |
1413 } | 1386 } |
1414 | 1387 |
1415 // Test that by moving the mouse cursor off the button onto the bubble it closes | 1388 // Test that by moving the mouse cursor off the button onto the bubble it closes |
1416 // the bubble. | 1389 // the bubble. |
1417 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) { | 1390 TEST_F(ShelfViewTest, ShouldHideTooltipWhenHoveringOnTooltip) { |
1418 internal::ShelfTooltipManager* tooltip_manager = | 1391 ShelfTooltipManager* tooltip_manager = shelf_view_->tooltip_manager(); |
1419 shelf_view_->tooltip_manager(); | |
1420 tooltip_manager->CreateZeroDelayTimerForTest(); | 1392 tooltip_manager->CreateZeroDelayTimerForTest(); |
1421 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 1393 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
1422 | 1394 |
1423 // Move the mouse off any item and check that no tooltip is shown. | 1395 // Move the mouse off any item and check that no tooltip is shown. |
1424 generator.MoveMouseTo(gfx::Point(0, 0)); | 1396 generator.MoveMouseTo(gfx::Point(0, 0)); |
1425 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1397 EXPECT_FALSE(tooltip_manager->IsVisible()); |
1426 | 1398 |
1427 // Move the mouse over the button and check that it is visible. | 1399 // Move the mouse over the button and check that it is visible. |
1428 views::View* app_list_button = shelf_view_->GetAppListButtonView(); | 1400 views::View* app_list_button = shelf_view_->GetAppListButtonView(); |
1429 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); | 1401 gfx::Rect bounds = app_list_button->GetBoundsInScreen(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 ShelfViewTestAPI test_for_overflow_view( | 1477 ShelfViewTestAPI test_for_overflow_view( |
1506 test_api_->overflow_bubble()->shelf_view()); | 1478 test_api_->overflow_bubble()->shelf_view()); |
1507 | 1479 |
1508 int ripped_index = test_for_overflow_view.GetLastVisibleIndex(); | 1480 int ripped_index = test_for_overflow_view.GetLastVisibleIndex(); |
1509 gfx::Size bubble_size = test_for_overflow_view.GetPreferredSize(); | 1481 gfx::Size bubble_size = test_for_overflow_view.GetPreferredSize(); |
1510 int item_width = test_for_overflow_view.GetButtonSize() + | 1482 int item_width = test_for_overflow_view.GetButtonSize() + |
1511 test_for_overflow_view.GetButtonSpacing(); | 1483 test_for_overflow_view.GetButtonSpacing(); |
1512 | 1484 |
1513 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1485 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
1514 gfx::Point()); | 1486 gfx::Point()); |
1515 internal::ShelfButton* button = | 1487 ShelfButton* button = test_for_overflow_view.GetButton(ripped_index); |
1516 test_for_overflow_view.GetButton(ripped_index); | |
1517 // Rip off the last visible item. | 1488 // Rip off the last visible item. |
1518 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint(); | 1489 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint(); |
1519 gfx::Point rip_off_point(start_point.x(), 0); | 1490 gfx::Point rip_off_point(start_point.x(), 0); |
1520 generator.MoveMouseTo(start_point.x(), start_point.y()); | 1491 generator.MoveMouseTo(start_point.x(), start_point.y()); |
1521 base::MessageLoop::current()->RunUntilIdle(); | 1492 base::MessageLoop::current()->RunUntilIdle(); |
1522 generator.PressLeftButton(); | 1493 generator.PressLeftButton(); |
1523 base::MessageLoop::current()->RunUntilIdle(); | 1494 base::MessageLoop::current()->RunUntilIdle(); |
1524 generator.MoveMouseTo(rip_off_point.x(), rip_off_point.y()); | 1495 generator.MoveMouseTo(rip_off_point.x(), rip_off_point.y()); |
1525 base::MessageLoop::current()->RunUntilIdle(); | 1496 base::MessageLoop::current()->RunUntilIdle(); |
1526 test_for_overflow_view.RunMessageLoopUntilAnimationsDone(); | 1497 test_for_overflow_view.RunMessageLoopUntilAnimationsDone(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 | 1537 |
1567 AddButtonsUntilOverflow(); | 1538 AddButtonsUntilOverflow(); |
1568 | 1539 |
1569 // Show overflow bubble. | 1540 // Show overflow bubble. |
1570 test_api_->ShowOverflowBubble(); | 1541 test_api_->ShowOverflowBubble(); |
1571 ASSERT_TRUE(test_api_->overflow_bubble() && | 1542 ASSERT_TRUE(test_api_->overflow_bubble() && |
1572 test_api_->overflow_bubble()->IsShowing()); | 1543 test_api_->overflow_bubble()->IsShowing()); |
1573 | 1544 |
1574 int item_width = test_api_->GetButtonSize() + | 1545 int item_width = test_api_->GetButtonSize() + |
1575 test_api_->GetButtonSpacing(); | 1546 test_api_->GetButtonSpacing(); |
1576 internal::OverflowBubbleView* bubble_view = | 1547 OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view(); |
1577 test_api_->overflow_bubble()->bubble_view(); | |
1578 test::OverflowBubbleViewTestAPI bubble_view_api(bubble_view); | 1548 test::OverflowBubbleViewTestAPI bubble_view_api(bubble_view); |
1579 | 1549 |
1580 // Add more buttons until OverflowBubble is scrollable and it has 3 invisible | 1550 // Add more buttons until OverflowBubble is scrollable and it has 3 invisible |
1581 // items. | 1551 // items. |
1582 while (bubble_view_api.GetContentsSize().width() < | 1552 while (bubble_view_api.GetContentsSize().width() < |
1583 (bubble_view->GetContentsBounds().width() + 3 * item_width)) | 1553 (bubble_view->GetContentsBounds().width() + 3 * item_width)) |
1584 AddAppShortcut(); | 1554 AddAppShortcut(); |
1585 | 1555 |
1586 ASSERT_TRUE(test_api_->overflow_bubble() && | 1556 ASSERT_TRUE(test_api_->overflow_bubble() && |
1587 test_api_->overflow_bubble()->IsShowing()); | 1557 test_api_->overflow_bubble()->IsShowing()); |
1588 | 1558 |
1589 ShelfViewTestAPI test_for_overflow_view( | 1559 ShelfViewTestAPI test_for_overflow_view( |
1590 test_api_->overflow_bubble()->shelf_view()); | 1560 test_api_->overflow_bubble()->shelf_view()); |
1591 int first_index = test_for_overflow_view.GetFirstVisibleIndex(); | 1561 int first_index = test_for_overflow_view.GetFirstVisibleIndex(); |
1592 int last_index = test_for_overflow_view.GetLastVisibleIndex(); | 1562 int last_index = test_for_overflow_view.GetLastVisibleIndex(); |
1593 | 1563 |
1594 internal::ShelfButton* first_button = | 1564 ShelfButton* first_button = test_for_overflow_view.GetButton(first_index); |
1595 test_for_overflow_view.GetButton(first_index); | 1565 ShelfButton* last_button = test_for_overflow_view.GetButton(last_index); |
1596 internal::ShelfButton* last_button = | |
1597 test_for_overflow_view.GetButton(last_index); | |
1598 gfx::Point first_point = first_button->GetBoundsInScreen().CenterPoint(); | 1566 gfx::Point first_point = first_button->GetBoundsInScreen().CenterPoint(); |
1599 gfx::Point last_point = last_button->GetBoundsInScreen().CenterPoint(); | 1567 gfx::Point last_point = last_button->GetBoundsInScreen().CenterPoint(); |
1600 gfx::Rect drag_reinsert_bounds = | 1568 gfx::Rect drag_reinsert_bounds = |
1601 test_for_overflow_view.GetBoundsForDragInsertInScreen(); | 1569 test_for_overflow_view.GetBoundsForDragInsertInScreen(); |
1602 EXPECT_TRUE(drag_reinsert_bounds.Contains(first_point)); | 1570 EXPECT_TRUE(drag_reinsert_bounds.Contains(first_point)); |
1603 EXPECT_FALSE(drag_reinsert_bounds.Contains(last_point)); | 1571 EXPECT_FALSE(drag_reinsert_bounds.Contains(last_point)); |
1604 | 1572 |
1605 // Scrolls sufficiently to show last item. | 1573 // Scrolls sufficiently to show last item. |
1606 bubble_view_api.ScrollByXOffset(3 * item_width); | 1574 bubble_view_api.ScrollByXOffset(3 * item_width); |
1607 drag_reinsert_bounds = | 1575 drag_reinsert_bounds = |
1608 test_for_overflow_view.GetBoundsForDragInsertInScreen(); | 1576 test_for_overflow_view.GetBoundsForDragInsertInScreen(); |
1609 first_point = first_button->GetBoundsInScreen().CenterPoint(); | 1577 first_point = first_button->GetBoundsInScreen().CenterPoint(); |
1610 last_point = last_button->GetBoundsInScreen().CenterPoint(); | 1578 last_point = last_button->GetBoundsInScreen().CenterPoint(); |
1611 EXPECT_FALSE(drag_reinsert_bounds.Contains(first_point)); | 1579 EXPECT_FALSE(drag_reinsert_bounds.Contains(first_point)); |
1612 EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point)); | 1580 EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point)); |
1613 } | 1581 } |
1614 | 1582 |
1615 // Check the drag insertion bounds of shelf view in multi monitor environment. | 1583 // Check the drag insertion bounds of shelf view in multi monitor environment. |
1616 TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) { | 1584 TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) { |
1617 // win8-aura doesn't support multiple display. | 1585 // win8-aura doesn't support multiple display. |
1618 if (!SupportsMultipleDisplays()) | 1586 if (!SupportsMultipleDisplays()) |
1619 return; | 1587 return; |
1620 | 1588 |
1621 UpdateDisplay("800x600,800x600"); | 1589 UpdateDisplay("800x600,800x600"); |
1622 Shelf* secondary_shelf = Shelf::ForWindow(Shell::GetAllRootWindows()[1]); | 1590 Shelf* secondary_shelf = Shelf::ForWindow(Shell::GetAllRootWindows()[1]); |
1623 internal::ShelfView* shelf_view_for_secondary = | 1591 ShelfView* shelf_view_for_secondary = |
1624 ShelfTestAPI(secondary_shelf).shelf_view(); | 1592 ShelfTestAPI(secondary_shelf).shelf_view(); |
1625 | 1593 |
1626 // The bounds should be big enough for 4 buttons + overflow chevron. | 1594 // The bounds should be big enough for 4 buttons + overflow chevron. |
1627 shelf_view_for_secondary->SetBounds(0, 0, 500, | 1595 shelf_view_for_secondary->SetBounds( |
1628 internal::ShelfLayoutManager::GetPreferredShelfSize()); | 1596 0, 0, 500, ShelfLayoutManager::GetPreferredShelfSize()); |
1629 | 1597 |
1630 ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary); | 1598 ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary); |
1631 // Speeds up animation for test. | 1599 // Speeds up animation for test. |
1632 test_api_for_secondary.SetAnimationDuration(1); | 1600 test_api_for_secondary.SetAnimationDuration(1); |
1633 | 1601 |
1634 AddButtonsUntilOverflow(); | 1602 AddButtonsUntilOverflow(); |
1635 | 1603 |
1636 // Test #1: Test drag insertion bounds of primary shelf. | 1604 // Test #1: Test drag insertion bounds of primary shelf. |
1637 // Show overflow bubble. | 1605 // Show overflow bubble. |
1638 test_api_->ShowOverflowBubble(); | 1606 test_api_->ShowOverflowBubble(); |
1639 ASSERT_TRUE(test_api_->overflow_bubble() && | 1607 ASSERT_TRUE(test_api_->overflow_bubble() && |
1640 test_api_->overflow_bubble()->IsShowing()); | 1608 test_api_->overflow_bubble()->IsShowing()); |
1641 | 1609 |
1642 ShelfViewTestAPI test_api_for_overflow_view( | 1610 ShelfViewTestAPI test_api_for_overflow_view( |
1643 test_api_->overflow_bubble()->shelf_view()); | 1611 test_api_->overflow_bubble()->shelf_view()); |
1644 | 1612 |
1645 internal::ShelfButton* button = test_api_for_overflow_view.GetButton( | 1613 ShelfButton* button = test_api_for_overflow_view.GetButton( |
1646 test_api_for_overflow_view.GetLastVisibleIndex()); | 1614 test_api_for_overflow_view.GetLastVisibleIndex()); |
1647 | 1615 |
1648 // Checks that a point in shelf is contained in drag insert bounds. | 1616 // Checks that a point in shelf is contained in drag insert bounds. |
1649 gfx::Point point_in_shelf_view = button->GetBoundsInScreen().CenterPoint(); | 1617 gfx::Point point_in_shelf_view = button->GetBoundsInScreen().CenterPoint(); |
1650 gfx::Rect drag_reinsert_bounds = | 1618 gfx::Rect drag_reinsert_bounds = |
1651 test_api_for_overflow_view.GetBoundsForDragInsertInScreen(); | 1619 test_api_for_overflow_view.GetBoundsForDragInsertInScreen(); |
1652 EXPECT_TRUE(drag_reinsert_bounds.Contains(point_in_shelf_view)); | 1620 EXPECT_TRUE(drag_reinsert_bounds.Contains(point_in_shelf_view)); |
1653 // Checks that a point out of shelf is not contained in drag insert bounds. | 1621 // Checks that a point out of shelf is not contained in drag insert bounds. |
1654 EXPECT_FALSE(drag_reinsert_bounds.Contains( | 1622 EXPECT_FALSE(drag_reinsert_bounds.Contains( |
1655 gfx::Point(point_in_shelf_view.x(), 0))); | 1623 gfx::Point(point_in_shelf_view.x(), 0))); |
1656 | 1624 |
1657 // Test #2: Test drag insertion bounds of secondary shelf. | 1625 // Test #2: Test drag insertion bounds of secondary shelf. |
1658 // Show overflow bubble. | 1626 // Show overflow bubble. |
1659 test_api_for_secondary.ShowOverflowBubble(); | 1627 test_api_for_secondary.ShowOverflowBubble(); |
1660 ASSERT_TRUE(test_api_for_secondary.overflow_bubble() && | 1628 ASSERT_TRUE(test_api_for_secondary.overflow_bubble() && |
1661 test_api_for_secondary.overflow_bubble()->IsShowing()); | 1629 test_api_for_secondary.overflow_bubble()->IsShowing()); |
1662 | 1630 |
1663 ShelfViewTestAPI test_api_for_overflow_view_of_secondary( | 1631 ShelfViewTestAPI test_api_for_overflow_view_of_secondary( |
1664 test_api_for_secondary.overflow_bubble()->shelf_view()); | 1632 test_api_for_secondary.overflow_bubble()->shelf_view()); |
1665 | 1633 |
1666 internal::ShelfButton* button_in_secondary = | 1634 ShelfButton* button_in_secondary = |
1667 test_api_for_overflow_view_of_secondary.GetButton( | 1635 test_api_for_overflow_view_of_secondary.GetButton( |
1668 test_api_for_overflow_view_of_secondary.GetLastVisibleIndex()); | 1636 test_api_for_overflow_view_of_secondary.GetLastVisibleIndex()); |
1669 | 1637 |
1670 // Checks that a point in shelf is contained in drag insert bounds. | 1638 // Checks that a point in shelf is contained in drag insert bounds. |
1671 gfx::Point point_in_secondary_shelf_view = | 1639 gfx::Point point_in_secondary_shelf_view = |
1672 button_in_secondary->GetBoundsInScreen().CenterPoint(); | 1640 button_in_secondary->GetBoundsInScreen().CenterPoint(); |
1673 gfx::Rect drag_reinsert_bounds_in_secondary = | 1641 gfx::Rect drag_reinsert_bounds_in_secondary = |
1674 test_api_for_overflow_view_of_secondary.GetBoundsForDragInsertInScreen(); | 1642 test_api_for_overflow_view_of_secondary.GetBoundsForDragInsertInScreen(); |
1675 EXPECT_TRUE(drag_reinsert_bounds_in_secondary.Contains( | 1643 EXPECT_TRUE(drag_reinsert_bounds_in_secondary.Contains( |
1676 point_in_secondary_shelf_view)); | 1644 point_in_secondary_shelf_view)); |
(...skipping 19 matching lines...) Expand all Loading... |
1696 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, second_root); | 1664 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, second_root); |
1697 ASSERT_EQ(SHELF_ALIGNMENT_LEFT, | 1665 ASSERT_EQ(SHELF_ALIGNMENT_LEFT, |
1698 Shell::GetInstance()->GetShelfAlignment(second_root)); | 1666 Shell::GetInstance()->GetShelfAlignment(second_root)); |
1699 | 1667 |
1700 // Initially, app list and browser shortcut are added. | 1668 // Initially, app list and browser shortcut are added. |
1701 EXPECT_EQ(2, model_->item_count()); | 1669 EXPECT_EQ(2, model_->item_count()); |
1702 int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT); | 1670 int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT); |
1703 EXPECT_GT(browser_index, 0); | 1671 EXPECT_GT(browser_index, 0); |
1704 | 1672 |
1705 Shelf* secondary_shelf = Shelf::ForWindow(second_root); | 1673 Shelf* secondary_shelf = Shelf::ForWindow(second_root); |
1706 internal::ShelfView* shelf_view_for_secondary = | 1674 ShelfView* shelf_view_for_secondary = |
1707 ShelfTestAPI(secondary_shelf).shelf_view(); | 1675 ShelfTestAPI(secondary_shelf).shelf_view(); |
1708 | 1676 |
1709 ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary); | 1677 ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary); |
1710 internal::ShelfButton* button = | 1678 ShelfButton* button = |
1711 test_api_for_secondary_shelf_view.GetButton(browser_index); | 1679 test_api_for_secondary_shelf_view.GetButton(browser_index); |
1712 | 1680 |
1713 // Fetch the start point of dragging. | 1681 // Fetch the start point of dragging. |
1714 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint(); | 1682 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint(); |
1715 wm::ConvertPointFromScreen(second_root, &start_point); | 1683 wm::ConvertPointFromScreen(second_root, &start_point); |
1716 | 1684 |
1717 aura::test::EventGenerator generator(second_root, start_point); | 1685 aura::test::EventGenerator generator(second_root, start_point); |
1718 | 1686 |
1719 // Rip off the browser item. | 1687 // Rip off the browser item. |
1720 generator.PressLeftButton(); | 1688 generator.PressLeftButton(); |
1721 generator.MoveMouseTo(start_point.x() + 400, start_point.y()); | 1689 generator.MoveMouseTo(start_point.x() + 400, start_point.y()); |
(...skipping 15 matching lines...) Expand all Loading... |
1737 class ShelfViewVisibleBoundsTest : public ShelfViewTest, | 1705 class ShelfViewVisibleBoundsTest : public ShelfViewTest, |
1738 public testing::WithParamInterface<bool> { | 1706 public testing::WithParamInterface<bool> { |
1739 public: | 1707 public: |
1740 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {} | 1708 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {} |
1741 | 1709 |
1742 void CheckAllItemsAreInBounds() { | 1710 void CheckAllItemsAreInBounds() { |
1743 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); | 1711 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); |
1744 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen(); | 1712 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen(); |
1745 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds)); | 1713 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds)); |
1746 for (int i = 0; i < test_api_->GetButtonCount(); ++i) | 1714 for (int i = 0; i < test_api_->GetButtonCount(); ++i) |
1747 if (internal::ShelfButton* button = test_api_->GetButton(i)) | 1715 if (ShelfButton* button = test_api_->GetButton(i)) |
1748 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen())); | 1716 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen())); |
1749 CheckAppListButtonIsInBounds(); | 1717 CheckAppListButtonIsInBounds(); |
1750 } | 1718 } |
1751 | 1719 |
1752 void CheckAppListButtonIsInBounds() { | 1720 void CheckAppListButtonIsInBounds() { |
1753 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); | 1721 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); |
1754 gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()-> | 1722 gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()-> |
1755 GetBoundsInScreen(); | 1723 GetBoundsInScreen(); |
1756 EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds)); | 1724 EXPECT_TRUE(visible_bounds.Contains(app_list_button_bounds)); |
1757 } | 1725 } |
(...skipping 19 matching lines...) Expand all Loading... |
1777 test_api_->RunMessageLoopUntilAnimationsDone(); | 1745 test_api_->RunMessageLoopUntilAnimationsDone(); |
1778 CheckAllItemsAreInBounds(); | 1746 CheckAllItemsAreInBounds(); |
1779 } | 1747 } |
1780 | 1748 |
1781 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 1749 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
1782 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 1750 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
1783 testing::Bool()); | 1751 testing::Bool()); |
1784 | 1752 |
1785 } // namespace test | 1753 } // namespace test |
1786 } // namespace ash | 1754 } // namespace ash |
OLD | NEW |