| 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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList); | 48 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool AppListControllerTest::IsCentered() const { | 52 bool AppListControllerTest::IsCentered() const { |
| 53 return GetParam(); | 53 return GetParam(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // 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. |
| 57 TEST_P(AppListControllerTest, HideOnFocusOut) { | 57 TEST_P(AppListControllerTest, HideOnFocusOut) { |
| 58 Shell::GetInstance()->ToggleAppList(NULL); | 58 Shell::GetInstance()->ShowAppList(NULL); |
| 59 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 59 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 60 | 60 |
| 61 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 61 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 62 wm::ActivateWindow(window.get()); | 62 wm::ActivateWindow(window.get()); |
| 63 | 63 |
| 64 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 64 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Tests that app launcher remains visible when focus is moved to a different | 67 // Tests that app launcher remains visible when focus is moved to a different |
| 68 // window in kShellWindowId_AppListContainer. | 68 // window in kShellWindowId_AppListContainer. |
| 69 TEST_P(AppListControllerTest, RemainVisibleWhenFocusingToApplistContainer) { | 69 TEST_P(AppListControllerTest, RemainVisibleWhenFocusingToApplistContainer) { |
| 70 Shell::GetInstance()->ToggleAppList(NULL); | 70 Shell::GetInstance()->ShowAppList(NULL); |
| 71 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 71 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 72 | 72 |
| 73 aura::Window* applist_container = Shell::GetContainer( | 73 aura::Window* applist_container = Shell::GetContainer( |
| 74 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 74 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |
| 75 scoped_ptr<aura::Window> window( | 75 scoped_ptr<aura::Window> window( |
| 76 aura::test::CreateTestWindowWithId(0, applist_container)); | 76 aura::test::CreateTestWindowWithId(0, applist_container)); |
| 77 wm::ActivateWindow(window.get()); | 77 wm::ActivateWindow(window.get()); |
| 78 | 78 |
| 79 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 79 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Tests that clicking outside the app-list bubble closes it. | 82 // Tests that clicking outside the app-list bubble closes it. |
| 83 TEST_P(AppListControllerTest, ClickOutsideBubbleClosesBubble) { | 83 TEST_P(AppListControllerTest, ClickOutsideBubbleClosesBubble) { |
| 84 Shell* shell = Shell::GetInstance(); | 84 Shell* shell = Shell::GetInstance(); |
| 85 shell->ToggleAppList(NULL); | 85 shell->ShowAppList(NULL); |
| 86 | 86 |
| 87 aura::Window* app_window = shell->GetAppListWindow(); | 87 aura::Window* app_window = shell->GetAppListWindow(); |
| 88 ASSERT_TRUE(app_window); | 88 ASSERT_TRUE(app_window); |
| 89 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow(), app_window); | 89 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow(), app_window); |
| 90 // Click on the bubble itself. The bubble should remain visible. | 90 // Click on the bubble itself. The bubble should remain visible. |
| 91 generator.ClickLeftButton(); | 91 generator.ClickLeftButton(); |
| 92 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 92 EXPECT_TRUE(shell->GetAppListTargetVisibility()); |
| 93 | 93 |
| 94 // Click outside the bubble. This should close it. | 94 // Click outside the bubble. This should close it. |
| 95 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 95 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
| 96 gfx::Point point_outside = | 96 gfx::Point point_outside = |
| 97 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 97 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
| 98 gfx::Vector2d(10, 0); | 98 gfx::Vector2d(10, 0); |
| 99 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); | 99 EXPECT_TRUE(shell->GetPrimaryRootWindow()->bounds().Contains(point_outside)); |
| 100 generator.MoveMouseToInHost(point_outside); | 100 generator.MoveMouseToInHost(point_outside); |
| 101 generator.ClickLeftButton(); | 101 generator.ClickLeftButton(); |
| 102 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 102 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Tests that clicking outside the app-list bubble closes it. | 105 // Tests that clicking outside the app-list bubble closes it. |
| 106 TEST_P(AppListControllerTest, TapOutsideBubbleClosesBubble) { | 106 TEST_P(AppListControllerTest, TapOutsideBubbleClosesBubble) { |
| 107 Shell* shell = Shell::GetInstance(); | 107 Shell* shell = Shell::GetInstance(); |
| 108 shell->ToggleAppList(NULL); | 108 shell->ShowAppList(NULL); |
| 109 | 109 |
| 110 aura::Window* app_window = shell->GetAppListWindow(); | 110 aura::Window* app_window = shell->GetAppListWindow(); |
| 111 ASSERT_TRUE(app_window); | 111 ASSERT_TRUE(app_window); |
| 112 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); | 112 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); |
| 113 | 113 |
| 114 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow()); | 114 ui::test::EventGenerator generator(shell->GetPrimaryRootWindow()); |
| 115 // Click on the bubble itself. The bubble should remain visible. | 115 // Click on the bubble itself. The bubble should remain visible. |
| 116 generator.GestureTapAt(app_window_bounds.CenterPoint()); | 116 generator.GestureTapAt(app_window_bounds.CenterPoint()); |
| 117 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 117 EXPECT_TRUE(shell->GetAppListTargetVisibility()); |
| 118 | 118 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 // Set up a screen with two displays (horizontally adjacent). | 134 // Set up a screen with two displays (horizontally adjacent). |
| 135 UpdateDisplay("800x600,800x600"); | 135 UpdateDisplay("800x600,800x600"); |
| 136 | 136 |
| 137 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 137 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 138 ASSERT_EQ(2u, root_windows.size()); | 138 ASSERT_EQ(2u, root_windows.size()); |
| 139 aura::Window* secondary_window = root_windows[1]; | 139 aura::Window* secondary_window = root_windows[1]; |
| 140 EXPECT_EQ("800,0 800x600", secondary_window->GetBoundsInScreen().ToString()); | 140 EXPECT_EQ("800,0 800x600", secondary_window->GetBoundsInScreen().ToString()); |
| 141 | 141 |
| 142 Shell::GetInstance()->ToggleAppList(secondary_window); | 142 Shell::GetInstance()->ShowAppList(secondary_window); |
| 143 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 143 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 144 | 144 |
| 145 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). | 145 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). |
| 146 UpdateDisplay("800x600"); | 146 UpdateDisplay("800x600"); |
| 147 | 147 |
| 148 // Updating the displays should close the app list. | 148 // Updating the displays should close the app list. |
| 149 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | 149 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Tests opening the app launcher on a tiny display that is too small to contain | 152 // Tests opening the app launcher on a tiny display that is too small to contain |
| 153 // it. | 153 // it. |
| 154 TEST_P(AppListControllerTest, TinyDisplay) { | 154 TEST_P(AppListControllerTest, TinyDisplay) { |
| 155 // Don't test this for the non-centered app list case; it isn't designed for | 155 // Don't test this for the non-centered app list case; it isn't designed for |
| 156 // small displays. The most common case of a small display --- when the | 156 // small displays. The most common case of a small display --- when the |
| 157 // virtual keyboard is open --- switches into the centered app list mode, so | 157 // virtual keyboard is open --- switches into the centered app list mode, so |
| 158 // we just want to run this test in that case. | 158 // we just want to run this test in that case. |
| 159 if (!IsCentered()) | 159 if (!IsCentered()) |
| 160 return; | 160 return; |
| 161 | 161 |
| 162 // UpdateDisplay is not supported in this case, so just skip the test. | 162 // UpdateDisplay is not supported in this case, so just skip the test. |
| 163 if (!SupportsHostWindowResize()) | 163 if (!SupportsHostWindowResize()) |
| 164 return; | 164 return; |
| 165 | 165 |
| 166 // Set up a screen with a tiny display (height smaller than the app list). | 166 // Set up a screen with a tiny display (height smaller than the app list). |
| 167 UpdateDisplay("400x300"); | 167 UpdateDisplay("400x300"); |
| 168 | 168 |
| 169 Shell::GetInstance()->ToggleAppList(NULL); | 169 Shell::GetInstance()->ShowAppList(NULL); |
| 170 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | 170 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); |
| 171 | 171 |
| 172 // The top of the app list should be on-screen (even if the bottom is not). | 172 // The top of the app list should be on-screen (even if the bottom is not). |
| 173 // We need to manually calculate the Y coordinate of the top of the app list | 173 // We need to manually calculate the Y coordinate of the top of the app list |
| 174 // from the anchor (center) and height. There isn't a bounds rect that gives | 174 // from the anchor (center) and height. There isn't a bounds rect that gives |
| 175 // the actual app list position (the widget bounds include the bubble border | 175 // the actual app list position (the widget bounds include the bubble border |
| 176 // which is much bigger than the actual app list size). | 176 // which is much bigger than the actual app list size). |
| 177 app_list::AppListView* app_list = Shell::GetInstance()->GetAppListView(); | 177 app_list::AppListView* app_list = Shell::GetInstance()->GetAppListView(); |
| 178 int app_list_view_top = | 178 int app_list_view_top = |
| 179 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 179 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
| 180 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); | 180 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); |
| 181 } | 181 } |
| 182 | 182 |
| 183 INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance, | 183 INSTANTIATE_TEST_CASE_P(AppListControllerTestInstance, |
| 184 AppListControllerTest, | 184 AppListControllerTest, |
| 185 ::testing::Bool()); | 185 ::testing::Bool()); |
| 186 | 186 |
| 187 } // namespace ash | 187 } // namespace ash |
| OLD | NEW |