| // Copyright 2014 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // Include test fixture. |
| GEN_INCLUDE(['walker_unittest_base.js']); |
| |
| /** |
| * Test fixture. |
| * @constructor |
| * @extends {CvoxWalkerTestBase} |
| */ |
| function CvoxSentenceWalkerUnitTest() {} |
| |
| CvoxSentenceWalkerUnitTest.prototype = { |
| __proto__: CvoxWalkerUnitTestBase.prototype, |
| |
| /** @override */ |
| closureModuleDeps: CvoxWalkerUnitTestBase.prototype.closureModuleDeps.concat( |
| 'cvox.SentenceWalker'), |
| |
| /** @override */ |
| newWalker: function() { |
| return new cvox.SentenceWalker(); |
| }, |
| |
| /** |
| * Set up simple html. |
| * @private |
| */ |
| setUpSimpleHtml_: function() { |
| this.loadDoc(function() {/*! |
| <div id="a"><p id="b">The quick</p><p id="c">brown. fox.</p></div> |
| */}); |
| } |
| }; |
| |
| CvoxWalkerUnitTestBase.addCommonTests('CvoxSentenceWalkerUnitTest'); |
| |
| TEST_F('CvoxSentenceWalkerUnitTest', 'testSimpleForwardSync', function() { |
| this.setUpSimpleHtml_(); |
| |
| var sel = cvox.CursorSelection.fromNode($('a')); |
| var ret = this.go(sel, 'sync', { |
| selText: 'The quick', |
| selParentNodeId: 'b', |
| selStartIndex: 0, |
| selEndIndex: 9, |
| selReversed: false |
| }); |
| |
| // valid selection |
| var ret2 = this.walker.sync(ret); |
| assertTrue(ret2.equals(ret)); |
| }); |
| |
| TEST_F('CvoxSentenceWalkerUnitTest', 'testSimpleReversedSync', function() { |
| this.setUpSimpleHtml_(); |
| |
| var sel = cvox.CursorSelection.fromNode($('a')); |
| sel.setReversed(true); |
| var ret = this.go(sel, 'sync', { |
| selText: 'brown. fox.', |
| selParentNodeId: 'c', |
| selStartIndex: 0, |
| selEndIndex: 6, |
| selReversed: true |
| }); |
| |
| // valid selection |
| var ret2 = this.walker.sync(ret); |
| assertTrue(ret2.equals(ret)); |
| }); |
| |
| TEST_F('CvoxSentenceWalkerUnitTest', 'testSimpleForwardNext', function() { |
| this.setUpSimpleHtml_(); |
| |
| var sel = cvox.CursorSelection.fromNode($('a')); |
| sel = this.walker.sync(sel); |
| var ret = this.go(sel, 'next', { |
| selText: 'brown. fox.', |
| selParentNodeId: 'c', |
| selStartIndex: 0, |
| selEndIndex: 6, |
| selReversed: false |
| }); |
| }); |
| |
| TEST_F('CvoxSentenceWalkerUnitTest', 'testSimpleReversedNext', function() { |
| this.setUpSimpleHtml_(); |
| |
| var sel = cvox.CursorSelection.fromNode($('a')); |
| sel = this.walker.sync(sel.setReversed(true)); |
| var ret = this.go(sel, 'next', { |
| selText: 'The quick', |
| selParentNodeId: 'b', |
| selStartIndex: 0, |
| selEndIndex: 9, |
| selReversed: true |
| }); |
| ret = this.go(ret, 'next', null); |
| }); |
| |
| TEST_F('CvoxSentenceWalkerUnitTest', 'testControlElements', function() { |
| this.loadDoc(function() {/*! |
| <div id="a"><p>Before</p><input type="text"/><p>After</p></div> |
| */}); |
| var node = $('a'); |
| var sel = this.walker.sync(cvox.CursorSelection.fromNode(node)); |
| var ret = this.go(sel, 'next', {descAnnotation: 'Edit text'}); |
| }); |