blob: 2da6b522982d274213b9b48a5bcf49992902451b [file] [log] [blame]
// 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 CvoxWordWalkerUnitTest() {}
CvoxWordWalkerUnitTest.prototype = {
__proto__: CvoxWalkerUnitTestBase.prototype,
/** @override */
closureModuleDeps: CvoxWalkerUnitTestBase.prototype.closureModuleDeps.concat(
'cvox.WordWalker'),
/** @override */
newWalker: function() {
return new cvox.WordWalker();
},
/**
* Set up for the simple tests so we don't have to repeat.
* @private
*/
setUpSimpleHtml_: function() {
this.loadDoc(function() {/*!
<div id="a"><p id="b">The </p><p id="c">quick brown.</p></div>
*/});
}
};
CvoxWalkerUnitTestBase.addCommonTests('CvoxWordWalkerUnitTest');
TEST_F('CvoxWordWalkerUnitTest', 'testSimpleForwardSync', function() {
this.setUpSimpleHtml_();
// invalid selection
var sel = cvox.CursorSelection.fromNode(document.getElementById('a'));
var ret = this.go(sel, 'sync', {
selText: 'The ',
selParentNodeId: 'b',
selStartIndex: 0,
selEndIndex: 3,
selReversed: false
});
// valid selection
var ret2 = this.walker.sync(ret);
assertTrue(ret2.equals(ret));
});
TEST_F('CvoxWordWalkerUnitTest', 'testSimpleReversedSync', function() {
this.setUpSimpleHtml_();
// invalid selection
var sel = cvox.CursorSelection.fromNode(document.getElementById('a'));
sel.setReversed(true);
var ret = this.go(sel, 'sync', {
selText: 'quick brown.',
selParentNodeId: 'c',
selStartIndex: 0,
selEndIndex: 5,
selReversed: true
});
// valid selection
var ret2 = this.walker.sync(ret);
assertTrue(ret2.equals(ret));
});
TEST_F('CvoxWordWalkerUnitTest', 'testSimpleForwardNext', function() {
this.setUpSimpleHtml_();
var sel = cvox.CursorSelection.fromNode(document.getElementById('a'));
sel = this.walker.sync(sel);
var ret = this.go(sel, 'next', {
selText: 'quick brown.',
selParentNodeId: 'c',
selStartIndex: 0,
selEndIndex: 5,
selReversed: false
});
});
TEST_F('CvoxWordWalkerUnitTest', 'testSimpleReversedNext', function() {
this.setUpSimpleHtml_();
var sel = cvox.CursorSelection.fromNode(document.getElementById('a'));
sel = this.walker.sync(sel.setReversed(true));
var ret = this.go(sel, 'next', {
selText: 'The ',
selParentNodeId: 'b',
selStartIndex: 0,
selEndIndex: 3,
selReversed: true
});
});