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 "base/memory/scoped_nsobject.h" | 5 #include "base/memory/scoped_nsobject.h" |
6 #import "testing/gtest_mac.h" | 6 #import "testing/gtest_mac.h" |
7 #include "ui/app_list/app_list_item_model.h" | 7 #include "ui/app_list/app_list_item_model.h" |
8 #import "ui/app_list/cocoa/apps_collection_view_drag_manager.h" | 8 #import "ui/app_list/cocoa/apps_collection_view_drag_manager.h" |
9 #import "ui/app_list/cocoa/apps_grid_controller.h" | 9 #import "ui/app_list/cocoa/apps_grid_controller.h" |
10 #import "ui/app_list/cocoa/apps_grid_view_item.h" | 10 #import "ui/app_list/cocoa/apps_grid_view_item.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 EXPECT_EQ(2u, [apps_grid_controller_ selectedItemIndex]); | 221 EXPECT_EQ(2u, [apps_grid_controller_ selectedItemIndex]); |
222 SimulateKeyAction(@selector(insertNewline:)); | 222 SimulateKeyAction(@selector(insertNewline:)); |
223 EXPECT_EQ(1, delegate()->activate_count()); | 223 EXPECT_EQ(1, delegate()->activate_count()); |
224 EXPECT_EQ(std::string("Item 2"), delegate()->last_activated()->title()); | 224 EXPECT_EQ(std::string("Item 2"), delegate()->last_activated()->title()); |
225 } | 225 } |
226 | 226 |
227 // Tests keyboard navigation across pages. | 227 // Tests keyboard navigation across pages. |
228 TEST_F(AppsGridControllerTest, CrossPageKeyboardNavigation) { | 228 TEST_F(AppsGridControllerTest, CrossPageKeyboardNavigation) { |
229 [AppsGridController setScrollAnimationDuration:0.0]; | 229 [AppsGridController setScrollAnimationDuration:0.0]; |
230 | 230 |
231 model()->PopulateApps(2 * kItemsPerPage); | 231 model()->PopulateApps(kItemsPerPage + 10); |
232 EXPECT_EQ(kItemsPerPage, [[GetPageAt(0) content] count]); | 232 EXPECT_EQ(kItemsPerPage, [[GetPageAt(0) content] count]); |
233 EXPECT_EQ(kItemsPerPage, [[GetPageAt(1) content] count]); | 233 EXPECT_EQ(10u, [[GetPageAt(1) content] count]); |
234 | 234 |
235 // Moving Left, Up, or PageUp from the top-left corner of the first page does | 235 // Moving Left, Up, or PageUp from the top-left corner of the first page does |
236 // nothing. | 236 // nothing. |
237 [apps_grid_controller_ selectItemAtIndex:0]; | 237 [apps_grid_controller_ selectItemAtIndex:0]; |
238 SimulateKeyAction(@selector(moveLeft:)); | 238 SimulateKeyAction(@selector(moveLeft:)); |
239 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); | 239 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); |
240 SimulateKeyAction(@selector(moveUp:)); | 240 SimulateKeyAction(@selector(moveUp:)); |
241 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); | 241 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); |
242 SimulateKeyAction(@selector(scrollPageUp:)); | 242 SimulateKeyAction(@selector(scrollPageUp:)); |
243 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); | 243 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); |
244 | 244 |
245 // Moving Right from the right side wraps to the next row. | 245 // Moving Right from the right side goes to the next page. Moving Left goes |
246 // back to the first page. | |
246 [apps_grid_controller_ selectItemAtIndex:3]; | 247 [apps_grid_controller_ selectItemAtIndex:3]; |
247 SimulateKeyAction(@selector(moveRight:)); | 248 SimulateKeyAction(@selector(moveRight:)); |
248 EXPECT_EQ(4u, [apps_grid_controller_ selectedItemIndex]); | |
249 | |
250 // Moving Down from the bottom goes to the next page and selects the same | |
251 // column. Moving Up again goes back to the first page. | |
252 [apps_grid_controller_ selectItemAtIndex:13]; | |
253 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
254 SimulateKeyAction(@selector(moveDown:)); | |
255 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); | |
256 EXPECT_EQ(kItemsPerPage + 1, [apps_grid_controller_ selectedItemIndex]); | |
257 SimulateKeyAction(@selector(moveUp:)); | |
258 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
259 EXPECT_EQ(13u, [apps_grid_controller_ selectedItemIndex]); | |
260 | |
261 // Moving Right from the bottom-right corner goes to the next page. | |
262 // Moving Left again goes back to the first page. | |
263 [apps_grid_controller_ selectItemAtIndex:15]; | |
264 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
265 SimulateKeyAction(@selector(moveRight:)); | |
266 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); | 249 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); |
267 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]); | 250 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]); |
268 SimulateKeyAction(@selector(moveLeft:)); | 251 SimulateKeyAction(@selector(moveLeft:)); |
269 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 252 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
270 EXPECT_EQ(15u, [apps_grid_controller_ selectedItemIndex]); | 253 EXPECT_EQ(3u, [apps_grid_controller_ selectedItemIndex]); |
254 | |
255 // Moving Down from the bottom does nothing. | |
256 [apps_grid_controller_ selectItemAtIndex:13]; | |
257 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
258 SimulateKeyAction(@selector(moveDown:)); | |
259 EXPECT_EQ(13u, [apps_grid_controller_ selectedItemIndex]); | |
260 | |
261 // Moving Right into a non-existent square on the next page will select the | |
262 // last item. | |
263 [apps_grid_controller_ selectItemAtIndex:15]; | |
264 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
265 SimulateKeyAction(@selector(moveRight:)); | |
266 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); | |
267 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]); | |
271 | 268 |
272 // PageDown and PageUp switches pages while maintaining the same selection | 269 // PageDown and PageUp switches pages while maintaining the same selection |
273 // position. | 270 // position. |
274 [apps_grid_controller_ selectItemAtIndex:10]; | 271 [apps_grid_controller_ selectItemAtIndex:6]; |
275 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 272 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
276 SimulateKeyAction(@selector(scrollPageDown:)); | 273 SimulateKeyAction(@selector(scrollPageDown:)); |
277 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); | 274 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); |
278 EXPECT_EQ(kItemsPerPage + 10, [apps_grid_controller_ selectedItemIndex]); | 275 EXPECT_EQ(kItemsPerPage + 6, [apps_grid_controller_ selectedItemIndex]); |
279 SimulateKeyAction(@selector(scrollPageUp:)); | 276 SimulateKeyAction(@selector(scrollPageUp:)); |
280 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | 277 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); |
281 EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]); | 278 EXPECT_EQ(6u, [apps_grid_controller_ selectedItemIndex]); |
279 | |
280 // PageDown into a non-existent square on the next page will select the last | |
281 // item. | |
282 [apps_grid_controller_ selectItemAtIndex:11]; | |
283 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
284 SimulateKeyAction(@selector(scrollPageDown:)); | |
285 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); | |
286 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]); | |
282 | 287 |
283 // Moving Right, Down, or PageDown from the bottom-right corner of the last | 288 // Moving Right, Down, or PageDown from the bottom-right corner of the last |
284 // page does nothing. | 289 // page (not the last item) does nothing. |
285 [apps_grid_controller_ selectItemAtIndex:(2 * kItemsPerPage - 1)]; | 290 [apps_grid_controller_ selectItemAtIndex:kItemsPerPage + 9]; |
286 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); | 291 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); |
287 SimulateKeyAction(@selector(moveRight:)); | 292 SimulateKeyAction(@selector(moveRight:)); |
288 EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); | 293 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]); |
289 SimulateKeyAction(@selector(moveDown:)); | 294 SimulateKeyAction(@selector(moveDown:)); |
290 EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); | 295 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]); |
291 SimulateKeyAction(@selector(scrollPageDown:)); | 296 SimulateKeyAction(@selector(scrollPageDown:)); |
292 EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); | 297 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]); |
293 | |
294 // Moving down on the bottom of the last page does nothing. | |
295 [apps_grid_controller_ selectItemAtIndex:(2 * kItemsPerPage - 4)]; | |
296 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); | |
297 SimulateKeyAction(@selector(moveDown:)); | |
298 EXPECT_EQ(kItemsPerPage + 12, [apps_grid_controller_ selectedItemIndex]); | |
299 | |
300 // Remove some items from the last page. | |
301 ReplaceTestModel(kItemsPerPage + 8); | |
302 EXPECT_EQ(8u, [[GetPageAt(1) content] count]); | |
303 EXPECT_EQ(NSNotFound, [apps_grid_controller_ selectedItemIndex]); | |
304 | |
305 // PageUp/Down to an invalid selection does nothing. | |
306 [apps_grid_controller_ selectItemAtIndex:10]; | |
307 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
308 SimulateKeyAction(@selector(scrollPageUp:)); | |
309 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
310 EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]); | |
311 SimulateKeyAction(@selector(scrollPageDown:)); | |
312 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); | |
313 EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]); | |
314 | 298 |
315 // After page switch, arrow keys select first item on current page. | 299 // After page switch, arrow keys select first item on current page. |
300 [apps_grid_controller_ scrollToPage:0]; | |
tapted
2013/05/23 11:26:16
should this be here? (delete?)
jackhou1
2013/05/24 01:52:49
Yeah the preceding code ends up on page 1, so scro
| |
316 [apps_grid_controller_ scrollToPage:1]; | 301 [apps_grid_controller_ scrollToPage:1]; |
317 EXPECT_EQ(NSNotFound, [apps_grid_controller_ selectedItemIndex]); | 302 EXPECT_EQ(NSNotFound, [apps_grid_controller_ selectedItemIndex]); |
318 SimulateKeyAction(@selector(moveUp:)); | 303 SimulateKeyAction(@selector(moveUp:)); |
319 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]); | 304 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]); |
320 } | 305 } |
321 | 306 |
322 // Highlighting an item should cause the page it's on to be visible. | 307 // Highlighting an item should cause the page it's on to be visible. |
323 TEST_F(AppsGridControllerTest, EnsureHighlightedVisible) { | 308 TEST_F(AppsGridControllerTest, EnsureHighlightedVisible) { |
324 model()->PopulateApps(3 * kItemsPerPage); | 309 model()->PopulateApps(3 * kItemsPerPage); |
325 EXPECT_EQ(kItemsPerPage, [[GetPageAt(2) content] count]); | 310 EXPECT_EQ(kItemsPerPage, [[GetPageAt(2) content] count]); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 // Scroll to end again, and keep dragging (should be ignored). | 676 // Scroll to end again, and keep dragging (should be ignored). |
692 [apps_grid_controller_ scrollToPage:2]; | 677 [apps_grid_controller_ scrollToPage:2]; |
693 [drag_manager onMouseDragged:mouse_at_cell_0]; | 678 [drag_manager onMouseDragged:mouse_at_cell_0]; |
694 EXPECT_EQ(0u, GetPageIndexForItem(1)); | 679 EXPECT_EQ(0u, GetPageIndexForItem(1)); |
695 [drag_manager onMouseUp:mouse_at_cell_0]; | 680 [drag_manager onMouseUp:mouse_at_cell_0]; |
696 EXPECT_EQ(0u, GetPageIndexForItem(1)); | 681 EXPECT_EQ(0u, GetPageIndexForItem(1)); |
697 } | 682 } |
698 | 683 |
699 } // namespace test | 684 } // namespace test |
700 } // namespace app_list | 685 } // namespace app_list |
OLD | NEW |