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_page_view.h" | |
26 #include "ui/app_list/views/search_result_tile_item_view.h" | 27 #include "ui/app_list/views/search_result_tile_item_view.h" |
27 #include "ui/app_list/views/start_page_view.h" | 28 #include "ui/app_list/views/start_page_view.h" |
28 #include "ui/app_list/views/test/apps_grid_view_test_api.h" | 29 #include "ui/app_list/views/test/apps_grid_view_test_api.h" |
29 #include "ui/app_list/views/tile_item_view.h" | 30 #include "ui/app_list/views/tile_item_view.h" |
30 #include "ui/views/controls/textfield/textfield.h" | 31 #include "ui/views/controls/textfield/textfield.h" |
31 #include "ui/views/test/views_test_base.h" | 32 #include "ui/views/test/views_test_base.h" |
32 #include "ui/views/views_delegate.h" | 33 #include "ui/views/views_delegate.h" |
33 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 34 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
34 | 35 |
35 namespace app_list { | 36 namespace app_list { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 121 } |
121 | 122 |
122 // Whether the experimental "landscape" app launcher UI is being tested. | 123 // Whether the experimental "landscape" app launcher UI is being tested. |
123 bool is_landscape() const { | 124 bool is_landscape() const { |
124 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; | 125 return test_type_ == LANDSCAPE || test_type_ == EXPERIMENTAL; |
125 } | 126 } |
126 | 127 |
127 private: | 128 private: |
128 // Switches the active launcher page in the contents view and lays out to | 129 // Switches the active launcher page in the contents view and lays out to |
129 // ensure all launcher pages are in the correct position. | 130 // ensure all launcher pages are in the correct position. |
130 void ShowContentsViewPageAndVerify(AppListModel::State state); | 131 bool ShowContentsViewPageAndVerify(AppListModel::State state); |
Matt Giuca
2014/10/29 03:40:53
Why did you change to bools now? Is it just becaus
calamity
2014/10/29 06:27:53
Yah, got a failure, got angry trying to find it.
| |
131 | 132 |
132 // Tests that the app list is in |state|. | 133 // Tests that the app list is in |state|. |
133 void VerifyPageActive(AppListModel::State state); | 134 bool VerifyPageActive(AppListModel::State state); |
134 | 135 |
135 // Shows the app list and waits until a paint occurs. | 136 // Shows the app list and waits until a paint occurs. |
136 void Show(); | 137 void Show(); |
137 | 138 |
138 // Closes the app list. This sets |view_| to NULL. | 139 // Closes the app list. This sets |view_| to NULL. |
139 void Close(); | 140 void Close(); |
140 | 141 |
141 // Gets the PaginationModel owned by |view_|. | 142 // Gets the PaginationModel owned by |view_|. |
142 PaginationModel* GetPaginationModel(); | 143 PaginationModel* GetPaginationModel(); |
143 | 144 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 } | 209 } |
209 | 210 |
210 // static | 211 // static |
211 void AppListViewTestContext::CheckView(views::View* subview) { | 212 void AppListViewTestContext::CheckView(views::View* subview) { |
212 ASSERT_TRUE(subview); | 213 ASSERT_TRUE(subview); |
213 EXPECT_TRUE(subview->parent()); | 214 EXPECT_TRUE(subview->parent()); |
214 EXPECT_TRUE(subview->visible()); | 215 EXPECT_TRUE(subview->visible()); |
215 EXPECT_TRUE(subview->IsDrawn()); | 216 EXPECT_TRUE(subview->IsDrawn()); |
216 } | 217 } |
217 | 218 |
218 void AppListViewTestContext::ShowContentsViewPageAndVerify( | 219 bool AppListViewTestContext::ShowContentsViewPageAndVerify( |
219 AppListModel::State state) { | 220 AppListModel::State state) { |
220 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); | 221 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); |
221 int index = contents_view->GetPageIndexForState(state); | 222 int index = contents_view->GetPageIndexForState(state); |
222 contents_view->SetActivePage(index); | 223 contents_view->SetActivePage(index); |
223 contents_view->Layout(); | 224 contents_view->Layout(); |
224 VerifyPageActive(state); | 225 return VerifyPageActive(state); |
225 } | 226 } |
226 | 227 |
227 void AppListViewTestContext::VerifyPageActive(AppListModel::State state) { | 228 bool AppListViewTestContext::VerifyPageActive(AppListModel::State state) { |
228 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); | 229 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); |
229 int index = contents_view->GetPageIndexForState(state); | 230 int index = contents_view->GetPageIndexForState(state); |
231 bool success = true; | |
230 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) { | 232 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) { |
231 EXPECT_EQ(i == index, | 233 success = success && |
232 contents_view->GetDefaultContentsBounds() == | 234 (i == index) == (contents_view->GetDefaultContentsBounds() == |
233 contents_view->GetPageView(i)->bounds()); | 235 contents_view->GetPageView(i)->bounds()); |
234 } | 236 } |
235 EXPECT_EQ(state, delegate_->GetTestModel()->state()); | 237 return success && state == delegate_->GetTestModel()->state(); |
236 } | 238 } |
237 | 239 |
238 void AppListViewTestContext::Show() { | 240 void AppListViewTestContext::Show() { |
239 view_->GetWidget()->Show(); | 241 view_->GetWidget()->Show(); |
240 run_loop_.reset(new base::RunLoop); | 242 run_loop_.reset(new base::RunLoop); |
241 view_->SetNextPaintCallback(run_loop_->QuitClosure()); | 243 view_->SetNextPaintCallback(run_loop_->QuitClosure()); |
242 run_loop_->Run(); | 244 run_loop_->Run(); |
243 | 245 |
244 EXPECT_TRUE(view_->GetWidget()->IsVisible()); | 246 EXPECT_TRUE(view_->GetWidget()->IsVisible()); |
245 } | 247 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 AppListMainView* main_view = view_->app_list_main_view(); | 362 AppListMainView* main_view = view_->app_list_main_view(); |
361 StartPageView* start_page_view = | 363 StartPageView* start_page_view = |
362 main_view->contents_view()->start_page_view(); | 364 main_view->contents_view()->start_page_view(); |
363 // Checks on the main view. | 365 // Checks on the main view. |
364 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); | 366 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); |
365 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); | 367 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); |
366 if (test_type_ == EXPERIMENTAL) { | 368 if (test_type_ == EXPERIMENTAL) { |
367 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); | 369 EXPECT_NO_FATAL_FAILURE(CheckView(start_page_view)); |
368 | 370 |
369 // Show the start page view. | 371 // Show the start page view. |
370 ShowContentsViewPageAndVerify(AppListModel::STATE_START); | 372 EXPECT_TRUE(ShowContentsViewPageAndVerify(AppListModel::STATE_START)); |
371 EXPECT_FALSE(main_view->search_box_view()->visible()); | 373 EXPECT_FALSE(main_view->search_box_view()->visible()); |
372 gfx::Size view_size(view_->GetPreferredSize()); | 374 gfx::Size view_size(view_->GetPreferredSize()); |
373 | 375 |
374 // Simulate clicking the "All apps" button. Check that we navigate to the | 376 // Simulate clicking the "All apps" button. Check that we navigate to the |
375 // apps grid view. | 377 // apps grid view. |
376 SimulateClick(start_page_view->all_apps_button()); | 378 SimulateClick(start_page_view->all_apps_button()); |
377 main_view->contents_view()->Layout(); | 379 main_view->contents_view()->Layout(); |
378 VerifyPageActive(AppListModel::STATE_APPS); | 380 EXPECT_TRUE(VerifyPageActive(AppListModel::STATE_APPS)); |
379 EXPECT_TRUE(main_view->search_box_view()->visible()); | 381 EXPECT_TRUE(main_view->search_box_view()->visible()); |
380 | 382 |
381 // Hiding and showing the search box should not affect the app list's | 383 // Hiding and showing the search box should not affect the app list's |
382 // preferred size. This is a regression test for http://crbug.com/386912. | 384 // preferred size. This is a regression test for http://crbug.com/386912. |
383 EXPECT_EQ(view_size.ToString(), view_->GetPreferredSize().ToString()); | 385 EXPECT_EQ(view_size.ToString(), view_->GetPreferredSize().ToString()); |
384 | 386 |
385 // Check tiles hide and show on deletion and addition. | 387 // Check tiles hide and show on deletion and addition. |
386 model->results()->Add(new TestTileSearchResult()); | 388 model->results()->Add(new TestTileSearchResult()); |
387 start_page_view->UpdateForTesting(); | 389 start_page_view->UpdateForTesting(); |
388 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); | 390 EXPECT_EQ(1u, GetVisibleViews(start_page_view->tile_views())); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 void AppListViewTestContext::RunSearchResultsTest() { | 501 void AppListViewTestContext::RunSearchResultsTest() { |
500 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 502 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
501 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 503 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
502 AppListTestModel* model = delegate_->GetTestModel(); | 504 AppListTestModel* model = delegate_->GetTestModel(); |
503 model->PopulateApps(3); | 505 model->PopulateApps(3); |
504 | 506 |
505 Show(); | 507 Show(); |
506 | 508 |
507 AppListMainView* main_view = view_->app_list_main_view(); | 509 AppListMainView* main_view = view_->app_list_main_view(); |
508 ContentsView* contents_view = main_view->contents_view(); | 510 ContentsView* contents_view = main_view->contents_view(); |
509 ShowContentsViewPageAndVerify(AppListModel::STATE_APPS); | 511 EXPECT_TRUE(ShowContentsViewPageAndVerify(AppListModel::STATE_APPS)); |
510 EXPECT_TRUE(main_view->search_box_view()->visible()); | 512 EXPECT_TRUE(main_view->search_box_view()->visible()); |
511 | 513 |
512 // Show the search results. | 514 // Show the search results. |
513 contents_view->ShowSearchResults(true); | 515 contents_view->ShowSearchResults(true); |
514 contents_view->Layout(); | 516 contents_view->Layout(); |
515 EXPECT_TRUE(contents_view->IsShowingSearchResults()); | 517 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
516 EXPECT_TRUE(main_view->search_box_view()->visible()); | 518 EXPECT_TRUE(main_view->search_box_view()->visible()); |
517 | 519 |
518 const gfx::Rect default_contents_bounds = | 520 const gfx::Rect default_contents_bounds = |
519 contents_view->GetDefaultContentsBounds(); | 521 contents_view->GetDefaultContentsBounds(); |
520 if (test_type_ == EXPERIMENTAL) { | 522 if (test_type_ == EXPERIMENTAL) { |
521 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_START)); | |
522 EXPECT_EQ(AppListModel::STATE_START, delegate_->GetTestModel()->state()); | |
523 EXPECT_EQ(default_contents_bounds, | |
524 contents_view->start_page_view()->bounds()); | |
525 } else { | |
526 EXPECT_TRUE( | |
527 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | |
528 EXPECT_EQ(AppListModel::STATE_SEARCH_RESULTS, | 523 EXPECT_EQ(AppListModel::STATE_SEARCH_RESULTS, |
529 delegate_->GetTestModel()->state()); | 524 delegate_->GetTestModel()->state()); |
530 EXPECT_EQ(default_contents_bounds, | 525 EXPECT_EQ(default_contents_bounds, |
531 contents_view->search_results_view()->bounds()); | 526 contents_view->search_results_page_view()->bounds()); |
527 } else { | |
528 EXPECT_EQ(AppListModel::STATE_SEARCH_RESULTS, | |
529 delegate_->GetTestModel()->state()); | |
530 EXPECT_EQ(default_contents_bounds, | |
531 contents_view->search_results_list_view()->bounds()); | |
532 } | 532 } |
533 | 533 |
534 // Hide the search results. | 534 // Hide the search results. |
535 contents_view->ShowSearchResults(false); | 535 contents_view->ShowSearchResults(false); |
536 contents_view->Layout(); | 536 contents_view->Layout(); |
537 EXPECT_FALSE(contents_view->IsShowingSearchResults()); | |
538 | 537 |
539 // Check that we return to the page that we were on before the search. | 538 // Check that we return to the page that we were on before the search. |
540 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_APPS)); | 539 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_APPS)); |
541 EXPECT_EQ(AppListModel::STATE_APPS, delegate_->GetTestModel()->state()); | 540 EXPECT_EQ(AppListModel::STATE_APPS, delegate_->GetTestModel()->state()); |
542 EXPECT_EQ(default_contents_bounds, | 541 EXPECT_EQ(default_contents_bounds, |
543 contents_view->apps_container_view()->bounds()); | 542 contents_view->apps_container_view()->bounds()); |
544 EXPECT_TRUE(main_view->search_box_view()->visible()); | 543 EXPECT_TRUE(main_view->search_box_view()->visible()); |
545 | 544 |
546 if (test_type_ == EXPERIMENTAL) { | 545 if (test_type_ == EXPERIMENTAL) { |
547 ShowContentsViewPageAndVerify(AppListModel::STATE_START); | 546 EXPECT_TRUE(ShowContentsViewPageAndVerify(AppListModel::STATE_START)); |
548 | 547 |
549 // Check that typing into the dummy search box triggers the search page. | 548 // Check that typing into the dummy search box triggers the search page. |
550 base::string16 search_text = base::UTF8ToUTF16("test"); | 549 base::string16 search_text = base::UTF8ToUTF16("test"); |
551 SearchBoxView* dummy_search_box = | 550 SearchBoxView* dummy_search_box = |
552 contents_view->start_page_view()->dummy_search_box_view(); | 551 contents_view->start_page_view()->dummy_search_box_view(); |
553 EXPECT_TRUE(dummy_search_box->IsDrawn()); | 552 EXPECT_TRUE(dummy_search_box->IsDrawn()); |
554 dummy_search_box->search_box()->InsertText(search_text); | 553 dummy_search_box->search_box()->InsertText(search_text); |
555 contents_view->Layout(); | 554 contents_view->Layout(); |
556 // Check that the current search is using |search_text|. | 555 // Check that the current search is using |search_text|. |
557 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); | 556 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); |
558 EXPECT_TRUE(contents_view->IsShowingSearchResults()); | |
559 EXPECT_FALSE(dummy_search_box->IsDrawn()); | |
560 EXPECT_TRUE(main_view->search_box_view()->visible()); | 557 EXPECT_TRUE(main_view->search_box_view()->visible()); |
561 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); | 558 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); |
562 EXPECT_TRUE(contents_view->IsStateActive(AppListModel::STATE_START)); | 559 EXPECT_TRUE( |
563 EXPECT_EQ(AppListModel::STATE_START, delegate_->GetTestModel()->state()); | 560 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
561 EXPECT_EQ(AppListModel::STATE_SEARCH_RESULTS, | |
562 delegate_->GetTestModel()->state()); | |
564 EXPECT_EQ(default_contents_bounds, | 563 EXPECT_EQ(default_contents_bounds, |
565 contents_view->start_page_view()->bounds()); | 564 contents_view->search_results_page_view()->bounds()); |
566 | 565 |
567 // Check that typing into the real search box triggers the search page. | 566 // Check that typing into the real search box triggers the search page. |
568 ShowContentsViewPageAndVerify(AppListModel::STATE_APPS); | 567 EXPECT_TRUE(ShowContentsViewPageAndVerify(AppListModel::STATE_APPS)); |
569 EXPECT_EQ(default_contents_bounds, | 568 EXPECT_EQ(default_contents_bounds, |
570 contents_view->apps_container_view()->bounds()); | 569 contents_view->apps_container_view()->bounds()); |
571 | 570 |
572 base::string16 new_search_text = base::UTF8ToUTF16("apple"); | 571 base::string16 new_search_text = base::UTF8ToUTF16("apple"); |
573 main_view->search_box_view()->search_box()->SetText(base::string16()); | 572 main_view->search_box_view()->search_box()->SetText(base::string16()); |
574 main_view->search_box_view()->search_box()->InsertText(new_search_text); | 573 main_view->search_box_view()->search_box()->InsertText(new_search_text); |
575 // Check that the current search is using |search_text|. | 574 // Check that the current search is using |search_text|. |
576 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); | 575 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); |
577 EXPECT_EQ(new_search_text, | 576 EXPECT_EQ(new_search_text, |
578 main_view->search_box_view()->search_box()->text()); | 577 main_view->search_box_view()->search_box()->text()); |
579 EXPECT_TRUE(contents_view->IsShowingSearchResults()); | 578 contents_view->Layout(); |
580 EXPECT_FALSE(dummy_search_box->IsDrawn()); | 579 EXPECT_TRUE( |
580 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | |
581 EXPECT_TRUE(main_view->search_box_view()->visible()); | 581 EXPECT_TRUE(main_view->search_box_view()->visible()); |
582 EXPECT_TRUE(dummy_search_box->search_box()->text().empty()); | 582 EXPECT_TRUE(dummy_search_box->search_box()->text().empty()); |
583 | 583 |
584 // Check that the dummy search box is clear when reshowing the start page. | 584 // Check that the dummy search box is clear when reshowing the start page. |
585 ShowContentsViewPageAndVerify(AppListModel::STATE_APPS); | 585 EXPECT_TRUE(ShowContentsViewPageAndVerify(AppListModel::STATE_APPS)); |
586 ShowContentsViewPageAndVerify(AppListModel::STATE_START); | 586 EXPECT_TRUE(ShowContentsViewPageAndVerify(AppListModel::STATE_START)); |
587 EXPECT_TRUE(dummy_search_box->IsDrawn()); | 587 EXPECT_TRUE(dummy_search_box->IsDrawn()); |
588 EXPECT_TRUE(dummy_search_box->search_box()->text().empty()); | 588 EXPECT_TRUE(dummy_search_box->search_box()->text().empty()); |
589 } | 589 } |
590 | 590 |
591 Close(); | 591 Close(); |
592 } | 592 } |
593 | 593 |
594 class AppListViewTestAura : public views::ViewsTestBase, | 594 class AppListViewTestAura : public views::ViewsTestBase, |
595 public ::testing::WithParamInterface<int> { | 595 public ::testing::WithParamInterface<int> { |
596 public: | 596 public: |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 744 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
745 AppListViewTestAura, | 745 AppListViewTestAura, |
746 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 746 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
747 | 747 |
748 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 748 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
749 AppListViewTestDesktop, | 749 AppListViewTestDesktop, |
750 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 750 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
751 | 751 |
752 } // namespace test | 752 } // namespace test |
753 } // namespace app_list | 753 } // namespace app_list |
OLD | NEW |