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

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

Issue 2802903003: Implementation of a full screen app list and re-alphabetized switches (Closed)
Patch Set: addressed comments, refactored Initialize, modified tests to add test coverage for the fullscreen l… Created 3 years, 8 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
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/ash_switches.h"
7 #include "ash/public/cpp/shell_window_ids.h" 8 #include "ash/public/cpp/shell_window_ids.h"
8 #include "ash/shell.h" 9 #include "ash/shell.h"
9 #include "ash/shell_port.h" 10 #include "ash/shell_port.h"
10 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
11 #include "ash/test/test_app_list_view_presenter_impl.h" 12 #include "ash/test/test_app_list_view_presenter_impl.h"
12 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
13 #include "ash/wm_window.h" 14 #include "ash/wm_window.h"
15 #include "base/command_line.h"
14 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "ui/app_list/app_list_switches.h"
15 #include "ui/app_list/views/app_list_view.h" 18 #include "ui/app_list/views/app_list_view.h"
16 #include "ui/aura/test/test_windows.h" 19 #include "ui/aura/test/test_windows.h"
17 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
18 #include "ui/display/display.h" 21 #include "ui/display/display.h"
19 #include "ui/display/screen.h" 22 #include "ui/display/screen.h"
20 #include "ui/events/test/event_generator.h" 23 #include "ui/events/test/event_generator.h"
21 24
22 namespace ash { 25 namespace ash {
23 namespace { 26 namespace {
24 27
25 int64_t GetPrimaryDisplayId() { 28 int64_t GetPrimaryDisplayId() {
26 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); 29 return display::Screen::GetScreen()->GetPrimaryDisplay().id();
27 } 30 }
28 31
32 void SetFullscreenAppListSwitch() {
vadimt 2017/04/19 00:57:15 You can define it in app_list_switches.h and use e
newcomer 2017/04/20 19:59:01 Done.
vadimt 2017/04/20 20:21:34 Thanks, but I made a mistake :(, I meant the metho
newcomer 2017/04/21 19:51:22 Roger and Done! I moved both functions into app_li
33 base::CommandLine::ForCurrentProcess()->AppendSwitch(
34 app_list::switches::kEnableFullscreenAppList);
35 }
36
29 } // namespace 37 } // namespace
30 38
31 class AppListPresenterDelegateTest : public test::AshTestBase { 39 class AppListPresenterDelegateTest
40 : public test::AshTestBase,
41 public ::testing::WithParamInterface<bool> {
vadimt 2017/04/19 00:57:15 Do we need that '::' before 'testing'?
newcomer 2017/04/20 19:59:01 Done.
32 public: 42 public:
33 AppListPresenterDelegateTest() {} 43 AppListPresenterDelegateTest() {}
34 ~AppListPresenterDelegateTest() override {} 44 ~AppListPresenterDelegateTest() override {}
35 45
36 app_list::AppListPresenterImpl* app_list_presenter_impl() { 46 app_list::AppListPresenterImpl* app_list_presenter_impl() {
37 return &app_list_presenter_impl_; 47 return &app_list_presenter_impl_;
38 } 48 }
39 49
40 // testing::Test: 50 // testing::Test:
41 void SetUp() override { 51 void SetUp() override {
42 AshTestBase::SetUp(); 52 AshTestBase::SetUp();
43 53
44 // Make the display big enough to hold the app list. 54 // Make the display big enough to hold the app list.
45 UpdateDisplay("1024x768"); 55 UpdateDisplay("1024x768");
46 } 56 }
47 57
48 private: 58 private:
49 test::TestAppListViewPresenterImpl app_list_presenter_impl_; 59 test::TestAppListViewPresenterImpl app_list_presenter_impl_;
50 60
51 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); 61 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest);
52 }; 62 };
53 63
64 // Instantiate the Boolean which is used to toggle the Fullscreen app list in
65 // the parameterized tests.
66 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool());
67
54 // Tests that app launcher hides when focus moves to a normal window. 68 // Tests that app launcher hides when focus moves to a normal window.
55 TEST_F(AppListPresenterDelegateTest, HideOnFocusOut) { 69 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) {
70 bool testWithFullscreen = GetParam();
sky 2017/04/19 15:18:51 test_with_fullscreen That said, why don't you conf
newcomer 2017/04/20 19:59:01 Done! Check SetUp().
71 if (testWithFullscreen)
72 SetFullscreenAppListSwitch();
73
56 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 74 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
57 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 75 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
58 76
59 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 77 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
60 wm::ActivateWindow(window.get()); 78 wm::ActivateWindow(window.get());
61 79
62 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); 80 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility());
63 } 81 }
64 82
65 // Tests that app launcher remains visible when focus is moved to a different 83 // Tests that app launcher remains visible when focus is moved to a different
66 // window in kShellWindowId_AppListContainer. 84 // window in kShellWindowId_AppListContainer.
67 TEST_F(AppListPresenterDelegateTest, 85 TEST_P(AppListPresenterDelegateTest,
68 RemainVisibleWhenFocusingToApplistContainer) { 86 RemainVisibleWhenFocusingToApplistContainer) {
87 bool testWithFullscreen = GetParam();
88 if (testWithFullscreen)
89 SetFullscreenAppListSwitch();
90
69 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 91 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
70 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 92 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
71 93
72 aura::Window* applist_container = Shell::GetContainer( 94 aura::Window* applist_container = Shell::GetContainer(
73 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer); 95 Shell::GetPrimaryRootWindow(), kShellWindowId_AppListContainer);
74 std::unique_ptr<aura::Window> window( 96 std::unique_ptr<aura::Window> window(
75 aura::test::CreateTestWindowWithId(0, applist_container)); 97 aura::test::CreateTestWindowWithId(0, applist_container));
76 wm::ActivateWindow(window.get()); 98 wm::ActivateWindow(window.get());
77 99
78 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 100 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
79 } 101 }
80 102
81 // Tests that clicking outside the app-list bubble closes it. 103 // Tests that clicking outside the app-list bubble closes it.
82 TEST_F(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) { 104 TEST_P(AppListPresenterDelegateTest, ClickOutsideBubbleClosesBubble) {
105 bool testWithFullscreen = GetParam();
106 if (testWithFullscreen)
107 SetFullscreenAppListSwitch();
83 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 108 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
84 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); 109 aura::Window* app_window = app_list_presenter_impl()->GetWindow();
85 ASSERT_TRUE(app_window); 110 ASSERT_TRUE(app_window);
86 ui::test::EventGenerator& generator = GetEventGenerator(); 111 ui::test::EventGenerator& generator = GetEventGenerator();
87 // Click on the bubble itself. The bubble should remain visible. 112 // Click on the bubble itself. The bubble should remain visible.
88 generator.MoveMouseToCenterOf(app_window); 113 generator.MoveMouseToCenterOf(app_window);
89 generator.ClickLeftButton(); 114 generator.ClickLeftButton();
90 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 115 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
91 116
92 // Click outside the bubble. This should close it. 117 // Click outside the bubble. This should close it.
93 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); 118 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
94 gfx::Point point_outside = 119 gfx::Point point_outside =
95 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + 120 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) +
96 gfx::Vector2d(10, 0); 121 gfx::Vector2d(10, 0);
97 generator.MoveMouseToInHost(point_outside); 122 generator.MoveMouseToInHost(point_outside);
98 generator.ClickLeftButton(); 123 generator.ClickLeftButton();
99 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); 124 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility());
100 } 125 }
101 126
102 // Tests that clicking outside the app-list bubble closes it. 127 // Tests that clicking outside the app-list bubble closes it.
103 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { 128 TEST_P(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) {
129 bool testWithFullscreen = GetParam();
130 if (testWithFullscreen)
131 SetFullscreenAppListSwitch();
104 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 132 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
105 133
106 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); 134 aura::Window* app_window = app_list_presenter_impl()->GetWindow();
107 ASSERT_TRUE(app_window); 135 ASSERT_TRUE(app_window);
108 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); 136 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
109 137
110 ui::test::EventGenerator& generator = GetEventGenerator(); 138 ui::test::EventGenerator& generator = GetEventGenerator();
111 // Click on the bubble itself. The bubble should remain visible. 139 // Click on the bubble itself. The bubble should remain visible.
112 generator.GestureTapAt(app_window_bounds.CenterPoint()); 140 generator.GestureTapAt(app_window_bounds.CenterPoint());
113 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 141 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
114 142
115 // Click outside the bubble. This should close it. 143 // Click outside the bubble. This should close it.
116 gfx::Point point_outside = 144 gfx::Point point_outside =
117 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + 145 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) +
118 gfx::Vector2d(10, 0); 146 gfx::Vector2d(10, 0);
119 generator.GestureTapAt(point_outside); 147 generator.GestureTapAt(point_outside);
120 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); 148 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility());
121 } 149 }
122 150
123 // Tests opening the app launcher on a non-primary display, then deleting the 151 // Tests opening the app launcher on a non-primary display, then deleting the
124 // display. 152 // display.
125 TEST_F(AppListPresenterDelegateTest, NonPrimaryDisplay) { 153 TEST_P(AppListPresenterDelegateTest, NonPrimaryDisplay) {
126 // Set up a screen with two displays (horizontally adjacent). 154 // Set up a screen with two displays (horizontally adjacent).
155 bool testWithFullscreen = GetParam();
156 if (testWithFullscreen)
157 SetFullscreenAppListSwitch();
158
127 UpdateDisplay("1024x768,1024x768"); 159 UpdateDisplay("1024x768,1024x768");
128 160
129 std::vector<WmWindow*> root_windows = ShellPort::Get()->GetAllRootWindows(); 161 std::vector<WmWindow*> root_windows = ShellPort::Get()->GetAllRootWindows();
130 ASSERT_EQ(2u, root_windows.size()); 162 ASSERT_EQ(2u, root_windows.size());
131 WmWindow* secondary_root = root_windows[1]; 163 WmWindow* secondary_root = root_windows[1];
132 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString()); 164 EXPECT_EQ("1024,0 1024x768", secondary_root->GetBoundsInScreen().ToString());
133 165
134 app_list_presenter_impl()->Show( 166 app_list_presenter_impl()->Show(
135 secondary_root->GetDisplayNearestWindow().id()); 167 secondary_root->GetDisplayNearestWindow().id());
136 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 168 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
(...skipping 12 matching lines...) Expand all
149 UpdateDisplay("400x300"); 181 UpdateDisplay("400x300");
150 182
151 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 183 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
152 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 184 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
153 185
154 // The top of the app list should be on-screen (even if the bottom is not). 186 // The top of the app list should be on-screen (even if the bottom is not).
155 // We need to manually calculate the Y coordinate of the top of the app list 187 // We need to manually calculate the Y coordinate of the top of the app list
156 // from the anchor (center) and height. There isn't a bounds rect that gives 188 // from the anchor (center) and height. There isn't a bounds rect that gives
157 // the actual app list position (the widget bounds include the bubble border 189 // the actual app list position (the widget bounds include the bubble border
158 // which is much bigger than the actual app list size). 190 // which is much bigger than the actual app list size).
191
159 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); 192 app_list::AppListView* app_list = app_list_presenter_impl()->GetView();
160 int app_list_view_top = 193 int app_list_view_top =
161 app_list->anchor_rect().y() - app_list->bounds().height() / 2; 194 app_list->anchor_rect().y() - app_list->bounds().height() / 2;
162 const int kMinimalAppListMargin = 10; 195 const int kMinimalAppListMargin = 10;
196
163 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); 197 EXPECT_GE(app_list_view_top, kMinimalAppListMargin);
164 } 198 }
165 199
166 } // namespace ash 200 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698