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

Side by Side Diff: ui/app_list/cocoa/apps_grid_controller_unittest.mm

Issue 15648003: Fix keyboard navigation in app launcher (OSX) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/cocoa/apps_grid_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 SimulateKeyAction(@selector(moveRight:)); 253 SimulateKeyAction(@selector(moveRight:));
254 SimulateKeyAction(@selector(moveRight:)); 254 SimulateKeyAction(@selector(moveRight:));
255 EXPECT_EQ(2u, [apps_grid_controller_ selectedItemIndex]); 255 EXPECT_EQ(2u, [apps_grid_controller_ selectedItemIndex]);
256 SimulateKeyAction(@selector(insertNewline:)); 256 SimulateKeyAction(@selector(insertNewline:));
257 EXPECT_EQ(1, delegate()->activate_count()); 257 EXPECT_EQ(1, delegate()->activate_count());
258 EXPECT_EQ(std::string("Item 2"), delegate()->last_activated()->title()); 258 EXPECT_EQ(std::string("Item 2"), delegate()->last_activated()->title());
259 } 259 }
260 260
261 // Tests keyboard navigation across pages. 261 // Tests keyboard navigation across pages.
262 TEST_F(AppsGridControllerTest, CrossPageKeyboardNavigation) { 262 TEST_F(AppsGridControllerTest, CrossPageKeyboardNavigation) {
263 model()->PopulateApps(2 * kItemsPerPage); 263 model()->PopulateApps(kItemsPerPage + 10);
264 EXPECT_EQ(kItemsPerPage, [[GetPageAt(0) content] count]); 264 EXPECT_EQ(kItemsPerPage, [[GetPageAt(0) content] count]);
265 EXPECT_EQ(kItemsPerPage, [[GetPageAt(1) content] count]); 265 EXPECT_EQ(10u, [[GetPageAt(1) content] count]);
266 266
267 // Moving Left, Up, or PageUp from the top-left corner of the first page does 267 // Moving Left, Up, or PageUp from the top-left corner of the first page does
268 // nothing. 268 // nothing.
269 [apps_grid_controller_ selectItemAtIndex:0]; 269 [apps_grid_controller_ selectItemAtIndex:0];
270 SimulateKeyAction(@selector(moveLeft:)); 270 SimulateKeyAction(@selector(moveLeft:));
271 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); 271 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]);
272 SimulateKeyAction(@selector(moveUp:)); 272 SimulateKeyAction(@selector(moveUp:));
273 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); 273 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]);
274 SimulateKeyAction(@selector(scrollPageUp:)); 274 SimulateKeyAction(@selector(scrollPageUp:));
275 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]); 275 EXPECT_EQ(0u, [apps_grid_controller_ selectedItemIndex]);
276 276
277 // Moving Right from the right side wraps to the next row. 277 // Moving Right from the right side goes to the next page. Moving Left goes
278 // back to the first page.
278 [apps_grid_controller_ selectItemAtIndex:3]; 279 [apps_grid_controller_ selectItemAtIndex:3];
279 SimulateKeyAction(@selector(moveRight:)); 280 SimulateKeyAction(@selector(moveRight:));
280 EXPECT_EQ(4u, [apps_grid_controller_ selectedItemIndex]);
281
282 // Moving Down from the bottom goes to the next page and selects the same
283 // column. Moving Up again goes back to the first page.
284 [apps_grid_controller_ selectItemAtIndex:13];
285 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
286 SimulateKeyAction(@selector(moveDown:));
287 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]);
288 EXPECT_EQ(kItemsPerPage + 1, [apps_grid_controller_ selectedItemIndex]);
289 SimulateKeyAction(@selector(moveUp:));
290 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
291 EXPECT_EQ(13u, [apps_grid_controller_ selectedItemIndex]);
292
293 // Moving Right from the bottom-right corner goes to the next page.
294 // Moving Left again goes back to the first page.
295 [apps_grid_controller_ selectItemAtIndex:15];
296 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
297 SimulateKeyAction(@selector(moveRight:));
298 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); 281 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]);
299 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]); 282 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]);
300 SimulateKeyAction(@selector(moveLeft:)); 283 SimulateKeyAction(@selector(moveLeft:));
301 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); 284 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
302 EXPECT_EQ(15u, [apps_grid_controller_ selectedItemIndex]); 285 EXPECT_EQ(3u, [apps_grid_controller_ selectedItemIndex]);
286
287 // Moving Down from the bottom does nothing.
288 [apps_grid_controller_ selectItemAtIndex:13];
289 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
290 SimulateKeyAction(@selector(moveDown:));
291 EXPECT_EQ(13u, [apps_grid_controller_ selectedItemIndex]);
292
293 // Moving Right into a non-existent square on the next page will select the
294 // last item.
295 [apps_grid_controller_ selectItemAtIndex:15];
296 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
297 SimulateKeyAction(@selector(moveRight:));
298 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]);
299 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]);
303 300
304 // PageDown and PageUp switches pages while maintaining the same selection 301 // PageDown and PageUp switches pages while maintaining the same selection
305 // position. 302 // position.
306 [apps_grid_controller_ selectItemAtIndex:10]; 303 [apps_grid_controller_ selectItemAtIndex:6];
307 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); 304 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
308 SimulateKeyAction(@selector(scrollPageDown:)); 305 SimulateKeyAction(@selector(scrollPageDown:));
309 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); 306 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]);
310 EXPECT_EQ(kItemsPerPage + 10, [apps_grid_controller_ selectedItemIndex]); 307 EXPECT_EQ(kItemsPerPage + 6, [apps_grid_controller_ selectedItemIndex]);
311 SimulateKeyAction(@selector(scrollPageUp:)); 308 SimulateKeyAction(@selector(scrollPageUp:));
312 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]); 309 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
313 EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]); 310 EXPECT_EQ(6u, [apps_grid_controller_ selectedItemIndex]);
311
312 // PageDown into a non-existent square on the next page will select the last
313 // item.
314 [apps_grid_controller_ selectItemAtIndex:11];
315 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
316 SimulateKeyAction(@selector(scrollPageDown:));
317 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]);
318 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]);
314 319
315 // Moving Right, Down, or PageDown from the bottom-right corner of the last 320 // Moving Right, Down, or PageDown from the bottom-right corner of the last
316 // page does nothing. 321 // page (not the last item) does nothing.
317 [apps_grid_controller_ selectItemAtIndex:(2 * kItemsPerPage - 1)]; 322 [apps_grid_controller_ selectItemAtIndex:kItemsPerPage + 9];
318 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]); 323 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]);
319 SimulateKeyAction(@selector(moveRight:)); 324 SimulateKeyAction(@selector(moveRight:));
320 EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); 325 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]);
321 SimulateKeyAction(@selector(moveDown:)); 326 SimulateKeyAction(@selector(moveDown:));
322 EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); 327 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]);
323 SimulateKeyAction(@selector(scrollPageDown:)); 328 SimulateKeyAction(@selector(scrollPageDown:));
324 EXPECT_EQ(kItemsPerPage + 15, [apps_grid_controller_ selectedItemIndex]); 329 EXPECT_EQ(kItemsPerPage + 9, [apps_grid_controller_ selectedItemIndex]);
325
326 // Moving down on the bottom of the last page does nothing.
327 [apps_grid_controller_ selectItemAtIndex:(2 * kItemsPerPage - 4)];
328 EXPECT_EQ(1u, [apps_grid_controller_ visiblePage]);
329 SimulateKeyAction(@selector(moveDown:));
330 EXPECT_EQ(kItemsPerPage + 12, [apps_grid_controller_ selectedItemIndex]);
331
332 // Remove some items from the last page.
333 ReplaceTestModel(kItemsPerPage + 8);
334 EXPECT_EQ(8u, [[GetPageAt(1) content] count]);
335 EXPECT_EQ(NSNotFound, [apps_grid_controller_ selectedItemIndex]);
336
337 // PageUp/Down to an invalid selection does nothing.
338 [apps_grid_controller_ selectItemAtIndex:10];
339 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
340 SimulateKeyAction(@selector(scrollPageUp:));
341 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
342 EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]);
343 SimulateKeyAction(@selector(scrollPageDown:));
344 EXPECT_EQ(0u, [apps_grid_controller_ visiblePage]);
345 EXPECT_EQ(10u, [apps_grid_controller_ selectedItemIndex]);
346 330
347 // After page switch, arrow keys select first item on current page. 331 // After page switch, arrow keys select first item on current page.
332 [apps_grid_controller_ scrollToPage:0];
348 [apps_grid_controller_ scrollToPage:1]; 333 [apps_grid_controller_ scrollToPage:1];
349 EXPECT_EQ(NSNotFound, [apps_grid_controller_ selectedItemIndex]); 334 EXPECT_EQ(NSNotFound, [apps_grid_controller_ selectedItemIndex]);
350 SimulateKeyAction(@selector(moveUp:)); 335 SimulateKeyAction(@selector(moveUp:));
351 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]); 336 EXPECT_EQ(kItemsPerPage, [apps_grid_controller_ selectedItemIndex]);
352 } 337 }
353 338
354 // Highlighting an item should cause the page it's on to be visible. 339 // Highlighting an item should cause the page it's on to be visible.
355 TEST_F(AppsGridControllerTest, EnsureHighlightedVisible) { 340 TEST_F(AppsGridControllerTest, EnsureHighlightedVisible) {
356 model()->PopulateApps(3 * kItemsPerPage); 341 model()->PopulateApps(3 * kItemsPerPage);
357 EXPECT_EQ(kItemsPerPage, [[GetPageAt(2) content] count]); 342 EXPECT_EQ(kItemsPerPage, [[GetPageAt(2) content] count]);
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 EXPECT_EQ(1u, [apps_grid_controller_ scheduledScrollPage]); 763 EXPECT_EQ(1u, [apps_grid_controller_ scheduledScrollPage]);
779 [drag_manager onMouseUp:at_center]; 764 [drag_manager onMouseUp:at_center];
780 EXPECT_EQ(2u, [apps_grid_controller_ visiblePage]); 765 EXPECT_EQ(2u, [apps_grid_controller_ visiblePage]);
781 EXPECT_EQ(2u, [apps_grid_controller_ scheduledScrollPage]); 766 EXPECT_EQ(2u, [apps_grid_controller_ scheduledScrollPage]);
782 767
783 [apps_grid_controller_ setPaginationObserver:nil]; 768 [apps_grid_controller_ setPaginationObserver:nil];
784 } 769 }
785 770
786 } // namespace test 771 } // namespace test
787 } // namespace app_list 772 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/cocoa/apps_grid_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698