app_list_bubble_search_page_unittest.cc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/app_list/views/app_list_bubble_search_page.h"
  5. #include "ash/app_list/test/app_list_test_helper.h"
  6. #include "ash/app_list/views/app_list_bubble_apps_page.h"
  7. #include "ash/constants/ash_features.h"
  8. #include "ash/test/ash_test_base.h"
  9. #include "ash/test/layer_animation_stopped_waiter.h"
  10. #include "base/test/scoped_feature_list.h"
  11. #include "ui/compositor/layer.h"
  12. #include "ui/compositor/layer_animation_element.h"
  13. #include "ui/compositor/layer_animator.h"
  14. #include "ui/compositor/scoped_animation_duration_scale_mode.h"
  15. #include "ui/compositor/test/test_utils.h"
  16. #include "ui/events/keycodes/keyboard_codes_posix.h"
  17. namespace ash {
  18. namespace {
  19. class AppListBubbleSearchPageTest : public AshTestBase {
  20. private:
  21. base::test::ScopedFeatureList features_{features::kProductivityLauncher};
  22. };
  23. TEST_F(AppListBubbleSearchPageTest, AnimateShowPage) {
  24. // Open the app list without animation.
  25. ASSERT_EQ(ui::ScopedAnimationDurationScaleMode::duration_multiplier(),
  26. ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
  27. auto* helper = GetAppListTestHelper();
  28. helper->AddAppItems(5);
  29. helper->ShowAppList();
  30. // Enable animations.
  31. ui::ScopedAnimationDurationScaleMode duration(
  32. ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
  33. // Type a key to switch to the search page.
  34. PressAndReleaseKey(ui::VKEY_A);
  35. // Both apps page and search page are visible during the transition animation.
  36. auto* apps_page = helper->GetBubbleAppsPage();
  37. EXPECT_TRUE(apps_page->GetVisible());
  38. auto* search_page = helper->GetBubbleSearchPage();
  39. EXPECT_TRUE(search_page->GetVisible());
  40. // The entire search page fades in.
  41. ui::Layer* layer = search_page->GetPageAnimationLayerForTest();
  42. ASSERT_TRUE(layer);
  43. auto* animator = layer->GetAnimator();
  44. ASSERT_TRUE(animator);
  45. EXPECT_TRUE(animator->IsAnimatingProperty(
  46. ui::LayerAnimationElement::AnimatableProperty::OPACITY));
  47. }
  48. TEST_F(AppListBubbleSearchPageTest, AnimateHidePage) {
  49. // Open the app list without animation.
  50. ASSERT_EQ(ui::ScopedAnimationDurationScaleMode::duration_multiplier(),
  51. ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
  52. auto* helper = GetAppListTestHelper();
  53. helper->AddAppItems(5);
  54. helper->ShowAppList();
  55. auto* apps_page = helper->GetBubbleAppsPage();
  56. ASSERT_TRUE(apps_page->GetVisible());
  57. // Type a key to switch to the search page. This should also be done without
  58. // animations.
  59. ASSERT_EQ(ui::ScopedAnimationDurationScaleMode::duration_multiplier(),
  60. ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
  61. PressAndReleaseKey(ui::VKEY_A);
  62. auto* search_page = helper->GetBubbleSearchPage();
  63. ASSERT_TRUE(search_page->GetVisible());
  64. // Enable animations.
  65. ui::ScopedAnimationDurationScaleMode duration(
  66. ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
  67. // Pressing backspace to delete the search triggers the hide animation.
  68. PressAndReleaseKey(ui::VKEY_BACK);
  69. ui::Layer* layer = search_page->GetPageAnimationLayerForTest();
  70. ASSERT_TRUE(layer);
  71. auto* animator = layer->GetAnimator();
  72. ASSERT_TRUE(animator);
  73. EXPECT_TRUE(animator->IsAnimatingProperty(
  74. ui::LayerAnimationElement::AnimatableProperty::OPACITY));
  75. EXPECT_TRUE(animator->IsAnimatingProperty(
  76. ui::LayerAnimationElement::AnimatableProperty::TRANSFORM));
  77. // Search page visibility updates at the end of the animation.
  78. LayerAnimationStoppedWaiter().Wait(layer);
  79. EXPECT_FALSE(search_page->GetVisible());
  80. }
  81. // Regression test for https://crbug.com/1323035
  82. TEST_F(AppListBubbleSearchPageTest,
  83. SearchPageVisibleAfterQuicklyClearingAndRepopulatingSearch) {
  84. // Open the app list without animation.
  85. ASSERT_EQ(ui::ScopedAnimationDurationScaleMode::duration_multiplier(),
  86. ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
  87. auto* helper = GetAppListTestHelper();
  88. helper->AddAppItems(5);
  89. helper->ShowAppList();
  90. auto* apps_page = helper->GetBubbleAppsPage();
  91. ASSERT_TRUE(apps_page->GetVisible());
  92. auto* search_page = helper->GetBubbleSearchPage();
  93. ASSERT_FALSE(search_page->GetVisible());
  94. // Enable animations.
  95. ui::ScopedAnimationDurationScaleMode duration(
  96. ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
  97. // Type a key to trigger the animation to transition to the search page.
  98. ui::Layer* layer = apps_page->GetPageAnimationLayerForTest();
  99. PressAndReleaseKey(ui::VKEY_A);
  100. ASSERT_TRUE(layer->GetAnimator()->is_animating());
  101. // Before the animation completes, delete the search then quickly re-enter it.
  102. // This should abort animations, animate back to the apps page, abort
  103. // animations again, then animate back to the search page.
  104. PressAndReleaseKey(ui::VKEY_BACK);
  105. ASSERT_TRUE(layer->GetAnimator()->is_animating());
  106. PressAndReleaseKey(ui::VKEY_A);
  107. ASSERT_TRUE(layer->GetAnimator()->is_animating());
  108. LayerAnimationStoppedWaiter().Wait(layer);
  109. EXPECT_FALSE(apps_page->GetVisible());
  110. EXPECT_TRUE(search_page->GetVisible());
  111. }
  112. } // namespace
  113. } // namespace ash