| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "ash/common/shelf/shelf_button.h" | 7 #include "ash/common/shelf/shelf_button.h" |
| 8 #include "ash/common/shelf/shelf_model.h" | 8 #include "ash/common/shelf/shelf_model.h" |
| 9 #include "ash/common/shelf/shelf_view.h" | 9 #include "ash/common/shelf/shelf_view.h" |
| 10 #include "ash/common/shelf/shelf_widget.h" | 10 #include "ash/common/shelf/shelf_widget.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 std::unique_ptr<test::ShelfViewTestAPI> test_; | 39 std::unique_ptr<test::ShelfViewTestAPI> test_; |
| 40 | 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(ShelfTest); | 41 DISALLOW_COPY_AND_ASSIGN(ShelfTest); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // Confirms that ShelfItem reflects the appropriated state. | 44 // Confirms that ShelfItem reflects the appropriated state. |
| 45 TEST_F(ShelfTest, StatusReflection) { | 45 TEST_F(ShelfTest, StatusReflection) { |
| 46 // Initially we have the app list. | 46 // Initially we have the app list. |
| 47 int button_count = test_api()->GetButtonCount(); | 47 int button_count = test_api()->GetButtonCount(); |
| 48 | 48 |
| 49 // Add running platform app. | 49 // Add a running app. |
| 50 ShelfItem item; | 50 ShelfItem item; |
| 51 item.type = TYPE_PLATFORM_APP; | 51 item.type = TYPE_APP; |
| 52 item.status = STATUS_RUNNING; | 52 item.status = STATUS_RUNNING; |
| 53 int index = shelf_model()->Add(item); | 53 int index = shelf_model()->Add(item); |
| 54 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); | 54 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); |
| 55 ShelfButton* button = test_api()->GetButton(index); | 55 ShelfButton* button = test_api()->GetButton(index); |
| 56 EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state()); | 56 EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state()); |
| 57 | 57 |
| 58 // Remove it. | 58 // Remove it. |
| 59 shelf_model()->RemoveItemAt(index); | 59 shelf_model()->RemoveItemAt(index); |
| 60 ASSERT_EQ(--button_count, test_api()->GetButtonCount()); | 60 ASSERT_EQ(--button_count, test_api()->GetButtonCount()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Confirm that using the menu will clear the hover attribute. To avoid another | 63 // Confirm that using the menu will clear the hover attribute. To avoid another |
| 64 // browser test we check this here. | 64 // browser test we check this here. |
| 65 TEST_F(ShelfTest, CheckHoverAfterMenu) { | 65 TEST_F(ShelfTest, CheckHoverAfterMenu) { |
| 66 // Initially we have the app list. | 66 // Initially we have the app list. |
| 67 int button_count = test_api()->GetButtonCount(); | 67 int button_count = test_api()->GetButtonCount(); |
| 68 | 68 |
| 69 // Add running platform app. | 69 // Add a running app. |
| 70 ShelfItem item; | 70 ShelfItem item; |
| 71 item.type = TYPE_PLATFORM_APP; | 71 item.type = TYPE_APP; |
| 72 item.status = STATUS_RUNNING; | 72 item.status = STATUS_RUNNING; |
| 73 int index = shelf_model()->Add(item); | 73 int index = shelf_model()->Add(item); |
| 74 | 74 |
| 75 std::unique_ptr<ShelfItemDelegate> delegate( | 75 std::unique_ptr<ShelfItemDelegate> delegate( |
| 76 new test::TestShelfItemDelegate(NULL)); | 76 new test::TestShelfItemDelegate(NULL)); |
| 77 shelf_model()->SetShelfItemDelegate(shelf_model()->items()[index].id, | 77 shelf_model()->SetShelfItemDelegate(shelf_model()->items()[index].id, |
| 78 std::move(delegate)); | 78 std::move(delegate)); |
| 79 | 79 |
| 80 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); | 80 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); |
| 81 ShelfButton* button = test_api()->GetButton(index); | 81 ShelfButton* button = test_api()->GetButton(index); |
| 82 button->AddState(ShelfButton::STATE_HOVERED); | 82 button->AddState(ShelfButton::STATE_HOVERED); |
| 83 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 83 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 84 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED); | 84 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED); |
| 85 | 85 |
| 86 // Remove it. | 86 // Remove it. |
| 87 shelf_model()->RemoveItemAt(index); | 87 shelf_model()->RemoveItemAt(index); |
| 88 } | 88 } |
| 89 | 89 |
| 90 TEST_F(ShelfTest, ShowOverflowBubble) { | 90 TEST_F(ShelfTest, ShowOverflowBubble) { |
| 91 ShelfWidget* shelf_widget = GetPrimaryShelf()->shelf_widget(); | 91 ShelfWidget* shelf_widget = GetPrimaryShelf()->shelf_widget(); |
| 92 ShelfID first_item_id = shelf_model()->next_id(); | 92 ShelfID first_item_id = shelf_model()->next_id(); |
| 93 | 93 |
| 94 // Add platform app button until overflow. | 94 // Add app buttons until overflow occurs. |
| 95 int items_added = 0; | 95 int items_added = 0; |
| 96 while (!test_api()->IsOverflowButtonVisible()) { | 96 while (!test_api()->IsOverflowButtonVisible()) { |
| 97 ShelfItem item; | 97 ShelfItem item; |
| 98 item.type = TYPE_PLATFORM_APP; | 98 item.type = TYPE_APP; |
| 99 item.status = STATUS_RUNNING; | 99 item.status = STATUS_RUNNING; |
| 100 shelf_model()->Add(item); | 100 shelf_model()->Add(item); |
| 101 | 101 |
| 102 ++items_added; | 102 ++items_added; |
| 103 ASSERT_LT(items_added, 10000); | 103 ASSERT_LT(items_added, 10000); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Shows overflow bubble. | 106 // Shows overflow bubble. |
| 107 test_api()->ShowOverflowBubble(); | 107 test_api()->ShowOverflowBubble(); |
| 108 EXPECT_TRUE(shelf_widget->IsShowingOverflowBubble()); | 108 EXPECT_TRUE(shelf_widget->IsShowingOverflowBubble()); |
| 109 | 109 |
| 110 // Removes the first item in main shelf view. | 110 // Removes the first item in main shelf view. |
| 111 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id)); | 111 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id)); |
| 112 | 112 |
| 113 // Waits for all transitions to finish and there should be no crash. | 113 // Waits for all transitions to finish and there should be no crash. |
| 114 test_api()->RunMessageLoopUntilAnimationsDone(); | 114 test_api()->RunMessageLoopUntilAnimationsDone(); |
| 115 EXPECT_FALSE(shelf_widget->IsShowingOverflowBubble()); | 115 EXPECT_FALSE(shelf_widget->IsShowingOverflowBubble()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace ash | 118 } // namespace ash |
| OLD | NEW |