| 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" |
| 11 #include "ui/app_list/app_list_switches.h" | 11 #include "ui/app_list/app_list_switches.h" |
| 12 #include "ui/app_list/pagination_model.h" | 12 #include "ui/app_list/pagination_model.h" |
| 13 #include "ui/app_list/test/app_list_test_model.h" | 13 #include "ui/app_list/test/app_list_test_model.h" |
| 14 #include "ui/app_list/test/app_list_test_view_delegate.h" | 14 #include "ui/app_list/test/app_list_test_view_delegate.h" |
| 15 #include "ui/app_list/views/app_list_folder_view.h" | 15 #include "ui/app_list/views/app_list_folder_view.h" |
| 16 #include "ui/app_list/views/app_list_main_view.h" | 16 #include "ui/app_list/views/app_list_main_view.h" |
| 17 #include "ui/app_list/views/apps_container_view.h" | 17 #include "ui/app_list/views/apps_container_view.h" |
| 18 #include "ui/app_list/views/apps_grid_view.h" | 18 #include "ui/app_list/views/apps_grid_view.h" |
| 19 #include "ui/app_list/views/contents_view.h" | 19 #include "ui/app_list/views/contents_view.h" |
| 20 #include "ui/app_list/views/search_box_view.h" | 20 #include "ui/app_list/views/search_box_view.h" |
| 21 #include "ui/app_list/views/search_result_list_view.h" |
| 21 #include "ui/app_list/views/start_page_view.h" | 22 #include "ui/app_list/views/start_page_view.h" |
| 22 #include "ui/app_list/views/test/apps_grid_view_test_api.h" | 23 #include "ui/app_list/views/test/apps_grid_view_test_api.h" |
| 23 #include "ui/app_list/views/tile_item_view.h" | 24 #include "ui/app_list/views/tile_item_view.h" |
| 24 #include "ui/aura/test/aura_test_base.h" | 25 #include "ui/aura/test/aura_test_base.h" |
| 25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 26 #include "ui/views/test/views_test_base.h" | 27 #include "ui/views/test/views_test_base.h" |
| 27 #include "ui/views/views_delegate.h" | 28 #include "ui/views/views_delegate.h" |
| 28 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 29 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 29 | 30 |
| 30 namespace app_list { | 31 namespace app_list { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // top level views. Then closes the window. | 70 // top level views. Then closes the window. |
| 70 void RunDisplayTest(); | 71 void RunDisplayTest(); |
| 71 | 72 |
| 72 // Hides and reshows the app list with a folder open, expecting the main grid | 73 // Hides and reshows the app list with a folder open, expecting the main grid |
| 73 // view to be shown. | 74 // view to be shown. |
| 74 void RunReshowWithOpenFolderTest(); | 75 void RunReshowWithOpenFolderTest(); |
| 75 | 76 |
| 76 // Tests displaying of the experimental app list and shows the start page. | 77 // Tests displaying of the experimental app list and shows the start page. |
| 77 void RunStartPageTest(); | 78 void RunStartPageTest(); |
| 78 | 79 |
| 79 // Tests that changing the App List profile. | 80 // Tests changing the App List profile. |
| 80 void RunProfileChangeTest(); | 81 void RunProfileChangeTest(); |
| 81 | 82 |
| 83 // Tests displaying of the search results. |
| 84 void RunSearchResultsTest(); |
| 85 |
| 82 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. | 86 // A standard set of checks on a view, e.g., ensuring it is drawn and visible. |
| 83 static void CheckView(views::View* subview); | 87 static void CheckView(views::View* subview); |
| 84 | 88 |
| 85 // Invoked when the Widget is closing, and the view it contains is about to | 89 // Invoked when the Widget is closing, and the view it contains is about to |
| 86 // be torn down. This only occurs in a run loop and will be used as a signal | 90 // be torn down. This only occurs in a run loop and will be used as a signal |
| 87 // to quit. | 91 // to quit. |
| 88 void NativeWidgetClosing() { | 92 void NativeWidgetClosing() { |
| 89 view_ = NULL; | 93 view_ = NULL; |
| 90 run_loop_->Quit(); | 94 run_loop_->Quit(); |
| 91 } | 95 } |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 EXPECT_EQ(2u, GetVisibleTileItemViews(start_page_view->tile_views())); | 352 EXPECT_EQ(2u, GetVisibleTileItemViews(start_page_view->tile_views())); |
| 349 | 353 |
| 350 // Old model updates should be ignored. | 354 // Old model updates should be ignored. |
| 351 original_test_model->CreateAndAddItem("Test App 2"); | 355 original_test_model->CreateAndAddItem("Test App 2"); |
| 352 if (test_type_ == EXPERIMENTAL) | 356 if (test_type_ == EXPERIMENTAL) |
| 353 EXPECT_EQ(2u, GetVisibleTileItemViews(start_page_view->tile_views())); | 357 EXPECT_EQ(2u, GetVisibleTileItemViews(start_page_view->tile_views())); |
| 354 | 358 |
| 355 Close(); | 359 Close(); |
| 356 } | 360 } |
| 357 | 361 |
| 362 void AppListViewTestContext::RunSearchResultsTest() { |
| 363 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
| 364 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
| 365 AppListTestModel* model = delegate_->GetTestModel(); |
| 366 model->PopulateApps(3); |
| 367 |
| 368 Show(); |
| 369 |
| 370 AppListMainView* main_view = view_->app_list_main_view(); |
| 371 ContentsView* contents_view = main_view->contents_view(); |
| 372 contents_view->SetActivePage( |
| 373 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); |
| 374 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); |
| 375 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 376 |
| 377 // Show the search results. |
| 378 contents_view->ShowSearchResults(true); |
| 379 contents_view->Layout(); |
| 380 EXPECT_TRUE(contents_view->IsShowingSearchResults()); |
| 381 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 382 |
| 383 if (test_type_ == EXPERIMENTAL) { |
| 384 EXPECT_TRUE( |
| 385 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START)); |
| 386 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view())); |
| 387 } else { |
| 388 EXPECT_TRUE(contents_view->IsNamedPageActive( |
| 389 ContentsView::NAMED_PAGE_SEARCH_RESULTS)); |
| 390 EXPECT_TRUE(IsViewAtOrigin(contents_view->search_results_view())); |
| 391 } |
| 392 |
| 393 // Hide the search results. |
| 394 contents_view->ShowSearchResults(false); |
| 395 contents_view->Layout(); |
| 396 EXPECT_FALSE(contents_view->IsShowingSearchResults()); |
| 397 if (test_type_ == EXPERIMENTAL) { |
| 398 EXPECT_TRUE( |
| 399 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START)); |
| 400 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view())); |
| 401 EXPECT_FALSE(main_view->search_box_view()->visible()); |
| 402 } else { |
| 403 EXPECT_TRUE( |
| 404 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_APPS)); |
| 405 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); |
| 406 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 407 } |
| 408 |
| 409 Close(); |
| 410 } |
| 411 |
| 358 class AppListViewTestAura : public views::ViewsTestBase, | 412 class AppListViewTestAura : public views::ViewsTestBase, |
| 359 public ::testing::WithParamInterface<int> { | 413 public ::testing::WithParamInterface<int> { |
| 360 public: | 414 public: |
| 361 AppListViewTestAura() {} | 415 AppListViewTestAura() {} |
| 362 virtual ~AppListViewTestAura() {} | 416 virtual ~AppListViewTestAura() {} |
| 363 | 417 |
| 364 // testing::Test overrides: | 418 // testing::Test overrides: |
| 365 virtual void SetUp() OVERRIDE { | 419 virtual void SetUp() OVERRIDE { |
| 366 views::ViewsTestBase::SetUp(); | 420 views::ViewsTestBase::SetUp(); |
| 367 test_context_.reset(new AppListViewTestContext(GetParam(), GetContext())); | 421 test_context_.reset(new AppListViewTestContext(GetParam(), GetContext())); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 524 |
| 471 // Tests that the profile changes operate correctly. | 525 // Tests that the profile changes operate correctly. |
| 472 TEST_P(AppListViewTestAura, ProfileChangeTest) { | 526 TEST_P(AppListViewTestAura, ProfileChangeTest) { |
| 473 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); | 527 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); |
| 474 } | 528 } |
| 475 | 529 |
| 476 TEST_P(AppListViewTestDesktop, ProfileChangeTest) { | 530 TEST_P(AppListViewTestDesktop, ProfileChangeTest) { |
| 477 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); | 531 EXPECT_NO_FATAL_FAILURE(test_context_->RunProfileChangeTest()); |
| 478 } | 532 } |
| 479 | 533 |
| 534 // Tests that the correct views are displayed for showing search results. |
| 535 TEST_P(AppListViewTestAura, SearchResultsTest) { |
| 536 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); |
| 537 } |
| 538 |
| 539 TEST_P(AppListViewTestDesktop, SearchResultsTest) { |
| 540 EXPECT_NO_FATAL_FAILURE(test_context_->RunSearchResultsTest()); |
| 541 } |
| 542 |
| 480 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 543 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
| 481 AppListViewTestAura, | 544 AppListViewTestAura, |
| 482 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 545 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 483 | 546 |
| 484 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 547 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
| 485 AppListViewTestDesktop, | 548 AppListViewTestDesktop, |
| 486 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 549 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 487 | 550 |
| 488 } // namespace test | 551 } // namespace test |
| 489 } // namespace app_list | 552 } // namespace app_list |
| OLD | NEW |