OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/app_list/shower/app_list_shower_impl.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "base/memory/ptr_util.h" | |
10 #include "ui/app_list/shower/app_list_shower_delegate_factory.h" | |
11 #include "ui/app_list/shower/test/app_list_shower_impl_test_api.h" | |
12 #include "ui/app_list/test/app_list_test_view_delegate.h" | |
13 #include "ui/app_list/views/app_list_view.h" | |
14 #include "ui/aura/client/focus_client.h" | |
15 #include "ui/aura/test/aura_test_base.h" | |
16 #include "ui/aura/window.h" | |
17 #include "ui/wm/core/default_activation_client.h" | |
18 #include "ui/wm/core/window_util.h" | |
19 | |
20 namespace app_list { | |
21 | |
22 namespace { | |
23 | |
24 // Test stub for AppListShowerDelegate | |
25 class AppListShowerDelegateTest : public AppListShowerDelegate { | |
26 public: | |
27 AppListShowerDelegateTest(aura::Window* container, | |
28 test::AppListTestViewDelegate* view_delegate) | |
29 : container_(container), view_delegate_(view_delegate) {} | |
30 ~AppListShowerDelegateTest() override {} | |
31 | |
32 bool init_called() const { return init_called_; } | |
33 bool on_shown_called() const { return on_shown_called_; } | |
34 bool on_dismissed_called() const { return on_dismissed_called_; } | |
35 bool update_bounds_called() const { return update_bounds_called_; } | |
36 | |
37 private: | |
38 // AppListShowerDelegate: | |
39 AppListViewDelegate* GetViewDelegate() override { return view_delegate_; } | |
40 void Init(AppListView* view, | |
41 aura::Window* root_window, | |
42 int current_apps_page) override { | |
43 init_called_ = true; | |
44 view_ = view; | |
45 view->InitAsFramelessWindow(container_, current_apps_page, | |
46 gfx::Rect(100, 50, 300, 200)); | |
47 } | |
48 void OnShown(aura::Window*) override { on_shown_called_ = true; } | |
49 void OnDismissed() override { on_dismissed_called_ = true; } | |
50 void UpdateBounds() override { update_bounds_called_ = true; } | |
51 gfx::Vector2d GetVisibilityAnimationOffset(aura::Window*) override { | |
52 return gfx::Vector2d(0, 0); | |
53 } | |
54 | |
55 private: | |
56 aura::Window* container_; | |
57 test::AppListTestViewDelegate* view_delegate_; | |
58 AppListView* view_ = nullptr; | |
59 bool init_called_ = false; | |
60 bool on_shown_called_ = false; | |
61 bool on_dismissed_called_ = false; | |
62 bool update_bounds_called_ = false; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(AppListShowerDelegateTest); | |
65 }; | |
66 | |
67 // Test fake for AppListShowerDelegateFactory, creates instances of | |
68 // AppListShowerDelegateTest. | |
69 class AppListShowerDelegateFactoryTest : public AppListShowerDelegateFactory { | |
70 public: | |
71 explicit AppListShowerDelegateFactoryTest(aura::Window* container) | |
72 : container_(container) {} | |
73 ~AppListShowerDelegateFactoryTest() override {} | |
74 | |
75 AppListShowerDelegateTest* current_delegate() { return current_delegate_; } | |
76 | |
77 // AppListShowerDelegateFactory: | |
78 std::unique_ptr<AppListShowerDelegate> GetDelegate( | |
79 AppListShower* shower) override { | |
80 current_delegate_ = | |
81 new AppListShowerDelegateTest(container_, &app_list_view_delegate_); | |
82 return base::WrapUnique(current_delegate_); | |
83 } | |
84 | |
85 private: | |
86 aura::Window* container_; | |
87 AppListShowerDelegateTest* current_delegate_ = nullptr; | |
88 test::AppListTestViewDelegate app_list_view_delegate_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(AppListShowerDelegateFactoryTest); | |
91 }; | |
92 | |
93 } // namespace | |
94 | |
95 class AppListShowerImplTest : public aura::test::AuraTestBase { | |
96 public: | |
97 AppListShowerImplTest(); | |
98 ~AppListShowerImplTest() override; | |
99 | |
100 AppListShowerImpl* shower() { return shower_.get(); } | |
101 aura::Window* container() { return container_.get(); } | |
102 | |
103 // Don't cache the return of this method - a new delegate is created every | |
104 // time the app list is shown. | |
105 AppListShowerDelegateTest* delegate() { return factory_->current_delegate(); } | |
106 | |
107 // aura::test::AuraTestBase: | |
108 void SetUp() override; | |
109 void TearDown() override; | |
110 | |
111 private: | |
112 std::unique_ptr<AppListShowerDelegateFactoryTest> factory_; | |
113 std::unique_ptr<AppListShowerImpl> shower_; | |
114 std::unique_ptr<aura::Window> container_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(AppListShowerImplTest); | |
117 }; | |
118 | |
119 AppListShowerImplTest::AppListShowerImplTest() {} | |
120 | |
121 AppListShowerImplTest::~AppListShowerImplTest() {} | |
122 | |
123 void AppListShowerImplTest::SetUp() { | |
124 AuraTestBase::SetUp(); | |
125 new wm::DefaultActivationClient(root_window()); | |
126 container_.reset(CreateNormalWindow(0, root_window(), nullptr)); | |
127 factory_.reset(new AppListShowerDelegateFactoryTest(container_.get())); | |
128 shower_.reset(new AppListShowerImpl(factory_.get())); | |
129 } | |
130 | |
131 void AppListShowerImplTest::TearDown() { | |
132 container_.reset(); | |
133 AuraTestBase::TearDown(); | |
134 } | |
135 | |
136 // Tests that app launcher is dismissed when focus moves to a window which is | |
137 // not app list window's sibling and that appropriate delegate callbacks are | |
138 // executed when the app launcher is shown and then when the app launcher is | |
139 // dismissed. | |
140 TEST_F(AppListShowerImplTest, HideOnFocusOut) { | |
141 aura::client::FocusClient* focus_client = | |
142 aura::client::GetFocusClient(root_window()); | |
143 shower()->Show(container()); | |
144 EXPECT_TRUE(delegate()->init_called()); | |
145 EXPECT_TRUE(delegate()->on_shown_called()); | |
146 EXPECT_FALSE(delegate()->on_dismissed_called()); | |
147 EXPECT_FALSE(delegate()->update_bounds_called()); | |
148 focus_client->FocusWindow(shower()->GetWindow()); | |
149 EXPECT_TRUE(shower()->GetTargetVisibility()); | |
150 | |
151 std::unique_ptr<aura::Window> window( | |
152 CreateNormalWindow(1, root_window(), nullptr)); | |
153 focus_client->FocusWindow(window.get()); | |
154 | |
155 EXPECT_TRUE(delegate()->on_dismissed_called()); | |
156 EXPECT_FALSE(delegate()->update_bounds_called()); | |
157 EXPECT_FALSE(shower()->GetTargetVisibility()); | |
158 } | |
159 | |
160 // Tests that app launcher remains visible when focus moves to a window which | |
161 // is app list window's sibling and that appropriate delegate callbacks are | |
162 // executed when the app launcher is shown. | |
163 TEST_F(AppListShowerImplTest, RemainVisibleWhenFocusingToSibling) { | |
164 aura::client::FocusClient* focus_client = | |
165 aura::client::GetFocusClient(root_window()); | |
166 shower()->Show(container()); | |
167 focus_client->FocusWindow(shower()->GetWindow()); | |
168 EXPECT_TRUE(shower()->GetTargetVisibility()); | |
169 EXPECT_TRUE(delegate()->init_called()); | |
170 EXPECT_TRUE(delegate()->on_shown_called()); | |
171 EXPECT_FALSE(delegate()->on_dismissed_called()); | |
172 EXPECT_FALSE(delegate()->update_bounds_called()); | |
173 | |
174 // Create a sibling window. | |
175 std::unique_ptr<aura::Window> window( | |
176 CreateNormalWindow(1, container(), nullptr)); | |
177 focus_client->FocusWindow(window.get()); | |
178 | |
179 EXPECT_TRUE(shower()->GetTargetVisibility()); | |
180 EXPECT_FALSE(delegate()->on_dismissed_called()); | |
181 EXPECT_FALSE(delegate()->update_bounds_called()); | |
182 } | |
183 | |
184 // Tests that UpdateBounds is called on the delegate when the root window | |
185 // is resized. | |
186 TEST_F(AppListShowerImplTest, RootWindowResize) { | |
187 shower()->Show(container()); | |
188 EXPECT_FALSE(delegate()->update_bounds_called()); | |
189 gfx::Rect bounds = root_window()->bounds(); | |
190 bounds.Inset(-10, 0); | |
191 root_window()->SetBounds(bounds); | |
192 EXPECT_TRUE(delegate()->update_bounds_called()); | |
193 } | |
194 | |
195 // Tests that the app list is dismissed and the delegate is destroyed when the | |
196 // app list's widget is destroyed. | |
197 TEST_F(AppListShowerImplTest, WidgetDestroyed) { | |
198 shower()->Show(container()); | |
199 EXPECT_TRUE(shower()->GetTargetVisibility()); | |
200 shower()->GetView()->GetWidget()->CloseNow(); | |
201 EXPECT_FALSE(shower()->GetTargetVisibility()); | |
202 test::AppListShowerImplTestApi shower_test_api(shower()); | |
203 EXPECT_FALSE(shower_test_api.shower_delegate()); | |
204 } | |
205 | |
206 } // namespace app_list | |
OLD | NEW |