| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <memory> | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/shell_window_ids.h" | |
| 9 #include "ash/test/ash_test_base.h" | |
| 10 #include "ash/test/ash_test_helper.h" | |
| 11 #include "ash/test/test_shell_delegate.h" | |
| 12 #include "ash/wm/window_util.h" | |
| 13 #include "base/command_line.h" | |
| 14 #include "ui/app_list/app_list_switches.h" | |
| 15 #include "ui/app_list/shower/app_list_shower_impl.h" | |
| 16 #include "ui/app_list/views/app_list_view.h" | |
| 17 #include "ui/aura/test/test_windows.h" | |
| 18 #include "ui/aura/window.h" | |
| 19 #include "ui/events/test/event_generator.h" | |
| 20 | |
| 21 namespace ash { | |
| 22 | |
| 23 namespace { | |
| 24 const int kMinimalCenteredAppListMargin = 10; | |
| 25 } | |
| 26 | |
| 27 // The parameter is true to test the centered app list, false for normal. | |
| 28 // (The test name ends in "/0" for normal, "/1" for centered.) | |
| 29 class AppListShowerDelegateTest : public test::AshTestBase, | |
| 30 public ::testing::WithParamInterface<bool> { | |
| 31 public: | |
| 32 AppListShowerDelegateTest(); | |
| 33 virtual ~AppListShowerDelegateTest(); | |
| 34 | |
| 35 // testing::Test: | |
| 36 void SetUp() override; | |
| 37 | |
| 38 app_list::AppListShowerImpl* GetAppListShower(); | |
| 39 bool IsCentered() const; | |
| 40 }; | |
| 41 | |
| 42 AppListShowerDelegateTest::AppListShowerDelegateTest() {} | |
| 43 | |
| 44 AppListShowerDelegateTest::~AppListShowerDelegateTest() {} | |
| 45 | |
| 46 void AppListShowerDelegateTest::SetUp() { | |
| 47 AshTestBase::SetUp(); | |
| 48 if (IsCentered()) { | |
| 49 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 50 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList); | |
| 51 } | |
| 52 | |
| 53 // Make the display big enough to hold the experimental app list. | |
| 54 UpdateDisplay("1024x768"); | |
| 55 } | |
| 56 | |
| 57 app_list::AppListShowerImpl* AppListShowerDelegateTest::GetAppListShower() { | |
| 58 return ash_test_helper()->test_shell_delegate()->app_list_shower(); | |
| 59 } | |
| 60 | |
| 61 bool AppListShowerDelegateTest::IsCentered() const { | |
| 62 return GetParam(); | |
| 63 } | |
| 64 | |
| 65 // Tests that app launcher hides when focus moves to a normal window. | |
| 66 TEST_P(AppListShowerDelegateTest, HideOnFocusOut) { | |
| 67 Shell::GetInstance()->ShowAppList(NULL); | |
| 68 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 69 | |
| 70 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | |
| 71 wm::ActivateWindow(window.get()); | |
| 72 | |
| 73 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 74 } | |
| 75 | |
| 76 // Tests that app launcher remains visible when focus is moved to a different | |
| 77 // window in kShellWindowId_AppListContainer. | |
| 78 TEST_P(AppListShowerDelegateTest, RemainVisibleWhenFocusingToApplistContainer) { | |
| 79 Shell::GetInstance()->ShowAppList(NULL); | |
| 80 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 81 | |
| 82 aura::Window* applist_container = Shell::GetContainer( | |
| 83 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | |
| 84 std::unique_ptr<aura::Window> window( | |
| 85 aura::test::CreateTestWindowWithId(0, applist_container)); | |
| 86 wm::ActivateWindow(window.get()); | |
| 87 | |
| 88 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 89 } | |
| 90 | |
| 91 // Tests that clicking outside the app-list bubble closes it. | |
| 92 TEST_P(AppListShowerDelegateTest, ClickOutsideBubbleClosesBubble) { | |
| 93 Shell* shell = Shell::GetInstance(); | |
| 94 shell->ShowAppList(NULL); | |
| 95 aura::Window* app_window = GetAppListShower()->GetWindow(); | |
| 96 ASSERT_TRUE(app_window); | |
| 97 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow(), app_window); | |
| 98 // Click on the bubble itself. The bubble should remain visible. | |
| 99 generator.ClickLeftButton(); | |
| 100 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | |
| 101 | |
| 102 // Click outside the bubble. This should close it. | |
| 103 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | |
| 104 gfx::Point point_outside = | |
| 105 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | |
| 106 gfx::Vector2d(10, 0); | |
| 107 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); | |
| 108 generator.MoveMouseToInHost(point_outside); | |
| 109 generator.ClickLeftButton(); | |
| 110 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | |
| 111 } | |
| 112 | |
| 113 // Tests that clicking outside the app-list bubble closes it. | |
| 114 TEST_P(AppListShowerDelegateTest, TapOutsideBubbleClosesBubble) { | |
| 115 Shell* shell = Shell::GetInstance(); | |
| 116 shell->ShowAppList(NULL); | |
| 117 | |
| 118 aura::Window* app_window = GetAppListShower()->GetWindow(); | |
| 119 ASSERT_TRUE(app_window); | |
| 120 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | |
| 121 | |
| 122 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow()); | |
| 123 // Click on the bubble itself. The bubble should remain visible. | |
| 124 generator.GestureTapAt(app_window_bounds.CenterPoint()); | |
| 125 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | |
| 126 | |
| 127 // Click outside the bubble. This should close it. | |
| 128 gfx::Point point_outside = | |
| 129 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | |
| 130 gfx::Vector2d(10, 0); | |
| 131 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); | |
| 132 generator.GestureTapAt(point_outside); | |
| 133 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | |
| 134 } | |
| 135 | |
| 136 // Tests opening the app launcher on a non-primary display, then deleting the | |
| 137 // display. | |
| 138 TEST_P(AppListShowerDelegateTest, NonPrimaryDisplay) { | |
| 139 if (!SupportsMultipleDisplays()) | |
| 140 return; | |
| 141 | |
| 142 // Set up a screen with two displays (horizontally adjacent). | |
| 143 UpdateDisplay("1024x768,1024x768"); | |
| 144 | |
| 145 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
| 146 ASSERT_EQ(2u, root_windows.size()); | |
| 147 aura::Window* secondary_window = root_windows[1]; | |
| 148 EXPECT_EQ("1024,0 1024x768", | |
| 149 secondary_window->GetBoundsInScreen().ToString()); | |
| 150 | |
| 151 Shell::GetInstance()->ShowAppList(secondary_window); | |
| 152 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 153 | |
| 154 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | |
| 155 UpdateDisplay("1024x768"); | |
| 156 | |
| 157 // Updating the displays should close the app list. | |
| 158 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 159 } | |
| 160 | |
| 161 // Tests opening the app launcher on a tiny display that is too small to contain | |
| 162 // it. | |
| 163 TEST_P(AppListShowerDelegateTest, TinyDisplay) { | |
| 164 // Don't test this for the non-centered app list case; it isn't designed for | |
| 165 // small displays. The most common case of a small display --- when the | |
| 166 // virtual keyboard is open --- switches into the centered app list mode, so | |
| 167 // we just want to run this test in that case. | |
| 168 if (!IsCentered()) | |
| 169 return; | |
| 170 | |
| 171 // UpdateDisplay is not supported in this case, so just skip the test. | |
| 172 if (!SupportsHostWindowResize()) | |
| 173 return; | |
| 174 | |
| 175 // Set up a screen with a tiny display (height smaller than the app list). | |
| 176 UpdateDisplay("400x300"); | |
| 177 | |
| 178 Shell::GetInstance()->ShowAppList(NULL); | |
| 179 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 180 | |
| 181 // The top of the app list should be on-screen (even if the bottom is not). | |
| 182 // We need to manually calculate the Y coordinate of the top of the app list | |
| 183 // from the anchor (center) and height. There isn't a bounds rect that gives | |
| 184 // the actual app list position (the widget bounds include the bubble border | |
| 185 // which is much bigger than the actual app list size). | |
| 186 app_list::AppListView* app_list = GetAppListShower()->GetView(); | |
| 187 int app_list_view_top = | |
| 188 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | |
| 189 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); | |
| 190 } | |
| 191 | |
| 192 INSTANTIATE_TEST_CASE_P(AppListShowerDelegateTestInstance, | |
| 193 AppListShowerDelegateTest, | |
| 194 ::testing::Bool()); | |
| 195 | |
| 196 } // namespace ash | |
| OLD | NEW |