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

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

Issue 2518423003: Combine shelf platform and windowed app types. (Closed)
Patch Set: Refinements and cleanup. Created 4 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
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_model.h" 5 #include "ash/common/shelf/shelf_model.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/common/shelf/shelf_model_observer.h" 10 #include "ash/common/shelf/shelf_model_observer.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 TEST_F(ShelfModelTest, BasicAssertions) { 100 TEST_F(ShelfModelTest, BasicAssertions) {
101 // Add an item. 101 // Add an item.
102 ShelfItem item; 102 ShelfItem item;
103 item.type = TYPE_APP_SHORTCUT; 103 item.type = TYPE_APP_SHORTCUT;
104 int index = model_->Add(item); 104 int index = model_->Add(item);
105 EXPECT_EQ(2, model_->item_count()); 105 EXPECT_EQ(2, model_->item_count());
106 EXPECT_EQ("added=1", observer_->StateStringAndClear()); 106 EXPECT_EQ("added=1", observer_->StateStringAndClear());
107 107
108 // Change to a platform app item. 108 // Change to a platform app item.
109 ShelfID original_id = model_->items()[index].id; 109 ShelfID original_id = model_->items()[index].id;
110 item.type = TYPE_PLATFORM_APP; 110 item.type = TYPE_APP;
111 model_->Set(index, item); 111 model_->Set(index, item);
112 EXPECT_EQ(original_id, model_->items()[index].id); 112 EXPECT_EQ(original_id, model_->items()[index].id);
113 EXPECT_EQ("changed=1", observer_->StateStringAndClear()); 113 EXPECT_EQ("changed=1", observer_->StateStringAndClear());
114 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[index].type); 114 EXPECT_EQ(TYPE_APP, model_->items()[index].type);
115 115
116 // Remove the item. 116 // Remove the item.
117 model_->RemoveItemAt(index); 117 model_->RemoveItemAt(index);
118 EXPECT_EQ(1, model_->item_count()); 118 EXPECT_EQ(1, model_->item_count());
119 EXPECT_EQ("removed=1", observer_->StateStringAndClear()); 119 EXPECT_EQ("removed=1", observer_->StateStringAndClear());
120 120
121 // Add an app item. 121 // Add an app item.
122 item.type = TYPE_APP_SHORTCUT; 122 item.type = TYPE_APP_SHORTCUT;
123 index = model_->Add(item); 123 index = model_->Add(item);
124 observer_->StateStringAndClear(); 124 observer_->StateStringAndClear();
(...skipping 24 matching lines...) Expand all
149 } 149 }
150 150
151 // Assertions around where items are added. 151 // Assertions around where items are added.
152 TEST_F(ShelfModelTest, AddIndices) { 152 TEST_F(ShelfModelTest, AddIndices) {
153 // Insert browser short cut at index 1. 153 // Insert browser short cut at index 1.
154 ShelfItem browser_shortcut; 154 ShelfItem browser_shortcut;
155 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 155 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
156 int browser_shortcut_index = model_->Add(browser_shortcut); 156 int browser_shortcut_index = model_->Add(browser_shortcut);
157 EXPECT_EQ(1, browser_shortcut_index); 157 EXPECT_EQ(1, browser_shortcut_index);
158 158
159 // platform app items should be after browser shortcut. 159 // App items should be after the browser shortcut.
160 ShelfItem item; 160 ShelfItem item;
161 item.type = TYPE_PLATFORM_APP; 161 item.type = TYPE_APP;
162 int platform_app_index1 = model_->Add(item); 162 int platform_app_index1 = model_->Add(item);
163 EXPECT_EQ(2, platform_app_index1); 163 EXPECT_EQ(2, platform_app_index1);
164 164
165 // Add another platform app item, it should follow first. 165 // Add another platform app item, it should follow first.
166 int platform_app_index2 = model_->Add(item); 166 int platform_app_index2 = model_->Add(item);
167 EXPECT_EQ(3, platform_app_index2); 167 EXPECT_EQ(3, platform_app_index2);
168 168
169 // APP_SHORTCUT priority is higher than PLATFORM_APP but same as 169 // APP_SHORTCUT priority is higher than PLATFORM_APP but same as
170 // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT. 170 // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT.
171 item.type = TYPE_APP_SHORTCUT; 171 item.type = TYPE_APP_SHORTCUT;
(...skipping 16 matching lines...) Expand all
188 int app_shortcut_index4 = model_->AddAt(6, item); 188 int app_shortcut_index4 = model_->AddAt(6, item);
189 EXPECT_EQ(5, app_shortcut_index4); 189 EXPECT_EQ(5, app_shortcut_index4);
190 190
191 item.type = TYPE_APP_SHORTCUT; 191 item.type = TYPE_APP_SHORTCUT;
192 int app_shortcut_index5 = model_->AddAt(3, item); 192 int app_shortcut_index5 = model_->AddAt(3, item);
193 EXPECT_EQ(3, app_shortcut_index5); 193 EXPECT_EQ(3, app_shortcut_index5);
194 194
195 // Before there are any panels, no icons should be right aligned. 195 // Before there are any panels, no icons should be right aligned.
196 EXPECT_EQ(model_->item_count(), model_->FirstPanelIndex()); 196 EXPECT_EQ(model_->item_count(), model_->FirstPanelIndex());
197 197
198 // Check that AddAt() figures out the correct indexes for platform apps and 198 // Check that AddAt() figures out the correct indexes for apps and panels.
199 // panels. 199 item.type = TYPE_APP;
200 item.type = TYPE_PLATFORM_APP;
201 int platform_app_index3 = model_->AddAt(3, item); 200 int platform_app_index3 = model_->AddAt(3, item);
202 EXPECT_EQ(7, platform_app_index3); 201 EXPECT_EQ(7, platform_app_index3);
203 202
204 item.type = TYPE_APP_PANEL; 203 item.type = TYPE_APP_PANEL;
205 int app_panel_index1 = model_->AddAt(2, item); 204 int app_panel_index1 = model_->AddAt(2, item);
206 EXPECT_EQ(10, app_panel_index1); 205 EXPECT_EQ(10, app_panel_index1);
207 206
208 item.type = TYPE_PLATFORM_APP; 207 item.type = TYPE_APP;
209 int platform_app_index4 = model_->AddAt(11, item); 208 int platform_app_index4 = model_->AddAt(11, item);
210 EXPECT_EQ(10, platform_app_index4); 209 EXPECT_EQ(10, platform_app_index4);
211 210
212 item.type = TYPE_APP_PANEL; 211 item.type = TYPE_APP_PANEL;
213 int app_panel_index2 = model_->AddAt(12, item); 212 int app_panel_index2 = model_->AddAt(12, item);
214 EXPECT_EQ(12, app_panel_index2); 213 EXPECT_EQ(12, app_panel_index2);
215 214
216 item.type = TYPE_PLATFORM_APP; 215 item.type = TYPE_APP;
217 int platform_app_index5 = model_->AddAt(7, item); 216 int platform_app_index5 = model_->AddAt(7, item);
218 EXPECT_EQ(7, platform_app_index5); 217 EXPECT_EQ(7, platform_app_index5);
219 218
220 item.type = TYPE_APP_PANEL; 219 item.type = TYPE_APP_PANEL;
221 int app_panel_index3 = model_->AddAt(13, item); 220 int app_panel_index3 = model_->AddAt(13, item);
222 EXPECT_EQ(13, app_panel_index3); 221 EXPECT_EQ(13, app_panel_index3);
223 222
224 // Right aligned index should be the first app panel index. 223 // Right aligned index should be the first app panel index.
225 EXPECT_EQ(12, model_->FirstPanelIndex()); 224 EXPECT_EQ(12, model_->FirstPanelIndex());
226 225
227 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[2].type); 226 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[2].type);
228 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type); 227 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
229 } 228 }
230 229
231 // Test that the indexes for the running applications are properly determined 230 // Test that the indexes for the running applications are properly determined.
232 // when the first running application is a windowed application. 231 TEST_F(ShelfModelTest, FirstRunningAppIndex) {
233 TEST_F(ShelfModelTest, FirstRunningAppIndexUsingWindowedAppFirst) {
234 // Insert the browser shortcut at index 1 and check that the running 232 // Insert the browser shortcut at index 1 and check that the running
235 // application index would be behind it. 233 // application index would be behind it.
236 ShelfItem item; 234 ShelfItem item;
237 item.type = TYPE_BROWSER_SHORTCUT; 235 item.type = TYPE_BROWSER_SHORTCUT;
238 EXPECT_EQ(1, model_->Add(item)); 236 EXPECT_EQ(1, model_->Add(item));
239 EXPECT_EQ(2, model_->FirstRunningAppIndex()); 237 EXPECT_EQ(2, model_->FirstRunningAppIndex());
240 238
241 // Insert a panel application at the end and check that the running 239 // Insert a panel application at the end and check that the running
242 // application index would be at / before the application panel. 240 // application index would be at / before the application panel.
243 item.type = TYPE_APP_PANEL; 241 item.type = TYPE_APP_PANEL;
244 EXPECT_EQ(2, model_->Add(item)); 242 EXPECT_EQ(2, model_->Add(item));
245 EXPECT_EQ(2, model_->FirstRunningAppIndex()); 243 EXPECT_EQ(2, model_->FirstRunningAppIndex());
246 244
247 // Insert an application shortcut and make sure that the running application 245 // Insert an application shortcut and make sure that the running application
248 // index would be behind it. 246 // index would be behind it.
249 item.type = TYPE_APP_SHORTCUT; 247 item.type = TYPE_APP_SHORTCUT;
250 EXPECT_EQ(2, model_->Add(item)); 248 EXPECT_EQ(2, model_->Add(item));
251 EXPECT_EQ(3, model_->FirstRunningAppIndex()); 249 EXPECT_EQ(3, model_->FirstRunningAppIndex());
252 250
253 // Insert different running application shortcuts - but first a windowed 251 // Insert a two app items and check the first running app index.
254 // application - and make sure that the same index gets returned. 252 item.type = TYPE_APP;
255 item.type = TYPE_WINDOWED_APP; 253 EXPECT_EQ(3, model_->Add(item));
256 int running_app_index = model_->Add(item);
257 EXPECT_EQ(3, running_app_index);
258 EXPECT_EQ(running_app_index, model_->FirstRunningAppIndex());
259 item.type = TYPE_PLATFORM_APP;
260 EXPECT_EQ(running_app_index + 1, model_->Add(item));
261 EXPECT_EQ(running_app_index, model_->FirstRunningAppIndex());
262 }
263
264 // Test that the indexes for the running applications are properly determined
265 // when the first running application is a platform application.
266 TEST_F(ShelfModelTest, FirstRunningAppIndexUsingPlatformAppFirst) {
267 // Insert the browser shortcut at index 1 and check that the running
268 // application index would be behind it.
269 ShelfItem item;
270 item.type = TYPE_BROWSER_SHORTCUT;
271 EXPECT_EQ(1, model_->Add(item));
272 EXPECT_EQ(2, model_->FirstRunningAppIndex());
273
274 // Insert a panel application at the end and check that the running
275 // application index would be at / before the application panel.
276 item.type = TYPE_APP_PANEL;
277 EXPECT_EQ(2, model_->Add(item));
278 EXPECT_EQ(2, model_->FirstRunningAppIndex());
279
280 // Insert an application shortcut and make sure that the running application
281 // index would be behind it.
282 item.type = TYPE_APP_SHORTCUT;
283 EXPECT_EQ(2, model_->Add(item));
284 EXPECT_EQ(3, model_->FirstRunningAppIndex()); 254 EXPECT_EQ(3, model_->FirstRunningAppIndex());
285 255 EXPECT_EQ(4, model_->Add(item));
286 // Insert different running application shortcuts - but first a platfom 256 EXPECT_EQ(3, model_->FirstRunningAppIndex());
287 // application - and make sure that the same index gets returned.
288 item.type = TYPE_PLATFORM_APP;
289 int running_app_index = model_->Add(item);
290 EXPECT_EQ(3, running_app_index);
291 EXPECT_EQ(running_app_index, model_->FirstRunningAppIndex());
292 item.type = TYPE_WINDOWED_APP;
293 EXPECT_EQ(running_app_index + 1, model_->Add(item));
294 EXPECT_EQ(running_app_index, model_->FirstRunningAppIndex());
295 } 257 }
296 258
297 // Assertions around id generation and usage. 259 // Assertions around id generation and usage.
298 TEST_F(ShelfModelTest, ShelfIDTests) { 260 TEST_F(ShelfModelTest, ShelfIDTests) {
299 // Get the next to use ID counter. 261 // Get the next to use ID counter.
300 ShelfID id = model_->next_id(); 262 ShelfID id = model_->next_id();
301 263
302 // Calling this function multiple times does not change the returned ID. 264 // Calling this function multiple times does not change the returned ID.
303 EXPECT_EQ(model_->next_id(), id); 265 EXPECT_EQ(model_->next_id(), id);
304 266
305 // Check that when we reserve a value it will be the previously retrieved ID, 267 // Check that when we reserve a value it will be the previously retrieved ID,
306 // but it will not change the item count and retrieving the next ID should 268 // but it will not change the item count and retrieving the next ID should
307 // produce something new. 269 // produce something new.
308 EXPECT_EQ(model_->reserve_external_id(), id); 270 EXPECT_EQ(model_->reserve_external_id(), id);
309 EXPECT_EQ(1, model_->item_count()); 271 EXPECT_EQ(1, model_->item_count());
310 ShelfID id2 = model_->next_id(); 272 ShelfID id2 = model_->next_id();
311 EXPECT_NE(id2, id); 273 EXPECT_NE(id2, id);
312 274
313 // Adding another item to the list should also produce a new ID. 275 // Adding another item to the list should also produce a new ID.
314 ShelfItem item; 276 ShelfItem item;
315 item.type = TYPE_PLATFORM_APP; 277 item.type = TYPE_APP;
316 model_->Add(item); 278 model_->Add(item);
317 EXPECT_NE(model_->next_id(), id2); 279 EXPECT_NE(model_->next_id(), id2);
318 } 280 }
319 281
320 // This verifies that converting an existing item into a lower weight category 282 // This verifies that converting an existing item into a lower weight category
321 // (e.g. shortcut to running but not pinned app) will move it to the proper 283 // (e.g. shortcut to running but not pinned app) will move it to the proper
322 // location. See crbug.com/248769. 284 // location. See crbug.com/248769.
323 TEST_F(ShelfModelTest, CorrectMoveItemsWhenStateChange) { 285 TEST_F(ShelfModelTest, CorrectMoveItemsWhenStateChange) {
324 // The first item is the app list and last item is the browser. 286 // The first item is the app list and last item is the browser.
325 ShelfItem browser_shortcut; 287 ShelfItem browser_shortcut;
326 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 288 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
327 int browser_shortcut_index = model_->Add(browser_shortcut); 289 int browser_shortcut_index = model_->Add(browser_shortcut);
328 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type); 290 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
329 EXPECT_EQ(1, browser_shortcut_index); 291 EXPECT_EQ(1, browser_shortcut_index);
330 292
331 // Add three shortcuts. They should all be moved between the two. 293 // Add three shortcuts. They should all be moved between the two.
332 ShelfItem item; 294 ShelfItem item;
333 item.type = TYPE_APP_SHORTCUT; 295 item.type = TYPE_APP_SHORTCUT;
334 int app1_index = model_->Add(item); 296 int app1_index = model_->Add(item);
335 EXPECT_EQ(2, app1_index); 297 EXPECT_EQ(2, app1_index);
336 int app2_index = model_->Add(item); 298 int app2_index = model_->Add(item);
337 EXPECT_EQ(3, app2_index); 299 EXPECT_EQ(3, app2_index);
338 int app3_index = model_->Add(item); 300 int app3_index = model_->Add(item);
339 EXPECT_EQ(4, app3_index); 301 EXPECT_EQ(4, app3_index);
340 302
341 // Now change the type of the second item and make sure that it is moving 303 // Now change the type of the second item and make sure that it is moving
342 // behind the shortcuts. 304 // behind the shortcuts.
343 item.type = TYPE_PLATFORM_APP; 305 item.type = TYPE_APP;
344 model_->Set(app2_index, item); 306 model_->Set(app2_index, item);
345 307
346 // The item should have moved in front of the app launcher. 308 // The item should have moved in front of the app launcher.
347 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[4].type); 309 EXPECT_EQ(TYPE_APP, model_->items()[4].type);
348 } 310 }
349 311
350 } // namespace ash 312 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698