| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/apps_grid_view.h" | 5 #include "ui/app_list/views/apps_grid_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/app_list/app_list_constants.h" | 20 #include "ui/app_list/app_list_constants.h" |
| 21 #include "ui/app_list/app_list_folder_item.h" | 21 #include "ui/app_list/app_list_folder_item.h" |
| 22 #include "ui/app_list/app_list_item.h" | 22 #include "ui/app_list/app_list_item.h" |
| 23 #include "ui/app_list/app_list_model.h" | 23 #include "ui/app_list/app_list_model.h" |
| 24 #include "ui/app_list/app_list_switches.h" | 24 #include "ui/app_list/app_list_switches.h" |
| 25 #include "ui/app_list/pagination_model.h" | 25 #include "ui/app_list/pagination_model.h" |
| 26 #include "ui/app_list/test/app_list_test_model.h" | 26 #include "ui/app_list/test/app_list_test_model.h" |
| 27 #include "ui/app_list/views/app_list_item_view.h" | 27 #include "ui/app_list/views/app_list_item_view.h" |
| 28 #include "ui/app_list/views/apps_grid_view_folder_delegate.h" | 28 #include "ui/app_list/views/apps_grid_view_folder_delegate.h" |
| 29 #include "ui/app_list/views/test/apps_grid_view_test_api.h" | 29 #include "ui/app_list/views/test/apps_grid_view_test_api.h" |
| 30 #include "ui/events/event_utils.h" | 30 #include "ui/events/event_utils.h" |
| 31 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
| 32 #include "ui/views/test/views_test_base.h" | 32 #include "ui/views/test/views_test_base.h" |
| 33 | 33 |
| 34 namespace app_list { | 34 namespace app_list { |
| 35 namespace test { | 35 namespace test { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 const int kCols = 2; | 39 const int kCols = 2; |
| 40 const int kRows = 2; | 40 const int kRows = 2; |
| 41 const int kTilesPerPage = kCols * kRows; | 41 const int kTilesPerPage = kCols * kRows; |
| 42 | 42 |
| 43 class PageFlipWaiter : public PaginationModelObserver { | 43 class PageFlipWaiter : public PaginationModelObserver { |
| 44 public: | 44 public: |
| 45 PageFlipWaiter(base::MessageLoopForUI* ui_loop, PaginationModel* model) | 45 explicit PageFlipWaiter(PaginationModel* model) |
| 46 : ui_loop_(ui_loop), model_(model), wait_(false) { | 46 : model_(model), wait_(false) { |
| 47 model_->AddObserver(this); | 47 model_->AddObserver(this); |
| 48 } | 48 } |
| 49 | 49 |
| 50 ~PageFlipWaiter() override { model_->RemoveObserver(this); } | 50 ~PageFlipWaiter() override { model_->RemoveObserver(this); } |
| 51 | 51 |
| 52 void Wait() { | 52 void Wait() { |
| 53 DCHECK(!wait_); | 53 DCHECK(!wait_); |
| 54 wait_ = true; | 54 wait_ = true; |
| 55 | 55 |
| 56 ui_loop_->Run(); | 56 ui_run_loop_.reset(new base::RunLoop); |
| 57 ui_run_loop_->Run(); |
| 57 wait_ = false; | 58 wait_ = false; |
| 58 } | 59 } |
| 59 | 60 |
| 60 void Reset() { selected_pages_.clear(); } | 61 void Reset() { selected_pages_.clear(); } |
| 61 | 62 |
| 62 const std::string& selected_pages() const { return selected_pages_; } | 63 const std::string& selected_pages() const { return selected_pages_; } |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 // PaginationModelObserver overrides: | 66 // PaginationModelObserver overrides: |
| 66 void TotalPagesChanged() override {} | 67 void TotalPagesChanged() override {} |
| 67 void SelectedPageChanged(int old_selected, int new_selected) override { | 68 void SelectedPageChanged(int old_selected, int new_selected) override { |
| 68 if (!selected_pages_.empty()) | 69 if (!selected_pages_.empty()) |
| 69 selected_pages_ += ','; | 70 selected_pages_ += ','; |
| 70 selected_pages_ += base::IntToString(new_selected); | 71 selected_pages_ += base::IntToString(new_selected); |
| 71 | 72 |
| 72 if (wait_) | 73 if (wait_) |
| 73 ui_loop_->QuitWhenIdle(); | 74 ui_run_loop_->QuitWhenIdle(); |
| 74 } | 75 } |
| 75 void TransitionStarted() override {} | 76 void TransitionStarted() override {} |
| 76 void TransitionChanged() override {} | 77 void TransitionChanged() override {} |
| 77 | 78 |
| 78 base::MessageLoopForUI* ui_loop_; | 79 std::unique_ptr<base::RunLoop> ui_run_loop_; |
| 79 PaginationModel* model_; | 80 PaginationModel* model_; |
| 80 bool wait_; | 81 bool wait_; |
| 81 std::string selected_pages_; | 82 std::string selected_pages_; |
| 82 | 83 |
| 83 DISALLOW_COPY_AND_ASSIGN(PageFlipWaiter); | 84 DISALLOW_COPY_AND_ASSIGN(PageFlipWaiter); |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 } // namespace | 87 } // namespace |
| 87 | 88 |
| 88 class AppsGridViewTest : public views::ViewsTestBase { | 89 class AppsGridViewTest : public views::ViewsTestBase { |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 apps_grid_view_->EndDrag(false); | 563 apps_grid_view_->EndDrag(false); |
| 563 EXPECT_EQ(std::string("Item 0,Item 1,Item 3,Extra"), | 564 EXPECT_EQ(std::string("Item 0,Item 1,Item 3,Extra"), |
| 564 model_->GetModelContent()); | 565 model_->GetModelContent()); |
| 565 test_api_->LayoutToIdealBounds(); | 566 test_api_->LayoutToIdealBounds(); |
| 566 } | 567 } |
| 567 | 568 |
| 568 TEST_F(AppsGridViewTest, MouseDragFlipPage) { | 569 TEST_F(AppsGridViewTest, MouseDragFlipPage) { |
| 569 test_api_->SetPageFlipDelay(10); | 570 test_api_->SetPageFlipDelay(10); |
| 570 GetPaginationModel()->SetTransitionDurations(10, 10); | 571 GetPaginationModel()->SetTransitionDurations(10, 10); |
| 571 | 572 |
| 572 PageFlipWaiter page_flip_waiter(message_loop(), GetPaginationModel()); | 573 PageFlipWaiter page_flip_waiter(GetPaginationModel()); |
| 573 | 574 |
| 574 const int kPages = 3; | 575 const int kPages = 3; |
| 575 model_->PopulateApps(kPages * kTilesPerPage); | 576 model_->PopulateApps(kPages * kTilesPerPage); |
| 576 EXPECT_EQ(kPages, GetPaginationModel()->total_pages()); | 577 EXPECT_EQ(kPages, GetPaginationModel()->total_pages()); |
| 577 EXPECT_EQ(0, GetPaginationModel()->selected_page()); | 578 EXPECT_EQ(0, GetPaginationModel()->selected_page()); |
| 578 | 579 |
| 579 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); | 580 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); |
| 580 gfx::Point to = gfx::Point(apps_grid_view_->width(), | 581 gfx::Point to = gfx::Point(apps_grid_view_->width(), |
| 581 apps_grid_view_->height() / 2); | 582 apps_grid_view_->height() / 2); |
| 582 | 583 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 AppListItemView* item_view = GetItemViewAt(0); | 768 AppListItemView* item_view = GetItemViewAt(0); |
| 768 ASSERT_TRUE(item_view); | 769 ASSERT_TRUE(item_view); |
| 769 const views::Label* title_label = item_view->title(); | 770 const views::Label* title_label = item_view->title(); |
| 770 EXPECT_FALSE(title_label->GetTooltipText( | 771 EXPECT_FALSE(title_label->GetTooltipText( |
| 771 title_label->bounds().CenterPoint(), &actual_tooltip)); | 772 title_label->bounds().CenterPoint(), &actual_tooltip)); |
| 772 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); | 773 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); |
| 773 } | 774 } |
| 774 | 775 |
| 775 } // namespace test | 776 } // namespace test |
| 776 } // namespace app_list | 777 } // namespace app_list |
| OLD | NEW |