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