OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list_main_view.h" | 5 #include "ui/app_list/views/app_list_main_view.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 EXPECT_EQ(1, FolderViewModel()->view_size()); | 258 EXPECT_EQ(1, FolderViewModel()->view_size()); |
259 | 259 |
260 AppListItemView* dragged = StartDragForReparent(0); | 260 AppListItemView* dragged = StartDragForReparent(0); |
261 | 261 |
262 // Drop it to the slot on the right of first slot. | 262 // Drop it to the slot on the right of first slot. |
263 gfx::Rect drop_target_tile(first_slot_tile); | 263 gfx::Rect drop_target_tile(first_slot_tile); |
264 drop_target_tile.Offset(first_slot_tile.width() * 2, 0); | 264 drop_target_tile.Offset(first_slot_tile.width() * 2, 0); |
265 gfx::Point point = drop_target_tile.CenterPoint(); | 265 gfx::Point point = drop_target_tile.CenterPoint(); |
266 SimulateUpdateDrag(FolderGridView(), AppsGridView::MOUSE, dragged, point); | 266 SimulateUpdateDrag(FolderGridView(), AppsGridView::MOUSE, dragged, point); |
267 SimulateUpdateDrag(FolderGridView(), AppsGridView::MOUSE, dragged, point); | |
268 base::RunLoop().RunUntilIdle(); | |
269 | 267 |
270 // Drop it. | 268 // Drop it. |
271 FolderGridView()->EndDrag(false); | 269 FolderGridView()->EndDrag(false); |
272 base::RunLoop().RunUntilIdle(); | |
273 | 270 |
274 // Folder icon view should be gone and there is only one item view. | 271 // Folder icon view should be gone and there is only one item view. |
275 EXPECT_EQ(1, RootViewModel()->view_size()); | 272 EXPECT_EQ(1, RootViewModel()->view_size()); |
276 EXPECT_EQ(AppListItemView::kViewClassName, | 273 EXPECT_EQ(AppListItemView::kViewClassName, |
277 RootViewModel()->view_at(0)->GetClassName()); | 274 RootViewModel()->view_at(0)->GetClassName()); |
278 | 275 |
279 // The item view should be in slot 1 instead of slot 2 where it is dropped. | 276 // The item view should be in slot 1 instead of slot 2 where it is dropped. |
280 AppsGridViewTestApi root_grid_view_test_api(RootGridView()); | 277 AppsGridViewTestApi root_grid_view_test_api(RootGridView()); |
281 root_grid_view_test_api.LayoutToIdealBounds(); | 278 root_grid_view_test_api.LayoutToIdealBounds(); |
282 EXPECT_EQ(first_slot_tile, RootViewModel()->view_at(0)->bounds()); | 279 EXPECT_EQ(first_slot_tile, RootViewModel()->view_at(0)->bounds()); |
283 | 280 |
284 // Single item folder should be auto removed. | 281 // Single item folder should be auto removed. |
285 EXPECT_EQ(NULL, | 282 EXPECT_EQ(NULL, |
286 delegate_->GetTestModel()->FindFolderItem("single_item_folder")); | 283 delegate_->GetTestModel()->FindFolderItem("single_item_folder")); |
287 } | 284 } |
288 | 285 |
| 286 // Tests dragging an item out of a single item folder and dropping it onto the |
| 287 // page switcher. Regression test for http://crbug.com/415530/. |
| 288 TEST_F(AppListMainViewTest, DragReparentItemOntoPageSwitcher) { |
| 289 AppListItemView* folder_item_view = CreateAndOpenSingleItemFolder(); |
| 290 const gfx::Rect first_slot_tile = folder_item_view->bounds(); |
| 291 |
| 292 delegate_->GetTestModel()->PopulateApps(20); |
| 293 |
| 294 EXPECT_EQ(1, FolderViewModel()->view_size()); |
| 295 EXPECT_EQ(21, RootViewModel()->view_size()); |
| 296 |
| 297 AppListItemView* dragged = StartDragForReparent(0); |
| 298 |
| 299 gfx::Rect main_view_bounds = main_view_->bounds(); |
| 300 // Drag the reparent item to the page switcher. |
| 301 gfx::Point point = |
| 302 gfx::Point(main_view_bounds.width() / 2, |
| 303 main_view_bounds.bottom() - first_slot_tile.height()); |
| 304 SimulateUpdateDrag(FolderGridView(), AppsGridView::MOUSE, dragged, point); |
| 305 |
| 306 // Drop it. |
| 307 FolderGridView()->EndDrag(false); |
| 308 |
| 309 // The folder should be destroyed. |
| 310 EXPECT_EQ(21, RootViewModel()->view_size()); |
| 311 EXPECT_EQ(NULL, |
| 312 delegate_->GetTestModel()->FindFolderItem("single_item_folder")); |
| 313 } |
| 314 |
289 // Test that an interrupted drag while reparenting an item from a folder, when | 315 // Test that an interrupted drag while reparenting an item from a folder, when |
290 // canceled via the root grid, correctly forwards the cancelation to the drag | 316 // canceled via the root grid, correctly forwards the cancelation to the drag |
291 // ocurring from the folder. | 317 // ocurring from the folder. |
292 TEST_F(AppListMainViewTest, MouseDragItemOutOfFolderWithCancel) { | 318 TEST_F(AppListMainViewTest, MouseDragItemOutOfFolderWithCancel) { |
293 CreateAndOpenSingleItemFolder(); | 319 CreateAndOpenSingleItemFolder(); |
294 AppListItemView* dragged = StartDragForReparent(0); | 320 AppListItemView* dragged = StartDragForReparent(0); |
295 | 321 |
296 // Now add an item to the model, not in any folder, e.g., as if by Sync. | 322 // Now add an item to the model, not in any folder, e.g., as if by Sync. |
297 EXPECT_TRUE(RootGridView()->has_dragged_view()); | 323 EXPECT_TRUE(RootGridView()->has_dragged_view()); |
298 EXPECT_TRUE(FolderGridView()->has_dragged_view()); | 324 EXPECT_TRUE(FolderGridView()->has_dragged_view()); |
299 delegate_->GetTestModel()->CreateAndAddItem("Extra"); | 325 delegate_->GetTestModel()->CreateAndAddItem("Extra"); |
300 | 326 |
301 // The drag operation should get canceled. | 327 // The drag operation should get canceled. |
302 EXPECT_FALSE(RootGridView()->has_dragged_view()); | 328 EXPECT_FALSE(RootGridView()->has_dragged_view()); |
303 EXPECT_FALSE(FolderGridView()->has_dragged_view()); | 329 EXPECT_FALSE(FolderGridView()->has_dragged_view()); |
304 | 330 |
305 // Additional mouse move operations should be ignored. | 331 // Additional mouse move operations should be ignored. |
306 gfx::Point point(1, 1); | 332 gfx::Point point(1, 1); |
307 SimulateUpdateDrag(FolderGridView(), AppsGridView::MOUSE, dragged, point); | 333 SimulateUpdateDrag(FolderGridView(), AppsGridView::MOUSE, dragged, point); |
308 EXPECT_FALSE(RootGridView()->has_dragged_view()); | 334 EXPECT_FALSE(RootGridView()->has_dragged_view()); |
309 EXPECT_FALSE(FolderGridView()->has_dragged_view()); | 335 EXPECT_FALSE(FolderGridView()->has_dragged_view()); |
310 } | 336 } |
311 | 337 |
312 } // namespace test | 338 } // namespace test |
313 } // namespace app_list | 339 } // namespace app_list |
OLD | NEW |