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/presenter/app_list_presenter_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/presenter/app_list_presenter_delegate_factory.h" | 10 #include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 // Test fake for AppListPresenterDelegateFactory, creates instances of | 68 // Test fake for AppListPresenterDelegateFactory, creates instances of |
69 // AppListPresenterDelegateTest. | 69 // AppListPresenterDelegateTest. |
70 class AppListPresenterDelegateFactoryTest | 70 class AppListPresenterDelegateFactoryTest |
71 : public AppListPresenterDelegateFactory { | 71 : public AppListPresenterDelegateFactory { |
72 public: | 72 public: |
73 explicit AppListPresenterDelegateFactoryTest(aura::Window* container) | 73 explicit AppListPresenterDelegateFactoryTest(aura::Window* container) |
74 : container_(container) {} | 74 : container_(container) {} |
75 ~AppListPresenterDelegateFactoryTest() override {} | 75 ~AppListPresenterDelegateFactoryTest() override {} |
76 | 76 |
77 AppListPresenterDelegateTest* current_delegate() { return current_delegate_; } | |
78 | |
79 // AppListPresenterDelegateFactory: | 77 // AppListPresenterDelegateFactory: |
80 std::unique_ptr<AppListPresenterDelegate> GetDelegate( | 78 std::unique_ptr<AppListPresenterDelegate> GetDelegate( |
81 AppListPresenter* presenter) override { | 79 AppListPresenterImpl* presenter) override { |
82 current_delegate_ = | 80 return base::MakeUnique<AppListPresenterDelegateTest>( |
83 new AppListPresenterDelegateTest(container_, &app_list_view_delegate_); | 81 container_, &app_list_view_delegate_); |
84 return base::WrapUnique(current_delegate_); | |
85 } | 82 } |
86 | 83 |
87 private: | 84 private: |
88 aura::Window* container_; | 85 aura::Window* container_; |
89 AppListPresenterDelegateTest* current_delegate_ = nullptr; | |
90 test::AppListTestViewDelegate app_list_view_delegate_; | 86 test::AppListTestViewDelegate app_list_view_delegate_; |
91 | 87 |
92 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateFactoryTest); | 88 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateFactoryTest); |
93 }; | 89 }; |
94 | 90 |
95 } // namespace | 91 } // namespace |
96 | 92 |
97 class AppListPresenterImplTest : public aura::test::AuraTestBase { | 93 class AppListPresenterImplTest : public aura::test::AuraTestBase { |
98 public: | 94 public: |
99 AppListPresenterImplTest(); | 95 AppListPresenterImplTest(); |
100 ~AppListPresenterImplTest() override; | 96 ~AppListPresenterImplTest() override; |
101 | 97 |
102 AppListPresenterImpl* presenter() { return presenter_.get(); } | 98 AppListPresenterImpl* presenter() { return presenter_.get(); } |
103 aura::Window* container() { return container_.get(); } | 99 aura::Window* container() { return container_.get(); } |
104 int64_t GetDisplayId() { return test_screen()->GetPrimaryDisplay().id(); } | 100 int64_t GetDisplayId() { return test_screen()->GetPrimaryDisplay().id(); } |
105 | 101 |
106 // Don't cache the return of this method - a new delegate is created every | 102 // Don't cache the return of this method - a new delegate is created every |
107 // time the app list is shown. | 103 // time the app list is shown. |
108 AppListPresenterDelegateTest* delegate() { | 104 AppListPresenterDelegateTest* delegate() { |
109 return factory_->current_delegate(); | 105 return static_cast<AppListPresenterDelegateTest*>( |
| 106 presenter_test_api_->presenter_delegate()); |
110 } | 107 } |
111 | 108 |
112 // aura::test::AuraTestBase: | 109 // aura::test::AuraTestBase: |
113 void SetUp() override; | 110 void SetUp() override; |
114 void TearDown() override; | 111 void TearDown() override; |
115 | 112 |
116 private: | 113 private: |
117 std::unique_ptr<AppListPresenterDelegateFactoryTest> factory_; | |
118 std::unique_ptr<AppListPresenterImpl> presenter_; | 114 std::unique_ptr<AppListPresenterImpl> presenter_; |
119 std::unique_ptr<aura::Window> container_; | 115 std::unique_ptr<aura::Window> container_; |
| 116 std::unique_ptr<test::AppListPresenterImplTestApi> presenter_test_api_; |
120 | 117 |
121 DISALLOW_COPY_AND_ASSIGN(AppListPresenterImplTest); | 118 DISALLOW_COPY_AND_ASSIGN(AppListPresenterImplTest); |
122 }; | 119 }; |
123 | 120 |
124 AppListPresenterImplTest::AppListPresenterImplTest() {} | 121 AppListPresenterImplTest::AppListPresenterImplTest() {} |
125 | 122 |
126 AppListPresenterImplTest::~AppListPresenterImplTest() {} | 123 AppListPresenterImplTest::~AppListPresenterImplTest() {} |
127 | 124 |
128 void AppListPresenterImplTest::SetUp() { | 125 void AppListPresenterImplTest::SetUp() { |
129 AuraTestBase::SetUp(); | 126 AuraTestBase::SetUp(); |
130 new wm::DefaultActivationClient(root_window()); | 127 new wm::DefaultActivationClient(root_window()); |
131 container_.reset(CreateNormalWindow(0, root_window(), nullptr)); | 128 container_.reset(CreateNormalWindow(0, root_window(), nullptr)); |
132 factory_.reset(new AppListPresenterDelegateFactoryTest(container_.get())); | 129 presenter_ = base::MakeUnique<AppListPresenterImpl>( |
133 presenter_.reset(new AppListPresenterImpl(factory_.get())); | 130 base::MakeUnique<AppListPresenterDelegateFactoryTest>(container_.get())); |
| 131 presenter_test_api_ = |
| 132 base::MakeUnique<test::AppListPresenterImplTestApi>(presenter()); |
134 } | 133 } |
135 | 134 |
136 void AppListPresenterImplTest::TearDown() { | 135 void AppListPresenterImplTest::TearDown() { |
137 container_.reset(); | 136 container_.reset(); |
138 AuraTestBase::TearDown(); | 137 AuraTestBase::TearDown(); |
139 } | 138 } |
140 | 139 |
141 // Tests that app launcher is dismissed when focus moves to a window which is | 140 // Tests that app launcher is dismissed when focus moves to a window which is |
142 // not app list window's sibling and that appropriate delegate callbacks are | 141 // not app list window's sibling and that appropriate delegate callbacks are |
143 // executed when the app launcher is shown and then when the app launcher is | 142 // executed when the app launcher is shown and then when the app launcher is |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 EXPECT_TRUE(delegate()->update_bounds_called()); | 196 EXPECT_TRUE(delegate()->update_bounds_called()); |
198 } | 197 } |
199 | 198 |
200 // Tests that the app list is dismissed and the delegate is destroyed when the | 199 // Tests that the app list is dismissed and the delegate is destroyed when the |
201 // app list's widget is destroyed. | 200 // app list's widget is destroyed. |
202 TEST_F(AppListPresenterImplTest, WidgetDestroyed) { | 201 TEST_F(AppListPresenterImplTest, WidgetDestroyed) { |
203 presenter()->Show(GetDisplayId()); | 202 presenter()->Show(GetDisplayId()); |
204 EXPECT_TRUE(presenter()->GetTargetVisibility()); | 203 EXPECT_TRUE(presenter()->GetTargetVisibility()); |
205 presenter()->GetView()->GetWidget()->CloseNow(); | 204 presenter()->GetView()->GetWidget()->CloseNow(); |
206 EXPECT_FALSE(presenter()->GetTargetVisibility()); | 205 EXPECT_FALSE(presenter()->GetTargetVisibility()); |
207 test::AppListPresenterImplTestApi presenter_test_api(presenter()); | 206 EXPECT_FALSE(delegate()); |
208 EXPECT_FALSE(presenter_test_api.presenter_delegate()); | |
209 } | 207 } |
210 | 208 |
211 } // namespace app_list | 209 } // namespace app_list |
OLD | NEW |