| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/shell.h" | 5 #include "ash/shell.h" |
| 6 #include "ash/shell_window_ids.h" | 6 #include "ash/shell_window_ids.h" |
| 7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 8 #include "ash/test/test_shell_delegate.h" | 8 #include "ash/test/test_shell_delegate.h" |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "ui/app_list/app_list_switches.h" | 12 #include "ui/app_list/app_list_switches.h" |
| 13 #include "ui/app_list/views/app_list_view.h" |
| 13 #include "ui/aura/test/event_generator.h" | 14 #include "ui/aura/test/event_generator.h" |
| 14 #include "ui/aura/test/test_windows.h" | 15 #include "ui/aura/test/test_windows.h" |
| 15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 | 19 |
| 20 namespace { |
| 21 |
| 22 const int kMinimalCenteredAppListMargin = 10; |
| 23 |
| 24 } |
| 25 |
| 19 // The parameter is true to test the centered app list, false for normal. | 26 // The parameter is true to test the centered app list, false for normal. |
| 20 // (The test name ends in "/0" for normal, "/1" for centered.) | 27 // (The test name ends in "/0" for normal, "/1" for centered.) |
| 21 class AppListControllerTest : public test::AshTestBase, | 28 class AppListControllerTest : public test::AshTestBase, |
| 22 public ::testing::WithParamInterface<bool> { | 29 public ::testing::WithParamInterface<bool> { |
| 23 public: | 30 public: |
| 24 AppListControllerTest(); | 31 AppListControllerTest(); |
| 25 virtual ~AppListControllerTest(); | 32 virtual ~AppListControllerTest(); |
| 26 virtual void SetUp() OVERRIDE; | 33 virtual void SetUp() OVERRIDE; |
| 34 |
| 35 bool IsCentered() const; |
| 27 }; | 36 }; |
| 28 | 37 |
| 29 AppListControllerTest::AppListControllerTest() { | 38 AppListControllerTest::AppListControllerTest() { |
| 30 } | 39 } |
| 31 | 40 |
| 32 AppListControllerTest::~AppListControllerTest() { | 41 AppListControllerTest::~AppListControllerTest() { |
| 33 } | 42 } |
| 34 | 43 |
| 35 void AppListControllerTest::SetUp() { | 44 void AppListControllerTest::SetUp() { |
| 36 AshTestBase::SetUp(); | 45 AshTestBase::SetUp(); |
| 37 if (GetParam()) { | 46 if (IsCentered()) { |
| 38 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 47 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 39 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList); | 48 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList); |
| 40 } | 49 } |
| 41 } | 50 } |
| 42 | 51 |
| 52 bool AppListControllerTest::IsCentered() const { |
| 53 return GetParam(); |
| 54 } |
| 55 |
| 43 // Tests that app launcher hides when focus moves to a normal window. | 56 // Tests that app launcher hides when focus moves to a normal window. |
| 44 TEST_P(AppListControllerTest, HideOnFocusOut) { | 57 TEST_P(AppListControllerTest, HideOnFocusOut) { |
| 45 Shell::GetInstance()->ToggleAppList(NULL); | 58 Shell::GetInstance()->ToggleAppList(NULL); |
| 46 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 59 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 47 | 60 |
| 48 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 61 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 49 wm::ActivateWindow(window.get()); | 62 wm::ActivateWindow(window.get()); |
| 50 | 63 |
| 51 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 64 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 52 } | 65 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 Shell::GetInstance()->ToggleAppList(secondary_window); | 143 Shell::GetInstance()->ToggleAppList(secondary_window); |
| 131 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 144 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 132 | 145 |
| 133 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | 146 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). |
| 134 UpdateDisplay("800x600"); | 147 UpdateDisplay("800x600"); |
| 135 | 148 |
| 136 // Updating the displays should close the app list. | 149 // Updating the displays should close the app list. |
| 137 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 150 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 138 } | 151 } |
| 139 | 152 |
| 153 // Tests opening the app launcher on a tiny display that is too small to contain |
| 154 // it. |
| 155 TEST_P(AppListControllerTest, TinyDisplay) { |
| 156 // Don't test this for the non-centered app list case; it isn't designed for |
| 157 // small displays. The most common case of a small display --- when the |
| 158 // virtual keyboard is open --- switches into the centered app list mode, so |
| 159 // we just want to run this test in that case. |
| 160 if (!IsCentered()) |
| 161 return; |
| 162 |
| 163 // UpdateDisplay is not supported in this case, so just skip the test. |
| 164 if (!SupportsHostWindowResize()) |
| 165 return; |
| 166 |
| 167 // Set up a screen with a tiny display (height smaller than the app list). |
| 168 UpdateDisplay("400x300"); |
| 169 |
| 170 Shell::GetInstance()->ToggleAppList(NULL); |
| 171 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 172 |
| 173 // The top of the app list should be on-screen (even if the bottom is not). |
| 174 // We need to manually calculate the Y coordinate of the top of the app list |
| 175 // from the anchor (center) and height. There isn't a bounds rect that gives |
| 176 // the actual app list position (the widget bounds include the bubble border |
| 177 // which is much bigger than the actual app list size). |
| 178 app_list::AppListView* app_list = Shell::GetInstance()->GetAppListView(); |
| 179 int app_list_view_top = |
| 180 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
| 181 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); |
| 182 } |
| 183 |
| 140 INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance, | 184 INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance, |
| 141 AppListControllerTest, | 185 AppListControllerTest, |
| 142 ::testing::Bool()); | 186 ::testing::Bool()); |
| 143 | 187 |
| 144 } // namespace ash | 188 } // namespace ash |
| OLD | NEW |