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

Side by Side Diff: chrome/test/data/webui/md_bookmarks/md_bookmarks_focus_test.js

Issue 2954273002: [MD Bookmarks] Restore focus after closing a dialog or context menu. (Closed)
Patch Set: fix deps Created 3 years, 5 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 /** 5 /**
6 * @fileoverview Tests for MD Bookmarks which are run as interactive ui tests. 6 * @fileoverview Tests for MD Bookmarks which are run as interactive ui tests.
7 * Should be used for tests which care about focus. 7 * Should be used for tests which care about focus.
8 */ 8 */
9 9
10 var ROOT_PATH = '../../../../../'; 10 var ROOT_PATH = '../../../../../';
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // enter on the menu button. This checks that we block this behavior 389 // enter on the menu button. This checks that we block this behavior
390 // during keydown on <bookmarks-list>. 390 // during keydown on <bookmarks-list>.
391 var button = items[0].$$('.more-vert-button'); 391 var button = items[0].$$('.more-vert-button');
392 button.focus(); 392 button.focus();
393 keydown(button, 'Enter'); 393 keydown(button, 'Enter');
394 394
395 assertEquals(button, items[0].root.activeElement); 395 assertEquals(button, items[0].root.activeElement);
396 }); 396 });
397 }); 397 });
398 398
399 suite('DialogFocusManager', function() {
400 var list;
401 var store;
402 var items;
403 var commandManager;
404 var dialogFocusManager;
405
406 function waitForClose(el) {
407 return new Promise(function(resolve) {
408 listenOnce(el, 'close', function(e) {
409 resolve();
410 })
411 });
412 }
413
414 function keydown(el, key) {
415 MockInteractions.keyDownOn(el, '', '', key);
416 }
417
418 setup(function() {
419 store = new bookmarks.TestStore({
420 nodes: testTree(createFolder(
421 '1',
422 [
423 createItem('2'),
424 createItem('3'),
425 createItem('4'),
426 createItem('5'),
427 createItem('6'),
428 createFolder('7', []),
429 ])),
430 selectedFolder: '1',
431 });
432 store.setReducersEnabled(true);
433 store.replaceSingleton();
434
435 list = document.createElement('bookmarks-list');
436 list.style.height = '100%';
437 list.style.width = '100%';
438 list.style.position = 'absolute';
439 replaceBody(list);
440 Polymer.dom.flush();
441 items = list.root.querySelectorAll('bookmarks-item');
442
443 commandManager = new TestCommandManager();
444 document.body.appendChild(commandManager);
445
446 dialogFocusManager = new bookmarks.DialogFocusManager();
447 bookmarks.DialogFocusManager.instance_ = dialogFocusManager;
448 });
449
450 test('restores focus on dialog dismissal', function() {
451 var focusedItem = items[0];
452 focusedItem.focus();
453 assertEquals(focusedItem, dialogFocusManager.getFocusedElement_());
454
455 commandManager.openCommandMenuAtPosition(0, 0);
456 var dropdown = commandManager.$.dropdown.getIfExists();
457
458 assertTrue(dropdown.open);
459 assertNotEquals(focusedItem, dialogFocusManager.getFocusedElement_());
460
461 keydown(dropdown, 'Escape');
462 assertFalse(dropdown.open);
463
464 return waitForClose(dropdown).then(() => {
465 assertEquals(focusedItem, dialogFocusManager.getFocusedElement_());
466 });
467 });
468
469 test('restores focus after stacked dialogs', function() {
470 var focusedItem = items[0];
471 focusedItem.focus();
472 assertEquals(focusedItem, dialogFocusManager.getFocusedElement_());
473
474 commandManager.openCommandMenuAtPosition(0, 0);
475 var dropdown = commandManager.$.dropdown.getIfExists();
476 dropdown.close();
477 assertNotEquals(focusedItem, dialogFocusManager.getFocusedElement_());
478
479 var editDialog = commandManager.$.editDialog.get();
480 editDialog.showEditDialog(store.data.nodes['2']);
481
482 return waitForClose(dropdown).then(() => {
483 editDialog.onCancelButtonTap_();
484 assertNotEquals(focusedItem, dialogFocusManager.getFocusedElement_());
485
486 return waitForClose(editDialog);
487 }).then(() => {
488 assertEquals(focusedItem, dialogFocusManager.getFocusedElement_());
489 });
490 });
491
492 test('restores focus after multiple shows of same dialog', function() {
493 var focusedItem = items[0];
494 focusedItem.focus();
495 assertEquals(focusedItem, dialogFocusManager.getFocusedElement_());
496
497 commandManager.openCommandMenuAtPosition(0, 0);
498 assertNotEquals(focusedItem, dialogFocusManager.getFocusedElement_());
499 var dropdown = commandManager.$.dropdown.getIfExists();
500 dropdown.close();
501
502 focusedItem = items[3];
503 focusedItem.focus();
504 commandManager.openCommandMenuAtPosition(0, 0);
505
506 return waitForClose(dropdown).then(() => {
507 assertTrue(dropdown.open);
508 dropdown.close();
509 assertNotEquals(
510 focusedItem, dialogFocusManager.getFocusedElement_());
511
512 return waitForClose(dropdown);
513 }).then(() => {
514 assertEquals(focusedItem, dialogFocusManager.getFocusedElement_());
515 });
516 });
517 });
518
399 mocha.run(); 519 mocha.run();
400 }); 520 });
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.cc ('k') | tools/gritsettings/resource_ids » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698