| 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 "ash/common/shelf/shelf.h" | |
| 6 | |
| 7 #include <utility> | 5 #include <utility> |
| 8 | 6 |
| 9 #include "ash/common/shelf/shelf_button.h" | 7 #include "ash/common/shelf/shelf_button.h" |
| 10 #include "ash/common/shelf/shelf_model.h" | 8 #include "ash/common/shelf/shelf_model.h" |
| 11 #include "ash/common/shelf/shelf_view.h" | 9 #include "ash/common/shelf/shelf_view.h" |
| 12 #include "ash/common/shelf/shelf_widget.h" | 10 #include "ash/common/shelf/shelf_widget.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" |
| 13 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 14 #include "ash/test/shelf_test_api.h" | |
| 15 #include "ash/test/shelf_view_test_api.h" | 13 #include "ash/test/shelf_view_test_api.h" |
| 16 #include "ash/test/test_shelf_item_delegate.h" | 14 #include "ash/test/test_shelf_item_delegate.h" |
| 17 #include "ash/wm/window_util.h" | |
| 18 #include "ui/aura/window_event_dispatcher.h" | |
| 19 #include "ui/views/view.h" | |
| 20 #include "ui/views/widget/widget.h" | |
| 21 | |
| 22 #if defined(OS_WIN) | |
| 23 #include "base/win/windows_version.h" | |
| 24 #endif | |
| 25 | 15 |
| 26 namespace ash { | 16 namespace ash { |
| 27 | 17 |
| 28 class ShelfTest : public test::AshTestBase { | 18 class ShelfTest : public test::AshTestBase { |
| 29 public: | 19 public: |
| 30 ShelfTest() : shelf_(nullptr), shelf_view_(nullptr), shelf_model_(nullptr) {} | 20 ShelfTest() : shelf_model_(nullptr) {} |
| 31 | 21 |
| 32 ~ShelfTest() override {} | 22 ~ShelfTest() override {} |
| 33 | 23 |
| 34 void SetUp() override { | 24 void SetUp() override { |
| 35 test::AshTestBase::SetUp(); | 25 test::AshTestBase::SetUp(); |
| 36 | 26 |
| 37 shelf_ = Shelf::ForPrimaryDisplay(); | 27 ShelfView* shelf_view = GetPrimaryShelf()->GetShelfViewForTesting(); |
| 38 ASSERT_TRUE(shelf_); | 28 shelf_model_ = shelf_view->model(); |
| 39 | 29 |
| 40 test::ShelfTestAPI test(shelf_); | 30 test_.reset(new test::ShelfViewTestAPI(shelf_view)); |
| 41 shelf_view_ = test.shelf_view(); | |
| 42 shelf_model_ = shelf_view_->model(); | |
| 43 | |
| 44 test_.reset(new test::ShelfViewTestAPI(shelf_view_)); | |
| 45 } | 31 } |
| 46 | 32 |
| 47 Shelf* shelf() { return shelf_; } | |
| 48 | |
| 49 ShelfView* shelf_view() { return shelf_view_; } | |
| 50 | |
| 51 ShelfModel* shelf_model() { return shelf_model_; } | 33 ShelfModel* shelf_model() { return shelf_model_; } |
| 52 | 34 |
| 53 test::ShelfViewTestAPI* test_api() { return test_.get(); } | 35 test::ShelfViewTestAPI* test_api() { return test_.get(); } |
| 54 | 36 |
| 55 private: | 37 private: |
| 56 Shelf* shelf_; | |
| 57 ShelfView* shelf_view_; | |
| 58 ShelfModel* shelf_model_; | 38 ShelfModel* shelf_model_; |
| 59 std::unique_ptr<test::ShelfViewTestAPI> test_; | 39 std::unique_ptr<test::ShelfViewTestAPI> test_; |
| 60 | 40 |
| 61 DISALLOW_COPY_AND_ASSIGN(ShelfTest); | 41 DISALLOW_COPY_AND_ASSIGN(ShelfTest); |
| 62 }; | 42 }; |
| 63 | 43 |
| 64 // Confirms that ShelfItem reflects the appropriated state. | 44 // Confirms that ShelfItem reflects the appropriated state. |
| 65 TEST_F(ShelfTest, StatusReflection) { | 45 TEST_F(ShelfTest, StatusReflection) { |
| 66 // Initially we have the app list. | 46 // Initially we have the app list. |
| 67 int button_count = test_api()->GetButtonCount(); | 47 int button_count = test_api()->GetButtonCount(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 ShelfButton* button = test_api()->GetButton(index); | 81 ShelfButton* button = test_api()->GetButton(index); |
| 102 button->AddState(ShelfButton::STATE_HOVERED); | 82 button->AddState(ShelfButton::STATE_HOVERED); |
| 103 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 83 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 104 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED); | 84 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED); |
| 105 | 85 |
| 106 // Remove it. | 86 // Remove it. |
| 107 shelf_model()->RemoveItemAt(index); | 87 shelf_model()->RemoveItemAt(index); |
| 108 } | 88 } |
| 109 | 89 |
| 110 TEST_F(ShelfTest, ShowOverflowBubble) { | 90 TEST_F(ShelfTest, ShowOverflowBubble) { |
| 111 ShelfWidget* shelf_widget = shelf()->shelf_widget(); | 91 ShelfWidget* shelf_widget = GetPrimaryShelf()->shelf_widget(); |
| 112 ShelfID first_item_id = shelf_model()->next_id(); | 92 ShelfID first_item_id = shelf_model()->next_id(); |
| 113 | 93 |
| 114 // Add platform app button until overflow. | 94 // Add platform app button until overflow. |
| 115 int items_added = 0; | 95 int items_added = 0; |
| 116 while (!test_api()->IsOverflowButtonVisible()) { | 96 while (!test_api()->IsOverflowButtonVisible()) { |
| 117 ShelfItem item; | 97 ShelfItem item; |
| 118 item.type = TYPE_PLATFORM_APP; | 98 item.type = TYPE_PLATFORM_APP; |
| 119 item.status = STATUS_RUNNING; | 99 item.status = STATUS_RUNNING; |
| 120 shelf_model()->Add(item); | 100 shelf_model()->Add(item); |
| 121 | 101 |
| 122 ++items_added; | 102 ++items_added; |
| 123 ASSERT_LT(items_added, 10000); | 103 ASSERT_LT(items_added, 10000); |
| 124 } | 104 } |
| 125 | 105 |
| 126 // Shows overflow bubble. | 106 // Shows overflow bubble. |
| 127 test_api()->ShowOverflowBubble(); | 107 test_api()->ShowOverflowBubble(); |
| 128 EXPECT_TRUE(shelf_widget->IsShowingOverflowBubble()); | 108 EXPECT_TRUE(shelf_widget->IsShowingOverflowBubble()); |
| 129 | 109 |
| 130 // Removes the first item in main shelf view. | 110 // Removes the first item in main shelf view. |
| 131 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id)); | 111 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id)); |
| 132 | 112 |
| 133 // 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. |
| 134 test_api()->RunMessageLoopUntilAnimationsDone(); | 114 test_api()->RunMessageLoopUntilAnimationsDone(); |
| 135 EXPECT_FALSE(shelf_widget->IsShowingOverflowBubble()); | 115 EXPECT_FALSE(shelf_widget->IsShowingOverflowBubble()); |
| 136 } | 116 } |
| 137 | 117 |
| 138 } // namespace ash | 118 } // namespace ash |
| OLD | NEW |