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"
24 #include "base/win/windows_version.h"
28 using ash::ShelfButton
;
32 class ShelfTest
: public ash::test::AshTestBase
{
38 item_delegate_manager_(NULL
) {}
40 virtual ~ShelfTest() {}
42 virtual void SetUp() {
43 test::AshTestBase::SetUp();
45 shelf_
= Shelf::ForPrimaryDisplay();
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 virtual void TearDown() OVERRIDE
{
58 test::AshTestBase::TearDown();
65 ShelfView
* shelf_view() {
69 ShelfModel
* shelf_model() {
73 ShelfItemDelegateManager
* item_manager() {
74 return item_delegate_manager_
;
77 ash::test::ShelfViewTestAPI
* test_api() {
83 ShelfView
* shelf_view_
;
84 ShelfModel
* shelf_model_
;
85 ShelfItemDelegateManager
* item_delegate_manager_
;
86 scoped_ptr
<test::ShelfViewTestAPI
> test_
;
88 DISALLOW_COPY_AND_ASSIGN(ShelfTest
);
91 // Confirms that ShelfItem reflects the appropriated state.
92 TEST_F(ShelfTest
, StatusReflection
) {
93 // Initially we have the app list.
94 int button_count
= test_api()->GetButtonCount();
96 // Add running platform app.
98 item
.type
= TYPE_PLATFORM_APP
;
99 item
.status
= STATUS_RUNNING
;
100 int index
= shelf_model()->Add(item
);
101 ASSERT_EQ(++button_count
, test_api()->GetButtonCount());
102 ShelfButton
* button
= test_api()->GetButton(index
);
103 EXPECT_EQ(ShelfButton::STATE_RUNNING
, button
->state());
106 shelf_model()->RemoveItemAt(index
);
107 ASSERT_EQ(--button_count
, test_api()->GetButtonCount());
110 // Confirm that using the menu will clear the hover attribute. To avoid another
111 // browser test we check this here.
112 TEST_F(ShelfTest
, checkHoverAfterMenu
) {
113 // Initially we have the app list.
114 int button_count
= test_api()->GetButtonCount();
116 // Add running platform app.
118 item
.type
= TYPE_PLATFORM_APP
;
119 item
.status
= STATUS_RUNNING
;
120 int index
= shelf_model()->Add(item
);
122 scoped_ptr
<ShelfItemDelegate
> delegate(
123 new test::TestShelfItemDelegate(NULL
));
124 item_manager()->SetShelfItemDelegate(shelf_model()->items()[index
].id
,
127 ASSERT_EQ(++button_count
, test_api()->GetButtonCount());
128 ShelfButton
* button
= test_api()->GetButton(index
);
129 button
->AddState(ShelfButton::STATE_HOVERED
);
130 button
->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE
);
131 EXPECT_FALSE(button
->state() & ShelfButton::STATE_HOVERED
);
134 shelf_model()->RemoveItemAt(index
);
137 TEST_F(ShelfTest
, ShowOverflowBubble
) {
138 ShelfID first_item_id
= shelf_model()->next_id();
140 // Add platform app button until overflow.
142 while (!test_api()->IsOverflowButtonVisible()) {
144 item
.type
= TYPE_PLATFORM_APP
;
145 item
.status
= STATUS_RUNNING
;
146 shelf_model()->Add(item
);
149 ASSERT_LT(items_added
, 10000);
152 // Shows overflow bubble.
153 test_api()->ShowOverflowBubble();
154 EXPECT_TRUE(shelf()->IsShowingOverflowBubble());
156 // Removes the first item in main shelf view.
157 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id
));
159 // Waits for all transitions to finish and there should be no crash.
160 test_api()->RunMessageLoopUntilAnimationsDone();
161 EXPECT_FALSE(shelf()->IsShowingOverflowBubble());