| 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 "base/strings/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/app_list/app_list_switches.h" | 12 #include "ui/app_list/app_list_switches.h" |
| 12 #include "ui/app_list/pagination_model.h" | 13 #include "ui/app_list/pagination_model.h" |
| 14 #include "ui/app_list/search_box_model.h" |
| 13 #include "ui/app_list/test/app_list_test_model.h" | 15 #include "ui/app_list/test/app_list_test_model.h" |
| 14 #include "ui/app_list/test/app_list_test_view_delegate.h" | 16 #include "ui/app_list/test/app_list_test_view_delegate.h" |
| 15 #include "ui/app_list/views/app_list_folder_view.h" | 17 #include "ui/app_list/views/app_list_folder_view.h" |
| 16 #include "ui/app_list/views/app_list_main_view.h" | 18 #include "ui/app_list/views/app_list_main_view.h" |
| 17 #include "ui/app_list/views/apps_container_view.h" | 19 #include "ui/app_list/views/apps_container_view.h" |
| 18 #include "ui/app_list/views/apps_grid_view.h" | 20 #include "ui/app_list/views/apps_grid_view.h" |
| 19 #include "ui/app_list/views/contents_switcher_view.h" | 21 #include "ui/app_list/views/contents_switcher_view.h" |
| 20 #include "ui/app_list/views/contents_view.h" | 22 #include "ui/app_list/views/contents_view.h" |
| 21 #include "ui/app_list/views/search_box_view.h" | 23 #include "ui/app_list/views/search_box_view.h" |
| 22 #include "ui/app_list/views/search_result_list_view.h" | 24 #include "ui/app_list/views/search_result_list_view.h" |
| 23 #include "ui/app_list/views/start_page_view.h" | 25 #include "ui/app_list/views/start_page_view.h" |
| 24 #include "ui/app_list/views/test/apps_grid_view_test_api.h" | 26 #include "ui/app_list/views/test/apps_grid_view_test_api.h" |
| 25 #include "ui/app_list/views/tile_item_view.h" | 27 #include "ui/app_list/views/tile_item_view.h" |
| 26 #include "ui/aura/test/aura_test_base.h" | 28 #include "ui/aura/test/aura_test_base.h" |
| 27 #include "ui/aura/window.h" | 29 #include "ui/aura/window.h" |
| 30 #include "ui/views/controls/textfield/textfield.h" |
| 28 #include "ui/views/test/views_test_base.h" | 31 #include "ui/views/test/views_test_base.h" |
| 29 #include "ui/views/views_delegate.h" | 32 #include "ui/views/views_delegate.h" |
| 30 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 33 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 31 | 34 |
| 32 namespace app_list { | 35 namespace app_list { |
| 33 namespace test { | 36 namespace test { |
| 34 | 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 enum TestType { | 40 enum TestType { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 view_ = NULL; | 100 view_ = NULL; |
| 98 run_loop_->Quit(); | 101 run_loop_->Quit(); |
| 99 } | 102 } |
| 100 | 103 |
| 101 // Whether the experimental "landscape" app launcher UI is being tested. | 104 // Whether the experimental "landscape" app launcher UI is being tested. |
| 102 bool is_landscape() const { | 105 bool is_landscape() const { |
| 103 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; | 106 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; |
| 104 } | 107 } |
| 105 | 108 |
| 106 private: | 109 private: |
| 110 // Switches the active launcher page in the contents view and lays out to |
| 111 // ensure all launcher pages are in the correct position. |
| 112 void ShowContentsViewPageAndVerify(int index); |
| 113 |
| 107 // Shows the app list and waits until a paint occurs. | 114 // Shows the app list and waits until a paint occurs. |
| 108 void Show(); | 115 void Show(); |
| 109 | 116 |
| 110 // Closes the app list. This sets |view_| to NULL. | 117 // Closes the app list. This sets |view_| to NULL. |
| 111 void Close(); | 118 void Close(); |
| 112 | 119 |
| 113 // Gets the PaginationModel owned by |view_|. | 120 // Gets the PaginationModel owned by |view_|. |
| 114 PaginationModel* GetPaginationModel(); | 121 PaginationModel* GetPaginationModel(); |
| 115 | 122 |
| 116 const TestType test_type_; | 123 const TestType test_type_; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 187 } |
| 181 | 188 |
| 182 // static | 189 // static |
| 183 void AppListViewTestContext::CheckView(views::View* subview) { | 190 void AppListViewTestContext::CheckView(views::View* subview) { |
| 184 ASSERT_TRUE(subview); | 191 ASSERT_TRUE(subview); |
| 185 EXPECT_TRUE(subview->parent()); | 192 EXPECT_TRUE(subview->parent()); |
| 186 EXPECT_TRUE(subview->visible()); | 193 EXPECT_TRUE(subview->visible()); |
| 187 EXPECT_TRUE(subview->IsDrawn()); | 194 EXPECT_TRUE(subview->IsDrawn()); |
| 188 } | 195 } |
| 189 | 196 |
| 197 void AppListViewTestContext::ShowContentsViewPageAndVerify(int index) { |
| 198 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); |
| 199 contents_view->SetActivePage(index); |
| 200 contents_view->Layout(); |
| 201 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) { |
| 202 EXPECT_EQ(i == index, IsViewAtOrigin(contents_view->GetPageView(i))); |
| 203 } |
| 204 } |
| 205 |
| 190 void AppListViewTestContext::Show() { | 206 void AppListViewTestContext::Show() { |
| 191 view_->GetWidget()->Show(); | 207 view_->GetWidget()->Show(); |
| 192 run_loop_.reset(new base::RunLoop); | 208 run_loop_.reset(new base::RunLoop); |
| 193 view_->SetNextPaintCallback(run_loop_->QuitClosure()); | 209 view_->SetNextPaintCallback(run_loop_->QuitClosure()); |
| 194 run_loop_->Run(); | 210 run_loop_->Run(); |
| 195 | 211 |
| 196 EXPECT_TRUE(view_->GetWidget()->IsVisible()); | 212 EXPECT_TRUE(view_->GetWidget()->IsVisible()); |
| 197 } | 213 } |
| 198 | 214 |
| 199 void AppListViewTestContext::Close() { | 215 void AppListViewTestContext::Close() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 AppListMainView* main_view = view_->app_list_main_view(); | 301 AppListMainView* main_view = view_->app_list_main_view(); |
| 286 StartPageView* start_page_view = | 302 StartPageView* start_page_view = |
| 287 main_view->contents_view()->start_page_view(); | 303 main_view->contents_view()->start_page_view(); |
| 288 // Checks on the main view. | 304 // Checks on the main view. |
| 289 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 305 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
| 290 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 306 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
| 291 if (test_type_ == EXPERIMENTAL) { | 307 if (test_type_ == EXPERIMENTAL) { |
| 292 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); | 308 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
| 293 | 309 |
| 294 ContentsView* contents_view = main_view->contents_view(); | 310 ContentsView* contents_view = main_view->contents_view(); |
| 295 contents_view->SetActivePage(contents_view->GetPageIndexForNamedPage( | 311 ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage( |
| 296 ContentsView::NAMED_PAGE_START)); | 312 ContentsView::NAMED_PAGE_START)); |
| 297 contents_view->Layout(); | |
| 298 EXPECT_FALSE(main_view->search_box_view()->visible()); | 313 EXPECT_FALSE(main_view->search_box_view()->visible()); |
| 299 EXPECT_TRUE(IsViewAtOrigin(start_page_view)); | |
| 300 EXPECT_FALSE(IsViewAtOrigin(contents_view->apps_container_view())); | |
| 301 EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views())); | 314 EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views())); |
| 302 | 315 |
| 303 contents_view->SetActivePage( | 316 ShowContentsViewPageAndVerify( |
| 304 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); | 317 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); |
| 305 contents_view->Layout(); | |
| 306 EXPECT_TRUE(main_view->search_box_view()->visible()); | 318 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 307 EXPECT_FALSE(IsViewAtOrigin(start_page_view)); | |
| 308 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); | |
| 309 | 319 |
| 310 // Check tiles hide and show on deletion and addition. | 320 // Check tiles hide and show on deletion and addition. |
| 311 model->CreateAndAddItem("Test app"); | 321 model->CreateAndAddItem("Test app"); |
| 312 EXPECT_EQ(4u, GetVisibleTileItemViews(start_page_view->tile_views())); | 322 EXPECT_EQ(4u, GetVisibleTileItemViews(start_page_view->tile_views())); |
| 313 model->DeleteItem(model->GetItemName(0)); | 323 model->DeleteItem(model->GetItemName(0)); |
| 314 EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views())); | 324 EXPECT_EQ(3u, GetVisibleTileItemViews(start_page_view->tile_views())); |
| 315 } else { | 325 } else { |
| 316 EXPECT_EQ(NULL, start_page_view); | 326 EXPECT_EQ(NULL, start_page_view); |
| 317 } | 327 } |
| 318 | 328 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 void AppListViewTestContext::RunSearchResultsTest() { | 425 void AppListViewTestContext::RunSearchResultsTest() { |
| 416 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 426 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
| 417 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 427 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
| 418 AppListTestModel* model = delegate_->GetTestModel(); | 428 AppListTestModel* model = delegate_->GetTestModel(); |
| 419 model->PopulateApps(3); | 429 model->PopulateApps(3); |
| 420 | 430 |
| 421 Show(); | 431 Show(); |
| 422 | 432 |
| 423 AppListMainView* main_view = view_->app_list_main_view(); | 433 AppListMainView* main_view = view_->app_list_main_view(); |
| 424 ContentsView* contents_view = main_view->contents_view(); | 434 ContentsView* contents_view = main_view->contents_view(); |
| 425 contents_view->SetActivePage( | 435 ShowContentsViewPageAndVerify( |
| 426 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); | 436 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); |
| 427 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); | 437 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); |
| 428 EXPECT_TRUE(main_view->search_box_view()->visible()); | 438 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 429 | 439 |
| 430 // Show the search results. | 440 // Show the search results. |
| 431 contents_view->ShowSearchResults(true); | 441 contents_view->ShowSearchResults(true); |
| 432 contents_view->Layout(); | 442 contents_view->Layout(); |
| 433 EXPECT_TRUE(contents_view->IsShowingSearchResults()); | 443 EXPECT_TRUE(contents_view->IsShowingSearchResults()); |
| 434 EXPECT_TRUE(main_view->search_box_view()->visible()); | 444 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 435 | 445 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 452 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START)); | 462 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START)); |
| 453 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view())); | 463 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view())); |
| 454 EXPECT_FALSE(main_view->search_box_view()->visible()); | 464 EXPECT_FALSE(main_view->search_box_view()->visible()); |
| 455 } else { | 465 } else { |
| 456 EXPECT_TRUE( | 466 EXPECT_TRUE( |
| 457 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_APPS)); | 467 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_APPS)); |
| 458 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); | 468 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); |
| 459 EXPECT_TRUE(main_view->search_box_view()->visible()); | 469 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 460 } | 470 } |
| 461 | 471 |
| 472 if (test_type_ == EXPERIMENTAL) { |
| 473 // Check that typing into the dummy search box triggers the search page. |
| 474 base::string16 search_text = base::UTF8ToUTF16("test"); |
| 475 SearchBoxView* dummy_search_box = |
| 476 contents_view->start_page_view()->dummy_search_box_view(); |
| 477 EXPECT_TRUE(dummy_search_box->IsDrawn()); |
| 478 dummy_search_box->search_box()->InsertText(search_text); |
| 479 contents_view->Layout(); |
| 480 // Check that the current search is using |search_text|. |
| 481 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); |
| 482 EXPECT_TRUE(contents_view->IsShowingSearchResults()); |
| 483 EXPECT_FALSE(dummy_search_box->IsDrawn()); |
| 484 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 485 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); |
| 486 EXPECT_TRUE( |
| 487 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START)); |
| 488 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view())); |
| 489 |
| 490 // Check that typing into the real search box triggers the search page. |
| 491 ShowContentsViewPageAndVerify( |
| 492 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); |
| 493 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); |
| 494 |
| 495 base::string16 new_search_text = base::UTF8ToUTF16("apple"); |
| 496 main_view->search_box_view()->search_box()->SetText(base::string16()); |
| 497 main_view->search_box_view()->search_box()->InsertText(new_search_text); |
| 498 // Check that the current search is using |search_text|. |
| 499 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); |
| 500 EXPECT_EQ(new_search_text, |
| 501 main_view->search_box_view()->search_box()->text()); |
| 502 EXPECT_TRUE(contents_view->IsShowingSearchResults()); |
| 503 EXPECT_FALSE(dummy_search_box->IsDrawn()); |
| 504 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 505 EXPECT_TRUE(dummy_search_box->search_box()->text().empty()); |
| 506 |
| 507 // Check that the dummy search box is clear when reshowing the start page. |
| 508 ShowContentsViewPageAndVerify( |
| 509 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); |
| 510 ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage( |
| 511 ContentsView::NAMED_PAGE_START)); |
| 512 EXPECT_TRUE(dummy_search_box->IsDrawn()); |
| 513 EXPECT_TRUE(dummy_search_box->search_box()->text().empty()); |
| 514 } |
| 515 |
| 462 Close(); | 516 Close(); |
| 463 } | 517 } |
| 464 | 518 |
| 465 class AppListViewTestAura : public views::ViewsTestBase, | 519 class AppListViewTestAura : public views::ViewsTestBase, |
| 466 public ::testing::WithParamInterface<int> { | 520 public ::testing::WithParamInterface<int> { |
| 467 public: | 521 public: |
| 468 AppListViewTestAura() {} | 522 AppListViewTestAura() {} |
| 469 virtual ~AppListViewTestAura() {} | 523 virtual ~AppListViewTestAura() {} |
| 470 | 524 |
| 471 // testing::Test overrides: | 525 // testing::Test overrides: |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 659 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
| 606 AppListViewTestAura, | 660 AppListViewTestAura, |
| 607 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 661 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 608 | 662 |
| 609 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 663 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
| 610 AppListViewTestDesktop, | 664 AppListViewTestDesktop, |
| 611 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 665 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 612 | 666 |
| 613 } // namespace test | 667 } // namespace test |
| 614 } // namespace app_list | 668 } // namespace app_list |
| OLD | NEW |