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

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

Issue 210583004: Make cancelling of app list correctly clean up folder UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
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"
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 173
173 scoped_ptr<AppListTestModel> model_; 174 scoped_ptr<AppListTestModel> model_;
174 scoped_ptr<PaginationModel> pagination_model_; 175 scoped_ptr<PaginationModel> pagination_model_;
175 scoped_ptr<AppsGridView> apps_grid_view_; 176 scoped_ptr<AppsGridView> apps_grid_view_;
176 scoped_ptr<AppsGridViewTestApi> test_api_; 177 scoped_ptr<AppsGridViewTestApi> test_api_;
177 178
178 private: 179 private:
179 DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest); 180 DISALLOW_COPY_AND_ASSIGN(AppsGridViewTest);
180 }; 181 };
181 182
183 class TestAppsGridViewFolderDelegate : public AppsGridViewFolderDelegate {
184 public:
185 TestAppsGridViewFolderDelegate() : show_bubble_(false) {}
186 ~TestAppsGridViewFolderDelegate() {}
187
188 // Overridden from AppsGridViewFolderDelegate:
189 virtual void UpdateFolderViewBackground(bool show_bubble) OVERRIDE {
190 show_bubble_ = show_bubble;
191 }
192
193 virtual void ReparentItem(AppListItemView* original_drag_view,
194 const gfx::Point& drag_point_in_folder_grid)
195 OVERRIDE {}
tapted 2014/03/26 02:53:54 nit: OVERRIDE looks lonely, unless clang-format di
calamity 2014/03/27 05:14:44 All hail our benevolent clang-format overlord.
196
197 virtual void DispatchDragEventForReparent(AppsGridView::Pointer pointer,
198 const ui::LocatedEvent& event)
199 OVERRIDE {}
200
201 virtual void DispatchEndDragEventForReparent(
202 bool events_forwarded_to_drag_drop_host) OVERRIDE {}
203
204 virtual bool IsPointOutsideOfFolderBoundary(const gfx::Point& point)
205 OVERRIDE {
206 return false;
207 }
208
209 bool show_bubble() { return show_bubble_; }
210
211 private:
212 bool show_bubble_;
213 };
tapted 2014/03/26 02:53:54 nit: DISALLOW_COPY_AND_ASSIGN(..)
calamity 2014/03/27 05:14:44 Done.
214
182 TEST_F(AppsGridViewTest, CreatePage) { 215 TEST_F(AppsGridViewTest, CreatePage) {
183 // Fully populates a page. 216 // Fully populates a page.
184 const int kPages = 1; 217 const int kPages = 1;
185 model_->PopulateApps(kPages * kTilesPerPage); 218 model_->PopulateApps(kPages * kTilesPerPage);
186 EXPECT_EQ(kPages, pagination_model_->total_pages()); 219 EXPECT_EQ(kPages, pagination_model_->total_pages());
187 220
188 // Adds one more and gets a new page created. 221 // Adds one more and gets a new page created.
189 model_->CreateAndAddItem("Extra"); 222 model_->CreateAndAddItem("Extra");
190 EXPECT_EQ(kPages + 1, pagination_model_->total_pages()); 223 EXPECT_EQ(kPages + 1, pagination_model_->total_pages());
191 } 224 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // Starts a touch drag first then a mouse drag. 378 // Starts a touch drag first then a mouse drag.
346 SimulateDrag(AppsGridView::TOUCH, touch_from, touch_to); 379 SimulateDrag(AppsGridView::TOUCH, touch_from, touch_to);
347 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to); 380 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to);
348 // Finishes the drag and touch drag wins. 381 // Finishes the drag and touch drag wins.
349 apps_grid_view_->EndDrag(false); 382 apps_grid_view_->EndDrag(false);
350 EXPECT_EQ(std::string("Item 1,Item 0,Item 3,Item 2"), 383 EXPECT_EQ(std::string("Item 1,Item 0,Item 3,Item 2"),
351 model_->GetModelContent()); 384 model_->GetModelContent());
352 test_api_->LayoutToIdealBounds(); 385 test_api_->LayoutToIdealBounds();
353 } 386 }
354 387
388 TEST_F(AppsGridViewTest, UpdateFolderBackgroundOnCancelDrag) {
389 const int kTotalItems = 4;
390 TestAppsGridViewFolderDelegate folder_delegate;
391 apps_grid_view_->set_folder_delegate(&folder_delegate);
392 model_->PopulateApps(kTotalItems);
393 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
394 model_->GetModelContent());
395
396 gfx::Point mouse_from = GetItemTileRectAt(0, 0).CenterPoint();
397 gfx::Point mouse_to = GetItemTileRectAt(0, 1).CenterPoint();
398
399 // Starts a mouse drag and then cancels it.
400 SimulateDrag(AppsGridView::MOUSE, mouse_from, mouse_to);
401 EXPECT_TRUE(folder_delegate.show_bubble());
402 apps_grid_view_->EndDrag(true);
403 EXPECT_FALSE(folder_delegate.show_bubble());
404 EXPECT_EQ(std::string("Item 0,Item 1,Item 2,Item 3"),
405 model_->GetModelContent());
406 }
407
355 TEST_F(AppsGridViewTest, HighlightWithKeyboard) { 408 TEST_F(AppsGridViewTest, HighlightWithKeyboard) {
356 const int kPages = 3; 409 const int kPages = 3;
357 const int kItems = (kPages - 1) * kTilesPerPage + 1; 410 const int kItems = (kPages - 1) * kTilesPerPage + 1;
358 model_->PopulateApps(kItems); 411 model_->PopulateApps(kItems);
359 412
360 const int first_index = 0; 413 const int first_index = 0;
361 const int last_index = kItems - 1; 414 const int last_index = kItems - 1;
362 const int last_index_on_page1_first_row = kRows - 1; 415 const int last_index_on_page1_first_row = kRows - 1;
363 const int last_index_on_page1 = kTilesPerPage - 1; 416 const int last_index_on_page1 = kTilesPerPage - 1;
364 const int first_index_on_page2 = kTilesPerPage; 417 const int first_index_on_page2 = kTilesPerPage;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 AppListItemView* item_view = GetItemViewAt(0); 514 AppListItemView* item_view = GetItemViewAt(0);
462 ASSERT_TRUE(item_view); 515 ASSERT_TRUE(item_view);
463 const views::Label* title_label = item_view->title(); 516 const views::Label* title_label = item_view->title();
464 EXPECT_FALSE(title_label->GetTooltipText( 517 EXPECT_FALSE(title_label->GetTooltipText(
465 title_label->bounds().CenterPoint(), &actual_tooltip)); 518 title_label->bounds().CenterPoint(), &actual_tooltip));
466 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text())); 519 EXPECT_EQ(title, base::UTF16ToUTF8(title_label->text()));
467 } 520 }
468 521
469 } // namespace test 522 } // namespace test
470 } // namespace app_list 523 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698