| 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 "base/strings/utf_string_conversions.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/app_list/app_list_switches.h" | 12 #include "ui/app_list/app_list_switches.h" |
| 13 #include "ui/app_list/pagination_model.h" | 13 #include "ui/app_list/pagination_model.h" |
| 14 #include "ui/app_list/search_box_model.h" | 14 #include "ui/app_list/search_box_model.h" |
| 15 #include "ui/app_list/test/app_list_test_model.h" | 15 #include "ui/app_list/test/app_list_test_model.h" |
| 16 #include "ui/app_list/test/app_list_test_view_delegate.h" | 16 #include "ui/app_list/test/app_list_test_view_delegate.h" |
| 17 #include "ui/app_list/test/test_search_result.h" | 17 #include "ui/app_list/test/test_search_result.h" |
| 18 #include "ui/app_list/views/app_list_folder_view.h" | 18 #include "ui/app_list/views/app_list_folder_view.h" |
| 19 #include "ui/app_list/views/app_list_main_view.h" | 19 #include "ui/app_list/views/app_list_main_view.h" |
| 20 #include "ui/app_list/views/apps_container_view.h" | 20 #include "ui/app_list/views/apps_container_view.h" |
| 21 #include "ui/app_list/views/apps_grid_view.h" | 21 #include "ui/app_list/views/apps_grid_view.h" |
| 22 #include "ui/app_list/views/contents_switcher_view.h" | 22 #include "ui/app_list/views/contents_switcher_view.h" |
| 23 #include "ui/app_list/views/contents_view.h" | 23 #include "ui/app_list/views/contents_view.h" |
| 24 #include "ui/app_list/views/search_box_view.h" | 24 #include "ui/app_list/views/search_box_view.h" |
| 25 #include "ui/app_list/views/search_result_list_view.h" | 25 #include "ui/app_list/views/search_result_list_view.h" |
| 26 #include "ui/app_list/views/search_result_tile_item_view.h" |
| 26 #include "ui/app_list/views/start_page_view.h" | 27 #include "ui/app_list/views/start_page_view.h" |
| 27 #include "ui/app_list/views/test/apps_grid_view_test_api.h" | 28 #include "ui/app_list/views/test/apps_grid_view_test_api.h" |
| 28 #include "ui/app_list/views/tile_item_view.h" | 29 #include "ui/app_list/views/tile_item_view.h" |
| 29 #include "ui/views/controls/textfield/textfield.h" | 30 #include "ui/views/controls/textfield/textfield.h" |
| 30 #include "ui/views/test/views_test_base.h" | 31 #include "ui/views/test/views_test_base.h" |
| 31 #include "ui/views/views_delegate.h" | 32 #include "ui/views/views_delegate.h" |
| 32 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 33 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 33 | 34 |
| 34 namespace app_list { | 35 namespace app_list { |
| 35 namespace test { | 36 namespace test { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 enum TestType { | 40 enum TestType { |
| 40 TEST_TYPE_START = 0, | 41 TEST_TYPE_START = 0, |
| 41 NORMAL = TEST_TYPE_START, | 42 NORMAL = TEST_TYPE_START, |
| 42 LANDSCAPE, | 43 LANDSCAPE, |
| 43 EXPERIMENTAL, | 44 EXPERIMENTAL, |
| 44 TEST_TYPE_END, | 45 TEST_TYPE_END, |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 size_t GetVisibleTileItemViews(const std::vector<TileItemView*>& tiles) { | 48 template <class T> |
| 49 size_t GetVisibleViews(const std::vector<T*>& tiles) { |
| 48 size_t count = 0; | 50 size_t count = 0; |
| 49 for (std::vector<TileItemView*>::const_iterator it = tiles.begin(); | 51 for (const auto& tile : tiles) { |
| 50 it != tiles.end(); | 52 if (tile->visible()) |
| 51 ++it) { | |
| 52 if ((*it)->visible()) | |
| 53 count++; | 53 count++; |
| 54 } | 54 } |
| 55 return count; | 55 return count; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void SimulateClick(views::View* view) { |
| 59 gfx::Point center = view->GetLocalBounds().CenterPoint(); |
| 60 view->OnMousePressed(ui::MouseEvent(ui::ET_MOUSE_PRESSED, |
| 61 center, |
| 62 center, |
| 63 ui::EF_LEFT_MOUSE_BUTTON, |
| 64 ui::EF_LEFT_MOUSE_BUTTON)); |
| 65 view->OnMouseReleased(ui::MouseEvent(ui::ET_MOUSE_RELEASED, |
| 66 center, |
| 67 center, |
| 68 ui::EF_LEFT_MOUSE_BUTTON, |
| 69 ui::EF_LEFT_MOUSE_BUTTON)); |
| 70 } |
| 71 |
| 58 // Choose a set that is 3 regular app list pages and 2 landscape app list pages. | 72 // Choose a set that is 3 regular app list pages and 2 landscape app list pages. |
| 59 const int kInitialItems = 34; | 73 const int kInitialItems = 34; |
| 60 | 74 |
| 61 class TestTileSearchResult : public TestSearchResult { | 75 class TestTileSearchResult : public TestSearchResult { |
| 62 public: | 76 public: |
| 63 TestTileSearchResult() { set_display_type(DISPLAY_TILE); } | 77 TestTileSearchResult() { set_display_type(DISPLAY_TILE); } |
| 64 ~TestTileSearchResult() override {} | 78 ~TestTileSearchResult() override {} |
| 65 | 79 |
| 66 private: | 80 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(TestTileSearchResult); | 81 DISALLOW_COPY_AND_ASSIGN(TestTileSearchResult); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Whether the experimental "landscape" app launcher UI is being tested. | 122 // Whether the experimental "landscape" app launcher UI is being tested. |
| 109 bool is_landscape() const { | 123 bool is_landscape() const { |
| 110 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; | 124 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; |
| 111 } | 125 } |
| 112 | 126 |
| 113 private: | 127 private: |
| 114 // Switches the active launcher page in the contents view and lays out to | 128 // Switches the active launcher page in the contents view and lays out to |
| 115 // ensure all launcher pages are in the correct position. | 129 // ensure all launcher pages are in the correct position. |
| 116 void ShowContentsViewPageAndVerify(AppListModel::State state); | 130 void ShowContentsViewPageAndVerify(AppListModel::State state); |
| 117 | 131 |
| 132 // Tests that the app list is in |state|. |
| 133 void VerifyPageActive(AppListModel::State state); |
| 134 |
| 118 // Shows the app list and waits until a paint occurs. | 135 // Shows the app list and waits until a paint occurs. |
| 119 void Show(); | 136 void Show(); |
| 120 | 137 |
| 121 // Closes the app list. This sets |view_| to NULL. | 138 // Closes the app list. This sets |view_| to NULL. |
| 122 void Close(); | 139 void Close(); |
| 123 | 140 |
| 124 // Gets the PaginationModel owned by |view_|. | 141 // Gets the PaginationModel owned by |view_|. |
| 125 PaginationModel* GetPaginationModel(); | 142 PaginationModel* GetPaginationModel(); |
| 126 | 143 |
| 127 const TestType test_type_; | 144 const TestType test_type_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 EXPECT_TRUE(subview->visible()); | 214 EXPECT_TRUE(subview->visible()); |
| 198 EXPECT_TRUE(subview->IsDrawn()); | 215 EXPECT_TRUE(subview->IsDrawn()); |
| 199 } | 216 } |
| 200 | 217 |
| 201 void AppListViewTestContext::ShowContentsViewPageAndVerify( | 218 void AppListViewTestContext::ShowContentsViewPageAndVerify( |
| 202 AppListModel::State state) { | 219 AppListModel::State state) { |
| 203 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); | 220 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); |
| 204 int index = contents_view->GetPageIndexForState(state); | 221 int index = contents_view->GetPageIndexForState(state); |
| 205 contents_view->SetActivePage(index); | 222 contents_view->SetActivePage(index); |
| 206 contents_view->Layout(); | 223 contents_view->Layout(); |
| 224 VerifyPageActive(state); |
| 225 } |
| 226 |
| 227 void AppListViewTestContext::VerifyPageActive(AppListModel::State state) { |
| 228 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); |
| 229 int index = contents_view->GetPageIndexForState(state); |
| 207 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) { | 230 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) { |
| 208 EXPECT_EQ(i == index, | 231 EXPECT_EQ(i == index, |
| 209 contents_view->GetDefaultContentsBounds() == | 232 contents_view->GetDefaultContentsBounds() == |
| 210 contents_view->GetPageView(i)->bounds()); | 233 contents_view->GetPageView(i)->bounds()); |
| 211 } | 234 } |
| 212 EXPECT_EQ(state, delegate_->GetTestModel()->state()); | 235 EXPECT_EQ(state, delegate_->GetTestModel()->state()); |
| 213 } | 236 } |
| 214 | 237 |
| 215 void AppListViewTestContext::Show() { | 238 void AppListViewTestContext::Show() { |
| 216 view_->GetWidget()->Show(); | 239 view_->GetWidget()->Show(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 main_view->contents_view()->start_page_view(); | 362 main_view->contents_view()->start_page_view(); |
| 340 // Checks on the main view. | 363 // Checks on the main view. |
| 341 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 364 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
| 342 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 365 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
| 343 if (test_type_ == EXPERIMENTAL) { | 366 if (test_type_ == EXPERIMENTAL) { |
| 344 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); | 367 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
| 345 | 368 |
| 346 // Show the start page view. | 369 // Show the start page view. |
| 347 ShowContentsViewPageAndVerify(AppListModel::STATE_START); | 370 ShowContentsViewPageAndVerify(AppListModel::STATE_START); |
| 348 EXPECT_FALSE(main_view->search_box_view()->visible()); | 371 EXPECT_FALSE(main_view->search_box_view()->visible()); |
| 372 gfx::Size view_size(view_->GetPreferredSize()); |
| 349 | 373 |
| 350 gfx::Size view_size(view_->GetPreferredSize()); | 374 // Simulate clicking the "All apps" button. Check that we navigate to the |
| 351 ShowContentsViewPageAndVerify(AppListModel::STATE_APPS); | 375 // apps grid view. |
| 376 SimulateClick(start_page_view->all_apps_button()); |
| 377 main_view->contents_view()->Layout(); |
| 378 VerifyPageActive(AppListModel::STATE_APPS); |
| 352 EXPECT_TRUE(main_view->search_box_view()->visible()); | 379 EXPECT_TRUE(main_view->search_box_view()->visible()); |
| 353 | 380 |
| 354 // Hiding and showing the search box should not affect the app list's | 381 // Hiding and showing the search box should not affect the app list's |
| 355 // preferred size. This is a regression test for http://crbug.com/386912. | 382 // preferred size. This is a regression test for http://crbug.com/386912. |
| 356 EXPECT_EQ(view_size.ToString(), view_->GetPreferredSize().ToString()); | 383 EXPECT_EQ(view_size.ToString(), view_->GetPreferredSize().ToString()); |
| 357 | 384 |
| 358 // Check tiles hide and show on deletion and addition. | 385 // Check tiles hide and show on deletion and addition. |
| 359 model->results()->Add(new TestTileSearchResult()); | 386 model->results()->Add(new TestTileSearchResult()); |
| 360 start_page_view->UpdateForTesting(); | 387 start_page_view->UpdateForTesting(); |
| 361 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views())); | 388 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); |
| 362 model->results()->DeleteAll(); | 389 model->results()->DeleteAll(); |
| 363 start_page_view->UpdateForTesting(); | 390 start_page_view->UpdateForTesting(); |
| 364 EXPECT_EQ(0u, GetVisibleTileItemViews(start_page_view->tile_views())); | 391 EXPECT_EQ(0u, GetVisibleViews(start_page_view->tile_views())); |
| 365 } else { | 392 } else { |
| 366 EXPECT_EQ(NULL, start_page_view); | 393 EXPECT_EQ(NULL, start_page_view); |
| 367 } | 394 } |
| 368 | 395 |
| 369 Close(); | 396 Close(); |
| 370 } | 397 } |
| 371 | 398 |
| 372 void AppListViewTestContext::RunPageSwitchingAnimationTest() { | 399 void AppListViewTestContext::RunPageSwitchingAnimationTest() { |
| 373 if (test_type_ == EXPERIMENTAL) { | 400 if (test_type_ == EXPERIMENTAL) { |
| 374 Show(); | 401 Show(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); | 475 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
| 449 } else { | 476 } else { |
| 450 EXPECT_EQ(NULL, contents_switcher_view); | 477 EXPECT_EQ(NULL, contents_switcher_view); |
| 451 EXPECT_EQ(NULL, start_page_view); | 478 EXPECT_EQ(NULL, start_page_view); |
| 452 } | 479 } |
| 453 | 480 |
| 454 // New model updates should be processed by the start page view. | 481 // New model updates should be processed by the start page view. |
| 455 delegate_->GetTestModel()->results()->Add(new TestTileSearchResult()); | 482 delegate_->GetTestModel()->results()->Add(new TestTileSearchResult()); |
| 456 if (test_type_ == EXPERIMENTAL) { | 483 if (test_type_ == EXPERIMENTAL) { |
| 457 start_page_view->UpdateForTesting(); | 484 start_page_view->UpdateForTesting(); |
| 458 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views())); | 485 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); |
| 459 } | 486 } |
| 460 | 487 |
| 461 // Old model updates should be ignored. | 488 // Old model updates should be ignored. |
| 462 original_test_model->results()->Add(new TestTileSearchResult()); | 489 original_test_model->results()->Add(new TestTileSearchResult()); |
| 463 original_test_model->results()->Add(new TestTileSearchResult()); | 490 original_test_model->results()->Add(new TestTileSearchResult()); |
| 464 if (test_type_ == EXPERIMENTAL) { | 491 if (test_type_ == EXPERIMENTAL) { |
| 465 start_page_view->UpdateForTesting(); | 492 start_page_view->UpdateForTesting(); |
| 466 EXPECT_EQ(1u, GetVisibleTileItemViews(start_page_view->tile_views())); | 493 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); |
| 467 } | 494 } |
| 468 | 495 |
| 469 Close(); | 496 Close(); |
| 470 } | 497 } |
| 471 | 498 |
| 472 void AppListViewTestContext::RunSearchResultsTest() { | 499 void AppListViewTestContext::RunSearchResultsTest() { |
| 473 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 500 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
| 474 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 501 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
| 475 AppListTestModel* model = delegate_->GetTestModel(); | 502 AppListTestModel* model = delegate_->GetTestModel(); |
| 476 model->PopulateApps(3); | 503 model->PopulateApps(3); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 744 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
| 718 AppListViewTestAura, | 745 AppListViewTestAura, |
| 719 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 746 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 720 | 747 |
| 721 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 748 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
| 722 AppListViewTestDesktop, | 749 AppListViewTestDesktop, |
| 723 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 750 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 724 | 751 |
| 725 } // namespace test | 752 } // namespace test |
| 726 } // namespace app_list | 753 } // namespace app_list |
| OLD | NEW |