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