OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/app_list_view.h" | 5 #include "ui/app_list/views/app_list_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; | 95 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; |
96 } | 96 } |
97 | 97 |
98 private: | 98 private: |
99 // Shows the app list and waits until a paint occurs. | 99 // Shows the app list and waits until a paint occurs. |
100 void Show(); | 100 void Show(); |
101 | 101 |
102 // Closes the app list. This sets |view_| to NULL. | 102 // Closes the app list. This sets |view_| to NULL. |
103 void Close(); | 103 void Close(); |
104 | 104 |
| 105 // Gets the PaginationModel owned by |view_|. |
| 106 PaginationModel* GetPaginationModel(); |
| 107 |
105 const TestType test_type_; | 108 const TestType test_type_; |
106 scoped_ptr<base::RunLoop> run_loop_; | 109 scoped_ptr<base::RunLoop> run_loop_; |
107 PaginationModel pagination_model_; | |
108 app_list::AppListView* view_; // Owned by native widget. | 110 app_list::AppListView* view_; // Owned by native widget. |
109 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; | 111 app_list::test::AppListTestViewDelegate* delegate_; // Owned by |view_|; |
110 | 112 |
111 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); | 113 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); |
112 }; | 114 }; |
113 | 115 |
114 // Extend the regular AppListTestViewDelegate to communicate back to the test | 116 // Extend the regular AppListTestViewDelegate to communicate back to the test |
115 // context. Note the test context doesn't simply inherit this, because the | 117 // context. Note the test context doesn't simply inherit this, because the |
116 // delegate is owned by the view. | 118 // delegate is owned by the view. |
117 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate { | 119 class UnitTestViewDelegate : public app_list::test::AppListTestViewDelegate { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 default: | 151 default: |
150 NOTREACHED(); | 152 NOTREACHED(); |
151 break; | 153 break; |
152 } | 154 } |
153 | 155 |
154 delegate_ = new UnitTestViewDelegate(this); | 156 delegate_ = new UnitTestViewDelegate(this); |
155 view_ = new app_list::AppListView(delegate_); | 157 view_ = new app_list::AppListView(delegate_); |
156 | 158 |
157 // Initialize centered around a point that ensures the window is wholly shown. | 159 // Initialize centered around a point that ensures the window is wholly shown. |
158 view_->InitAsBubbleAtFixedLocation(parent, | 160 view_->InitAsBubbleAtFixedLocation(parent, |
159 &pagination_model_, | 161 0, |
160 gfx::Point(300, 300), | 162 gfx::Point(300, 300), |
161 views::BubbleBorder::FLOAT, | 163 views::BubbleBorder::FLOAT, |
162 false /* border_accepts_events */); | 164 false /* border_accepts_events */); |
163 } | 165 } |
164 | 166 |
165 AppListViewTestContext::~AppListViewTestContext() { | 167 AppListViewTestContext::~AppListViewTestContext() { |
166 // The view observes the PaginationModel which is about to get destroyed, so | 168 // The view observes the PaginationModel which is about to get destroyed, so |
167 // if the view is not already deleted by the time this destructor is called, | 169 // if the view is not already deleted by the time this destructor is called, |
168 // there will be problems. | 170 // there will be problems. |
169 EXPECT_FALSE(view_); | 171 EXPECT_FALSE(view_); |
(...skipping 18 matching lines...) Expand all Loading... |
188 | 190 |
189 void AppListViewTestContext::Close() { | 191 void AppListViewTestContext::Close() { |
190 view_->GetWidget()->Close(); | 192 view_->GetWidget()->Close(); |
191 run_loop_.reset(new base::RunLoop); | 193 run_loop_.reset(new base::RunLoop); |
192 run_loop_->Run(); | 194 run_loop_->Run(); |
193 | 195 |
194 // |view_| should have been deleted and set to NULL via ViewClosing(). | 196 // |view_| should have been deleted and set to NULL via ViewClosing(). |
195 EXPECT_FALSE(view_); | 197 EXPECT_FALSE(view_); |
196 } | 198 } |
197 | 199 |
| 200 PaginationModel* AppListViewTestContext::GetPaginationModel() { |
| 201 return view_->GetAppsPaginationModel(); |
| 202 } |
| 203 |
198 void AppListViewTestContext::RunDisplayTest() { | 204 void AppListViewTestContext::RunDisplayTest() { |
199 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 205 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
200 EXPECT_EQ(-1, pagination_model_.total_pages()); | 206 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
201 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 207 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
202 | 208 |
203 Show(); | 209 Show(); |
204 if (is_landscape()) | 210 if (is_landscape()) |
205 EXPECT_EQ(2, pagination_model_.total_pages()); | 211 EXPECT_EQ(2, GetPaginationModel()->total_pages()); |
206 else | 212 else |
207 EXPECT_EQ(3, pagination_model_.total_pages()); | 213 EXPECT_EQ(3, GetPaginationModel()->total_pages()); |
208 EXPECT_EQ(0, pagination_model_.selected_page()); | 214 EXPECT_EQ(0, GetPaginationModel()->selected_page()); |
209 | 215 |
210 // Checks on the main view. | 216 // Checks on the main view. |
211 AppListMainView* main_view = view_->app_list_main_view(); | 217 AppListMainView* main_view = view_->app_list_main_view(); |
212 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 218 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
213 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); | 219 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->search_box_view())); |
214 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 220 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
215 | 221 |
216 Close(); | 222 Close(); |
217 } | 223 } |
218 | 224 |
219 void AppListViewTestContext::RunReshowWithOpenFolderTest() { | 225 void AppListViewTestContext::RunReshowWithOpenFolderTest() { |
220 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 226 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
221 EXPECT_EQ(-1, pagination_model_.total_pages()); | 227 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
222 | 228 |
223 AppListTestModel* model = delegate_->GetTestModel(); | 229 AppListTestModel* model = delegate_->GetTestModel(); |
224 model->PopulateApps(kInitialItems); | 230 model->PopulateApps(kInitialItems); |
225 const std::string folder_id = | 231 const std::string folder_id = |
226 model->MergeItems(model->top_level_item_list()->item_at(0)->id(), | 232 model->MergeItems(model->top_level_item_list()->item_at(0)->id(), |
227 model->top_level_item_list()->item_at(1)->id()); | 233 model->top_level_item_list()->item_at(1)->id()); |
228 | 234 |
229 AppListFolderItem* folder_item = model->FindFolderItem(folder_id); | 235 AppListFolderItem* folder_item = model->FindFolderItem(folder_id); |
230 EXPECT_TRUE(folder_item); | 236 EXPECT_TRUE(folder_item); |
231 | 237 |
(...skipping 23 matching lines...) Expand all Loading... |
255 // The main grid view should be showing after a reshow. | 261 // The main grid view should be showing after a reshow. |
256 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 262 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
257 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); | 263 EXPECT_NO_FATAL_FAILURE(CheckView(container_view->apps_grid_view())); |
258 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); | 264 EXPECT_FALSE(container_view->app_list_folder_view()->visible()); |
259 | 265 |
260 Close(); | 266 Close(); |
261 } | 267 } |
262 | 268 |
263 void AppListViewTestContext::RunStartPageTest() { | 269 void AppListViewTestContext::RunStartPageTest() { |
264 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 270 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
265 EXPECT_EQ(-1, pagination_model_.total_pages()); | 271 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
266 AppListTestModel* model = delegate_->GetTestModel(); | 272 AppListTestModel* model = delegate_->GetTestModel(); |
267 model->PopulateApps(3); | 273 model->PopulateApps(3); |
268 | 274 |
269 Show(); | 275 Show(); |
270 | 276 |
271 AppListMainView* main_view = view_->app_list_main_view(); | 277 AppListMainView* main_view = view_->app_list_main_view(); |
272 StartPageView* start_page_view = | 278 StartPageView* start_page_view = |
273 main_view->contents_view()->start_page_view(); | 279 main_view->contents_view()->start_page_view(); |
274 // Checks on the main view. | 280 // Checks on the main view. |
275 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 281 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
(...skipping 23 matching lines...) Expand all Loading... |
299 EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views())); | 305 EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views())); |
300 } else { | 306 } else { |
301 EXPECT_EQ(NULL, start_page_view); | 307 EXPECT_EQ(NULL, start_page_view); |
302 } | 308 } |
303 | 309 |
304 Close(); | 310 Close(); |
305 } | 311 } |
306 | 312 |
307 void AppListViewTestContext::RunProfileChangeTest() { | 313 void AppListViewTestContext::RunProfileChangeTest() { |
308 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 314 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
309 EXPECT_EQ(-1, pagination_model_.total_pages()); | 315 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
310 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 316 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
311 | 317 |
312 Show(); | 318 Show(); |
313 | 319 |
314 if (is_landscape()) | 320 if (is_landscape()) |
315 EXPECT_EQ(2, pagination_model_.total_pages()); | 321 EXPECT_EQ(2, GetPaginationModel()->total_pages()); |
316 else | 322 else |
317 EXPECT_EQ(3, pagination_model_.total_pages()); | 323 EXPECT_EQ(3, GetPaginationModel()->total_pages()); |
318 | 324 |
319 // Change the profile. The original model needs to be kept alive for | 325 // Change the profile. The original model needs to be kept alive for |
320 // observers to unregister themselves. | 326 // observers to unregister themselves. |
321 scoped_ptr<AppListTestModel> original_test_model( | 327 scoped_ptr<AppListTestModel> original_test_model( |
322 delegate_->ReleaseTestModel()); | 328 delegate_->ReleaseTestModel()); |
323 delegate_->set_next_profile_app_count(1); | 329 delegate_->set_next_profile_app_count(1); |
324 | 330 |
325 // The original ContentsView is destroyed here. | 331 // The original ContentsView is destroyed here. |
326 view_->SetProfileByPath(base::FilePath()); | 332 view_->SetProfileByPath(base::FilePath()); |
327 EXPECT_EQ(1, pagination_model_.total_pages()); | 333 EXPECT_EQ(1, GetPaginationModel()->total_pages()); |
328 | 334 |
329 StartPageView* start_page_view = | 335 StartPageView* start_page_view = |
330 view_->app_list_main_view()->contents_view()->start_page_view(); | 336 view_->app_list_main_view()->contents_view()->start_page_view(); |
331 if (test_type_ == EXPERIMENTAL) { | 337 if (test_type_ == EXPERIMENTAL) { |
332 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); | 338 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
333 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views())); | 339 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views())); |
334 } else { | 340 } else { |
335 EXPECT_EQ(NULL, start_page_view); | 341 EXPECT_EQ(NULL, start_page_view); |
336 } | 342 } |
337 | 343 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 479 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
474 AppListViewTestAura, | 480 AppListViewTestAura, |
475 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 481 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
476 | 482 |
477 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 483 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
478 AppListViewTestDesktop, | 484 AppListViewTestDesktop, |
479 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 485 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
480 | 486 |
481 } // namespace test | 487 } // namespace test |
482 } // namespace app_list | 488 } // namespace app_list |
OLD | NEW |