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

Side by Side Diff: ash/common/shelf/shelf_window_watcher_unittest.cc

Issue 2713923002: chromeos: moves a bunch of tests to common_unittests (Closed)
Patch Set: feedback Created 3 years, 10 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/common/shelf/shelf_window_watcher.h" 5 #include "ash/common/shelf/shelf_window_watcher.h"
6 6
7 #include "ash/common/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/shelf/shelf_item_types.h" 8 #include "ash/common/shelf/shelf_item_types.h"
9 #include "ash/common/shelf/shelf_model.h" 9 #include "ash/common/shelf/shelf_model.h"
10 #include "ash/common/wm/window_resizer.h" 10 #include "ash/common/wm/window_resizer.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 EXPECT_EQ(3, model_->item_count()); 65 EXPECT_EQ(3, model_->item_count());
66 66
67 // Each ShelfItem is removed when the associated window is destroyed. 67 // Each ShelfItem is removed when the associated window is destroyed.
68 widget1.reset(); 68 widget1.reset();
69 EXPECT_EQ(2, model_->item_count()); 69 EXPECT_EQ(2, model_->item_count());
70 widget2.reset(); 70 widget2.reset();
71 EXPECT_EQ(1, model_->item_count()); 71 EXPECT_EQ(1, model_->item_count());
72 } 72 }
73 73
74 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemProperties) { 74 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemProperties) {
75 // TODO: investigate failure in mash. http://crbug.com/695562.
76 if (WmShell::Get()->IsRunningInMash())
77 return;
78
75 // ShelfModel only has an APP_LIST item. 79 // ShelfModel only has an APP_LIST item.
76 EXPECT_EQ(1, model_->item_count()); 80 EXPECT_EQ(1, model_->item_count());
77 81
78 // Creating windows without a valid ShelfItemType does not add items. 82 // Creating windows without a valid ShelfItemType does not add items.
79 std::unique_ptr<views::Widget> widget1 = 83 std::unique_ptr<views::Widget> widget1 =
80 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 84 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
81 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get()); 85 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get());
82 std::unique_ptr<views::Widget> widget2 = 86 std::unique_ptr<views::Widget> widget2 =
83 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 87 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
84 WmWindow* window2 = WmLookup::Get()->GetWindowForWidget(widget2.get()); 88 WmWindow* window2 = WmLookup::Get()->GetWindowForWidget(widget2.get());
(...skipping 17 matching lines...) Expand all
102 window1->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED); 106 window1->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED);
103 EXPECT_EQ(2, model_->item_count()); 107 EXPECT_EQ(2, model_->item_count());
104 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED); 108 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED);
105 EXPECT_EQ(1, model_->item_count()); 109 EXPECT_EQ(1, model_->item_count());
106 // Clearing twice doesn't do anything. 110 // Clearing twice doesn't do anything.
107 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED); 111 window2->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_UNDEFINED);
108 EXPECT_EQ(1, model_->item_count()); 112 EXPECT_EQ(1, model_->item_count());
109 } 113 }
110 114
111 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { 115 TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
116 // TODO: investigate failure in mash. http://crbug.com/695562.
117 if (WmShell::Get()->IsRunningInMash())
118 return;
119
112 // ShelfModel only have APP_LIST item. 120 // ShelfModel only have APP_LIST item.
113 EXPECT_EQ(1, model_->item_count()); 121 EXPECT_EQ(1, model_->item_count());
114 std::unique_ptr<views::Widget> widget1 = 122 std::unique_ptr<views::Widget> widget1 =
115 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 123 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
116 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get()); 124 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get());
117 std::unique_ptr<views::Widget> widget2 = 125 std::unique_ptr<views::Widget> widget2 =
118 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 126 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
119 WmWindow* window2 = WmLookup::Get()->GetWindowForWidget(widget2.get()); 127 WmWindow* window2 = WmLookup::Get()->GetWindowForWidget(widget2.get());
120 128
121 // Create a ShelfItem for the first window. 129 // Create a ShelfItem for the first window.
(...skipping 14 matching lines...) Expand all
136 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status); 144 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status);
137 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); 145 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
138 146
139 // The ShelfItem for the second window is active when the window is activated. 147 // The ShelfItem for the second window is active when the window is activated.
140 widget2->Activate(); 148 widget2->Activate();
141 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 149 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
142 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 150 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
143 } 151 }
144 152
145 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { 153 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) {
154 // TODO: investigate failure in mash. http://crbug.com/695562.
155 if (WmShell::Get()->IsRunningInMash())
156 return;
157
146 // ShelfModel only has an APP_LIST item. 158 // ShelfModel only has an APP_LIST item.
147 EXPECT_EQ(1, model_->item_count()); 159 EXPECT_EQ(1, model_->item_count());
148 160
149 std::unique_ptr<views::Widget> widget = 161 std::unique_ptr<views::Widget> widget =
150 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 162 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
151 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 163 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
152 164
153 // Create a ShelfItem for |window|. 165 // Create a ShelfItem for |window|.
154 ShelfID id = CreateShelfItem(window); 166 ShelfID id = CreateShelfItem(window);
155 EXPECT_EQ(2, model_->item_count()); 167 EXPECT_EQ(2, model_->item_count());
156 168
157 int index = model_->ItemIndexByID(id); 169 int index = model_->ItemIndexByID(id);
158 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 170 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
159 171
160 // Update the ShelfItemType for |window|. 172 // Update the ShelfItemType for |window|.
161 window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP); 173 window->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP);
162 // No new item is created after updating a launcher item. 174 // No new item is created after updating a launcher item.
163 EXPECT_EQ(2, model_->item_count()); 175 EXPECT_EQ(2, model_->item_count());
164 // index and id are not changed after updating a launcher item. 176 // index and id are not changed after updating a launcher item.
165 EXPECT_EQ(index, model_->ItemIndexByID(id)); 177 EXPECT_EQ(index, model_->ItemIndexByID(id));
166 EXPECT_EQ(id, model_->items()[index].id); 178 EXPECT_EQ(id, model_->items()[index].id);
167 } 179 }
168 180
169 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { 181 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
182 // TODO: investigate failure in mash. http://crbug.com/695562.
183 if (WmShell::Get()->IsRunningInMash())
184 return;
185
170 // ShelfModel only has an APP_LIST item. 186 // ShelfModel only has an APP_LIST item.
171 EXPECT_EQ(1, model_->item_count()); 187 EXPECT_EQ(1, model_->item_count());
172 188
173 std::unique_ptr<views::Widget> widget = 189 std::unique_ptr<views::Widget> widget =
174 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 190 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
175 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 191 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
176 wm::WindowState* window_state = window->GetWindowState(); 192 wm::WindowState* window_state = window->GetWindowState();
177 193
178 // Create a ShelfItem for |window|. 194 // Create a ShelfItem for |window|.
179 ShelfID id = CreateShelfItem(window); 195 ShelfID id = CreateShelfItem(window);
(...skipping 17 matching lines...) Expand all
197 EXPECT_FALSE(window_state->IsMaximized()); 213 EXPECT_FALSE(window_state->IsMaximized());
198 // No new item is created after restoring a window |window|. 214 // No new item is created after restoring a window |window|.
199 EXPECT_EQ(2, model_->item_count()); 215 EXPECT_EQ(2, model_->item_count());
200 // Index and id are not changed after maximizing a window |window|. 216 // Index and id are not changed after maximizing a window |window|.
201 EXPECT_EQ(index, model_->ItemIndexByID(id)); 217 EXPECT_EQ(index, model_->ItemIndexByID(id));
202 EXPECT_EQ(id, model_->items()[index].id); 218 EXPECT_EQ(id, model_->items()[index].id);
203 } 219 }
204 220
205 // Check that an item is maintained when its associated Window is docked. 221 // Check that an item is maintained when its associated Window is docked.
206 TEST_F(ShelfWindowWatcherTest, DockWindow) { 222 TEST_F(ShelfWindowWatcherTest, DockWindow) {
223 // TODO: investigate failure in mash. http://crbug.com/695562.
224 if (WmShell::Get()->IsRunningInMash())
225 return;
226
207 // ShelfModel only has an APP_LIST item. 227 // ShelfModel only has an APP_LIST item.
208 EXPECT_EQ(1, model_->item_count()); 228 EXPECT_EQ(1, model_->item_count());
209 229
210 std::unique_ptr<views::Widget> widget = 230 std::unique_ptr<views::Widget> widget =
211 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 231 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
212 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 232 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
213 233
214 // Create a ShelfItem for |window|. 234 // Create a ShelfItem for |window|.
215 ShelfID id = CreateShelfItem(window); 235 ShelfID id = CreateShelfItem(window);
216 EXPECT_EQ(2, model_->item_count()); 236 EXPECT_EQ(2, model_->item_count());
(...skipping 16 matching lines...) Expand all
233 253
234 // The shelf item is removed when the window is closed, even if it is in the 254 // The shelf item is removed when the window is closed, even if it is in the
235 // docked container at the time. 255 // docked container at the time.
236 widget.reset(); 256 widget.reset();
237 EXPECT_EQ(1, model_->item_count()); 257 EXPECT_EQ(1, model_->item_count());
238 } 258 }
239 259
240 // Check |window|'s item is not changed during the dragging. 260 // Check |window|'s item is not changed during the dragging.
241 // TODO(simonhong): Add a test for removing a Window during the dragging. 261 // TODO(simonhong): Add a test for removing a Window during the dragging.
242 TEST_F(ShelfWindowWatcherTest, DragWindow) { 262 TEST_F(ShelfWindowWatcherTest, DragWindow) {
263 // TODO: investigate failure in mash. http://crbug.com/695562.
264 if (WmShell::Get()->IsRunningInMash())
265 return;
266
243 // ShelfModel only has an APP_LIST item. 267 // ShelfModel only has an APP_LIST item.
244 EXPECT_EQ(1, model_->item_count()); 268 EXPECT_EQ(1, model_->item_count());
245 269
246 std::unique_ptr<views::Widget> widget = 270 std::unique_ptr<views::Widget> widget =
247 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); 271 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect());
248 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 272 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
249 273
250 // Create a ShelfItem for |window|. 274 // Create a ShelfItem for |window|.
251 ShelfID id = CreateShelfItem(window); 275 ShelfID id = CreateShelfItem(window);
252 EXPECT_EQ(2, model_->item_count()); 276 EXPECT_EQ(2, model_->item_count());
253 277
254 int index = model_->ItemIndexByID(id); 278 int index = model_->ItemIndexByID(id);
255 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); 279 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status);
256 280
257 // Simulate dragging of |window| and check its item is not changed. 281 // Simulate dragging of |window| and check its item is not changed.
258 std::unique_ptr<WindowResizer> resizer(CreateWindowResizer( 282 std::unique_ptr<WindowResizer> resizer(CreateWindowResizer(
259 window, gfx::Point(), HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 283 window, gfx::Point(), HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE));
260 ASSERT_TRUE(resizer.get()); 284 ASSERT_TRUE(resizer.get());
261 resizer->Drag(gfx::Point(50, 50), 0); 285 resizer->Drag(gfx::Point(50, 50), 0);
262 resizer->CompleteDrag(); 286 resizer->CompleteDrag();
263 287
264 // Index and id are not changed after dragging a |window|. 288 // Index and id are not changed after dragging a |window|.
265 EXPECT_EQ(index, model_->ItemIndexByID(id)); 289 EXPECT_EQ(index, model_->ItemIndexByID(id));
266 EXPECT_EQ(id, model_->items()[index].id); 290 EXPECT_EQ(id, model_->items()[index].id);
267 } 291 }
268 292
269 // Ensure shelf items are added and removed as panels are opened and closed. 293 // Ensure shelf items are added and removed as panels are opened and closed.
270 TEST_F(ShelfWindowWatcherTest, PanelWindow) { 294 TEST_F(ShelfWindowWatcherTest, PanelWindow) {
295 // TODO: investigate failure in mash. http://crbug.com/695562.
296 if (WmShell::Get()->IsRunningInMash())
297 return;
298
271 // ShelfModel only has an APP_LIST item. 299 // ShelfModel only has an APP_LIST item.
272 EXPECT_EQ(1, model_->item_count()); 300 EXPECT_EQ(1, model_->item_count());
273 301
274 // Adding windows with valid ShelfItemType properties adds shelf items. 302 // Adding windows with valid ShelfItemType properties adds shelf items.
275 std::unique_ptr<views::Widget> widget1 = 303 std::unique_ptr<views::Widget> widget1 =
276 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect()); 304 CreateTestWidget(nullptr, kShellWindowId_PanelContainer, gfx::Rect());
277 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get()); 305 WmWindow* window1 = WmLookup::Get()->GetWindowForWidget(widget1.get());
278 window1->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP_PANEL); 306 window1->SetIntProperty(WmWindowProperty::SHELF_ITEM_TYPE, TYPE_APP_PANEL);
279 EXPECT_EQ(2, model_->item_count()); 307 EXPECT_EQ(2, model_->item_count());
280 std::unique_ptr<views::Widget> widget2 = 308 std::unique_ptr<views::Widget> widget2 =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get()); 378 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget.get());
351 ShelfWindowWatcherTest::CreateShelfItem(window); 379 ShelfWindowWatcherTest::CreateShelfItem(window);
352 EXPECT_EQ(1, model->item_count()); 380 EXPECT_EQ(1, model->item_count());
353 381
354 // Start the test user session; ShelfWindowWatcher will find the open window. 382 // Start the test user session; ShelfWindowWatcher will find the open window.
355 SetSessionStarted(true); 383 SetSessionStarted(true);
356 EXPECT_EQ(2, model->item_count()); 384 EXPECT_EQ(2, model->item_count());
357 } 385 }
358 386
359 } // namespace ash 387 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_tooltip_manager_unittest.cc ('k') | ash/common/system/ime/tray_ime_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698