| 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 "ash/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 ShelfButton* button = GetButtonByID(last_added); | 1249 ShelfButton* button = GetButtonByID(last_added); |
| 1250 ASSERT_EQ(ShelfButton::STATE_RUNNING, button->state()); | 1250 ASSERT_EQ(ShelfButton::STATE_RUNNING, button->state()); |
| 1251 item.status = STATUS_ACTIVE; | 1251 item.status = STATUS_ACTIVE; |
| 1252 model_->Set(index, item); | 1252 model_->Set(index, item); |
| 1253 ASSERT_EQ(ShelfButton::STATE_ACTIVE, button->state()); | 1253 ASSERT_EQ(ShelfButton::STATE_ACTIVE, button->state()); |
| 1254 item.status = STATUS_ATTENTION; | 1254 item.status = STATUS_ATTENTION; |
| 1255 model_->Set(index, item); | 1255 model_->Set(index, item); |
| 1256 ASSERT_EQ(ShelfButton::STATE_ATTENTION, button->state()); | 1256 ASSERT_EQ(ShelfButton::STATE_ATTENTION, button->state()); |
| 1257 } | 1257 } |
| 1258 | 1258 |
| 1259 // Test what drag movements will rip an item off the shelf. |
| 1260 TEST_F(ShelfViewTest, ShelfRipOff) { |
| 1261 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 1262 |
| 1263 // The test makes some assumptions that the shelf is bottom aligned. |
| 1264 ASSERT_EQ(test_api_->shelf_view()->shelf()->alignment(), |
| 1265 SHELF_ALIGNMENT_BOTTOM); |
| 1266 |
| 1267 // The rip off threshold. Taken from |kRipOffDistance| in shelf_view.cc. |
| 1268 const int kRipOffDistance = 48; |
| 1269 |
| 1270 // Add two apps (which is on the main shelf) and then add buttons until |
| 1271 // overflow. Add one more app (which is on the overflow shelf). |
| 1272 ShelfID first_app_id = AddAppShortcut(); |
| 1273 ShelfID second_app_id = AddAppShortcut(); |
| 1274 AddButtonsUntilOverflow(); |
| 1275 ShelfID overflow_app_id = AddAppShortcut(); |
| 1276 |
| 1277 // Verify that dragging an app off the shelf will trigger the app getting |
| 1278 // ripped off, unless the distance is less than |kRipOffDistance|. |
| 1279 gfx::Point first_app_location = GetButtonCenter(GetButtonByID(first_app_id)); |
| 1280 generator.set_current_location(first_app_location); |
| 1281 generator.PressLeftButton(); |
| 1282 // Drag the mouse to just off the shelf. |
| 1283 generator.MoveMouseBy(0, -kShelfSize / 2 - 1); |
| 1284 EXPECT_FALSE(test_api_->IsRippedOffFromShelf()); |
| 1285 // Drag the mouse past the rip off threshold. |
| 1286 generator.MoveMouseBy(0, -kRipOffDistance); |
| 1287 EXPECT_TRUE(test_api_->IsRippedOffFromShelf()); |
| 1288 // Drag the mouse back to the original position, so that the app does not get |
| 1289 // deleted. |
| 1290 generator.MoveMouseTo(first_app_location); |
| 1291 generator.ReleaseLeftButton(); |
| 1292 EXPECT_FALSE(test_api_->IsRippedOffFromShelf()); |
| 1293 |
| 1294 // Open overflow shelf and test api for it. |
| 1295 test_api_->ShowOverflowBubble(); |
| 1296 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 1297 ShelfViewTestAPI test_api_for_overflow( |
| 1298 test_api_->overflow_bubble()->shelf_view()); |
| 1299 |
| 1300 // Verify that when an app from the main shelf is dragged to a location on the |
| 1301 // overflow shelf, it is ripped off. |
| 1302 gfx::Point second_app_location = |
| 1303 GetButtonCenter(GetButtonByID(second_app_id)); |
| 1304 gfx::Point overflow_app_location = GetButtonCenter( |
| 1305 test_api_for_overflow.GetButton(model_->ItemIndexByID(overflow_app_id))); |
| 1306 generator.set_current_location(second_app_location); |
| 1307 generator.PressLeftButton(); |
| 1308 generator.MoveMouseTo(overflow_app_location); |
| 1309 EXPECT_TRUE(test_api_->IsRippedOffFromShelf()); |
| 1310 generator.MoveMouseTo(second_app_location); |
| 1311 generator.ReleaseLeftButton(); |
| 1312 EXPECT_FALSE(test_api_->IsRippedOffFromShelf()); |
| 1313 |
| 1314 // Verify that when an app from the overflow shelf is dragged to a location on |
| 1315 // the main shelf, it is ripped off. |
| 1316 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 1317 generator.set_current_location(overflow_app_location); |
| 1318 generator.PressLeftButton(); |
| 1319 generator.MoveMouseTo(second_app_location); |
| 1320 EXPECT_TRUE(test_api_for_overflow.IsRippedOffFromShelf()); |
| 1321 generator.MoveMouseTo(overflow_app_location); |
| 1322 generator.ReleaseLeftButton(); |
| 1323 EXPECT_FALSE(test_api_for_overflow.IsRippedOffFromShelf()); |
| 1324 } |
| 1325 |
| 1259 // Confirm that item status changes are reflected in the buttons | 1326 // Confirm that item status changes are reflected in the buttons |
| 1260 // for platform apps. | 1327 // for platform apps. |
| 1261 TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) { | 1328 TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) { |
| 1262 // All buttons should be visible. | 1329 // All buttons should be visible. |
| 1263 ASSERT_EQ(test_api_->GetButtonCount(), test_api_->GetLastVisibleIndex() + 1); | 1330 ASSERT_EQ(test_api_->GetButtonCount(), test_api_->GetLastVisibleIndex() + 1); |
| 1264 | 1331 |
| 1265 // Add platform app button. | 1332 // Add platform app button. |
| 1266 ShelfID last_added = AddApp(); | 1333 ShelfID last_added = AddApp(); |
| 1267 ShelfItem item = GetItemByID(last_added); | 1334 ShelfItem item = GetItemByID(last_added); |
| 1268 int index = model_->ItemIndexByID(last_added); | 1335 int index = model_->ItemIndexByID(last_added); |
| (...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3134 EXPECT_EQ(views::InkDropState::ACTIVATED, | 3201 EXPECT_EQ(views::InkDropState::ACTIVATED, |
| 3135 overflow_button_ink_drop_->GetTargetInkDropState()); | 3202 overflow_button_ink_drop_->GetTargetInkDropState()); |
| 3136 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), | 3203 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), |
| 3137 IsEmpty()); | 3204 IsEmpty()); |
| 3138 | 3205 |
| 3139 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 3206 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 3140 } | 3207 } |
| 3141 | 3208 |
| 3142 } // namespace test | 3209 } // namespace test |
| 3143 } // namespace ash | 3210 } // namespace ash |
| OLD | NEW |