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