Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / ash / shelf / shelf_unittest.cc
blob87d6b1a07c15f50dde67addb5f74a9494a85ffe9
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
3 // found in the LICENSE file.
5 #include "ash/shelf/shelf.h"
6 #include "ash/shelf/shelf_button.h"
7 #include "ash/shelf/shelf_item_delegate_manager.h"
8 #include "ash/shelf/shelf_model.h"
9 #include "ash/shelf/shelf_view.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/shelf_test_api.h"
14 #include "ash/test/shelf_view_test_api.h"
15 #include "ash/test/test_shelf_item_delegate.h"
16 #include "ash/wm/window_util.h"
17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/gfx/display.h"
19 #include "ui/gfx/screen.h"
20 #include "ui/views/view.h"
21 #include "ui/views/widget/widget.h"
23 #if defined(OS_WIN)
24 #include "base/win/windows_version.h"
25 #endif
27 using ash::ShelfView;
28 using ash::ShelfButton;
30 namespace ash {
32 class ShelfTest : public ash::test::AshTestBase {
33 public:
34 ShelfTest()
35 : shelf_(NULL),
36 shelf_view_(NULL),
37 shelf_model_(NULL),
38 item_delegate_manager_(NULL) {}
40 ~ShelfTest() override {}
42 void SetUp() override {
43 test::AshTestBase::SetUp();
45 shelf_ = Shelf::ForPrimaryDisplay();
46 ASSERT_TRUE(shelf_);
48 test::ShelfTestAPI test(shelf_);
49 shelf_view_ = test.shelf_view();
50 shelf_model_ = shelf_view_->model();
51 item_delegate_manager_ =
52 Shell::GetInstance()->shelf_item_delegate_manager();
54 test_.reset(new ash::test::ShelfViewTestAPI(shelf_view_));
57 void TearDown() override { test::AshTestBase::TearDown(); }
59 Shelf* shelf() {
60 return shelf_;
63 ShelfView* shelf_view() {
64 return shelf_view_;
67 ShelfModel* shelf_model() {
68 return shelf_model_;
71 ShelfItemDelegateManager* item_manager() {
72 return item_delegate_manager_;
75 ash::test::ShelfViewTestAPI* test_api() {
76 return test_.get();
79 private:
80 Shelf* shelf_;
81 ShelfView* shelf_view_;
82 ShelfModel* shelf_model_;
83 ShelfItemDelegateManager* item_delegate_manager_;
84 scoped_ptr<test::ShelfViewTestAPI> test_;
86 DISALLOW_COPY_AND_ASSIGN(ShelfTest);
89 // Confirms that ShelfItem reflects the appropriated state.
90 TEST_F(ShelfTest, StatusReflection) {
91 // Initially we have the app list.
92 int button_count = test_api()->GetButtonCount();
94 // Add running platform app.
95 ShelfItem item;
96 item.type = TYPE_PLATFORM_APP;
97 item.status = STATUS_RUNNING;
98 int index = shelf_model()->Add(item);
99 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
100 ShelfButton* button = test_api()->GetButton(index);
101 EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state());
103 // Remove it.
104 shelf_model()->RemoveItemAt(index);
105 ASSERT_EQ(--button_count, test_api()->GetButtonCount());
108 // Confirm that using the menu will clear the hover attribute. To avoid another
109 // browser test we check this here.
110 TEST_F(ShelfTest, checkHoverAfterMenu) {
111 // Initially we have the app list.
112 int button_count = test_api()->GetButtonCount();
114 // Add running platform app.
115 ShelfItem item;
116 item.type = TYPE_PLATFORM_APP;
117 item.status = STATUS_RUNNING;
118 int index = shelf_model()->Add(item);
120 scoped_ptr<ShelfItemDelegate> delegate(
121 new test::TestShelfItemDelegate(NULL));
122 item_manager()->SetShelfItemDelegate(shelf_model()->items()[index].id,
123 delegate.Pass());
125 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
126 ShelfButton* button = test_api()->GetButton(index);
127 button->AddState(ShelfButton::STATE_HOVERED);
128 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
129 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED);
131 // Remove it.
132 shelf_model()->RemoveItemAt(index);
135 TEST_F(ShelfTest, ShowOverflowBubble) {
136 ShelfID first_item_id = shelf_model()->next_id();
138 // Add platform app button until overflow.
139 int items_added = 0;
140 while (!test_api()->IsOverflowButtonVisible()) {
141 ShelfItem item;
142 item.type = TYPE_PLATFORM_APP;
143 item.status = STATUS_RUNNING;
144 shelf_model()->Add(item);
146 ++items_added;
147 ASSERT_LT(items_added, 10000);
150 // Shows overflow bubble.
151 test_api()->ShowOverflowBubble();
152 EXPECT_TRUE(shelf()->IsShowingOverflowBubble());
154 // Removes the first item in main shelf view.
155 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id));
157 // Waits for all transitions to finish and there should be no crash.
158 test_api()->RunMessageLoopUntilAnimationsDone();
159 EXPECT_FALSE(shelf()->IsShowingOverflowBubble());
162 } // namespace ash