OLD | NEW |
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 Loading... |
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 ShelfItem 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 ShelfItem 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 |
305 // Assertions around id generation and usage. | 388 // Assertions around id generation and usage. |
306 TEST_F(ShelfModelTest, ShelfIDTests) { | 389 TEST_F(ShelfModelTest, ShelfIDTests) { |
307 // Get the next to use ID counter. | 390 // Get the next to use ID counter. |
308 ShelfID id = model_->next_id(); | 391 ShelfID id = model_->next_id(); |
309 | 392 |
310 // Calling this function multiple times does not change the returned ID. | 393 // Calling this function multiple times does not change the returned ID. |
311 EXPECT_EQ(model_->next_id(), id); | 394 EXPECT_EQ(model_->next_id(), id); |
312 | 395 |
313 // Check that when we reserve a value it will be the previously retrieved ID, | 396 // Check that when we reserve a value it will be the previously retrieved ID, |
314 // but it will not change the item count and retrieving the next ID should | 397 // 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 Loading... |
348 | 431 |
349 // Now change the type of the second item and make sure that it is moving | 432 // Now change the type of the second item and make sure that it is moving |
350 // behind the shortcuts. | 433 // behind the shortcuts. |
351 item.type = TYPE_PLATFORM_APP; | 434 item.type = TYPE_PLATFORM_APP; |
352 model_->Set(app2_index, item); | 435 model_->Set(app2_index, item); |
353 | 436 |
354 // The item should have moved in front of the app launcher. | 437 // The item should have moved in front of the app launcher. |
355 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[4].type); | 438 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[4].type); |
356 } | 439 } |
357 | 440 |
| 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 ShelfItem 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 ShelfItem 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 |
358 } // namespace ash | 471 } // namespace ash |
OLD | NEW |