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

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

Issue 2007183002: Make ChromeVox cursor robust to deleted nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 6 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 <option> banana</option> 67 <option> banana</option>
68 </select> 68 </select>
69 */}, 69 */},
70 70
71 iframesDoc: function() {/*! 71 iframesDoc: function() {/*!
72 <p>start</p> 72 <p>start</p>
73 <button>Before</button> 73 <button>Before</button>
74 <iframe srcdoc="<button>Inside</button><h1>Inside</h1>"></iframe> 74 <iframe srcdoc="<button>Inside</button><h1>Inside</h1>"></iframe>
75 <button>After</button> 75 <button>After</button>
76 */}, 76 */},
77
78 disappearingObjectDoc: function() {/*!
79 <p>start</p>
80 <article>
81 <p>Before1</p>
82 <p>Before2</p>
83 <p>Before3</p>
84 </article>
85 <article>
86 <p id="disappearing">Disappearing</p>
87 </article>
88 <article>
89 <p>After1</p>
90 <p>After2</p>
91 <p>After3</p>
92 </article>
93 </div>
94 <div id="live" aria-live="polite"></div>
95 <div id="delete" role="button">Delete</div>
96 <script>
97 document.getElementById('delete').addEventListener('click', function() {
98 var d = document.getElementById('disappearing');
99 d.parentElement.removeChild(d);
100 document.getElementById('live').innerText = 'Deleted';
101 });
102 </script>
103 */},
77 }; 104 };
78 105
79 /** Tests that ChromeVox classic is in this context. */ 106 /** Tests that ChromeVox classic is in this context. */
80 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() { 107 SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() {
81 assertEquals('object', typeof(cvox)); 108 assertEquals('object', typeof(cvox));
82 assertEquals('function', typeof(cvox.ChromeVoxBackground)); 109 assertEquals('function', typeof(cvox.ChromeVoxBackground));
83 }); 110 });
84 111
85 /** Tests that ChromeVox next is in this context. */ 112 /** Tests that ChromeVox next is in this context. */
86 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() { 113 SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 .expectSpeech('a') 259 .expectSpeech('a')
233 .expectSpeech('Link'); 260 .expectSpeech('Link');
234 mockFeedback.replay(); 261 mockFeedback.replay();
235 }); 262 });
236 }); 263 });
237 264
238 TEST_F('BackgroundTest', 'AriaLabel', function() { 265 TEST_F('BackgroundTest', 'AriaLabel', function() {
239 var mockFeedback = this.createMockFeedback(); 266 var mockFeedback = this.createMockFeedback();
240 this.runWithLoadedTree('<a aria-label="foo" href="a">a</a>', 267 this.runWithLoadedTree('<a aria-label="foo" href="a">a</a>',
241 function(rootNode) { 268 function(rootNode) {
242 rootNode.find({role: 'link'}).focus(); 269 rootNode.find({role: RoleType.link}).focus();
243 mockFeedback.expectSpeech('foo') 270 mockFeedback.expectSpeech('foo')
244 .expectSpeech('Link') 271 .expectSpeech('Link')
245 .expectBraille('foo lnk'); 272 .expectBraille('foo lnk');
246 mockFeedback.replay(); 273 mockFeedback.replay();
247 } 274 }
248 ); 275 );
249 }); 276 });
250 277
251 TEST_F('BackgroundTest', 'ShowContextMenu', function() { 278 TEST_F('BackgroundTest', 'ShowContextMenu', function() {
252 var mockFeedback = this.createMockFeedback(); 279 var mockFeedback = this.createMockFeedback();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 <p>Some more text</p> 313 <p>Some more text</p>
287 <input type="text" id ="text" value="Edit me"> 314 <input type="text" id ="text" value="Edit me">
288 <script> 315 <script>
289 document.getElementById('btn1').addEventListener('click', function() { 316 document.getElementById('btn1').addEventListener('click', function() {
290 document.getElementById('btn2').focus(); 317 document.getElementById('btn2').focus();
291 }, false); 318 }, false);
292 </script> 319 </script>
293 */}, 320 */},
294 function(rootNode) { 321 function(rootNode) {
295 var button1 = rootNode.find({role: RoleType.button, 322 var button1 = rootNode.find({role: RoleType.button,
296 name: 'Click me'}); 323 attributes: { name: 'Click me' }});
297 var textField = rootNode.find( 324 var textField = rootNode.find(
298 {role: RoleType.textField}); 325 {role: RoleType.textField});
299 mockFeedback.expectBraille('start') 326 mockFeedback.expectBraille('start')
300 .call(button1.focus.bind(button1)) 327 .call(button1.focus.bind(button1))
301 .expectBraille(/^Click me btn/) 328 .expectBraille(/^Click me btn/)
302 .call(route.bind(null, 5)) 329 .call(route.bind(null, 5))
303 .expectBraille(/Focus me btn/) 330 .expectBraille(/Focus me btn/)
304 .call(textField.focus.bind(textField)) 331 .call(textField.focus.bind(textField))
305 .expectBraille('Edit me ed', {startIndex: 0}) 332 .expectBraille('Edit me ed', {startIndex: 0})
306 .call(route.bind(null, 3)) 333 .call(route.bind(null, 3))
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 }); 470 });
444 471
445 TEST_F('BackgroundTest', 'ActiveOrInactive', function() { 472 TEST_F('BackgroundTest', 'ActiveOrInactive', function() {
446 var mockFeedback = this.createMockFeedback(); 473 var mockFeedback = this.createMockFeedback();
447 this.runWithLoadedTree(function() {/*! 474 this.runWithLoadedTree(function() {/*!
448 <a href="a">a</a> 475 <a href="a">a</a>
449 <button>b</button> 476 <button>b</button>
450 <input type="text"></input> 477 <input type="text"></input>
451 */}, 478 */},
452 function(rootNode) { 479 function(rootNode) {
453 var focusButton = function() { rootNode.find({role: 'button'}).focus(); }; 480 var focusButton = function() {
481 rootNode.find({role: RoleType.button}).focus();
482 };
454 var on = function() { cvox.ChromeVox.isActive = true; }; 483 var on = function() { cvox.ChromeVox.isActive = true; };
455 var off = function() { cvox.ChromeVox.isActive = false; }; 484 var off = function() { cvox.ChromeVox.isActive = false; };
456 485
457 function focusThen(toFocus, then) { 486 function focusThen(toFocus, then) {
458 toFocus.addEventListener('focus', function innerFocus(e) { 487 toFocus.addEventListener('focus', function innerFocus(e) {
459 if (e.target != toFocus) 488 if (e.target != toFocus)
460 return; 489 return;
461 rootNode.removeEventListener('focus', innerFocus, true); 490 rootNode.removeEventListener('focus', innerFocus, true);
462 then && then(); 491 then && then();
463 }, true); 492 }, true);
464 toFocus.focus(); 493 toFocus.focus();
465 } 494 }
466 495
467 mockFeedback.call(focusButton) 496 mockFeedback.call(focusButton)
468 .expectSpeech('b').expectSpeech('Button') 497 .expectSpeech('b').expectSpeech('Button')
469 .call(off) 498 .call(off)
470 .call(focusThen.bind(this, rootNode.find({ role: 'link' }), on)) 499 .call(focusThen.bind(this, rootNode.find(
471 .call(focusThen.bind(this, rootNode.find({ role: 'textField' }))) 500 { role: RoleType.link }), on))
501 .call(focusThen.bind(this, rootNode.find(
502 { role: RoleType.textField })))
472 .expectNextSpeechUtteranceIsNot('a') 503 .expectNextSpeechUtteranceIsNot('a')
473 .expectSpeech('Edit text'); 504 .expectSpeech('Edit text');
474 505
475 mockFeedback.replay(); 506 mockFeedback.replay();
476 }); 507 });
477 }); 508 });
478 509
479 TEST_F('BackgroundTest', 'ModeSwitching', function() { 510 TEST_F('BackgroundTest', 'ModeSwitching', function() {
480 this.runWithLoadedTree('<button></button>', function(root) { 511 this.runWithLoadedTree('<button></button>', function(root) {
481 var fakeDesktop = {}; 512 var fakeDesktop = {};
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 global.backgroundObj.refreshMode(fakeSubRoot); 565 global.backgroundObj.refreshMode(fakeSubRoot);
535 assertEquals('next', global.backgroundObj.mode); 566 assertEquals('next', global.backgroundObj.mode);
536 }.bind(this)); 567 }.bind(this));
537 }); 568 });
538 569
539 TEST_F('BackgroundTest', 'FocusIframe', function() { 570 TEST_F('BackgroundTest', 'FocusIframe', function() {
540 this.runWithLoadedTree( function() {/*! 571 this.runWithLoadedTree( function() {/*!
541 <iframe tabindex=0 src="data:text/html,<p>Inside</p>"></iframe> 572 <iframe tabindex=0 src="data:text/html,<p>Inside</p>"></iframe>
542 <button>outside</button> 573 <button>outside</button>
543 */}, function(root) { 574 */}, function(root) {
544 var iframe = root.find({role: 'iframe'}); 575 var iframe = root.find({role: RoleType.iframe});
545 var button = root.find({role: 'button'}); 576 var button = root.find({role: RoleType.button});
546 577
547 assertEquals('iframe', iframe.role); 578 assertEquals('iframe', iframe.role);
548 assertEquals('button', button.role); 579 assertEquals('button', button.role);
549 580
550 var didFocus = false; 581 var didFocus = false;
551 iframe.focus = function() { 582 iframe.focus = function() {
552 didFocus = true; 583 didFocus = true;
553 }; 584 };
554 var b = global.backgroundObj; 585 var b = global.backgroundObj;
555 b.currentRange_ = cursors.Range.fromNode(button); 586 b.currentRange_ = cursors.Range.fromNode(button);
556 b.onGotCommand('previousElement'); 587 b.onGotCommand('previousElement');
557 assertFalse(didFocus); 588 assertFalse(didFocus);
558 }.bind(this)); 589 }.bind(this));
559 }); 590 });
560 591
561 TEST_F('BackgroundTest', 'NoisySlider', function() { 592 TEST_F('BackgroundTest', 'NoisySlider', function() {
562 var mockFeedback = this.createMockFeedback(); 593 var mockFeedback = this.createMockFeedback();
563 this.runWithLoadedTree( function() {/*! 594 this.runWithLoadedTree( function() {/*!
564 <button id="go">go</button> 595 <button id="go">go</button>
565 <div id="slider" tabindex=0 role="slider"></div> 596 <div id="slider" tabindex=0 role="slider"></div>
566 <script> 597 <script>
567 function update() { 598 function update() {
568 var s = document.getElementById('slider'); 599 var s = document.getElementById('slider');
569 s.setAttribute('aria-valuetext', 'noisy'); 600 s.setAttribute('aria-valuetext', 'noisy');
570 setTimeout(update, 500); 601 setTimeout(update, 500);
571 } 602 }
572 update(); 603 update();
573 </script> 604 </script>
574 */}, function(root) { 605 */}, function(root) {
575 var go = root.find({role: 'button'}); 606 var go = root.find({role: RoleType.button});
576 var slider = root.find({role: 'slider'}); 607 var slider = root.find({role: RoleType.slider});
577 var focusButton = go.focus.bind(go); 608 var focusButton = go.focus.bind(go);
578 var focusSlider = slider.focus.bind(slider); 609 var focusSlider = slider.focus.bind(slider);
579 mockFeedback.call(focusButton) 610 mockFeedback.call(focusButton)
580 .expectNextSpeechUtteranceIsNot('noisy') 611 .expectNextSpeechUtteranceIsNot('noisy')
581 .call(focusSlider) 612 .call(focusSlider)
582 .expectSpeech('noisy') 613 .expectSpeech('noisy')
583 .expectSpeech('noisy') 614 .expectSpeech('noisy')
584 .replay(); 615 .replay();
585 }.bind(this)); 616 }.bind(this));
586 }); 617 });
587 618
588 TEST_F('BackgroundTest', 'Checkbox', function() { 619 TEST_F('BackgroundTest', 'Checkbox', function() {
589 var mockFeedback = this.createMockFeedback(); 620 var mockFeedback = this.createMockFeedback();
590 this.runWithLoadedTree(function() {/*! 621 this.runWithLoadedTree(function() {/*!
591 <div id="go" role="checkbox">go</div> 622 <div id="go" role="checkbox">go</div>
592 <script> 623 <script>
593 var go = document.getElementById('go'); 624 var go = document.getElementById('go');
594 var isChecked = true; 625 var isChecked = true;
595 go.addEventListener('click', function(e) { 626 go.addEventListener('click', function(e) {
596 if (isChecked) 627 if (isChecked)
597 go.setAttribute('aria-checked', true); 628 go.setAttribute('aria-checked', true);
598 else 629 else
599 go.removeAttribute('aria-checked'); 630 go.removeAttribute('aria-checked');
600 isChecked = !isChecked; 631 isChecked = !isChecked;
601 }); 632 });
602 </script> 633 </script>
603 */}, function(root) { 634 */}, function(root) {
604 var cbx = root.find({role: 'checkBox'}); 635 var cbx = root.find({role: RoleType.checkBox});
605 var click = cbx.doDefault.bind(cbx); 636 var click = cbx.doDefault.bind(cbx);
606 mockFeedback.call(click) 637 mockFeedback.call(click)
607 .expectSpeech('go') 638 .expectSpeech('go')
608 .expectSpeech('Check box') 639 .expectSpeech('Check box')
609 .expectSpeech('checked') 640 .expectSpeech('checked')
610 .call(click) 641 .call(click)
611 .expectSpeech('go') 642 .expectSpeech('go')
612 .expectSpeech('Check box') 643 .expectSpeech('Check box')
613 .expectSpeech('not checked') 644 .expectSpeech('not checked')
614 .replay(); 645 .replay();
615 }); 646 });
616 }); 647 });
617 648
618 /** Tests navigating into and out of iframes using nextButton */ 649 /** Tests navigating into and out of iframes using nextButton */
619 TEST_F('BackgroundTest', 'ForwardNavigationThroughIframeButtons', function() { 650 TEST_F('BackgroundTest', 'ForwardNavigationThroughIframeButtons', function() {
620 var mockFeedback = this.createMockFeedback(); 651 var mockFeedback = this.createMockFeedback();
621 652
622 var running = false; 653 var running = false;
623 var runTestIfIframeIsLoaded = function(rootNode) { 654 var runTestIfIframeIsLoaded = function(rootNode) {
624 if (running) 655 if (running)
625 return; 656 return;
626 657
627 // Return if the iframe hasn't loaded yet. 658 // Return if the iframe hasn't loaded yet.
628 var iframe = rootNode.find({role: 'iframe'}); 659 var iframe = rootNode.find({role: RoleType.iframe});
629 var childDoc = iframe.firstChild; 660 var childDoc = iframe.firstChild;
630 if (!childDoc || childDoc.children.length == 0) 661 if (!childDoc || childDoc.children.length == 0)
631 return; 662 return;
632 663
633 running = true; 664 running = true;
634 var doCmd = this.doCmd.bind(this); 665 var doCmd = this.doCmd.bind(this);
635 666
636 var beforeButton = rootNode.find({role: RoleType.button, 667 var beforeButton = rootNode.find({role: RoleType.button,
637 name: 'Before'}); 668 name: 'Before'});
638 beforeButton.focus(); 669 beforeButton.focus();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 740
710 TEST_F('BackgroundTest', 'SelectOptionSelected', function() { 741 TEST_F('BackgroundTest', 'SelectOptionSelected', function() {
711 var mockFeedback = this.createMockFeedback(); 742 var mockFeedback = this.createMockFeedback();
712 this.runWithLoadedTree(function() {/*! 743 this.runWithLoadedTree(function() {/*!
713 <select> 744 <select>
714 <option>apple 745 <option>apple
715 <option>banana 746 <option>banana
716 <option>grapefruit 747 <option>grapefruit
717 </select> 748 </select>
718 */}, function(root) { 749 */}, function(root) {
719 var select = root.find({role: 'popUpButton'}); 750 var select = root.find({role: RoleType.popUpButton});
720 var clickSelect = select.doDefault.bind(select); 751 var clickSelect = select.doDefault.bind(select);
721 var lastOption = select.lastChild.lastChild; 752 var lastOption = select.lastChild.lastChild;
722 var selectLastOption = lastOption.doDefault.bind(lastOption); 753 var selectLastOption = lastOption.doDefault.bind(lastOption);
723 754
724 mockFeedback.call(clickSelect) 755 mockFeedback.call(clickSelect)
725 .expectSpeech('apple') 756 .expectSpeech('apple')
726 .expectSpeech('Button') 757 .expectSpeech('Button')
727 .call(selectLastOption) 758 .call(selectLastOption)
728 .expectNextSpeechUtteranceIsNot('apple') 759 .expectNextSpeechUtteranceIsNot('apple')
729 .expectSpeech('grapefruit') 760 .expectSpeech('grapefruit')
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 */}, function(root) { 797 */}, function(root) {
767 var nextEditText = this.doCmd('nextEditText'); 798 var nextEditText = this.doCmd('nextEditText');
768 var previousEditText = this.doCmd('previousEditText'); 799 var previousEditText = this.doCmd('previousEditText');
769 mockFeedback.call(nextEditText) 800 mockFeedback.call(nextEditText)
770 .expectSpeech('Combo box') 801 .expectSpeech('Combo box')
771 .call(previousEditText) 802 .call(previousEditText)
772 .expectSpeech('Edit text') 803 .expectSpeech('Edit text')
773 .replay(); 804 .replay();
774 }); 805 });
775 }); 806 });
807
808 /** Tests that navigation works when the current object disappears. */
809 TEST_F('BackgroundTest', 'DisappearingObject', function() {
810 var mockFeedback = this.createMockFeedback();
811 this.runWithLoadedTree(this.disappearingObjectDoc, function(rootNode) {
812 var deleteButton = rootNode.find({role: RoleType.button,
813 attributes: { name: 'Delete' }});
814 var pressDelete = deleteButton.doDefault.bind(deleteButton);
815 var doCmd = this.doCmd.bind(this);
David Tseng 2016/06/01 20:20:25 You don't need to bind; also, let's export this on
dmazzoni 2016/06/01 22:46:56 Done.
816
817 mockFeedback.expectSpeech('start').expectBraille('start');
818
819 mockFeedback.call(doCmd('nextObject'))
820 .expectSpeech('Before1')
821 .call(doCmd('nextObject'))
822 .expectSpeech('Before2')
823 .call(doCmd('nextObject'))
824 .expectSpeech('Before3')
825 .call(doCmd('nextObject'))
826 .expectSpeech('Disappearing')
827 .call(pressDelete)
828 .expectSpeech('Deleted')
829 .call(doCmd('nextObject'))
830 .expectSpeech('After1')
831 .call(doCmd('nextObject'))
832 .expectSpeech('After2')
833 .call(doCmd('previousObject'))
834 .expectSpeech('After1')
835 .call(doCmd('previousObject'))
836 .expectSpeech('Before3');
837
838 mockFeedback.replay();
839 });
840 });
841
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698