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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "ash/ash_switches.h" | |
8 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
9 #include "ash/shell.h" | 8 #include "ash/shell.h" |
10 #include "ash/shell_port.h" | 9 #include "ash/shell_port.h" |
11 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
12 #include "ash/test/test_app_list_view_presenter_impl.h" | 11 #include "ash/test/test_app_list_view_presenter_impl.h" |
13 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
14 #include "ash/wm_window.h" | 13 #include "ash/wm_window.h" |
15 #include "base/command_line.h" | |
16 #include "base/macros.h" | 14 #include "base/macros.h" |
17 #include "ui/app_list/app_list_switches.h" | |
18 #include "ui/app_list/views/app_list_view.h" | 15 #include "ui/app_list/views/app_list_view.h" |
19 #include "ui/aura/test/test_windows.h" | 16 #include "ui/aura/test/test_windows.h" |
20 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
21 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
22 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
23 #include "ui/events/test/event_generator.h" | 20 #include "ui/events/test/event_generator.h" |
24 | 21 |
25 namespace ash { | 22 namespace ash { |
26 namespace { | 23 namespace { |
27 | 24 |
28 int64_t GetPrimaryDisplayId() { | 25 int64_t GetPrimaryDisplayId() { |
29 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 26 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
30 } | 27 } |
31 | 28 |
32 void SetFullscreenAppListSwitch() { | |
33 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
34 app_list::switches::kEnableFullscreenAppList); | |
35 } | |
36 | |
37 } // namespace | 29 } // namespace |
38 | 30 |
39 class AppListPresenterDelegateTest : public test::AshTestBase, | 31 class AppListPresenterDelegateTest : public test::AshTestBase { |
40 public testing::WithParamInterface<bool> { | |
41 public: | 32 public: |
42 AppListPresenterDelegateTest() {} | 33 AppListPresenterDelegateTest() {} |
43 ~AppListPresenterDelegateTest() override {} | 34 ~AppListPresenterDelegateTest() override {} |
44 | 35 |
45 app_list::AppListPresenterImpl* app_list_presenter_impl() { | 36 app_list::AppListPresenterImpl* app_list_presenter_impl() { |
46 return &app_list_presenter_impl_; | 37 return &app_list_presenter_impl_; |
47 } | 38 } |
48 | 39 |
49 // testing::Test: | 40 // testing::Test: |
50 void SetUp() override { | 41 void SetUp() override { |
51 AshTestBase::SetUp(); | 42 AshTestBase::SetUp(); |
52 | 43 |
53 // If the current test is parameterized. | |
54 if (testing::UnitTest::GetInstance()->current_test_info()->value_param()) { | |
55 test_with_fullscreen_ = GetParam(); | |
56 if (test_with_fullscreen_) | |
57 SetFullscreenAppListSwitch(); | |
58 } | |
59 // Make the display big enough to hold the app list. | 44 // Make the display big enough to hold the app list. |
60 UpdateDisplay("1024x768"); | 45 UpdateDisplay("1024x768"); |
61 } | 46 } |
62 | 47 |
63 private: | 48 private: |
64 test::TestAppListViewPresenterImpl app_list_presenter_impl_; | 49 test::TestAppListViewPresenterImpl app_list_presenter_impl_; |
65 bool test_with_fullscreen_; | |
66 | 50 |
67 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); | 51 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); |
68 }; | 52 }; |
69 | 53 |
70 // Instantiate the Boolean which is used to toggle the Fullscreen app list in | |
71 // the parameterized tests. | |
72 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool()); | |
73 | |
74 // Tests that app launcher hides when focus moves to a normal window. | 54 // Tests that app launcher hides when focus moves to a normal window. |
75 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { | 55 TEST_F(AppListPresenterDelegateTest, HideOnFocusOut) { |
76 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 56 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
77 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 57 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
78 | 58 |
79 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 59 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
80 wm::ActivateWindow(window.get()); | 60 wm::ActivateWindow(window.get()); |
81 | 61 |
82 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 62 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
83 } | 63 } |
84 | 64 |
85 // Tests that app launcher remains visible when focus is moved to a different | 65 // Tests that app launcher remains visible when focus is moved to a different |
86 // window in kShellWindowId_AppListContainer. | 66 // window in kShellWindowId_AppListContainer. |
87 TEST_P(AppListPresenterDelegateTest, | 67 TEST_F(AppListPresenterDelegateTest, |
88 RemainVisibleWhenFocusingToApplistContainer) { | 68 RemainVisibleWhenFocusingToApplistContainer) { |
89 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 69 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
90 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 70 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
91 | 71 |
92 aura::Window* applist_container = Shell::GetContainer( | 72 aura::Window* applist_container = Shell::GetContainer( |
93 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); | 73 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); |
94 std::unique_ptr<aura::Window> window( | 74 std::unique_ptr<aura::Window> window( |
95 aura::test::CreateTestWindowWithId(0, applist_container)); | 75 aura::test::CreateTestWindowWithId(0, applist_container)); |
96 wm::ActivateWindow(window.get()); | 76 wm::ActivateWindow(window.get()); |
97 | 77 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Click outside the bubble. This should close it. | 115 // Click outside the bubble. This should close it. |
136 gfx::Point point_outside = | 116 gfx::Point point_outside = |
137 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + | 117 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + |
138 gfx::Vector2d(10, 0); | 118 gfx::Vector2d(10, 0); |
139 generator.GestureTapAt(point_outside); | 119 generator.GestureTapAt(point_outside); |
140 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); | 120 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); |
141 } | 121 } |
142 | 122 |
143 // Tests opening the app launcher on a non-primary display, then deleting the | 123 // Tests opening the app launcher on a non-primary display, then deleting the |
144 // display. | 124 // display. |
145 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { | 125 TEST_F(AppListPresenterDelegateTest, NonPrimaryDisplay) { |
146 // Set up a screen with two displays (horizontally adjacent). | 126 // Set up a screen with two displays (horizontally adjacent). |
147 UpdateDisplay("1024x768,1024x768"); | 127 UpdateDisplay("1024x768,1024x768"); |
148 | 128 |
149 std::vector<WmWindow*> root_windows = ShellPort::Get()->GetAllRootWindows(); | 129 std::vector<WmWindow*> root_windows = ShellPort::Get()->GetAllRootWindows(); |
150 ASSERT_EQ(2u, root_windows.size()); | 130 ASSERT_EQ(2u, root_windows.size()); |
151 WmWindow* secondary_root = root_windows[1]; | 131 WmWindow* secondary_root = root_windows[1]; |
152 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); | 132 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); |
153 | 133 |
154 app_list_presenter_impl()->Show( | 134 app_list_presenter_impl()->Show( |
155 secondary_root->GetDisplayNearestWindow().id()); | 135 secondary_root->GetDisplayNearestWindow().id()); |
(...skipping 13 matching lines...) Expand all Loading... |
169 UpdateDisplay("400x300"); | 149 UpdateDisplay("400x300"); |
170 | 150 |
171 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); | 151 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); |
172 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); | 152 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); |
173 | 153 |
174 // The top of the app list should be on-screen (even if the bottom is not). | 154 // The top of the app list should be on-screen (even if the bottom is not). |
175 // We need to manually calculate the Y coordinate of the top of the app list | 155 // We need to manually calculate the Y coordinate of the top of the app list |
176 // from the anchor (center) and height. There isn't a bounds rect that gives | 156 // from the anchor (center) and height. There isn't a bounds rect that gives |
177 // the actual app list position (the widget bounds include the bubble border | 157 // the actual app list position (the widget bounds include the bubble border |
178 // which is much bigger than the actual app list size). | 158 // which is much bigger than the actual app list size). |
179 | |
180 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); | 159 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); |
181 int app_list_view_top = | 160 int app_list_view_top = |
182 app_list->anchor_rect().y() - app_list->bounds().height() / 2; | 161 app_list->anchor_rect().y() - app_list->bounds().height() / 2; |
183 const int kMinimalAppListMargin = 10; | 162 const int kMinimalAppListMargin = 10; |
184 | |
185 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); | 163 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); |
186 } | 164 } |
187 | 165 |
188 } // namespace ash | 166 } // namespace ash |
OLD | NEW |