| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 bool page_changed_; | 92 bool page_changed_; |
| 93 base::OneShotTimer<PageFlipWaiter> wait_timer_; | 93 base::OneShotTimer<PageFlipWaiter> wait_timer_; |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(PageFlipWaiter); | 95 DISALLOW_COPY_AND_ASSIGN(PageFlipWaiter); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| 100 class AppsGridViewTest : public views::ViewsTestBase { | 100 class AppsGridViewTest : public views::ViewsTestBase { |
| 101 public: | 101 public: |
| 102 AppsGridViewTest() {} | 102 AppsGridViewTest() : pagination_model_(NULL) {} |
| 103 virtual ~AppsGridViewTest() {} | 103 virtual ~AppsGridViewTest() {} |
| 104 | 104 |
| 105 // testing::Test overrides: | 105 // testing::Test overrides: |
| 106 virtual void SetUp() OVERRIDE { | 106 virtual void SetUp() OVERRIDE { |
| 107 views::ViewsTestBase::SetUp(); | 107 views::ViewsTestBase::SetUp(); |
| 108 model_.reset(new AppListTestModel); | 108 model_.reset(new AppListTestModel); |
| 109 pagination_model_.reset(new PaginationModel); | |
| 110 | 109 |
| 111 apps_grid_view_.reset(new AppsGridView(NULL, pagination_model_.get())); | 110 apps_grid_view_.reset(new AppsGridView(NULL)); |
| 112 apps_grid_view_->SetLayout(kIconDimension, kCols, kRows); | 111 apps_grid_view_->SetLayout(kIconDimension, kCols, kRows); |
| 113 apps_grid_view_->SetBoundsRect(gfx::Rect(gfx::Size(kWidth, kHeight))); | 112 apps_grid_view_->SetBoundsRect(gfx::Rect(gfx::Size(kWidth, kHeight))); |
| 114 apps_grid_view_->SetModel(model_.get()); | 113 apps_grid_view_->SetModel(model_.get()); |
| 115 apps_grid_view_->SetItemList(model_->top_level_item_list()); | 114 apps_grid_view_->SetItemList(model_->top_level_item_list()); |
| 116 | 115 |
| 117 test_api_.reset(new AppsGridViewTestApi(apps_grid_view_.get())); | 116 test_api_.reset(new AppsGridViewTestApi(apps_grid_view_.get())); |
| 117 |
| 118 pagination_model_ = apps_grid_view_->pagination_model(); |
| 118 } | 119 } |
| 119 virtual void TearDown() OVERRIDE { | 120 virtual void TearDown() OVERRIDE { |
| 120 apps_grid_view_.reset(); // Release apps grid view before models. | 121 apps_grid_view_.reset(); // Release apps grid view before models. |
| 121 views::ViewsTestBase::TearDown(); | 122 views::ViewsTestBase::TearDown(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 protected: | 125 protected: |
| 125 void EnsureFoldersEnabled() { | 126 void EnsureFoldersEnabled() { |
| 126 // Folders require AppList sync to be enabled. | 127 // Folders require AppList sync to be enabled. |
| 127 CommandLine::ForCurrentProcess()->AppendSwitch( | 128 CommandLine::ForCurrentProcess()->AppendSwitch( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 translated_to, to, 0, 0); | 173 translated_to, to, 0, 0); |
| 173 apps_grid_view_->UpdateDragFromItem(pointer, drag_event); | 174 apps_grid_view_->UpdateDragFromItem(pointer, drag_event); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void SimulateKeyPress(ui::KeyboardCode key_code) { | 177 void SimulateKeyPress(ui::KeyboardCode key_code) { |
| 177 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, 0, false); | 178 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, 0, false); |
| 178 apps_grid_view_->OnKeyPressed(key_event); | 179 apps_grid_view_->OnKeyPressed(key_event); |
| 179 } | 180 } |
| 180 | 181 |
| 181 scoped_ptr<AppListTestModel> model_; | 182 scoped_ptr<AppListTestModel> model_; |
| 182 scoped_ptr<PaginationModel> pagination_model_; | |
| 183 scoped_ptr<AppsGridView> apps_grid_view_; | 183 scoped_ptr<AppsGridView> apps_grid_view_; |
| 184 scoped_ptr<AppsGridViewTestApi> test_api_; | 184 scoped_ptr<AppsGridViewTestApi> test_api_; |
| 185 | 185 |
| 186 PaginationModel* pagination_model_; // Owned by |apps_grid_view_|. |
| 187 |
| 186 private: | 188 private: |
| 187 DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest); | 189 DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest); |
| 188 }; | 190 }; |
| 189 | 191 |
| 190 class TestAppsGridViewFolderDelegate : public AppsGridViewFolderDelegate { | 192 class TestAppsGridViewFolderDelegate : public AppsGridViewFolderDelegate { |
| 191 public: | 193 public: |
| 192 TestAppsGridViewFolderDelegate() : show_bubble_(false) {} | 194 TestAppsGridViewFolderDelegate() : show_bubble_(false) {} |
| 193 virtual ~TestAppsGridViewFolderDelegate() {} | 195 virtual ~TestAppsGridViewFolderDelegate() {} |
| 194 | 196 |
| 195 // Overridden from AppsGridViewFolderDelegate: | 197 // Overridden from AppsGridViewFolderDelegate: |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 apps_grid_view_->EndDrag(false); | 498 apps_grid_view_->EndDrag(false); |
| 497 EXPECT_EQ(std::string("Item 0,Item 1,Item 3,Extra"), | 499 EXPECT_EQ(std::string("Item 0,Item 1,Item 3,Extra"), |
| 498 model_->GetModelContent()); | 500 model_->GetModelContent()); |
| 499 test_api_->LayoutToIdealBounds(); | 501 test_api_->LayoutToIdealBounds(); |
| 500 } | 502 } |
| 501 | 503 |
| 502 TEST_F(AppsGridViewTest, MouseDragFlipPage) { | 504 TEST_F(AppsGridViewTest, MouseDragFlipPage) { |
| 503 test_api_->SetPageFlipDelay(10); | 505 test_api_->SetPageFlipDelay(10); |
| 504 pagination_model_->SetTransitionDurations(10, 10); | 506 pagination_model_->SetTransitionDurations(10, 10); |
| 505 | 507 |
| 506 PageFlipWaiter page_flip_waiter(message_loop(), | 508 PageFlipWaiter page_flip_waiter(message_loop(), pagination_model_); |
| 507 pagination_model_.get()); | |
| 508 | 509 |
| 509 const int kPages = 3; | 510 const int kPages = 3; |
| 510 model_->PopulateApps(kPages * kTilesPerPage); | 511 model_->PopulateApps(kPages * kTilesPerPage); |
| 511 EXPECT_EQ(kPages, pagination_model_->total_pages()); | 512 EXPECT_EQ(kPages, pagination_model_->total_pages()); |
| 512 EXPECT_EQ(0, pagination_model_->selected_page()); | 513 EXPECT_EQ(0, pagination_model_->selected_page()); |
| 513 | 514 |
| 514 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); | 515 gfx::Point from = GetItemTileRectAt(0, 0).CenterPoint(); |
| 515 gfx::Point to = gfx::Point(apps_grid_view_->width(), | 516 gfx::Point to = gfx::Point(apps_grid_view_->width(), |
| 516 apps_grid_view_->height() / 2); | 517 apps_grid_view_->height() / 2); |
| 517 | 518 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 AppListItemView* item_view = GetItemViewAt(0); | 712 AppListItemView* item_view = GetItemViewAt(0); |
| 712 ASSERT_TRUE(item_view); | 713 ASSERT_TRUE(item_view); |
| 713 const views::Label* title_label = item_view->title(); | 714 const views::Label* title_label = item_view->title(); |
| 714 EXPECT_FALSE(title_label->GetTooltipText( | 715 EXPECT_FALSE(title_label->GetTooltipText( |
| 715 title_label->bounds().CenterPoint(), &actual_tooltip)); | 716 title_label->bounds().CenterPoint(), &actual_tooltip)); |
| 716 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); | 717 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); |
| 717 } | 718 } |
| 718 | 719 |
| 719 } // namespace test | 720 } // namespace test |
| 720 } // namespace app_list | 721 } // namespace app_list |
| OLD | NEW |