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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // top level views. Then closes the window. | 69 // top level views. Then closes the window. |
70 void RunDisplayTest(); | 70 void RunDisplayTest(); |
71 | 71 |
72 // Hides and reshows the app list with a folder open, expecting the main grid | 72 // Hides and reshows the app list with a folder open, expecting the main grid |
73 // view to be shown. | 73 // view to be shown. |
74 void RunReshowWithOpenFolderTest(); | 74 void RunReshowWithOpenFolderTest(); |
75 | 75 |
76 // Tests displaying of the experimental app list and shows the start page. | 76 // Tests displaying of the experimental app list and shows the start page. |
77 void RunStartPageTest(); | 77 void RunStartPageTest(); |
78 | 78 |
| 79 // Tests that changing the App List profile. |
| 80 void RunProfileChangeTest(); |
| 81 |
79 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. | 82 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. |
80 static void CheckView(views::View* subview); | 83 static void CheckView(views::View* subview); |
81 | 84 |
82 // Invoked when the Widget is closing, and the view it contains is about to | 85 // Invoked when the Widget is closing, and the view it contains is about to |
83 // be torn down. This only occurs in a run loop and will be used as a signal | 86 // be torn down. This only occurs in a run loop and will be used as a signal |
84 // to quit. | 87 // to quit. |
85 void NativeWidgetClosing() { | 88 void NativeWidgetClosing() { |
86 view_ = NULL; | 89 view_ = NULL; |
87 run_loop_->Quit(); | 90 run_loop_->Quit(); |
88 } | 91 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 EXPECT_EQ(4u, GetVisibleTileItemViews(start_page_view->tile_views())); | 297 EXPECT_EQ(4u, GetVisibleTileItemViews(start_page_view->tile_views())); |
295 model->DeleteItem(model->GetItemName(0)); | 298 model->DeleteItem(model->GetItemName(0)); |
296 EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views())); | 299 EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views())); |
297 } else { | 300 } else { |
298 EXPECT_EQ(NULL, start_page_view); | 301 EXPECT_EQ(NULL, start_page_view); |
299 } | 302 } |
300 | 303 |
301 Close(); | 304 Close(); |
302 } | 305 } |
303 | 306 |
| 307 void AppListViewTestContext::RunProfileChangeTest() { |
| 308 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
| 309 EXPECT_EQ(-1, pagination_model_.total_pages()); |
| 310 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
| 311 |
| 312 Show(); |
| 313 |
| 314 if (is_landscape()) |
| 315 EXPECT_EQ(2, pagination_model_.total_pages()); |
| 316 else |
| 317 EXPECT_EQ(3, pagination_model_.total_pages()); |
| 318 |
| 319 // Change the profile. The original model needs to be kept alive for |
| 320 // observers to unregister themselves. |
| 321 scoped_ptr<AppListTestModel> original_test_model( |
| 322 delegate_->ReleaseTestModel()); |
| 323 delegate_->set_next_profile_app_count(1); |
| 324 |
| 325 // The original ContentsView is destroyed here. |
| 326 view_->SetProfileByPath(base::FilePath()); |
| 327 EXPECT_EQ(1, pagination_model_.total_pages()); |
| 328 |
| 329 StartPageView* start_page_view = |
| 330 view_->app_list_main_view()->contents_view()->start_page_view(); |
| 331 if (test_type_ == EXPERIMENTAL) { |
| 332 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
| 333 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views())); |
| 334 } else { |
| 335 EXPECT_EQ(NULL, start_page_view); |
| 336 } |
| 337 |
| 338 // New model updates should be processed by the start page view. |
| 339 delegate_->GetTestModel()->CreateAndAddItem("Test App"); |
| 340 if (test_type_ == EXPERIMENTAL) |
| 341 EXPECT_EQ(2u, GetVisibleTileItemViews(start_page_view->tile_views())); |
| 342 |
| 343 // Old model updates should be ignored. |
| 344 original_test_model->CreateAndAddItem("Test App 2"); |
| 345 if (test_type_ == EXPERIMENTAL) |
| 346 EXPECT_EQ(2u, GetVisibleTileItemViews(start_page_view->tile_views())); |
| 347 |
| 348 Close(); |
| 349 } |
| 350 |
304 class AppListViewTestAura : public views::ViewsTestBase, | 351 class AppListViewTestAura : public views::ViewsTestBase, |
305 public ::testing::WithParamInterface<int> { | 352 public ::testing::WithParamInterface<int> { |
306 public: | 353 public: |
307 AppListViewTestAura() {} | 354 AppListViewTestAura() {} |
308 virtual ~AppListViewTestAura() {} | 355 virtual ~AppListViewTestAura() {} |
309 | 356 |
310 // testing::Test overrides: | 357 // testing::Test overrides: |
311 virtual void SetUp() OVERRIDE { | 358 virtual void SetUp() OVERRIDE { |
312 views::ViewsTestBase::SetUp(); | 359 views::ViewsTestBase::SetUp(); |
313 test_context_.reset(new AppListViewTestContext(GetParam(), GetContext())); | 360 test_context_.reset(new AppListViewTestContext(GetParam(), GetContext())); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 454 |
408 // Tests that the start page view operates correctly. | 455 // Tests that the start page view operates correctly. |
409 TEST_P(AppListViewTestAura, StartPageTest) { | 456 TEST_P(AppListViewTestAura, StartPageTest) { |
410 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); | 457 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); |
411 } | 458 } |
412 | 459 |
413 TEST_P(AppListViewTestDesktop, StartPageTest) { | 460 TEST_P(AppListViewTestDesktop, StartPageTest) { |
414 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); | 461 EXPECT_NO_FATAL_FAILURE(test_context_->RunStartPageTest()); |
415 } | 462 } |
416 | 463 |
| 464 // Tests that the profile changes operate correctly. |
| 465 TEST_P(AppListViewTestAura, ProfileChangeTest) { |
| 466 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); |
| 467 } |
| 468 |
| 469 TEST_P(AppListViewTestDesktop, ProfileChangeTest) { |
| 470 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); |
| 471 } |
| 472 |
417 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 473 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
418 AppListViewTestAura, | 474 AppListViewTestAura, |
419 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 475 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
420 | 476 |
421 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 477 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
422 AppListViewTestDesktop, | 478 AppListViewTestDesktop, |
423 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 479 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
424 | 480 |
425 } // namespace test | 481 } // namespace test |
426 } // namespace app_list | 482 } // namespace app_list |
OLD | NEW |