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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/background_test.extjs

Issue 2150623002: Refactor: Extract a KeyboardHandler and CommandHandler from Background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test. Created 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 test fixture. 5 // Include test fixture.
6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js', 6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js',
7 '../../testing/assert_additions.js']); 7 '../../testing/assert_additions.js']);
8 8
9 GEN_INCLUDE(['../../testing/mock_feedback.js']); 9 GEN_INCLUDE(['../../testing/mock_feedback.js']);
10 10
(...skipping 29 matching lines...) Expand all
40 return mockFeedback; 40 return mockFeedback;
41 }, 41 },
42 42
43 /** 43 /**
44 * Create a function which perform the command |cmd|. 44 * Create a function which perform the command |cmd|.
45 * @param {string} cmd 45 * @param {string} cmd
46 * @return {function() : void} 46 * @return {function() : void}
47 */ 47 */
48 doCmd: function(cmd) { 48 doCmd: function(cmd) {
49 return function() { 49 return function() {
50 ChromeVoxState.instance.onGotCommand(cmd); 50 CommandHandler.onCommand(cmd);
51 }; 51 };
52 }, 52 },
53 53
54 linksAndHeadingsDoc: function() {/*! 54 linksAndHeadingsDoc: function() {/*!
55 <p>start</p> 55 <p>start</p>
56 <a href='#a'>alpha</a> 56 <a href='#a'>alpha</a>
57 <a href='#b'>beta</a> 57 <a href='#b'>beta</a>
58 <p> 58 <p>
59 <h1>charlie</h1> 59 <h1>charlie</h1>
60 <a href='foo'>delta</a> 60 <a href='foo'>delta</a>
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 .expectSpeech(/slider/) 430 .expectSpeech(/slider/)
431 .expectEarcon(cvox.Earcon.SLIDER); 431 .expectEarcon(cvox.Earcon.SLIDER);
432 432
433 mockFeedback.replay(); 433 mockFeedback.replay();
434 }.bind(this)); 434 }.bind(this));
435 }); 435 });
436 436
437 TEST_F('BackgroundTest', 'ToggleChromeVoxVersion', function() { 437 TEST_F('BackgroundTest', 'ToggleChromeVoxVersion', function() {
438 var mockFeedback = this.createMockFeedback(); 438 var mockFeedback = this.createMockFeedback();
439 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() { 439 this.runWithLoadedTree(this.linksAndHeadingsDoc, function() {
440 var gotCmd = ChromeVoxState.instance.onGotCommand; 440 var gotCmd = CommandHandler.onCommand;
441 441
442 // The command came from the background keyboard handler. 442 // The command came from the background keyboard handler.
443 var togglerFromBackground = gotCmd.bind(gotCmd, 'toggleChromeVoxVersion'); 443 var togglerFromBackground = gotCmd.bind(gotCmd, 'toggleChromeVoxVersion');
444 444
445 // The command came from a content script. 445 // The command came from a content script.
446 var togglerFromContent = gotCmd.bind(gotCmd, 'toggleChromeVoxVersion', 446 var togglerFromContent = gotCmd.bind(gotCmd, 'toggleChromeVoxVersion',
447 true); 447 true);
448 448
449 mockFeedback.call(togglerFromBackground) 449 mockFeedback.call(togglerFromBackground)
450 .expectSpeech('Switched to Classic ChromeVox') 450 .expectSpeech('Switched to Classic ChromeVox')
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 575
576 assertEquals('iframe', iframe.role); 576 assertEquals('iframe', iframe.role);
577 assertEquals('button', button.role); 577 assertEquals('button', button.role);
578 578
579 var didFocus = false; 579 var didFocus = false;
580 iframe.focus = function() { 580 iframe.focus = function() {
581 didFocus = true; 581 didFocus = true;
582 }; 582 };
583 var b = ChromeVoxState.instance; 583 var b = ChromeVoxState.instance;
584 b.currentRange_ = cursors.Range.fromNode(button); 584 b.currentRange_ = cursors.Range.fromNode(button);
585 b.onGotCommand('previousElement'); 585 doCmd('previousElement');
586 assertFalse(didFocus); 586 assertFalse(didFocus);
587 }.bind(this)); 587 }.bind(this));
588 }); 588 });
589 589
590 TEST_F('BackgroundTest', 'NoisySlider', function() { 590 TEST_F('BackgroundTest', 'NoisySlider', function() {
591 var mockFeedback = this.createMockFeedback(); 591 var mockFeedback = this.createMockFeedback();
592 this.runWithLoadedTree( function() {/*! 592 this.runWithLoadedTree( function() {/*!
593 <button id="go">go</button> 593 <button id="go">go</button>
594 <div id="slider" tabindex=0 role="slider"></div> 594 <div id="slider" tabindex=0 role="slider"></div>
595 <script> 595 <script>
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 }); 762 });
763 763
764 TEST_F('BackgroundTest', 'ToggleButton', function() { 764 TEST_F('BackgroundTest', 'ToggleButton', function() {
765 var mockFeedback = this.createMockFeedback(); 765 var mockFeedback = this.createMockFeedback();
766 this.runWithLoadedTree(function() {/*! 766 this.runWithLoadedTree(function() {/*!
767 <div aria-pressed="true" role="button">ok</div> 767 <div aria-pressed="true" role="button">ok</div>
768 <div aria-pressed="false" role="button">cancel</div> 768 <div aria-pressed="false" role="button">cancel</div>
769 <div aria-pressed role="button">close</div> 769 <div aria-pressed role="button">close</div>
770 */}, function(root) { 770 */}, function(root) {
771 var b = ChromeVoxState.instance; 771 var b = ChromeVoxState.instance;
772 var move = b.onGotCommand.bind(b, 'nextObject'); 772 var move = doCmd('nextObject');
773 mockFeedback.call(move) 773 mockFeedback.call(move)
774 .expectSpeech('ok') 774 .expectSpeech('ok')
775 .expectSpeech('Button') 775 .expectSpeech('Button')
776 .expectSpeech('Pressed') 776 .expectSpeech('Pressed')
777 777
778 .call(move) 778 .call(move)
779 .expectSpeech('cancel') 779 .expectSpeech('cancel')
780 .expectSpeech('Button') 780 .expectSpeech('Button')
781 .expectSpeech('Not pressed') 781 .expectSpeech('Not pressed')
782 782
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 970
971 TEST_F('BackgroundTest', 'Selection', function() { 971 TEST_F('BackgroundTest', 'Selection', function() {
972 var mockFeedback = this.createMockFeedback(); 972 var mockFeedback = this.createMockFeedback();
973 this.runWithLoadedTree(function(root) {/*! 973 this.runWithLoadedTree(function(root) {/*!
974 <p>simple</p> 974 <p>simple</p>
975 <p>doc</p> 975 <p>doc</p>
976 */}, function(root) { 976 */}, function(root) {
977 // Fakes a toggleSelection command. 977 // Fakes a toggleSelection command.
978 root.addEventListener('textSelectionChanged', function() { 978 root.addEventListener('textSelectionChanged', function() {
979 if (root.focusOffset == 3) 979 if (root.focusOffset == 3)
980 ChromeVoxState.instance.onGotCommand('toggleSelection'); 980 CommandHandler.onCommand('toggleSelection');
981 }, true); 981 }, true);
982 982
983 mockFeedback.call(doCmd('toggleSelection')) 983 mockFeedback.call(doCmd('toggleSelection'))
984 .expectSpeech('simple', 'selected') 984 .expectSpeech('simple', 'selected')
985 .call(doCmd('nextCharacter')) 985 .call(doCmd('nextCharacter'))
986 .expectSpeech('i', 'selected') 986 .expectSpeech('i', 'selected')
987 .call(doCmd('previousCharacter')) 987 .call(doCmd('previousCharacter'))
988 .expectSpeech('i', 'unselected') 988 .expectSpeech('i', 'unselected')
989 .call(doCmd('nextCharacter')) 989 .call(doCmd('nextCharacter'))
990 .call(doCmd('nextCharacter')) 990 .call(doCmd('nextCharacter'))
991 .expectSpeech('End selection', 'sim') 991 .expectSpeech('End selection', 'sim')
992 .replay(); 992 .replay();
993 }); 993 });
994 }); 994 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698