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/root_window.h"
18 #include "ui/gfx/display.h"
19 #include "ui/gfx/screen.h"
20 #include "ui/views/corewm/corewm_switches.h"
21 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h"
25 #include "base/win/windows_version.h"
28 using ash::internal::ShelfView;
29 using ash::internal::ShelfButton;
33 class ShelfTest : public ash::test::AshTestBase {
39 item_delegate_manager_(NULL) {}
41 virtual ~ShelfTest() {}
43 virtual void SetUp() {
44 test::AshTestBase::SetUp();
46 shelf_ = Shelf::ForPrimaryDisplay();
49 test::ShelfTestAPI test(shelf_);
50 shelf_view_ = test.shelf_view();
51 shelf_model_ = shelf_view_->model();
52 item_delegate_manager_ =
53 Shell::GetInstance()->shelf_item_delegate_manager();
55 test_.reset(new ash::test::ShelfViewTestAPI(shelf_view_));
58 virtual void TearDown() OVERRIDE {
59 test::AshTestBase::TearDown();
66 ShelfView* shelf_view() {
70 ShelfModel* shelf_model() {
74 ShelfItemDelegateManager* item_manager() {
75 return item_delegate_manager_;
78 ash::test::ShelfViewTestAPI* test_api() {
84 ShelfView* shelf_view_;
85 ShelfModel* shelf_model_;
86 ShelfItemDelegateManager* item_delegate_manager_;
87 scoped_ptr<test::ShelfViewTestAPI> test_;
89 DISALLOW_COPY_AND_ASSIGN(ShelfTest);
92 // Confirms that ShelfItem reflects the appropriated state.
93 TEST_F(ShelfTest, StatusReflection) {
94 // Initially we have the app list.
95 int button_count = test_api()->GetButtonCount();
97 // Add running platform app.
99 item.type = TYPE_PLATFORM_APP;
100 item.status = STATUS_RUNNING;
101 int index = shelf_model()->Add(item);
102 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
103 ShelfButton* button = test_api()->GetButton(index);
104 EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state());
107 shelf_model()->RemoveItemAt(index);
108 ASSERT_EQ(--button_count, test_api()->GetButtonCount());
111 // Confirm that using the menu will clear the hover attribute. To avoid another
112 // browser test we check this here.
113 TEST_F(ShelfTest, checkHoverAfterMenu) {
114 // Initially we have the app list.
115 int button_count = test_api()->GetButtonCount();
117 // Add running platform app.
119 item.type = TYPE_PLATFORM_APP;
120 item.status = STATUS_RUNNING;
121 int index = shelf_model()->Add(item);
123 scoped_ptr<ShelfItemDelegate> delegate(
124 new test::TestShelfItemDelegate(NULL));
125 item_manager()->SetShelfItemDelegate(shelf_model()->items()[index].id,
128 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
129 ShelfButton* button = test_api()->GetButton(index);
130 button->AddState(ShelfButton::STATE_HOVERED);
131 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
132 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED);
135 shelf_model()->RemoveItemAt(index);
138 TEST_F(ShelfTest, ShowOverflowBubble) {
139 ShelfID first_item_id = shelf_model()->next_id();
141 // Add platform app button until overflow.
143 while (!test_api()->IsOverflowButtonVisible()) {
145 item.type = TYPE_PLATFORM_APP;
146 item.status = STATUS_RUNNING;
147 shelf_model()->Add(item);
150 ASSERT_LT(items_added, 10000);
153 // Shows overflow bubble.
154 test_api()->ShowOverflowBubble();
155 EXPECT_TRUE(shelf()->IsShowingOverflowBubble());
157 // Removes the first item in main shelf view.
158 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id));
160 // Waits for all transitions to finish and there should be no crash.
161 test_api()->RunMessageLoopUntilAnimationsDone();
162 EXPECT_FALSE(shelf()->IsShowingOverflowBubble());