Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(871)

Side by Side Diff: ui/app_list/views/app_list_view_unittest.cc

Issue 657653002: Move app list search box into AppListView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/app_list_view.cc ('k') | ui/app_list/views/apps_grid_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 26 matching lines...) Expand all
37 namespace { 37 namespace {
38 38
39 enum TestType { 39 enum TestType {
40 TEST_TYPE_START = 0, 40 TEST_TYPE_START = 0,
41 NORMAL = TEST_TYPE_START, 41 NORMAL = TEST_TYPE_START,
42 LANDSCAPE, 42 LANDSCAPE,
43 EXPERIMENTAL, 43 EXPERIMENTAL,
44 TEST_TYPE_END, 44 TEST_TYPE_END,
45 }; 45 };
46 46
47 bool IsViewAtOrigin(views::View* view) {
48 return view->bounds().origin().IsOrigin();
49 }
50
51 size_t GetVisibleTileItemViews(const std::vector<TileItemView*>& tiles) { 47 size_t GetVisibleTileItemViews(const std::vector<TileItemView*>& tiles) {
52 size_t count = 0; 48 size_t count = 0;
53 for (std::vector<TileItemView*>::const_iterator it = tiles.begin(); 49 for (std::vector<TileItemView*>::const_iterator it = tiles.begin();
54 it != tiles.end(); 50 it != tiles.end();
55 ++it) { 51 ++it) {
56 if ((*it)->visible()) 52 if ((*it)->visible())
57 count++; 53 count++;
58 } 54 }
59 return count; 55 return count;
60 } 56 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 EXPECT_TRUE(subview->parent()); 196 EXPECT_TRUE(subview->parent());
201 EXPECT_TRUE(subview->visible()); 197 EXPECT_TRUE(subview->visible());
202 EXPECT_TRUE(subview->IsDrawn()); 198 EXPECT_TRUE(subview->IsDrawn());
203 } 199 }
204 200
205 void AppListViewTestContext::ShowContentsViewPageAndVerify(int index) { 201 void AppListViewTestContext::ShowContentsViewPageAndVerify(int index) {
206 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); 202 ContentsView* contents_view = view_->app_list_main_view()->contents_view();
207 contents_view->SetActivePage(index); 203 contents_view->SetActivePage(index);
208 contents_view->Layout(); 204 contents_view->Layout();
209 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) { 205 for (int i = 0; i < contents_view->NumLauncherPages(); ++i) {
210 EXPECT_EQ(i == index, IsViewAtOrigin(contents_view->GetPageView(i))); 206 EXPECT_EQ(i == index,
207 contents_view->GetDefaultContentsBounds() ==
208 contents_view->GetPageView(i)->bounds());
211 } 209 }
212 } 210 }
213 211
214 void AppListViewTestContext::Show() { 212 void AppListViewTestContext::Show() {
215 view_->GetWidget()->Show(); 213 view_->GetWidget()->Show();
216 run_loop_.reset(new base::RunLoop); 214 run_loop_.reset(new base::RunLoop);
217 view_->SetNextPaintCallback(run_loop_->QuitClosure()); 215 view_->SetNextPaintCallback(run_loop_->QuitClosure());
218 run_loop_->Run(); 216 run_loop_->Run();
219 217
220 EXPECT_TRUE(view_->GetWidget()->IsVisible()); 218 EXPECT_TRUE(view_->GetWidget()->IsVisible());
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 EXPECT_NO_FATAL_FAILURE(CheckView(main_view)); 376 EXPECT_NO_FATAL_FAILURE(CheckView(main_view));
379 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view())); 377 EXPECT_NO_FATAL_FAILURE(CheckView(main_view->contents_view()));
380 378
381 ContentsView* contents_view = main_view->contents_view(); 379 ContentsView* contents_view = main_view->contents_view();
382 // Pad the ContentsView with blank pages so we have at least 3 views. 380 // Pad the ContentsView with blank pages so we have at least 3 views.
383 while (contents_view->NumLauncherPages() < 3) 381 while (contents_view->NumLauncherPages() < 3)
384 contents_view->AddBlankPageForTesting(); 382 contents_view->AddBlankPageForTesting();
385 383
386 contents_view->SetActivePage(0); 384 contents_view->SetActivePage(0);
387 contents_view->Layout(); 385 contents_view->Layout();
388 EXPECT_TRUE(IsViewAtOrigin(contents_view->GetPageView(0))); 386
389 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(1))); 387 const gfx::Rect expected_bounds = contents_view->GetDefaultContentsBounds();
390 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(2))); 388
389 EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds());
390 EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds());
391 EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds());
391 392
392 // Change pages. View should not have moved without Layout(). 393 // Change pages. View should not have moved without Layout().
393 contents_view->SetActivePage(1); 394 contents_view->SetActivePage(1);
394 EXPECT_TRUE(IsViewAtOrigin(contents_view->GetPageView(0))); 395 EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds());
395 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(1))); 396 EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds());
396 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(2))); 397 EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds());
397 398
398 // Change to a third page. This queues up the second animation behind the 399 // Change to a third page. This queues up the second animation behind the
399 // first. 400 // first.
400 contents_view->SetActivePage(2); 401 contents_view->SetActivePage(2);
401 EXPECT_TRUE(IsViewAtOrigin(contents_view->GetPageView(0))); 402 EXPECT_EQ(expected_bounds, contents_view->GetPageView(0)->bounds());
402 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(1))); 403 EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds());
403 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(2))); 404 EXPECT_NE(expected_bounds, contents_view->GetPageView(2)->bounds());
404 405
405 // Call Layout(). Should jump to the third page. 406 // Call Layout(). Should jump to the third page.
406 contents_view->Layout(); 407 contents_view->Layout();
407 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(0))); 408 EXPECT_NE(expected_bounds, contents_view->GetPageView(0)->bounds());
408 EXPECT_FALSE(IsViewAtOrigin(contents_view->GetPageView(1))); 409 EXPECT_NE(expected_bounds, contents_view->GetPageView(1)->bounds());
409 EXPECT_TRUE(IsViewAtOrigin(contents_view->GetPageView(2))); 410 EXPECT_EQ(expected_bounds, contents_view->GetPageView(2)->bounds());
410 } 411 }
411 412
412 Close(); 413 Close();
413 } 414 }
414 415
415 void AppListViewTestContext::RunProfileChangeTest() { 416 void AppListViewTestContext::RunProfileChangeTest() {
416 EXPECT_FALSE(view_->GetWidget()->IsVisible()); 417 EXPECT_FALSE(view_->GetWidget()->IsVisible());
417 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); 418 EXPECT_EQ(-1, GetPaginationModel()->total_pages());
418 delegate_->GetTestModel()->PopulateApps(kInitialItems); 419 delegate_->GetTestModel()->PopulateApps(kInitialItems);
419 420
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 ShowContentsViewPageAndVerify( 480 ShowContentsViewPageAndVerify(
480 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); 481 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS));
481 EXPECT_TRUE(main_view->search_box_view()->visible()); 482 EXPECT_TRUE(main_view->search_box_view()->visible());
482 483
483 // Show the search results. 484 // Show the search results.
484 contents_view->ShowSearchResults(true); 485 contents_view->ShowSearchResults(true);
485 contents_view->Layout(); 486 contents_view->Layout();
486 EXPECT_TRUE(contents_view->IsShowingSearchResults()); 487 EXPECT_TRUE(contents_view->IsShowingSearchResults());
487 EXPECT_TRUE(main_view->search_box_view()->visible()); 488 EXPECT_TRUE(main_view->search_box_view()->visible());
488 489
490 const gfx::Rect default_contents_bounds =
491 contents_view->GetDefaultContentsBounds();
489 if (test_type_ == EXPERIMENTAL) { 492 if (test_type_ == EXPERIMENTAL) {
490 EXPECT_TRUE( 493 EXPECT_TRUE(
491 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START)); 494 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START));
492 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view())); 495 EXPECT_EQ(default_contents_bounds,
496 contents_view->start_page_view()->bounds());
493 } else { 497 } else {
494 EXPECT_TRUE(contents_view->IsNamedPageActive( 498 EXPECT_TRUE(contents_view->IsNamedPageActive(
495 ContentsView::NAMED_PAGE_SEARCH_RESULTS)); 499 ContentsView::NAMED_PAGE_SEARCH_RESULTS));
496 EXPECT_TRUE(IsViewAtOrigin(contents_view->search_results_view())); 500 EXPECT_EQ(default_contents_bounds,
501 contents_view->search_results_view()->bounds());
497 } 502 }
498 503
499 // Hide the search results. 504 // Hide the search results.
500 contents_view->ShowSearchResults(false); 505 contents_view->ShowSearchResults(false);
501 contents_view->Layout(); 506 contents_view->Layout();
502 EXPECT_FALSE(contents_view->IsShowingSearchResults()); 507 EXPECT_FALSE(contents_view->IsShowingSearchResults());
503 508
504 // Check that we return to the page that we were on before the search. 509 // Check that we return to the page that we were on before the search.
505 EXPECT_TRUE(contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_APPS)); 510 EXPECT_TRUE(contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_APPS));
506 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); 511 EXPECT_EQ(default_contents_bounds,
512 contents_view->apps_container_view()->bounds());
507 EXPECT_TRUE(main_view->search_box_view()->visible()); 513 EXPECT_TRUE(main_view->search_box_view()->visible());
508 514
509 if (test_type_ == EXPERIMENTAL) { 515 if (test_type_ == EXPERIMENTAL) {
510 ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage( 516 ShowContentsViewPageAndVerify(contents_view->GetPageIndexForNamedPage(
511 ContentsView::NAMED_PAGE_START)); 517 ContentsView::NAMED_PAGE_START));
512 518
513 // Check that typing into the dummy search box triggers the search page. 519 // Check that typing into the dummy search box triggers the search page.
514 base::string16 search_text = base::UTF8ToUTF16("test"); 520 base::string16 search_text = base::UTF8ToUTF16("test");
515 SearchBoxView* dummy_search_box = 521 SearchBoxView* dummy_search_box =
516 contents_view->start_page_view()->dummy_search_box_view(); 522 contents_view->start_page_view()->dummy_search_box_view();
517 EXPECT_TRUE(dummy_search_box->IsDrawn()); 523 EXPECT_TRUE(dummy_search_box->IsDrawn());
518 dummy_search_box->search_box()->InsertText(search_text); 524 dummy_search_box->search_box()->InsertText(search_text);
519 contents_view->Layout(); 525 contents_view->Layout();
520 // Check that the current search is using |search_text|. 526 // Check that the current search is using |search_text|.
521 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); 527 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text());
522 EXPECT_TRUE(contents_view->IsShowingSearchResults()); 528 EXPECT_TRUE(contents_view->IsShowingSearchResults());
523 EXPECT_FALSE(dummy_search_box->IsDrawn()); 529 EXPECT_FALSE(dummy_search_box->IsDrawn());
524 EXPECT_TRUE(main_view->search_box_view()->visible()); 530 EXPECT_TRUE(main_view->search_box_view()->visible());
525 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); 531 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text());
526 EXPECT_TRUE( 532 EXPECT_TRUE(
527 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START)); 533 contents_view->IsNamedPageActive(ContentsView::NAMED_PAGE_START));
528 EXPECT_TRUE(IsViewAtOrigin(contents_view->start_page_view())); 534 EXPECT_EQ(default_contents_bounds,
535 contents_view->start_page_view()->bounds());
529 536
530 // Check that typing into the real search box triggers the search page. 537 // Check that typing into the real search box triggers the search page.
531 ShowContentsViewPageAndVerify( 538 ShowContentsViewPageAndVerify(
532 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS)); 539 contents_view->GetPageIndexForNamedPage(ContentsView::NAMED_PAGE_APPS));
533 EXPECT_TRUE(IsViewAtOrigin(contents_view->apps_container_view())); 540 EXPECT_EQ(default_contents_bounds,
541 contents_view->apps_container_view()->bounds());
534 542
535 base::string16 new_search_text = base::UTF8ToUTF16("apple"); 543 base::string16 new_search_text = base::UTF8ToUTF16("apple");
536 main_view->search_box_view()->search_box()->SetText(base::string16()); 544 main_view->search_box_view()->search_box()->SetText(base::string16());
537 main_view->search_box_view()->search_box()->InsertText(new_search_text); 545 main_view->search_box_view()->search_box()->InsertText(new_search_text);
538 // Check that the current search is using |search_text|. 546 // Check that the current search is using |search_text|.
539 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); 547 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text());
540 EXPECT_EQ(new_search_text, 548 EXPECT_EQ(new_search_text,
541 main_view->search_box_view()->search_box()->text()); 549 main_view->search_box_view()->search_box()->text());
542 EXPECT_TRUE(contents_view->IsShowingSearchResults()); 550 EXPECT_TRUE(contents_view->IsShowingSearchResults());
543 EXPECT_FALSE(dummy_search_box->IsDrawn()); 551 EXPECT_FALSE(dummy_search_box->IsDrawn());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, 717 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance,
710 AppListViewTestAura, 718 AppListViewTestAura,
711 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); 719 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
712 720
713 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, 721 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance,
714 AppListViewTestDesktop, 722 AppListViewTestDesktop,
715 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); 723 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END));
716 724
717 } // namespace test 725 } // namespace test
718 } // namespace app_list 726 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_view.cc ('k') | ui/app_list/views/apps_grid_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698