Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ash/app_list/app_list_presenter_delegate_unittest.cc

Issue 2342773002: Removed experimental app list flags. Experimental is now the only way. (Closed)
Patch Set: Rebase on CL 2341113003. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/app/generated_resources.grd » ('j') | chrome/browser/about_flags.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/shell_window_ids.h" 7 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "ash/common/wm_window.h" 9 #include "ash/common/wm_window.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/ash_test_helper.h" 12 #include "ash/test/ash_test_helper.h"
13 #include "ash/test/test_shell_delegate.h" 13 #include "ash/test/test_shell_delegate.h"
14 #include "ash/wm/window_util.h" 14 #include "ash/wm/window_util.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "ui/app_list/app_list_switches.h" 16 #include "ui/app_list/app_list_switches.h"
17 #include "ui/app_list/presenter/app_list_presenter_impl.h" 17 #include "ui/app_list/presenter/app_list_presenter_impl.h"
18 #include "ui/app_list/views/app_list_view.h" 18 #include "ui/app_list/views/app_list_view.h"
19 #include "ui/aura/test/test_windows.h" 19 #include "ui/aura/test/test_windows.h"
20 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
21 #include "ui/events/test/event_generator.h" 21 #include "ui/events/test/event_generator.h"
22 22
23 namespace ash { 23 namespace ash {
24 24
25 namespace { 25 namespace {
26 const int kMinimalCenteredAppListMargin = 10; 26 const int kMinimalAppListMargin = 10;
27 } 27 }
28 28
29 // The parameter is true to test the centered app list, false for normal. 29 class AppListPresenterDelegateTest : public test::AshTestBase {
30 // (The test name ends in "/0" for normal, "/1" for centered.)
31 class AppListPresenterDelegateTest
32 : public test::AshTestBase,
33 public ::testing::WithParamInterface<bool> {
34 public: 30 public:
35 AppListPresenterDelegateTest(); 31 AppListPresenterDelegateTest();
36 virtual ~AppListPresenterDelegateTest(); 32 ~AppListPresenterDelegateTest() override;
37 33
38 // testing::Test: 34 // testing::Test:
39 void SetUp() override; 35 void SetUp() override;
40 36
41 app_list::AppListPresenterImpl* GetAppListPresenter(); 37 app_list::AppListPresenterImpl* GetAppListPresenter();
42 bool IsCentered() const;
43 }; 38 };
44 39
45 AppListPresenterDelegateTest::AppListPresenterDelegateTest() {} 40 AppListPresenterDelegateTest::AppListPresenterDelegateTest() {}
46 41
47 AppListPresenterDelegateTest::~AppListPresenterDelegateTest() {} 42 AppListPresenterDelegateTest::~AppListPresenterDelegateTest() {}
48 43
49 void AppListPresenterDelegateTest::SetUp() { 44 void AppListPresenterDelegateTest::SetUp() {
50 AshTestBase::SetUp(); 45 AshTestBase::SetUp();
51 if (IsCentered()) {
52 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
53 command_line->AppendSwitch(app_list::switches::kEnableCenteredAppList);
54 }
55 46
56 // Make the display big enough to hold the experimental app list. 47 // Make the display big enough to hold the experimental app list.
James Cook 2016/09/16 15:48:17 nit: remove "experimental"
Matt Giuca 2016/09/19 00:19:56 Done.
57 UpdateDisplay("1024x768"); 48 UpdateDisplay("1024x768");
58 } 49 }
59 50
60 app_list::AppListPresenterImpl* 51 app_list::AppListPresenterImpl*
61 AppListPresenterDelegateTest::GetAppListPresenter() { 52 AppListPresenterDelegateTest::GetAppListPresenter() {
62 return ash_test_helper()->test_shell_delegate()->app_list_presenter(); 53 return ash_test_helper()->test_shell_delegate()->app_list_presenter();
63 } 54 }
64 55
65 bool AppListPresenterDelegateTest::IsCentered() const {
66 return GetParam();
67 }
68
69 // 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.
70 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { 57 TEST_F(AppListPresenterDelegateTest, HideOnFocusOut) {
71 WmShell::Get()->ShowAppList(); 58 WmShell::Get()->ShowAppList();
72 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 59 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility());
73 60
74 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 61 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
75 wm::ActivateWindow(window.get()); 62 wm::ActivateWindow(window.get());
76 63
77 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); 64 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility());
78 } 65 }
79 66
80 // 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
81 // window in kShellWindowId_AppListContainer. 68 // window in kShellWindowId_AppListContainer.
82 TEST_P(AppListPresenterDelegateTest, 69 TEST_F(AppListPresenterDelegateTest,
83 RemainVisibleWhenFocusingToApplistContainer) { 70 RemainVisibleWhenFocusingToApplistContainer) {
84 WmShell::Get()->ShowAppList(); 71 WmShell::Get()->ShowAppList();
85 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 72 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility());
86 73
87 aura::Window* applist_container = Shell::GetContainer( 74 aura::Window* applist_container = Shell::GetContainer(
88 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); 75 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer);
89 std::unique_ptr<aura::Window> window( 76 std::unique_ptr<aura::Window> window(
90 aura::test::CreateTestWindowWithId(0, applist_container)); 77 aura::test::CreateTestWindowWithId(0, applist_container));
91 wm::ActivateWindow(window.get()); 78 wm::ActivateWindow(window.get());
92 79
93 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 80 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility());
94 } 81 }
95 82
96 // Tests that clicking outside the app-list bubble closes it. 83 // Tests that clicking outside the app-list bubble closes it.
97 TEST_P(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { 84 TEST_F(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) {
98 WmShell::Get()->ShowAppList(); 85 WmShell::Get()->ShowAppList();
99 aura::Window* app_window = GetAppListPresenter()->GetWindow(); 86 aura::Window* app_window = GetAppListPresenter()->GetWindow();
100 ASSERT_TRUE(app_window); 87 ASSERT_TRUE(app_window);
101 ui::test::EventGenerator& generator = GetEventGenerator(); 88 ui::test::EventGenerator& generator = GetEventGenerator();
102 // Click on the bubble itself. The bubble should remain visible. 89 // Click on the bubble itself. The bubble should remain visible.
103 generator.MoveMouseToCenterOf(app_window); 90 generator.MoveMouseToCenterOf(app_window);
104 generator.ClickLeftButton(); 91 generator.ClickLeftButton();
105 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 92 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility());
106 93
107 // Click outside the bubble. This should close it. 94 // Click outside the bubble. This should close it.
108 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); 95 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
109 gfx::Point point_outside = 96 gfx::Point point_outside =
110 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + 97 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) +
111 gfx::Vector2d(10, 0); 98 gfx::Vector2d(10, 0);
112 generator.MoveMouseToInHost(point_outside); 99 generator.MoveMouseToInHost(point_outside);
113 generator.ClickLeftButton(); 100 generator.ClickLeftButton();
114 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); 101 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility());
115 } 102 }
116 103
117 // Tests that clicking outside the app-list bubble closes it. 104 // Tests that clicking outside the app-list bubble closes it.
118 TEST_P(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { 105 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) {
119 WmShell::Get()->ShowAppList(); 106 WmShell::Get()->ShowAppList();
120 107
121 aura::Window* app_window = GetAppListPresenter()->GetWindow(); 108 aura::Window* app_window = GetAppListPresenter()->GetWindow();
122 ASSERT_TRUE(app_window); 109 ASSERT_TRUE(app_window);
123 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); 110 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
124 111
125 ui::test::EventGenerator& generator = GetEventGenerator(); 112 ui::test::EventGenerator& generator = GetEventGenerator();
126 // Click on the bubble itself. The bubble should remain visible. 113 // Click on the bubble itself. The bubble should remain visible.
127 generator.GestureTapAt(app_window_bounds.CenterPoint()); 114 generator.GestureTapAt(app_window_bounds.CenterPoint());
128 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 115 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility());
129 116
130 // Click outside the bubble. This should close it. 117 // Click outside the bubble. This should close it.
131 gfx::Point point_outside = 118 gfx::Point point_outside =
132 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + 119 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) +
133 gfx::Vector2d(10, 0); 120 gfx::Vector2d(10, 0);
134 generator.GestureTapAt(point_outside); 121 generator.GestureTapAt(point_outside);
135 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); 122 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility());
136 } 123 }
137 124
138 // Tests opening the app launcher on a non-primary display, then deleting the 125 // Tests opening the app launcher on a non-primary display, then deleting the
139 // display. 126 // display.
140 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) { 127 TEST_F(AppListPresenterDelegateTest, NonPrimaryDisplay) {
141 if (!SupportsMultipleDisplays()) 128 if (!SupportsMultipleDisplays())
142 return; 129 return;
143 130
144 // Set up a screen with two displays (horizontally adjacent). 131 // Set up a screen with two displays (horizontally adjacent).
145 UpdateDisplay("1024x768,1024x768"); 132 UpdateDisplay("1024x768,1024x768");
146 133
147 std::vector<WmWindow*> root_windows = WmShell::Get()->GetAllRootWindows(); 134 std::vector<WmWindow*> root_windows = WmShell::Get()->GetAllRootWindows();
148 ASSERT_EQ(2u, root_windows.size()); 135 ASSERT_EQ(2u, root_windows.size());
149 WmWindow* secondary_root = root_windows[1]; 136 WmWindow* secondary_root = root_windows[1];
150 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); 137 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString());
151 138
152 WmShell::Get()->delegate()->GetAppListPresenter()->Show( 139 WmShell::Get()->delegate()->GetAppListPresenter()->Show(
153 secondary_root->GetDisplayNearestWindow().id()); 140 secondary_root->GetDisplayNearestWindow().id());
154 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 141 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility());
155 142
156 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990). 143 // Remove the secondary display. Shouldn't crash (http://crbug.com/368990).
157 UpdateDisplay("1024x768"); 144 UpdateDisplay("1024x768");
158 145
159 // Updating the displays should close the app list. 146 // Updating the displays should close the app list.
160 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); 147 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility());
161 } 148 }
162 149
163 // Tests opening the app launcher on a tiny display that is too small to contain 150 // Tests opening the app launcher on a tiny display that is too small to contain
164 // it. 151 // it.
165 TEST_P(AppListPresenterDelegateTest, TinyDisplay) { 152 TEST_F(AppListPresenterDelegateTest, TinyDisplay) {
166 // Don't test this for the non-centered app list case; it isn't designed for
167 // small displays. The most common case of a small display --- when the
168 // virtual keyboard is open --- switches into the centered app list mode, so
169 // we just want to run this test in that case.
170 if (!IsCentered())
171 return;
172
173 // UpdateDisplay is not supported in this case, so just skip the test. 153 // UpdateDisplay is not supported in this case, so just skip the test.
174 if (!SupportsHostWindowResize()) 154 if (!SupportsHostWindowResize())
175 return; 155 return;
176 156
177 // Set up a screen with a tiny display (height smaller than the app list). 157 // Set up a screen with a tiny display (height smaller than the app list).
178 UpdateDisplay("400x300"); 158 UpdateDisplay("400x300");
179 159
180 WmShell::Get()->ShowAppList(); 160 WmShell::Get()->ShowAppList();
181 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 161 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility());
182 162
183 // The top of the app list should be on-screen (even if the bottom is not). 163 // The top of the app list should be on-screen (even if the bottom is not).
184 // We need to manually calculate the Y coordinate of the top of the app list 164 // We need to manually calculate the Y coordinate of the top of the app list
185 // from the anchor (center) and height. There isn't a bounds rect that gives 165 // from the anchor (center) and height. There isn't a bounds rect that gives
186 // the actual app list position (the widget bounds include the bubble border 166 // the actual app list position (the widget bounds include the bubble border
187 // which is much bigger than the actual app list size). 167 // which is much bigger than the actual app list size).
188 app_list::AppListView* app_list = GetAppListPresenter()->GetView(); 168 app_list::AppListView* app_list = GetAppListPresenter()->GetView();
189 int app_list_view_top = 169 int app_list_view_top =
190 app_list->anchor_rect().y() - app_list->bounds().height() / 2; 170 app_list->anchor_rect().y() - app_list->bounds().height() / 2;
191 EXPECT_GE(app_list_view_top, kMinimalCenteredAppListMargin); 171 EXPECT_GE(app_list_view_top, kMinimalAppListMargin);
192 } 172 }
193 173
194 INSTANTIATE_TEST_CASE_P(AppListPresenterDelegateTestInstance,
195 AppListPresenterDelegateTest,
196 ::testing::Bool());
197
198 } // namespace ash 174 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | chrome/app/generated_resources.grd » ('j') | chrome/browser/about_flags.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698