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

Side by Side Diff: ui/app_list/views/apps_grid_view_unittest.cc

Issue 302803002: Refactor app list so AppsGridView owns the PaginationModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile error (conflict). Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/views/apps_grid_view.cc ('k') | ui/app_list/views/contents_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 class AppsGridViewTest : public views::ViewsTestBase { 100 class AppsGridViewTest : public views::ViewsTestBase {
101 public: 101 public:
102 AppsGridViewTest() {} 102 AppsGridViewTest() {}
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()));
118 } 117 }
119 virtual void TearDown() OVERRIDE { 118 virtual void TearDown() OVERRIDE {
120 apps_grid_view_.reset(); // Release apps grid view before models. 119 apps_grid_view_.reset(); // Release apps grid view before models.
121 views::ViewsTestBase::TearDown(); 120 views::ViewsTestBase::TearDown();
(...skipping 23 matching lines...) Expand all
145 gfx::Rect GetItemTileRectAt(int row, int col) { 144 gfx::Rect GetItemTileRectAt(int row, int col) {
146 DCHECK_GT(model_->top_level_item_list()->item_count(), 0u); 145 DCHECK_GT(model_->top_level_item_list()->item_count(), 0u);
147 146
148 gfx::Insets insets(apps_grid_view_->GetInsets()); 147 gfx::Insets insets(apps_grid_view_->GetInsets());
149 gfx::Rect rect(gfx::Point(insets.left(), insets.top()), 148 gfx::Rect rect(gfx::Point(insets.left(), insets.top()),
150 GetItemViewAt(0)->bounds().size()); 149 GetItemViewAt(0)->bounds().size());
151 rect.Offset(col * rect.width(), row * rect.height()); 150 rect.Offset(col * rect.width(), row * rect.height());
152 return rect; 151 return rect;
153 } 152 }
154 153
154 PaginationModel* GetPaginationModel() {
155 return apps_grid_view_->pagination_model();
156 }
157
155 // Points are in |apps_grid_view_|'s coordinates. 158 // Points are in |apps_grid_view_|'s coordinates.
156 void SimulateDrag(AppsGridView::Pointer pointer, 159 void SimulateDrag(AppsGridView::Pointer pointer,
157 const gfx::Point& from, 160 const gfx::Point& from,
158 const gfx::Point& to) { 161 const gfx::Point& to) {
159 AppListItemView* view = GetItemViewForPoint(from); 162 AppListItemView* view = GetItemViewForPoint(from);
160 DCHECK(view); 163 DCHECK(view);
161 164
162 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin( 165 gfx::Point translated_from = gfx::PointAtOffsetFromOrigin(
163 from - view->bounds().origin()); 166 from - view->bounds().origin());
164 gfx::Point translated_to = gfx::PointAtOffsetFromOrigin( 167 gfx::Point translated_to = gfx::PointAtOffsetFromOrigin(
165 to - view->bounds().origin()); 168 to - view->bounds().origin());
166 169
167 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED, 170 ui::MouseEvent pressed_event(ui::ET_MOUSE_PRESSED,
168 translated_from, from, 0, 0); 171 translated_from, from, 0, 0);
169 apps_grid_view_->InitiateDrag(view, pointer, pressed_event); 172 apps_grid_view_->InitiateDrag(view, pointer, pressed_event);
170 173
171 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, 174 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED,
172 translated_to, to, 0, 0); 175 translated_to, to, 0, 0);
173 apps_grid_view_->UpdateDragFromItem(pointer, drag_event); 176 apps_grid_view_->UpdateDragFromItem(pointer, drag_event);
174 } 177 }
175 178
176 void SimulateKeyPress(ui::KeyboardCode key_code) { 179 void SimulateKeyPress(ui::KeyboardCode key_code) {
177 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, 0, false); 180 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, key_code, 0, false);
178 apps_grid_view_->OnKeyPressed(key_event); 181 apps_grid_view_->OnKeyPressed(key_event);
179 } 182 }
180 183
181 scoped_ptr<AppListTestModel> model_; 184 scoped_ptr<AppListTestModel> model_;
182 scoped_ptr<PaginationModel> pagination_model_;
183 scoped_ptr<AppsGridView> apps_grid_view_; 185 scoped_ptr<AppsGridView> apps_grid_view_;
184 scoped_ptr<AppsGridViewTestApi> test_api_; 186 scoped_ptr<AppsGridViewTestApi> test_api_;
185 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) {}
(...skipping 30 matching lines...) Expand all
223 private: 225 private:
224 bool show_bubble_; 226 bool show_bubble_;
225 227
226 DISALLOW_COPY_AND_ASSIGN(TestAppsGridViewFolderDelegate); 228 DISALLOW_COPY_AND_ASSIGN(TestAppsGridViewFolderDelegate);
227 }; 229 };
228 230
229 TEST_F(AppsGridViewTest, CreatePage) { 231 TEST_F(AppsGridViewTest, CreatePage) {
230 // Fully populates a page. 232 // Fully populates a page.
231 const int kPages = 1; 233 const int kPages = 1;
232 model_->PopulateApps(kPages * kTilesPerPage); 234 model_->PopulateApps(kPages * kTilesPerPage);
233 EXPECT_EQ(kPages, pagination_model_->total_pages()); 235 EXPECT_EQ(kPages, GetPaginationModel()->total_pages());
234 236
235 // Adds one more and gets a new page created. 237 // Adds one more and gets a new page created.
236 model_->CreateAndAddItem("Extra"); 238 model_->CreateAndAddItem("Extra");
237 EXPECT_EQ(kPages + 1, pagination_model_->total_pages()); 239 EXPECT_EQ(kPages + 1, GetPaginationModel()->total_pages());
238 } 240 }
239 241
240 TEST_F(AppsGridViewTest, EnsureHighlightedVisible) { 242 TEST_F(AppsGridViewTest, EnsureHighlightedVisible) {
241 const int kPages = 3; 243 const int kPages = 3;
242 model_->PopulateApps(kPages * kTilesPerPage); 244 model_->PopulateApps(kPages * kTilesPerPage);
243 EXPECT_EQ(kPages, pagination_model_->total_pages()); 245 EXPECT_EQ(kPages, GetPaginationModel()->total_pages());
244 EXPECT_EQ(0, pagination_model_->selected_page()); 246 EXPECT_EQ(0, GetPaginationModel()->selected_page());
245 247
246 // Highlight first one and last one one first page and first page should be 248 // Highlight first one and last one one first page and first page should be
247 // selected. 249 // selected.
248 model_->HighlightItemAt(0); 250 model_->HighlightItemAt(0);
249 EXPECT_EQ(0, pagination_model_->selected_page()); 251 EXPECT_EQ(0, GetPaginationModel()->selected_page());
250 model_->HighlightItemAt(kTilesPerPage - 1); 252 model_->HighlightItemAt(kTilesPerPage - 1);
251 EXPECT_EQ(0, pagination_model_->selected_page()); 253 EXPECT_EQ(0, GetPaginationModel()->selected_page());
252 254
253 // Highlight first one on 2nd page and 2nd page should be selected. 255 // Highlight first one on 2nd page and 2nd page should be selected.
254 model_->HighlightItemAt(kTilesPerPage + 1); 256 model_->HighlightItemAt(kTilesPerPage + 1);
255 EXPECT_EQ(1, pagination_model_->selected_page()); 257 EXPECT_EQ(1, GetPaginationModel()->selected_page());
256 258
257 // Highlight last one in the model and last page should be selected. 259 // Highlight last one in the model and last page should be selected.
258 model_->HighlightItemAt(model_->top_level_item_list()->item_count() - 1); 260 model_->HighlightItemAt(model_->top_level_item_list()->item_count() - 1);
259 EXPECT_EQ(kPages - 1, pagination_model_->selected_page()); 261 EXPECT_EQ(kPages - 1, GetPaginationModel()->selected_page());
260 } 262 }
261 263
262 TEST_F(AppsGridViewTest, RemoveSelectedLastApp) { 264 TEST_F(AppsGridViewTest, RemoveSelectedLastApp) {
263 const int kTotalItems = 2; 265 const int kTotalItems = 2;
264 const int kLastItemIndex = kTotalItems - 1; 266 const int kLastItemIndex = kTotalItems - 1;
265 267
266 model_->PopulateApps(kTotalItems); 268 model_->PopulateApps(kTotalItems);
267 269
268 AppListItemView* last_view = GetItemViewAt(kLastItemIndex); 270 AppListItemView* last_view = GetItemViewAt(kLastItemIndex);
269 apps_grid_view_->SetSelectedView(last_view); 271 apps_grid_view_->SetSelectedView(last_view);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 SimulateDrag(AppsGridView::MOUSE, from, to); 496 SimulateDrag(AppsGridView::MOUSE, from, to);
495 model_->CreateAndAddItem("Extra"); 497 model_->CreateAndAddItem("Extra");
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 GetPaginationModel()->SetTransitionDurations(10, 10);
505 507
506 PageFlipWaiter page_flip_waiter(message_loop(), 508 PageFlipWaiter page_flip_waiter(message_loop(), GetPaginationModel());
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, GetPaginationModel()->total_pages());
512 EXPECT_EQ(0, pagination_model_->selected_page()); 513 EXPECT_EQ(0, GetPaginationModel()->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
518 // Drag to right edge. 519 // Drag to right edge.
519 SimulateDrag(AppsGridView::MOUSE, from, to); 520 SimulateDrag(AppsGridView::MOUSE, from, to);
520 521
521 // Page should be flipped after sometime. 522 // Page should be flipped after sometime.
522 EXPECT_TRUE(page_flip_waiter.Wait(0)); 523 EXPECT_TRUE(page_flip_waiter.Wait(0));
523 EXPECT_EQ(1, pagination_model_->selected_page()); 524 EXPECT_EQ(1, GetPaginationModel()->selected_page());
524 525
525 // Stay there and page should be flipped again. 526 // Stay there and page should be flipped again.
526 EXPECT_TRUE(page_flip_waiter.Wait(0)); 527 EXPECT_TRUE(page_flip_waiter.Wait(0));
527 EXPECT_EQ(2, pagination_model_->selected_page()); 528 EXPECT_EQ(2, GetPaginationModel()->selected_page());
528 529
529 // Stay there longer and no page flip happen since we are at the last page. 530 // Stay there longer and no page flip happen since we are at the last page.
530 EXPECT_FALSE(page_flip_waiter.Wait(100)); 531 EXPECT_FALSE(page_flip_waiter.Wait(100));
531 EXPECT_EQ(2, pagination_model_->selected_page()); 532 EXPECT_EQ(2, GetPaginationModel()->selected_page());
532 533
533 apps_grid_view_->EndDrag(true); 534 apps_grid_view_->EndDrag(true);
534 535
535 // Now drag to the left edge and test the other direction. 536 // Now drag to the left edge and test the other direction.
536 to.set_x(0); 537 to.set_x(0);
537 538
538 SimulateDrag(AppsGridView::MOUSE, from, to); 539 SimulateDrag(AppsGridView::MOUSE, from, to);
539 540
540 EXPECT_TRUE(page_flip_waiter.Wait(0)); 541 EXPECT_TRUE(page_flip_waiter.Wait(0));
541 EXPECT_EQ(1, pagination_model_->selected_page()); 542 EXPECT_EQ(1, GetPaginationModel()->selected_page());
542 543
543 EXPECT_TRUE(page_flip_waiter.Wait(0)); 544 EXPECT_TRUE(page_flip_waiter.Wait(0));
544 EXPECT_EQ(0, pagination_model_->selected_page()); 545 EXPECT_EQ(0, GetPaginationModel()->selected_page());
545 546
546 EXPECT_FALSE(page_flip_waiter.Wait(100)); 547 EXPECT_FALSE(page_flip_waiter.Wait(100));
547 EXPECT_EQ(0, pagination_model_->selected_page()); 548 EXPECT_EQ(0, GetPaginationModel()->selected_page());
548 apps_grid_view_->EndDrag(true); 549 apps_grid_view_->EndDrag(true);
549 } 550 }
550 551
551 TEST_F(AppsGridViewTest, SimultaneousDragWithFolderDisabled) { 552 TEST_F(AppsGridViewTest, SimultaneousDragWithFolderDisabled) {
552 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSyncAppList); 553 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSyncAppList);
553 const int kTotalItems = 4; 554 const int kTotalItems = 4;
554 model_->PopulateApps(kTotalItems); 555 model_->PopulateApps(kTotalItems);
555 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), 556 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
556 model_->GetModelContent()); 557 model_->GetModelContent());
557 558
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 last_index))); 670 last_index)));
670 apps_grid_view_->SetSelectedView(GetItemViewAt(last_index_on_page2_last_row)); 671 apps_grid_view_->SetSelectedView(GetItemViewAt(last_index_on_page2_last_row));
671 SimulateKeyPress(ui::VKEY_NEXT); 672 SimulateKeyPress(ui::VKEY_NEXT);
672 EXPECT_TRUE(apps_grid_view_->IsSelectedView(GetItemViewAt( 673 EXPECT_TRUE(apps_grid_view_->IsSelectedView(GetItemViewAt(
673 last_index))); 674 last_index)));
674 675
675 676
676 677
677 // After page switch, arrow keys select first item on current page. 678 // After page switch, arrow keys select first item on current page.
678 apps_grid_view_->SetSelectedView(GetItemViewAt(first_index)); 679 apps_grid_view_->SetSelectedView(GetItemViewAt(first_index));
679 pagination_model_->SelectPage(1, false); 680 GetPaginationModel()->SelectPage(1, false);
680 SimulateKeyPress(ui::VKEY_UP); 681 SimulateKeyPress(ui::VKEY_UP);
681 EXPECT_TRUE(apps_grid_view_->IsSelectedView(GetItemViewAt( 682 EXPECT_TRUE(apps_grid_view_->IsSelectedView(GetItemViewAt(
682 first_index_on_page2))); 683 first_index_on_page2)));
683 } 684 }
684 685
685 TEST_F(AppsGridViewTest, ItemLabelShortNameOverride) { 686 TEST_F(AppsGridViewTest, ItemLabelShortNameOverride) {
686 // If the app's full name and short name differ, the title label's tooltip 687 // If the app's full name and short name differ, the title label's tooltip
687 // should always be the full name of the app. 688 // should always be the full name of the app.
688 std::string expected_text("xyz"); 689 std::string expected_text("xyz");
689 std::string expected_tooltip("tooltip"); 690 std::string expected_tooltip("tooltip");
(...skipping 21 matching lines...) Expand all
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
OLDNEW
« no previous file with comments | « ui/app_list/views/apps_grid_view.cc ('k') | ui/app_list/views/contents_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698