Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: ash/shelf/shelf_unittest.cc

Issue 115113006: Rename Launcher to Shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/shelf/shelf_tooltip_manager_unittest.cc ('k') | ash/shelf/shelf_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/launcher/launcher.h" 5 #include "ash/shelf/shelf.h"
6 #include "ash/shelf/shelf_button.h" 6 #include "ash/shelf/shelf_button.h"
7 #include "ash/shelf/shelf_item_delegate_manager.h" 7 #include "ash/shelf/shelf_item_delegate_manager.h"
8 #include "ash/shelf/shelf_model.h" 8 #include "ash/shelf/shelf_model.h"
9 #include "ash/shelf/shelf_view.h" 9 #include "ash/shelf/shelf_view.h"
10 #include "ash/shelf/shelf_widget.h" 10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/launcher_test_api.h" 13 #include "ash/test/shelf_test_api.h"
14 #include "ash/test/shelf_view_test_api.h" 14 #include "ash/test/shelf_view_test_api.h"
15 #include "ash/test/test_shelf_item_delegate.h" 15 #include "ash/test/test_shelf_item_delegate.h"
16 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
17 #include "ui/aura/root_window.h" 17 #include "ui/aura/root_window.h"
18 #include "ui/gfx/display.h" 18 #include "ui/gfx/display.h"
19 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
20 #include "ui/views/corewm/corewm_switches.h" 20 #include "ui/views/corewm/corewm_switches.h"
21 #include "ui/views/view.h" 21 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
23 23
24 #if defined(OS_WIN) 24 #if defined(OS_WIN)
25 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
26 #endif 26 #endif
27 27
28 typedef ash::test::AshTestBase LauncherTest;
29 using ash::internal::ShelfView; 28 using ash::internal::ShelfView;
30 using ash::internal::ShelfButton; 29 using ash::internal::ShelfButton;
31 30
32 namespace ash { 31 namespace ash {
33 32
34 class LauncherTest : public ash::test::AshTestBase { 33 class ShelfTest : public ash::test::AshTestBase {
35 public: 34 public:
36 LauncherTest() : launcher_(NULL), 35 ShelfTest()
37 shelf_view_(NULL), 36 : shelf_(NULL),
38 shelf_model_(NULL), 37 shelf_view_(NULL),
39 item_delegate_manager_(NULL) { 38 shelf_model_(NULL),
40 } 39 item_delegate_manager_(NULL) {}
41 40
42 virtual ~LauncherTest() {} 41 virtual ~ShelfTest() {}
43 42
44 virtual void SetUp() { 43 virtual void SetUp() {
45 test::AshTestBase::SetUp(); 44 test::AshTestBase::SetUp();
46 45
47 launcher_ = Launcher::ForPrimaryDisplay(); 46 shelf_ = Shelf::ForPrimaryDisplay();
48 ASSERT_TRUE(launcher_); 47 ASSERT_TRUE(shelf_);
49 48
50 ash::test::LauncherTestAPI test(launcher_); 49 test::ShelfTestAPI test(shelf_);
51 shelf_view_ = test.shelf_view(); 50 shelf_view_ = test.shelf_view();
52 shelf_model_ = shelf_view_->model(); 51 shelf_model_ = shelf_view_->model();
53 item_delegate_manager_ = 52 item_delegate_manager_ =
54 Shell::GetInstance()->shelf_item_delegate_manager(); 53 Shell::GetInstance()->shelf_item_delegate_manager();
55 54
56 test_.reset(new ash::test::ShelfViewTestAPI(shelf_view_)); 55 test_.reset(new ash::test::ShelfViewTestAPI(shelf_view_));
57 } 56 }
58 57
59 virtual void TearDown() OVERRIDE { 58 virtual void TearDown() OVERRIDE {
60 test::AshTestBase::TearDown(); 59 test::AshTestBase::TearDown();
61 } 60 }
62 61
63 Launcher* launcher() { 62 Shelf* shelf() {
64 return launcher_; 63 return shelf_;
65 } 64 }
66 65
67 ShelfView* shelf_view() { 66 ShelfView* shelf_view() {
68 return shelf_view_; 67 return shelf_view_;
69 } 68 }
70 69
71 ShelfModel* shelf_model() { 70 ShelfModel* shelf_model() {
72 return shelf_model_; 71 return shelf_model_;
73 } 72 }
74 73
75 ShelfItemDelegateManager* item_manager() { 74 ShelfItemDelegateManager* item_manager() {
76 return item_delegate_manager_; 75 return item_delegate_manager_;
77 } 76 }
78 77
79 ash::test::ShelfViewTestAPI* test_api() { 78 ash::test::ShelfViewTestAPI* test_api() {
80 return test_.get(); 79 return test_.get();
81 } 80 }
82 81
83 private: 82 private:
84 Launcher* launcher_; 83 Shelf* shelf_;
85 ShelfView* shelf_view_; 84 ShelfView* shelf_view_;
86 ShelfModel* shelf_model_; 85 ShelfModel* shelf_model_;
87 ShelfItemDelegateManager* item_delegate_manager_; 86 ShelfItemDelegateManager* item_delegate_manager_;
88 scoped_ptr<test::ShelfViewTestAPI> test_; 87 scoped_ptr<test::ShelfViewTestAPI> test_;
89 88
90 DISALLOW_COPY_AND_ASSIGN(LauncherTest); 89 DISALLOW_COPY_AND_ASSIGN(ShelfTest);
91 }; 90 };
92 91
93 // Confirms that LauncherItem reflects the appropriated state. 92 // Confirms that LauncherItem reflects the appropriated state.
94 TEST_F(LauncherTest, StatusReflection) { 93 TEST_F(ShelfTest, StatusReflection) {
95 // Initially we have the app list. 94 // Initially we have the app list.
96 int button_count = test_api()->GetButtonCount(); 95 int button_count = test_api()->GetButtonCount();
97 96
98 // Add running platform app. 97 // Add running platform app.
99 LauncherItem item; 98 LauncherItem item;
100 item.type = TYPE_PLATFORM_APP; 99 item.type = TYPE_PLATFORM_APP;
101 item.status = STATUS_RUNNING; 100 item.status = STATUS_RUNNING;
102 int index = shelf_model()->Add(item); 101 int index = shelf_model()->Add(item);
103 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); 102 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
104 ShelfButton* button = test_api()->GetButton(index); 103 ShelfButton* button = test_api()->GetButton(index);
105 EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state()); 104 EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state());
106 105
107 // Remove it. 106 // Remove it.
108 shelf_model()->RemoveItemAt(index); 107 shelf_model()->RemoveItemAt(index);
109 ASSERT_EQ(--button_count, test_api()->GetButtonCount()); 108 ASSERT_EQ(--button_count, test_api()->GetButtonCount());
110 } 109 }
111 110
112 // Confirm that using the menu will clear the hover attribute. To avoid another 111 // Confirm that using the menu will clear the hover attribute. To avoid another
113 // browser test we check this here. 112 // browser test we check this here.
114 TEST_F(LauncherTest, checkHoverAfterMenu) { 113 TEST_F(ShelfTest, checkHoverAfterMenu) {
115 // Initially we have the app list. 114 // Initially we have the app list.
116 int button_count = test_api()->GetButtonCount(); 115 int button_count = test_api()->GetButtonCount();
117 116
118 // Add running platform app. 117 // Add running platform app.
119 LauncherItem item; 118 LauncherItem item;
120 item.type = TYPE_PLATFORM_APP; 119 item.type = TYPE_PLATFORM_APP;
121 item.status = STATUS_RUNNING; 120 item.status = STATUS_RUNNING;
122 int index = shelf_model()->Add(item); 121 int index = shelf_model()->Add(item);
123 122
124 scoped_ptr<ShelfItemDelegate> delegate( 123 scoped_ptr<ShelfItemDelegate> delegate(
125 new test::TestShelfItemDelegate(NULL)); 124 new test::TestShelfItemDelegate(NULL));
126 item_manager()->SetShelfItemDelegate(shelf_model()->items()[index].id, 125 item_manager()->SetShelfItemDelegate(shelf_model()->items()[index].id,
127 delegate.Pass()); 126 delegate.Pass());
128 127
129 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); 128 ASSERT_EQ(++button_count, test_api()->GetButtonCount());
130 ShelfButton* button = test_api()->GetButton(index); 129 ShelfButton* button = test_api()->GetButton(index);
131 button->AddState(ShelfButton::STATE_HOVERED); 130 button->AddState(ShelfButton::STATE_HOVERED);
132 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 131 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
133 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED); 132 EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED);
134 133
135 // Remove it. 134 // Remove it.
136 shelf_model()->RemoveItemAt(index); 135 shelf_model()->RemoveItemAt(index);
137 } 136 }
138 137
139 TEST_F(LauncherTest, ShowOverflowBubble) { 138 TEST_F(ShelfTest, ShowOverflowBubble) {
140 LauncherID first_item_id = shelf_model()->next_id(); 139 LauncherID first_item_id = shelf_model()->next_id();
141 140
142 // Add platform app button until overflow. 141 // Add platform app button until overflow.
143 int items_added = 0; 142 int items_added = 0;
144 while (!test_api()->IsOverflowButtonVisible()) { 143 while (!test_api()->IsOverflowButtonVisible()) {
145 LauncherItem item; 144 LauncherItem item;
146 item.type = TYPE_PLATFORM_APP; 145 item.type = TYPE_PLATFORM_APP;
147 item.status = STATUS_RUNNING; 146 item.status = STATUS_RUNNING;
148 shelf_model()->Add(item); 147 shelf_model()->Add(item);
149 148
150 ++items_added; 149 ++items_added;
151 ASSERT_LT(items_added, 10000); 150 ASSERT_LT(items_added, 10000);
152 } 151 }
153 152
154 // Shows overflow bubble. 153 // Shows overflow bubble.
155 test_api()->ShowOverflowBubble(); 154 test_api()->ShowOverflowBubble();
156 EXPECT_TRUE(launcher()->IsShowingOverflowBubble()); 155 EXPECT_TRUE(shelf()->IsShowingOverflowBubble());
157 156
158 // Removes the first item in main shelf view. 157 // Removes the first item in main shelf view.
159 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id)); 158 shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id));
160 159
161 // Waits for all transitions to finish and there should be no crash. 160 // Waits for all transitions to finish and there should be no crash.
162 test_api()->RunMessageLoopUntilAnimationsDone(); 161 test_api()->RunMessageLoopUntilAnimationsDone();
163 EXPECT_FALSE(launcher()->IsShowingOverflowBubble()); 162 EXPECT_FALSE(shelf()->IsShowingOverflowBubble());
164 } 163 }
165 164
166 } // namespace ash 165 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_tooltip_manager_unittest.cc ('k') | ash/shelf/shelf_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698