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