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

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: Created 4 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
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>"></iframe> 74 <iframe srcdoc="<button>Inside</button>"></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 510
480 TEST_F('BackgroundTest', 'ModeSwitching', function() { 511 TEST_F('BackgroundTest', 'ModeSwitching', function() {
481 this.runWithLoadedTree('<button></button>', function(root) { 512 this.runWithLoadedTree('<button></button>', function(root) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 global.backgroundObj.refreshMode(fakeSubRoot); 566 global.backgroundObj.refreshMode(fakeSubRoot);
536 assertEquals('next', global.backgroundObj.mode); 567 assertEquals('next', global.backgroundObj.mode);
537 }.bind(this)); 568 }.bind(this));
538 }); 569 });
539 570
540 TEST_F('BackgroundTest', 'FocusIframe', function() { 571 TEST_F('BackgroundTest', 'FocusIframe', function() {
541 this.runWithLoadedTree( function() {/*! 572 this.runWithLoadedTree( function() {/*!
542 <iframe tabindex=0 src="data:text/html,<p>Inside</p>"></iframe> 573 <iframe tabindex=0 src="data:text/html,<p>Inside</p>"></iframe>
543 <button>outside</button> 574 <button>outside</button>
544 */}, function(root) { 575 */}, function(root) {
545 var iframe = root.find({role: 'iframe'}); 576 var iframe = root.find({role: RoleType.iframe});
546 var button = root.find({role: 'button'}); 577 var button = root.find({role: RoleType.button});
547 578
548 assertEquals('iframe', iframe.role); 579 assertEquals('iframe', iframe.role);
549 assertEquals('button', button.role); 580 assertEquals('button', button.role);
550 581
551 var didFocus = false; 582 var didFocus = false;
552 iframe.focus = function() { 583 iframe.focus = function() {
553 didFocus = true; 584 didFocus = true;
554 }; 585 };
555 var b = global.backgroundObj; 586 var b = global.backgroundObj;
556 b.currentRange_ = cursors.Range.fromNode(button); 587 b.currentRange_ = cursors.Range.fromNode(button);
557 b.onGotCommand('previousElement'); 588 b.onGotCommand('previousElement');
558 assertFalse(didFocus); 589 assertFalse(didFocus);
559 }.bind(this)); 590 }.bind(this));
560 }); 591 });
561 592
562 TEST_F('BackgroundTest', 'NoisySlider', function() { 593 TEST_F('BackgroundTest', 'NoisySlider', function() {
563 var mockFeedback = this.createMockFeedback(); 594 var mockFeedback = this.createMockFeedback();
564 this.runWithLoadedTree( function() {/*! 595 this.runWithLoadedTree( function() {/*!
565 <button id="go">go</button> 596 <button id="go">go</button>
566 <div id="slider" tabindex=0 role="slider"></div> 597 <div id="slider" tabindex=0 role="slider"></div>
567 <script> 598 <script>
568 function update() { 599 function update() {
569 var s = document.getElementById('slider'); 600 var s = document.getElementById('slider');
570 s.setAttribute('aria-valuetext', 'noisy'); 601 s.setAttribute('aria-valuetext', 'noisy');
571 setTimeout(update, 500); 602 setTimeout(update, 500);
572 } 603 }
573 update(); 604 update();
574 </script> 605 </script>
575 */}, function(root) { 606 */}, function(root) {
576 var go = root.find({role: 'button'}); 607 var go = root.find({role: RoleType.button});
577 var slider = root.find({role: 'slider'}); 608 var slider = root.find({role: RoleType.slider});
578 var focusButton = go.focus.bind(go); 609 var focusButton = go.focus.bind(go);
579 var focusSlider = slider.focus.bind(slider); 610 var focusSlider = slider.focus.bind(slider);
580 mockFeedback.call(focusButton) 611 mockFeedback.call(focusButton)
581 .expectNextSpeechUtteranceIsNot('noisy') 612 .expectNextSpeechUtteranceIsNot('noisy')
582 .call(focusSlider) 613 .call(focusSlider)
583 .expectSpeech('noisy') 614 .expectSpeech('noisy')
584 .expectSpeech('noisy') 615 .expectSpeech('noisy')
585 .replay(); 616 .replay();
586 }.bind(this)); 617 }.bind(this));
587 }); 618 });
588 619
589 TEST_F('BackgroundTest', 'Checkbox', function() { 620 TEST_F('BackgroundTest', 'Checkbox', function() {
590 var mockFeedback = this.createMockFeedback(); 621 var mockFeedback = this.createMockFeedback();
591 this.runWithLoadedTree(function() {/*! 622 this.runWithLoadedTree(function() {/*!
592 <div id="go" role="checkbox">go</div> 623 <div id="go" role="checkbox">go</div>
593 <script> 624 <script>
594 var go = document.getElementById('go'); 625 var go = document.getElementById('go');
595 var isChecked = true; 626 var isChecked = true;
596 go.addEventListener('click', function(e) { 627 go.addEventListener('click', function(e) {
597 if (isChecked) 628 if (isChecked)
598 go.setAttribute('aria-checked', true); 629 go.setAttribute('aria-checked', true);
599 else 630 else
600 go.removeAttribute('aria-checked'); 631 go.removeAttribute('aria-checked');
601 isChecked = !isChecked; 632 isChecked = !isChecked;
602 }); 633 });
603 </script> 634 </script>
604 */}, function(root) { 635 */}, function(root) {
605 var cbx = root.find({role: 'checkBox'}); 636 var cbx = root.find({role: RoleType.checkBox});
606 var click = cbx.doDefault.bind(cbx); 637 var click = cbx.doDefault.bind(cbx);
607 mockFeedback.call(click) 638 mockFeedback.call(click)
608 .expectSpeech('go') 639 .expectSpeech('go')
609 .expectSpeech('Check box') 640 .expectSpeech('Check box')
610 .expectSpeech('checked') 641 .expectSpeech('checked')
611 .call(click) 642 .call(click)
612 .expectSpeech('go') 643 .expectSpeech('go')
613 .expectSpeech('Check box') 644 .expectSpeech('Check box')
614 .expectSpeech('not checked') 645 .expectSpeech('not checked')
615 .replay(); 646 .replay();
616 }); 647 });
617 }); 648 });
618 649
619 /** Tests navigating into and out of iframes.. */ 650 /** Tests navigating into and out of iframes.. */
620 TEST_F('BackgroundTest', 'DISABLED_ForwardNavigationThroughIframes', function() { 651 TEST_F('BackgroundTest', 'DISABLED_ForwardNavigationThroughIframes', function() {
621 var mockFeedback = this.createMockFeedback(); 652 var mockFeedback = this.createMockFeedback();
622 653
623 var runTestIfIframeIsLoaded = function(rootNode) { 654 var runTestIfIframeIsLoaded = function(rootNode) {
624 // Return if the iframe hasn't loaded yet. 655 // Return if the iframe hasn't loaded yet.
625 var iframe = rootNode.find({role: 'iframe'}); 656 var iframe = rootNode.find({role: RoleType.iframe});
626 var childDoc = iframe.firstChild; 657 var childDoc = iframe.firstChild;
627 if (childDoc && childDoc.children.length == 0) { 658 if (childDoc && childDoc.children.length == 0) {
628 return; 659 return;
629 } 660 }
630 661
631 var doCmd = this.doCmd.bind(this); 662 var doCmd = this.doCmd.bind(this);
632 663
633 mockFeedback.expectSpeech('start').expectBraille('start'); 664 mockFeedback.expectSpeech('start').expectBraille('start');
634 665
635 mockFeedback.call(doCmd('nextButton')) 666 mockFeedback.call(doCmd('nextButton'))
(...skipping 19 matching lines...) Expand all
655 686
656 TEST_F('BackgroundTest', 'SelectOptionSelected', function() { 687 TEST_F('BackgroundTest', 'SelectOptionSelected', function() {
657 var mockFeedback = this.createMockFeedback(); 688 var mockFeedback = this.createMockFeedback();
658 this.runWithLoadedTree(function() {/*! 689 this.runWithLoadedTree(function() {/*!
659 <select> 690 <select>
660 <option>apple 691 <option>apple
661 <option>banana 692 <option>banana
662 <option>grapefruit 693 <option>grapefruit
663 </select> 694 </select>
664 */}, function(root) { 695 */}, function(root) {
665 var select = root.find({role: 'popUpButton'}); 696 var select = root.find({role: RoleType.popUpButton});
666 var clickSelect = select.doDefault.bind(select); 697 var clickSelect = select.doDefault.bind(select);
667 var lastOption = select.lastChild.lastChild; 698 var lastOption = select.lastChild.lastChild;
668 var selectLastOption = lastOption.doDefault.bind(lastOption); 699 var selectLastOption = lastOption.doDefault.bind(lastOption);
669 700
670 mockFeedback.call(clickSelect) 701 mockFeedback.call(clickSelect)
671 .expectSpeech('apple') 702 .expectSpeech('apple')
672 .expectSpeech('Button') 703 .expectSpeech('Button')
673 .call(selectLastOption) 704 .call(selectLastOption)
674 .expectNextSpeechUtteranceIsNot('apple') 705 .expectNextSpeechUtteranceIsNot('apple')
675 .expectSpeech('grapefruit') 706 .expectSpeech('grapefruit')
676 .replay(); 707 .replay();
677 }); 708 });
678 }); 709 });
710
711 /** Tests that navigation works when the current object disappears. */
712 TEST_F('BackgroundTest', 'DisappearingObject', function() {
713 var mockFeedback = this.createMockFeedback();
714 this.runWithLoadedTree(this.disappearingObjectDoc, function(rootNode) {
715 var deleteButton = rootNode.find({role: RoleType.button,
716 attributes: { name: 'Delete' }});
717 var pressDelete = deleteButton.doDefault.bind(deleteButton);
718 var doCmd = this.doCmd.bind(this);
719
720 mockFeedback.expectSpeech('start').expectBraille('start');
721
722 mockFeedback.call(doCmd('nextObject'))
723 .expectSpeech('Before1')
724 .call(doCmd('nextObject'))
725 .expectSpeech('Before2')
726 .call(doCmd('nextObject'))
727 .expectSpeech('Before3')
728 .call(doCmd('nextObject'))
729 .expectSpeech('Disappearing')
730 .call(pressDelete)
731 .expectSpeech('Deleted')
732 .call(doCmd('nextObject'))
733 .expectSpeech('After1')
734 .call(doCmd('nextObject'))
735 .expectSpeech('After2')
736 .call(doCmd('previousObject'))
737 .expectSpeech('After1')
738 .call(doCmd('previousObject'))
739 .expectSpeech('Article')
740 .call(doCmd('previousObject'))
741 .expectSpeech('Before3');
742
743 mockFeedback.replay();
744 });
745 });
746
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698