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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 260 |
257 void AppListViewTestContext::Close() { | 261 void AppListViewTestContext::Close() { |
258 view_->GetWidget()->Close(); | 262 view_->GetWidget()->Close(); |
259 run_loop_.reset(new base::RunLoop); | 263 run_loop_.reset(new base::RunLoop); |
260 run_loop_->Run(); | 264 run_loop_->Run(); |
261 | 265 |
262 // |view_| should have been deleted and set to NULL via ViewClosing(). | 266 // |view_| should have been deleted and set to NULL via ViewClosing(). |
263 EXPECT_FALSE(view_); | 267 EXPECT_FALSE(view_); |
264 } | 268 } |
265 | 269 |
| 270 bool AppListViewTestContext::CheckSearchBoxWidget(const gfx::Rect& expected) { |
| 271 ContentsView* contents_view = view_->app_list_main_view()->contents_view(); |
| 272 gfx::Point point = expected.origin(); |
| 273 views::View::ConvertPointToScreen(contents_view, &point); |
| 274 |
| 275 return gfx::Rect(point, expected.size()) == |
| 276 view_->search_box_widget()->GetWindowBoundsInScreen(); |
| 277 } |
| 278 |
266 PaginationModel* AppListViewTestContext::GetPaginationModel() { | 279 PaginationModel* AppListViewTestContext::GetPaginationModel() { |
267 return view_->GetAppsPaginationModel(); | 280 return view_->GetAppsPaginationModel(); |
268 } | 281 } |
269 | 282 |
270 void AppListViewTestContext::RunDisplayTest() { | 283 void AppListViewTestContext::RunDisplayTest() { |
271 EXPECT_FALSE(view_->GetWidget()->IsVisible()); | 284 EXPECT_FALSE(view_->GetWidget()->IsVisible()); |
272 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); | 285 EXPECT_EQ(-1, GetPaginationModel()->total_pages()); |
273 delegate_->GetTestModel()->PopulateApps(kInitialItems); | 286 delegate_->GetTestModel()->PopulateApps(kInitialItems); |
274 | 287 |
275 Show(); | 288 Show(); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 EXPECT_EQ(default_contents_bounds, | 608 EXPECT_EQ(default_contents_bounds, |
596 contents_view->apps_container_view()->bounds()); | 609 contents_view->apps_container_view()->bounds()); |
597 | 610 |
598 if (test_type_ == EXPERIMENTAL) { | 611 if (test_type_ == EXPERIMENTAL) { |
599 // Check that typing into the search box triggers the search page. | 612 // Check that typing into the search box triggers the search page. |
600 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); | 613 EXPECT_TRUE(SetAppListState(AppListModel::STATE_START)); |
601 view_->Layout(); | 614 view_->Layout(); |
602 EXPECT_EQ(default_contents_bounds, | 615 EXPECT_EQ(default_contents_bounds, |
603 contents_view->start_page_view()->bounds()); | 616 contents_view->start_page_view()->bounds()); |
604 // TODO(mgiuca): The search box should be small and centered. | 617 // TODO(mgiuca): The search box should be small and centered. |
605 EXPECT_EQ(contents_view->GetDefaultSearchBoxBounds(), | 618 EXPECT_TRUE( |
606 view_->search_box_view()->bounds()); | 619 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
607 | 620 |
608 base::string16 search_text = base::UTF8ToUTF16("test"); | 621 base::string16 search_text = base::UTF8ToUTF16("test"); |
609 main_view->search_box_view()->search_box()->SetText(base::string16()); | 622 main_view->search_box_view()->search_box()->SetText(base::string16()); |
610 main_view->search_box_view()->search_box()->InsertText(search_text); | 623 main_view->search_box_view()->search_box()->InsertText(search_text); |
611 // Check that the current search is using |search_text|. | 624 // Check that the current search is using |search_text|. |
612 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); | 625 EXPECT_EQ(search_text, delegate_->GetTestModel()->search_box()->text()); |
613 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); | 626 EXPECT_EQ(search_text, main_view->search_box_view()->search_box()->text()); |
614 view_->Layout(); | 627 view_->Layout(); |
615 EXPECT_TRUE( | 628 EXPECT_TRUE( |
616 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | 629 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
617 EXPECT_EQ(contents_view->GetDefaultSearchBoxBounds(), | 630 EXPECT_TRUE( |
618 view_->search_box_view()->bounds()); | 631 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
619 | 632 |
620 // Check that typing into the search box triggers the search page. | 633 // Check that typing into the search box triggers the search page. |
621 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); | 634 EXPECT_TRUE(SetAppListState(AppListModel::STATE_APPS)); |
622 view_->Layout(); | 635 view_->Layout(); |
623 EXPECT_EQ(default_contents_bounds, | 636 EXPECT_EQ(default_contents_bounds, |
624 contents_view->apps_container_view()->bounds()); | 637 contents_view->apps_container_view()->bounds()); |
625 EXPECT_EQ(contents_view->GetDefaultSearchBoxBounds(), | 638 EXPECT_TRUE( |
626 view_->search_box_view()->bounds()); | 639 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
627 | 640 |
628 base::string16 new_search_text = base::UTF8ToUTF16("apple"); | 641 base::string16 new_search_text = base::UTF8ToUTF16("apple"); |
629 main_view->search_box_view()->search_box()->SetText(base::string16()); | 642 main_view->search_box_view()->search_box()->SetText(base::string16()); |
630 main_view->search_box_view()->search_box()->InsertText(new_search_text); | 643 main_view->search_box_view()->search_box()->InsertText(new_search_text); |
631 // Check that the current search is using |new_search_text|. | 644 // Check that the current search is using |new_search_text|. |
632 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); | 645 EXPECT_EQ(new_search_text, delegate_->GetTestModel()->search_box()->text()); |
633 EXPECT_EQ(new_search_text, | 646 EXPECT_EQ(new_search_text, |
634 main_view->search_box_view()->search_box()->text()); | 647 main_view->search_box_view()->search_box()->text()); |
635 view_->Layout(); | 648 view_->Layout(); |
636 EXPECT_TRUE( | 649 EXPECT_TRUE( |
637 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); | 650 contents_view->IsStateActive(AppListModel::STATE_SEARCH_RESULTS)); |
638 EXPECT_EQ(contents_view->GetDefaultSearchBoxBounds(), | 651 EXPECT_TRUE( |
639 view_->search_box_view()->bounds()); | 652 CheckSearchBoxWidget(contents_view->GetDefaultSearchBoxBounds())); |
640 } | 653 } |
641 | 654 |
642 Close(); | 655 Close(); |
643 } | 656 } |
644 | 657 |
645 class AppListViewTestAura : public views::ViewsTestBase, | 658 class AppListViewTestAura : public views::ViewsTestBase, |
646 public ::testing::WithParamInterface<int> { | 659 public ::testing::WithParamInterface<int> { |
647 public: | 660 public: |
648 AppListViewTestAura() {} | 661 AppListViewTestAura() {} |
649 virtual ~AppListViewTestAura() {} | 662 virtual ~AppListViewTestAura() {} |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, | 817 INSTANTIATE_TEST_CASE_P(AppListViewTestAuraInstance, |
805 AppListViewTestAura, | 818 AppListViewTestAura, |
806 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 819 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
807 | 820 |
808 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, | 821 INSTANTIATE_TEST_CASE_P(AppListViewTestDesktopInstance, |
809 AppListViewTestDesktop, | 822 AppListViewTestDesktop, |
810 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); | 823 ::testing::Range<int>(TEST_TYPE_START, TEST_TYPE_END)); |
811 | 824 |
812 } // namespace test | 825 } // namespace test |
813 } // namespace app_list | 826 } // namespace app_list |
OLD | NEW |