Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / shelf / shelf_unittest.cc
blob01380bc142fd2dec25d49e2bc456797b63f90928
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 virtual ~ShelfTest() {}
42 virtual void SetUp() {
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 virtual void TearDown() OVERRIDE {
58 test::AshTestBase::TearDown();
61 Shelf* shelf() {
62 return shelf_;
65 ShelfView* shelf_view() {
66 return shelf_view_;
69 ShelfModel* shelf_model() {
70 return shelf_model_;
73 ShelfItemDelegateManager* item_manager() {
74 return item_delegate_manager_;
77 ash::test::ShelfViewTestAPI* test_api() {
78 return test_.get();
81 private:
82 Shelf* shelf_;
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.
97 ShelfItem item;
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());
105 // Remove it.
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.
117 ShelfItem item;
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,
125 delegate.Pass());
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);
133 // Remove it.
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.
141 int items_added = 0;
142 while (!test_api()->IsOverflowButtonVisible()) {
143 ShelfItem item;
144 item.type = TYPE_PLATFORM_APP;
145 item.status = STATUS_RUNNING;
146 shelf_model()->Add(item);
148 ++items_added;
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());
164 } // namespace ash