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

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

Issue 140323010: Ash:Shelf - Cleanup of Alternate Shelf (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + remove AlternateShelf from variable names Created 6 years, 11 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 | Annotate | Revision Log
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/shelf/shelf_model.h" 5 #include "ash/shelf/shelf_model.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // application - and make sure that the same index gets returned. 295 // application - and make sure that the same index gets returned.
296 item.type = TYPE_PLATFORM_APP; 296 item.type = TYPE_PLATFORM_APP;
297 int running_app_index = model_->Add(item); 297 int running_app_index = model_->Add(item);
298 EXPECT_EQ(3, running_app_index); 298 EXPECT_EQ(3, running_app_index);
299 EXPECT_EQ(running_app_index, model_->FirstRunningAppIndex()); 299 EXPECT_EQ(running_app_index, model_->FirstRunningAppIndex());
300 item.type = TYPE_WINDOWED_APP; 300 item.type = TYPE_WINDOWED_APP;
301 EXPECT_EQ(running_app_index + 1, model_->Add(item)); 301 EXPECT_EQ(running_app_index + 1, model_->Add(item));
302 EXPECT_EQ(running_app_index, model_->FirstRunningAppIndex()); 302 EXPECT_EQ(running_app_index, model_->FirstRunningAppIndex());
303 } 303 }
304 304
305 // Assertions around where items are added.
306 TEST_F(ShelfModelTest, AddIndicesForLegacyShelfLayout) {
307 CommandLine::ForCurrentProcess()->AppendSwitch(
308 ash::switches::kAshDisableAlternateShelfLayout);
309
310 // Insert browser short cut at index 0.
311 LauncherItem browser_shortcut;
312 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
313 int browser_shortcut_index = model_->Add(browser_shortcut);
314 EXPECT_EQ(0, browser_shortcut_index);
315
316 // platform app items should be after browser shortcut.
317 LauncherItem item;
318 item.type = TYPE_PLATFORM_APP;
319 int platform_app_index1 = model_->Add(item);
320 EXPECT_EQ(1, platform_app_index1);
321
322 // Add another platform app item, it should follow first.
323 int platform_app_index2 = model_->Add(item);
324 EXPECT_EQ(2, platform_app_index2);
325
326 // APP_SHORTCUT priority is higher than PLATFORM_APP but same as
327 // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT.
328 item.type = TYPE_APP_SHORTCUT;
329 int app_shortcut_index1 = model_->Add(item);
330 EXPECT_EQ(1, app_shortcut_index1);
331
332 item.type = TYPE_APP_SHORTCUT;
333 int app_shortcut_index2 = model_->Add(item);
334 EXPECT_EQ(2, app_shortcut_index2);
335
336 // Check that AddAt() figures out the correct indexes for app shortcuts.
337 // APP_SHORTCUT and BROWSER_SHORTCUT has the same weight.
338 // So APP_SHORTCUT is located at index 0. And, BROWSER_SHORTCUT is located at
339 // index 1.
340 item.type = TYPE_APP_SHORTCUT;
341 int app_shortcut_index3 = model_->AddAt(0, item);
342 EXPECT_EQ(0, app_shortcut_index3);
343
344 item.type = TYPE_APP_SHORTCUT;
345 int app_shortcut_index4 = model_->AddAt(5, item);
346 EXPECT_EQ(4, app_shortcut_index4);
347
348 item.type = TYPE_APP_SHORTCUT;
349 int app_shortcut_index5 = model_->AddAt(2, item);
350 EXPECT_EQ(2, app_shortcut_index5);
351
352 // Before there are any panels, no icons should be right aligned.
353 EXPECT_EQ(model_->item_count(), model_->FirstPanelIndex());
354
355 // Check that AddAt() figures out the correct indexes for platform apps and
356 // panels.
357 item.type = TYPE_PLATFORM_APP;
358 int platform_app_index3 = model_->AddAt(2, item);
359 EXPECT_EQ(6, platform_app_index3);
360
361 item.type = TYPE_APP_PANEL;
362 int app_panel_index1 = model_->AddAt(2, item);
363 EXPECT_EQ(10, app_panel_index1);
364
365 item.type = TYPE_PLATFORM_APP;
366 int platform_app_index4 = model_->AddAt(11, item);
367 EXPECT_EQ(9, platform_app_index4);
368
369 item.type = TYPE_APP_PANEL;
370 int app_panel_index2 = model_->AddAt(12, item);
371 EXPECT_EQ(12, app_panel_index2);
372
373 item.type = TYPE_PLATFORM_APP;
374 int platform_app_index5 = model_->AddAt(7, item);
375 EXPECT_EQ(7, platform_app_index5);
376
377 item.type = TYPE_APP_PANEL;
378 int app_panel_index3 = model_->AddAt(13, item);
379 EXPECT_EQ(13, app_panel_index3);
380
381 // Right aligned index should be the first app panel index.
382 EXPECT_EQ(12, model_->FirstPanelIndex());
383
384 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[1].type);
385 EXPECT_EQ(TYPE_APP_LIST, model_->items()[model_->FirstPanelIndex() - 1].type);
386 }
387
388 // Assertions around id generation and usage. 305 // Assertions around id generation and usage.
389 TEST_F(ShelfModelTest, LauncherIDTests) { 306 TEST_F(ShelfModelTest, LauncherIDTests) {
390 // Get the next to use ID counter. 307 // Get the next to use ID counter.
391 LauncherID id = model_->next_id(); 308 LauncherID id = model_->next_id();
392 309
393 // Calling this function multiple times does not change the returned ID. 310 // Calling this function multiple times does not change the returned ID.
394 EXPECT_EQ(model_->next_id(), id); 311 EXPECT_EQ(model_->next_id(), id);
395 312
396 // Check that when we reserve a value it will be the previously retrieved ID, 313 // Check that when we reserve a value it will be the previously retrieved ID,
397 // but it will not change the item count and retrieving the next ID should 314 // but it will not change the item count and retrieving the next ID should
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 348
432 // Now change the type of the second item and make sure that it is moving 349 // Now change the type of the second item and make sure that it is moving
433 // behind the shortcuts. 350 // behind the shortcuts.
434 item.type = TYPE_PLATFORM_APP; 351 item.type = TYPE_PLATFORM_APP;
435 model_->Set(app2_index, item); 352 model_->Set(app2_index, item);
436 353
437 // The item should have moved in front of the app launcher. 354 // The item should have moved in front of the app launcher.
438 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[4].type); 355 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[4].type);
439 } 356 }
440 357
441 TEST_F(ShelfModelTest, CorrectMoveItemsWhenStateChangeForLegacyShelfLayout) {
442 CommandLine::ForCurrentProcess()->AppendSwitch(
443 ash::switches::kAshDisableAlternateShelfLayout);
444
445 // The first item is the browser and the second item is app list.
446 LauncherItem browser_shortcut;
447 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
448 int browser_shortcut_index = model_->Add(browser_shortcut);
449 EXPECT_EQ(0, browser_shortcut_index);
450 EXPECT_EQ(TYPE_APP_LIST, model_->items()[1].type);
451
452 // Add three shortcuts. They should all be moved between the two.
453 LauncherItem item;
454 item.type = TYPE_APP_SHORTCUT;
455 int app1_index = model_->Add(item);
456 EXPECT_EQ(1, app1_index);
457 int app2_index = model_->Add(item);
458 EXPECT_EQ(2, app2_index);
459 int app3_index = model_->Add(item);
460 EXPECT_EQ(3, app3_index);
461
462 // Now change the type of the second item and make sure that it is moving
463 // behind the shortcuts.
464 item.type = TYPE_PLATFORM_APP;
465 model_->Set(app2_index, item);
466
467 // The item should have moved in front of the app launcher.
468 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[3].type);
469 }
470
471 } // namespace ash 358 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698