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

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

Powered by Google App Engine
This is Rietveld 408576698