| OLD | NEW |
| 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_view.h" | 5 #include "ash/launcher/launcher_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/launcher/launcher.h" | 10 #include "ash/launcher/launcher.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 model_->Add(item); | 213 model_->Add(item); |
| 214 return id; | 214 return id; |
| 215 } | 215 } |
| 216 | 216 |
| 217 LauncherID AddTabbedBrowser() { | 217 LauncherID AddTabbedBrowser() { |
| 218 LauncherID id = AddTabbedBrowserNoWait(); | 218 LauncherID id = AddTabbedBrowserNoWait(); |
| 219 test_api_->RunMessageLoopUntilAnimationsDone(); | 219 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 220 return id; | 220 return id; |
| 221 } | 221 } |
| 222 | 222 |
| 223 LauncherID AddPanel() { |
| 224 LauncherID id = AddPanelNoWait(); |
| 225 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 226 return id; |
| 227 } |
| 228 |
| 223 LauncherID AddPlatformAppNoWait() { | 229 LauncherID AddPlatformAppNoWait() { |
| 224 LauncherItem item; | 230 LauncherItem item; |
| 225 item.type = TYPE_PLATFORM_APP; | 231 item.type = TYPE_PLATFORM_APP; |
| 226 item.status = STATUS_RUNNING; | 232 item.status = STATUS_RUNNING; |
| 227 | 233 |
| 228 LauncherID id = model_->next_id(); | 234 LauncherID id = model_->next_id(); |
| 229 model_->Add(item); | 235 model_->Add(item); |
| 230 return id; | 236 return id; |
| 231 } | 237 } |
| 232 | 238 |
| 239 LauncherID AddPanelNoWait() { |
| 240 LauncherItem item; |
| 241 item.type = TYPE_APP_PANEL; |
| 242 item.status = STATUS_RUNNING; |
| 243 |
| 244 LauncherID id = model_->next_id(); |
| 245 model_->Add(item); |
| 246 return id; |
| 247 } |
| 248 |
| 233 LauncherID AddPlatformApp() { | 249 LauncherID AddPlatformApp() { |
| 234 LauncherID id = AddPlatformAppNoWait(); | 250 LauncherID id = AddPlatformAppNoWait(); |
| 235 test_api_->RunMessageLoopUntilAnimationsDone(); | 251 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 236 return id; | 252 return id; |
| 237 } | 253 } |
| 238 | 254 |
| 239 void RemoveByID(LauncherID id) { | 255 void RemoveByID(LauncherID id) { |
| 240 model_->RemoveItemAt(model_->ItemIndexByID(id)); | 256 model_->RemoveItemAt(model_->ItemIndexByID(id)); |
| 241 test_api_->RunMessageLoopUntilAnimationsDone(); | 257 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 242 } | 258 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 }; | 342 }; |
| 327 | 343 |
| 328 // Adds browser button until overflow and verifies that the last added browser | 344 // Adds browser button until overflow and verifies that the last added browser |
| 329 // button is hidden. | 345 // button is hidden. |
| 330 TEST_F(LauncherViewTest, AddBrowserUntilOverflow) { | 346 TEST_F(LauncherViewTest, AddBrowserUntilOverflow) { |
| 331 // All buttons should be visible. | 347 // All buttons should be visible. |
| 332 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 348 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 333 test_api_->GetButtonCount()); | 349 test_api_->GetButtonCount()); |
| 334 | 350 |
| 335 // Add tabbed browser until overflow. | 351 // Add tabbed browser until overflow. |
| 352 int items_added = 0; |
| 336 LauncherID last_added = AddTabbedBrowser(); | 353 LauncherID last_added = AddTabbedBrowser(); |
| 337 while (!test_api_->IsOverflowButtonVisible()) { | 354 while (!test_api_->IsOverflowButtonVisible()) { |
| 338 // Added button is visible after animation while in this loop. | 355 // Added button is visible after animation while in this loop. |
| 339 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | 356 EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
| 340 | 357 |
| 341 last_added = AddTabbedBrowser(); | 358 last_added = AddTabbedBrowser(); |
| 359 ++items_added; |
| 360 ASSERT_LT(items_added, 10000); |
| 342 } | 361 } |
| 343 | 362 |
| 344 // The last added button should be invisible. | 363 // The last added button should be invisible. |
| 345 EXPECT_FALSE(GetButtonByID(last_added)->visible()); | 364 EXPECT_FALSE(GetButtonByID(last_added)->visible()); |
| 346 } | 365 } |
| 347 | 366 |
| 348 // Adds one browser button then adds app shortcut until overflow. Verifies that | 367 // Adds one browser button then adds app shortcut until overflow. Verifies that |
| 349 // the browser button gets hidden on overflow and last added app shortcut is | 368 // the browser button gets hidden on overflow and last added app shortcut is |
| 350 // still visible. | 369 // still visible. |
| 351 TEST_F(LauncherViewTest, AddAppShortcutWithBrowserButtonUntilOverflow) { | 370 TEST_F(LauncherViewTest, AddAppShortcutWithBrowserButtonUntilOverflow) { |
| 352 // All buttons should be visible. | 371 // All buttons should be visible. |
| 353 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 372 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 354 test_api_->GetButtonCount()); | 373 test_api_->GetButtonCount()); |
| 355 | 374 |
| 356 LauncherID browser_button_id = AddTabbedBrowser(); | 375 LauncherID browser_button_id = AddTabbedBrowser(); |
| 357 | 376 |
| 358 // Add app shortcut until overflow. | 377 // Add app shortcut until overflow. |
| 378 int items_added = 0; |
| 359 LauncherID last_added = AddAppShortcut(); | 379 LauncherID last_added = AddAppShortcut(); |
| 360 while (!test_api_->IsOverflowButtonVisible()) { | 380 while (!test_api_->IsOverflowButtonVisible()) { |
| 361 // Added button is visible after animation while in this loop. | 381 // Added button is visible after animation while in this loop. |
| 362 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | 382 EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
| 363 | 383 |
| 364 last_added = AddAppShortcut(); | 384 last_added = AddAppShortcut(); |
| 385 ++items_added; |
| 386 ASSERT_LT(items_added, 10000); |
| 365 } | 387 } |
| 366 | 388 |
| 367 // The last added app short button should be visible. | 389 // The last added app short button should be visible. |
| 368 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | 390 EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
| 369 // And the browser button is invisible. | 391 // And the browser button is invisible. |
| 370 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); | 392 EXPECT_FALSE(GetButtonByID(browser_button_id)->visible()); |
| 371 } | 393 } |
| 372 | 394 |
| 395 TEST_F(LauncherViewTest, AddPanelHidesTabbedBrowser) { |
| 396 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 397 test_api_->GetButtonCount()); |
| 398 |
| 399 // Add tabbed browser until overflow, remember last visible tabbed browser. |
| 400 int items_added = 0; |
| 401 LauncherID first_added = AddTabbedBrowser(); |
| 402 EXPECT_TRUE(GetButtonByID(first_added)->visible()); |
| 403 LauncherID last_visible = first_added; |
| 404 while (true) { |
| 405 LauncherID added = AddTabbedBrowser(); |
| 406 if (test_api_->IsOverflowButtonVisible()) { |
| 407 EXPECT_FALSE(GetButtonByID(added)->visible()); |
| 408 break; |
| 409 } |
| 410 last_visible = added; |
| 411 ++items_added; |
| 412 ASSERT_LT(items_added, 10000); |
| 413 } |
| 414 |
| 415 LauncherID panel = AddPanel(); |
| 416 EXPECT_TRUE(GetButtonByID(panel)->visible()); |
| 417 EXPECT_FALSE(GetButtonByID(last_visible)->visible()); |
| 418 |
| 419 RemoveByID(panel); |
| 420 EXPECT_TRUE(GetButtonByID(last_visible)->visible()); |
| 421 } |
| 422 |
| 423 TEST_F(LauncherViewTest, PanelsHideLast) { |
| 424 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 425 test_api_->GetButtonCount()); |
| 426 |
| 427 // Add tabbed browser. |
| 428 LauncherID browser = AddTabbedBrowser(); |
| 429 LauncherID first_panel = AddPanel(); |
| 430 |
| 431 EXPECT_TRUE(GetButtonByID(browser)->visible()); |
| 432 EXPECT_TRUE(GetButtonByID(first_panel)->visible()); |
| 433 |
| 434 LauncherID last_panel = first_panel; |
| 435 int items_added = 0; |
| 436 while (!test_api_->IsOverflowButtonVisible()) { |
| 437 last_panel = AddPanel(); |
| 438 ++items_added; |
| 439 ASSERT_LT(items_added, 10000); |
| 440 } |
| 441 |
| 442 EXPECT_TRUE(GetButtonByID(last_panel)->visible()); |
| 443 EXPECT_TRUE(GetButtonByID(first_panel)->visible()); |
| 444 EXPECT_FALSE(GetButtonByID(browser)->visible()); |
| 445 } |
| 446 |
| 373 // Adds button until overflow then removes first added one. Verifies that | 447 // Adds button until overflow then removes first added one. Verifies that |
| 374 // the last added one changes from invisible to visible and overflow | 448 // the last added one changes from invisible to visible and overflow |
| 375 // chevron is gone. | 449 // chevron is gone. |
| 376 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) { | 450 TEST_F(LauncherViewTest, RemoveButtonRevealsOverflowed) { |
| 377 // All buttons should be visible. | 451 // All buttons should be visible. |
| 378 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 452 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 379 test_api_->GetButtonCount()); | 453 test_api_->GetButtonCount()); |
| 380 | 454 |
| 381 // Add tabbed browser until overflow. | 455 // Add tabbed browser until overflow. |
| 382 LauncherID first_added= AddTabbedBrowser(); | 456 int items_added = 0; |
| 457 LauncherID first_added = AddTabbedBrowser(); |
| 383 LauncherID last_added = first_added; | 458 LauncherID last_added = first_added; |
| 384 while (!test_api_->IsOverflowButtonVisible()) | 459 while (!test_api_->IsOverflowButtonVisible()) { |
| 385 last_added = AddTabbedBrowser(); | 460 last_added = AddTabbedBrowser(); |
| 461 ++items_added; |
| 462 ASSERT_LT(items_added, 10000); |
| 463 } |
| 386 | 464 |
| 387 // Expect add more than 1 button. First added is visible and last is not. | 465 // Expect add more than 1 button. First added is visible and last is not. |
| 388 EXPECT_NE(first_added, last_added); | 466 EXPECT_NE(first_added, last_added); |
| 389 EXPECT_TRUE(GetButtonByID(first_added)->visible()); | 467 EXPECT_TRUE(GetButtonByID(first_added)->visible()); |
| 390 EXPECT_FALSE(GetButtonByID(last_added)->visible()); | 468 EXPECT_FALSE(GetButtonByID(last_added)->visible()); |
| 391 | 469 |
| 392 // Remove first added. | 470 // Remove first added. |
| 393 RemoveByID(first_added); | 471 RemoveByID(first_added); |
| 394 | 472 |
| 395 // Last added button becomes visible and overflow chevron is gone. | 473 // Last added button becomes visible and overflow chevron is gone. |
| 396 EXPECT_TRUE(GetButtonByID(last_added)->visible()); | 474 EXPECT_TRUE(GetButtonByID(last_added)->visible()); |
| 397 EXPECT_EQ(1.0f, GetButtonByID(last_added)->layer()->opacity()); | 475 EXPECT_EQ(1.0f, GetButtonByID(last_added)->layer()->opacity()); |
| 398 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); | 476 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); |
| 399 } | 477 } |
| 400 | 478 |
| 401 // Verifies that remove last overflowed button should hide overflow chevron. | 479 // Verifies that remove last overflowed button should hide overflow chevron. |
| 402 TEST_F(LauncherViewTest, RemoveLastOverflowed) { | 480 TEST_F(LauncherViewTest, RemoveLastOverflowed) { |
| 403 // All buttons should be visible. | 481 // All buttons should be visible. |
| 404 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 482 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 405 test_api_->GetButtonCount()); | 483 test_api_->GetButtonCount()); |
| 406 | 484 |
| 407 // Add tabbed browser until overflow. | 485 // Add tabbed browser until overflow. |
| 408 LauncherID last_added= AddTabbedBrowser(); | 486 int items_added = 0; |
| 409 while (!test_api_->IsOverflowButtonVisible()) | 487 LauncherID last_added = AddTabbedBrowser(); |
| 488 while (!test_api_->IsOverflowButtonVisible()) { |
| 410 last_added = AddTabbedBrowser(); | 489 last_added = AddTabbedBrowser(); |
| 490 ++items_added; |
| 491 ASSERT_LT(items_added, 10000); |
| 492 } |
| 411 | 493 |
| 412 RemoveByID(last_added); | 494 RemoveByID(last_added); |
| 413 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); | 495 EXPECT_FALSE(test_api_->IsOverflowButtonVisible()); |
| 414 } | 496 } |
| 415 | 497 |
| 416 // Adds browser button without waiting for animation to finish and verifies | 498 // Adds browser button without waiting for animation to finish and verifies |
| 417 // that all added buttons are visible. | 499 // that all added buttons are visible. |
| 418 TEST_F(LauncherViewTest, AddButtonQuickly) { | 500 TEST_F(LauncherViewTest, AddButtonQuickly) { |
| 419 // All buttons should be visible. | 501 // All buttons should be visible. |
| 420 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 502 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 421 test_api_->GetButtonCount()); | 503 test_api_->GetButtonCount()); |
| 422 | 504 |
| 423 // Add a few tabbed browser quickly without wait for animation. | 505 // Add a few tabbed browser quickly without wait for animation. |
| 424 int added_count = 0; | 506 int added_count = 0; |
| 425 while (!test_api_->IsOverflowButtonVisible()) { | 507 while (!test_api_->IsOverflowButtonVisible()) { |
| 426 AddTabbedBrowserNoWait(); | 508 AddTabbedBrowserNoWait(); |
| 427 ++added_count; | 509 ++added_count; |
| 510 ASSERT_LT(added_count, 10000); |
| 428 } | 511 } |
| 429 | 512 |
| 430 // LauncherView should be big enough to hold at least 3 new buttons. | 513 // LauncherView should be big enough to hold at least 3 new buttons. |
| 431 ASSERT_GE(added_count, 3); | 514 ASSERT_GE(added_count, 3); |
| 432 | 515 |
| 433 // Wait for the last animation to finish. | 516 // Wait for the last animation to finish. |
| 434 test_api_->RunMessageLoopUntilAnimationsDone(); | 517 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 435 | 518 |
| 436 // Verifies non-overflow buttons are visible. | 519 // Verifies non-overflow buttons are visible. |
| 437 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { | 520 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 // Resizing launcher view while an add animation without fade-in is running, | 778 // Resizing launcher view while an add animation without fade-in is running, |
| 696 // which happens when overflow happens. App list button should end up in its | 779 // which happens when overflow happens. App list button should end up in its |
| 697 // new ideal bounds. | 780 // new ideal bounds. |
| 698 TEST_F(LauncherViewTest, ResizeDuringOverflowAddAnimation) { | 781 TEST_F(LauncherViewTest, ResizeDuringOverflowAddAnimation) { |
| 699 // All buttons should be visible. | 782 // All buttons should be visible. |
| 700 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 783 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 701 test_api_->GetButtonCount()); | 784 test_api_->GetButtonCount()); |
| 702 | 785 |
| 703 // Add buttons until overflow. Let the non-overflow add animations finish but | 786 // Add buttons until overflow. Let the non-overflow add animations finish but |
| 704 // leave the last running. | 787 // leave the last running. |
| 788 int items_added = 0; |
| 705 AddTabbedBrowserNoWait(); | 789 AddTabbedBrowserNoWait(); |
| 706 while (!test_api_->IsOverflowButtonVisible()) { | 790 while (!test_api_->IsOverflowButtonVisible()) { |
| 707 test_api_->RunMessageLoopUntilAnimationsDone(); | 791 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 708 AddTabbedBrowserNoWait(); | 792 AddTabbedBrowserNoWait(); |
| 793 ++items_added; |
| 794 ASSERT_LT(items_added, 10000); |
| 709 } | 795 } |
| 710 | 796 |
| 711 // Resize launcher view with that animation running and stay overflown. | 797 // Resize launcher view with that animation running and stay overflown. |
| 712 gfx::Rect bounds = launcher_view_->bounds(); | 798 gfx::Rect bounds = launcher_view_->bounds(); |
| 713 bounds.set_width(bounds.width() - kLauncherPreferredSize); | 799 bounds.set_width(bounds.width() - kLauncherPreferredSize); |
| 714 launcher_view_->SetBoundsRect(bounds); | 800 launcher_view_->SetBoundsRect(bounds); |
| 715 ASSERT_TRUE(test_api_->IsOverflowButtonVisible()); | 801 ASSERT_TRUE(test_api_->IsOverflowButtonVisible()); |
| 716 | 802 |
| 717 // Finish the animation. | 803 // Finish the animation. |
| 718 test_api_->RunMessageLoopUntilAnimationsDone(); | 804 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 719 | 805 |
| 720 // App list button should ends up in its new ideal bounds. | 806 // App list button should ends up in its new ideal bounds. |
| 721 const int app_list_button_index = test_api_->GetButtonCount() - 1; | 807 const int app_list_button_index = test_api_->GetButtonCount() - 1; |
| 722 const gfx::Rect& app_list_ideal_bounds = | 808 const gfx::Rect& app_list_ideal_bounds = |
| 723 test_api_->GetIdealBoundsByIndex(app_list_button_index); | 809 test_api_->GetIdealBoundsByIndex(app_list_button_index); |
| 724 const gfx::Rect& app_list_bounds = | 810 const gfx::Rect& app_list_bounds = |
| 725 test_api_->GetBoundsByIndex(app_list_button_index); | 811 test_api_->GetBoundsByIndex(app_list_button_index); |
| 726 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); | 812 EXPECT_EQ(app_list_bounds, app_list_ideal_bounds); |
| 727 } | 813 } |
| 728 | 814 |
| 729 } // namespace test | 815 } // namespace test |
| 730 } // namespace ash | 816 } // namespace ash |
| OLD | NEW |