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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/app_list/app_list_item.h" | 17 #include "ui/app_list/app_list_item.h" |
18 #include "ui/app_list/app_list_model.h" | 18 #include "ui/app_list/app_list_model.h" |
19 #include "ui/app_list/app_list_switches.h" | 19 #include "ui/app_list/app_list_switches.h" |
20 #include "ui/app_list/pagination_model.h" | 20 #include "ui/app_list/pagination_model.h" |
21 #include "ui/app_list/test/app_list_test_model.h" | 21 #include "ui/app_list/test/app_list_test_model.h" |
22 #include "ui/app_list/views/app_list_item_view.h" | 22 #include "ui/app_list/views/app_list_item_view.h" |
| 23 #include "ui/app_list/views/apps_grid_view_folder_delegate.h" |
23 #include "ui/app_list/views/test/apps_grid_view_test_api.h" | 24 #include "ui/app_list/views/test/apps_grid_view_test_api.h" |
24 #include "ui/views/test/views_test_base.h" | 25 #include "ui/views/test/views_test_base.h" |
25 | 26 |
26 namespace app_list { | 27 namespace app_list { |
27 namespace test { | 28 namespace test { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const int kIconDimension = 48; | 32 const int kIconDimension = 48; |
32 const int kCols = 2; | 33 const int kCols = 2; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 172 |
172 scoped_ptr<AppListTestModel> model_; | 173 scoped_ptr<AppListTestModel> model_; |
173 scoped_ptr<PaginationModel> pagination_model_; | 174 scoped_ptr<PaginationModel> pagination_model_; |
174 scoped_ptr<AppsGridView> apps_grid_view_; | 175 scoped_ptr<AppsGridView> apps_grid_view_; |
175 scoped_ptr<AppsGridViewTestApi> test_api_; | 176 scoped_ptr<AppsGridViewTestApi> test_api_; |
176 | 177 |
177 private: | 178 private: |
178 DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest); | 179 DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest); |
179 }; | 180 }; |
180 | 181 |
| 182 class TestAppsGridViewFolderDelegate : public AppsGridViewFolderDelegate { |
| 183 public: |
| 184 TestAppsGridViewFolderDelegate() : show_bubble_(false) {} |
| 185 virtual ~TestAppsGridViewFolderDelegate() {} |
| 186 |
| 187 // Overridden from AppsGridViewFolderDelegate: |
| 188 virtual void UpdateFolderViewBackground(bool show_bubble) OVERRIDE { |
| 189 show_bubble_ = show_bubble; |
| 190 } |
| 191 |
| 192 virtual void ReparentItem(AppListItemView* original_drag_view, |
| 193 const gfx::Point& drag_point_in_folder_grid) |
| 194 OVERRIDE {} |
| 195 |
| 196 virtual void DispatchDragEventForReparent(AppsGridView::Pointer pointer, |
| 197 const ui::LocatedEvent& event) |
| 198 OVERRIDE {} |
| 199 |
| 200 virtual void DispatchEndDragEventForReparent( |
| 201 bool events_forwarded_to_drag_drop_host) OVERRIDE {} |
| 202 |
| 203 virtual bool IsPointOutsideOfFolderBoundary(const gfx::Point& point) |
| 204 OVERRIDE { |
| 205 return false; |
| 206 } |
| 207 |
| 208 virtual bool IsOEMFolder() const OVERRIDE { return false; } |
| 209 |
| 210 bool show_bubble() { return show_bubble_; } |
| 211 |
| 212 private: |
| 213 bool show_bubble_; |
| 214 |
| 215 DISALLOW_COPY_AND_ASSIGN(TestAppsGridViewFolderDelegate); |
| 216 }; |
| 217 |
181 TEST_F(AppsGridViewTest, CreatePage) { | 218 TEST_F(AppsGridViewTest, CreatePage) { |
182 // Fully populates a page. | 219 // Fully populates a page. |
183 const int kPages = 1; | 220 const int kPages = 1; |
184 model_->PopulateApps(kPages * kTilesPerPage); | 221 model_->PopulateApps(kPages * kTilesPerPage); |
185 EXPECT_EQ(kPages, pagination_model_->total_pages()); | 222 EXPECT_EQ(kPages, pagination_model_->total_pages()); |
186 | 223 |
187 // Adds one more and gets a new page created. | 224 // Adds one more and gets a new page created. |
188 model_->CreateAndAddItem("Extra"); | 225 model_->CreateAndAddItem("Extra"); |
189 EXPECT_EQ(kPages + 1, pagination_model_->total_pages()); | 226 EXPECT_EQ(kPages + 1, pagination_model_->total_pages()); |
190 } | 227 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 // Starts a touch drag first then a mouse drag. | 381 // Starts a touch drag first then a mouse drag. |
345 SimulateDrag(AppsGridView::TOUCH, touch_from, touch_to); | 382 SimulateDrag(AppsGridView::TOUCH, touch_from, touch_to); |
346 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to); | 383 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to); |
347 // Finishes the drag and touch drag wins. | 384 // Finishes the drag and touch drag wins. |
348 apps_grid_view_->EndDrag(false); | 385 apps_grid_view_->EndDrag(false); |
349 EXPECT_EQ(std::string("Item 1,Item 0,Item 3,Item 2"), | 386 EXPECT_EQ(std::string("Item 1,Item 0,Item 3,Item 2"), |
350 model_->GetModelContent()); | 387 model_->GetModelContent()); |
351 test_api_->LayoutToIdealBounds(); | 388 test_api_->LayoutToIdealBounds(); |
352 } | 389 } |
353 | 390 |
| 391 TEST_F(AppsGridViewTest, UpdateFolderBackgroundOnCancelDrag) { |
| 392 const int kTotalItems = 4; |
| 393 TestAppsGridViewFolderDelegate folder_delegate; |
| 394 apps_grid_view_->set_folder_delegate(&folder_delegate); |
| 395 model_->PopulateApps(kTotalItems); |
| 396 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), |
| 397 model_->GetModelContent()); |
| 398 |
| 399 gfx::Point mouse_from = GetItemTileRectAt(0, 0).CenterPoint(); |
| 400 gfx::Point mouse_to = GetItemTileRectAt(0, 1).CenterPoint(); |
| 401 |
| 402 // Starts a mouse drag and then cancels it. |
| 403 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to); |
| 404 EXPECT_TRUE(folder_delegate.show_bubble()); |
| 405 apps_grid_view_->EndDrag(true); |
| 406 EXPECT_FALSE(folder_delegate.show_bubble()); |
| 407 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"), |
| 408 model_->GetModelContent()); |
| 409 } |
| 410 |
354 TEST_F(AppsGridViewTest, HighlightWithKeyboard) { | 411 TEST_F(AppsGridViewTest, HighlightWithKeyboard) { |
355 const int kPages = 3; | 412 const int kPages = 3; |
356 const int kItems = (kPages - 1) * kTilesPerPage + 1; | 413 const int kItems = (kPages - 1) * kTilesPerPage + 1; |
357 model_->PopulateApps(kItems); | 414 model_->PopulateApps(kItems); |
358 | 415 |
359 const int first_index = 0; | 416 const int first_index = 0; |
360 const int last_index = kItems - 1; | 417 const int last_index = kItems - 1; |
361 const int last_index_on_page1_first_row = kRows - 1; | 418 const int last_index_on_page1_first_row = kRows - 1; |
362 const int last_index_on_page1 = kTilesPerPage - 1; | 419 const int last_index_on_page1 = kTilesPerPage - 1; |
363 const int first_index_on_page2 = kTilesPerPage; | 420 const int first_index_on_page2 = kTilesPerPage; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 AppListItemView* item_view = GetItemViewAt(0); | 517 AppListItemView* item_view = GetItemViewAt(0); |
461 ASSERT_TRUE(item_view); | 518 ASSERT_TRUE(item_view); |
462 const views::Label* title_label = item_view->title(); | 519 const views::Label* title_label = item_view->title(); |
463 EXPECT_FALSE(title_label->GetTooltipText( | 520 EXPECT_FALSE(title_label->GetTooltipText( |
464 title_label->bounds().CenterPoint(), &actual_tooltip)); | 521 title_label->bounds().CenterPoint(), &actual_tooltip)); |
465 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); | 522 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); |
466 } | 523 } |
467 | 524 |
468 } // namespace test | 525 } // namespace test |
469 } // namespace app_list | 526 } // namespace app_list |
OLD | NEW |