| 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" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 // Returns whether the app list showing |state|. | 136 // Returns whether the app list showing |state|. |
| 137 bool IsStateShown(AppListModel::State state); | 137 bool IsStateShown(AppListModel::State state); |
| 138 | 138 |
| 139 // Shows the app list and waits until a paint occurs. | 139 // Shows the app list and waits until a paint occurs. |
| 140 void Show(); | 140 void Show(); |
| 141 | 141 |
| 142 // Closes the app list. This sets |view_| to NULL. | 142 // Closes the app list. This sets |view_| to NULL. |
| 143 void Close(); | 143 void Close(); |
| 144 | 144 |
| 145 // Checks the search box widget is at |expected| in the contents view's |
| 146 // coordinate space. |
| 147 bool CheckSearchBoxWidget(const gfx::Rect& expected); |
| 148 |
| 145 // Gets the PaginationModel owned by |view_|. | 149 // Gets the PaginationModel owned by |view_|. |
| 146 PaginationModel* GetPaginationModel(); | 150 PaginationModel* GetPaginationModel(); |
| 147 | 151 |
| 148 const TestType test_type_; | 152 const TestType test_type_; |
| 149 scoped_ptr<base::RunLoop> run_loop_; | 153 scoped_ptr<base::RunLoop> run_loop_; |
| 150 app_list::AppListView* view_; // Owned by native widget. | 154 app_list::AppListView* view_; // Owned by native widget. |
| 151 scoped_ptr<app_list::test::AppListTestViewDelegate> delegate_; | 155 scoped_ptr<app_list::test::AppListTestViewDelegate> delegate_; |
| 152 | 156 |
| 153 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); | 157 DISALLOW_COPY_AND_ASSIGN(AppListViewTestContext); |
| 154 }; | 158 }; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 256 |
| 253 void AppListViewTestContext::Close() { | 257 void AppListViewTestContext::Close() { |
| 254 view_->GetWidget()->Close(); | 258 view_->GetWidget()->Close(); |
| 255 run_loop_.reset(new base::RunLoop); | 259 run_loop_.reset(new base::RunLoop); |
| 256 run_loop_->Run(); | 260 run_loop_->Run(); |
| 257 | 261 |
| 258 // |view_| should have been deleted and set to NULL via ViewClosing(). | 262 // |view_| should have been deleted and set to NULL via ViewClosing(). |
| 259 EXPECT_FALSE(view_); | 263 EXPECT_FALSE(view_); |
| 260 } | 264 } |
| 261 | 265 |
| 266 bool AppListViewTestContext::CheckSearchBoxWidget(const gfx::Rect& expected) { |
| 267 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); |
| 268 gfx::Point point = expected.origin(); |
| 269 views::View::ConvertPointToScreen(contents_view, &point); |
| 270 |
| 271 return gfx::Rect(point, expected.size()) == |
| 272 view_->search_box_widget()->GetWindowBoundsInScreen(); |
| 273 } |
| 274 |
| 262 PaginationModel* AppListViewTestContext::GetPaginationModel() { | 275 PaginationModel* AppListViewTestContext::GetPaginationModel() { |
| 263 return view_->GetAppsPaginationModel(); | 276 return view_->GetAppsPaginationModel(); |
| 264 } | 277 } |
| 265 | 278 |
| 266 void AppListViewTestContext::RunDisplayTest() { | 279 void AppListViewTestContext::RunDisplayTest() { |
| 267 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 280 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
| 268 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 281 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
| 269 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 282 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
| 270 | 283 |
| 271 Show(); | 284 Show(); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 EXPECT_EQ(default_contents_bounds, | 604 EXPECT_EQ(default_contents_bounds, |
| 592 contents_view->apps_container_view()->bounds()); | 605 contents_view->apps_container_view()->bounds()); |
| 593 | 606 |
| 594 if (test_type_ == EXPERIMENTAL) { | 607 if (test_type_ == EXPERIMENTAL) { |
| 595 // Check that typing into the search box triggers the search page. | 608 // Check that typing into the search box triggers the search page. |
| 596 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); | 609 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); |
| 597 view_->Layout(); | 610 view_->Layout(); |
| 598 EXPECT_EQ(default_contents_bounds, | 611 EXPECT_EQ(default_contents_bounds, |
| 599 contents_view->start_page_view()->bounds()); | 612 contents_view->start_page_view()->bounds()); |
| 600 // TODO(mgiuca): The search box should be small and centered. | 613 // TODO(mgiuca): The search box should be small and centered. |
| 601 EXPECT_EQ(contents_view->GetDefaultSearchBoxBounds(), | 614 EXPECT_TRUE( |
| 602 view_->search_box_view()->bounds()); | 615 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
| 603 | 616 |
| 604 base::string16 search_text = base::UTF8ToUTF16("test"); | 617 base::string16 search_text = base::UTF8ToUTF16("test"); |
| 605 main_view->search_box_view()->search_box()->SetText(base::string16()); | 618 main_view->search_box_view()->search_box()->SetText(base::string16()); |
| 606 main_view->search_box_view()->search_box()->InsertText(search_text); | 619 main_view->search_box_view()->search_box()->InsertText(search_text); |
| 607 // Check that the current search is using |search_text|. | 620 // Check that the current search is using |search_text|. |
| 608 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); | 621 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); |
| 609 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); | 622 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); |
| 610 view_->Layout(); | 623 view_->Layout(); |
| 611 EXPECT_TRUE( | 624 EXPECT_TRUE( |
| 612 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | 625 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
| 613 EXPECT_EQ(contents_view->GetDefaultSearchBoxBounds(), | 626 EXPECT_TRUE( |
| 614 view_->search_box_view()->bounds()); | 627 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
| 615 | 628 |
| 616 // Check that typing into the search box triggers the search page. | 629 // Check that typing into the search box triggers the search page. |
| 617 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); | 630 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); |
| 618 view_->Layout(); | 631 view_->Layout(); |
| 619 EXPECT_EQ(default_contents_bounds, | 632 EXPECT_EQ(default_contents_bounds, |
| 620 contents_view->apps_container_view()->bounds()); | 633 contents_view->apps_container_view()->bounds()); |
| 621 EXPECT_EQ(contents_view->GetDefaultSearchBoxBounds(), | 634 EXPECT_TRUE( |
| 622 view_->search_box_view()->bounds()); | 635 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
| 623 | 636 |
| 624 base::string16 new_search_text = base::UTF8ToUTF16("apple"); | 637 base::string16 new_search_text = base::UTF8ToUTF16("apple"); |
| 625 main_view->search_box_view()->search_box()->SetText(base::string16()); | 638 main_view->search_box_view()->search_box()->SetText(base::string16()); |
| 626 main_view->search_box_view()->search_box()->InsertText(new_search_text); | 639 main_view->search_box_view()->search_box()->InsertText(new_search_text); |
| 627 // Check that the current search is using |new_search_text|. | 640 // Check that the current search is using |new_search_text|. |
| 628 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); | 641 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); |
| 629 EXPECT_EQ(new_search_text, | 642 EXPECT_EQ(new_search_text, |
| 630 main_view->search_box_view()->search_box()->text()); | 643 main_view->search_box_view()->search_box()->text()); |
| 631 view_->Layout(); | 644 view_->Layout(); |
| 632 EXPECT_TRUE( | 645 EXPECT_TRUE( |
| 633 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | 646 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
| 634 EXPECT_EQ(contents_view->GetDefaultSearchBoxBounds(), | 647 EXPECT_TRUE( |
| 635 view_->search_box_view()->bounds()); | 648 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
| 636 } | 649 } |
| 637 | 650 |
| 638 Close(); | 651 Close(); |
| 639 } | 652 } |
| 640 | 653 |
| 641 class AppListViewTestAura : public views::ViewsTestBase, | 654 class AppListViewTestAura : public views::ViewsTestBase, |
| 642 public ::testing::WithParamInterface<int> { | 655 public ::testing::WithParamInterface<int> { |
| 643 public: | 656 public: |
| 644 AppListViewTestAura() {} | 657 AppListViewTestAura() {} |
| 645 virtual ~AppListViewTestAura() {} | 658 virtual ~AppListViewTestAura() {} |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 813 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
| 801 AppListViewTestAura, | 814 AppListViewTestAura, |
| 802 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 815 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 803 | 816 |
| 804 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 817 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
| 805 AppListViewTestDesktop, | 818 AppListViewTestDesktop, |
| 806 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 819 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
| 807 | 820 |
| 808 } // namespace test | 821 } // namespace test |
| 809 } // namespace app_list | 822 } // namespace app_list |
| OLD | NEW |