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