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