Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / chromevox / walkers / character_walker_test.unitjs
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
3 // found in the LICENSE file.
4
5 // Include test fixture.
6 GEN_INCLUDE(['walker_unittest_base.js']);
7
8 /**
9  * Test fixture.
10  * @constructor
11  * @extends {CvoxWalkerTestBase}
12  */
13 function CvoxCharacterWalkerUnitTest() {}
14
15 CvoxCharacterWalkerUnitTest.prototype = {
16   __proto__: CvoxWalkerUnitTestBase.prototype,
17
18   /** @override */
19   closureModuleDeps: CvoxWalkerUnitTestBase.prototype.closureModuleDeps.concat(
20       'cvox.CharacterWalker'),
21
22   /** @override */
23   newWalker: function() {
24     return new cvox.CharacterWalker();
25   },
26
27   /**
28    * Set up for simple tests so we don't have to repeat.
29    * @private
30    */
31   setUpSimpleHtml_: function() {
32     this.loadDoc(function() {/*!
33       <div id="a"><p id="b">Th</p><p id="c">e quick</p></div>
34      */});
35   }
36 };
37
38 CvoxWalkerUnitTestBase.addCommonTests('CvoxCharacterWalkerUnitTest');
39
40 TEST_F('CvoxCharacterWalkerUnitTest', 'SimpleForwardSync', function() {
41   this.setUpSimpleHtml_();
42
43   // invalid selection
44   var sel = cvox.CursorSelection.fromNode($('a'));
45   var ret = this.go(sel, 'sync', {
46     selText: 'Th',
47     selParentNodeId: 'b',
48     selStartIndex: 0,
49     selEndIndex: 1,
50     selReversed: false
51   });
52
53   // valid selection
54   var ret2 = this.walker.sync(ret);
55   assertTrue(ret2.equals(ret));
56 });
57
58 TEST_F('CvoxCharacterWalkerUnitTest', 'testSimpleReversedSync', function() {
59   this.setUpSimpleHtml_();
60
61   // invalid selection
62   var sel = cvox.CursorSelection.fromNode($('a'));
63   sel.setReversed(true);
64   var ret = this.go(sel, 'sync', {
65     selText: 'e quick',
66     selParentNodeId: 'c',
67     selStartIndex: 0,
68     selEndIndex: 1,
69     selReversed: true
70   });
71
72   // valid selection
73   var ret2 = this.walker.sync(ret);
74   assertTrue(ret2.equals(ret));
75 });
76
77 TEST_F('CvoxCharacterWalkerUnitTest', 'testSimpleForwardNext', function() {
78   this.setUpSimpleHtml_();
79
80   var sel = cvox.CursorSelection.fromNode($('a'));
81   sel = this.walker.sync(sel);
82   var ret = this.go(sel, 'next', {
83     selText: 'Th',
84     selParentNodeId: 'b',
85     selStartIndex: 1,
86     selEndIndex: 2,
87     selReversed: false
88   });
89 });
90
91 TEST_F('CvoxCharacterWalkerUnitTest', 'testSimpleReversedNext', function() {
92   this.setUpSimpleHtml_();
93
94   var sel = cvox.CursorSelection.fromNode($('a'));
95   sel = this.walker.sync(sel.setReversed(true));
96   var ret = this.go(sel, 'next', {
97     selText: 'Th',
98     selParentNodeId: 'b',
99     selStartIndex: 1,
100     selEndIndex: 2,
101     selReversed: true
102   });
103 });
104
105 /**
106  * Tests for how spaces should be navigated character by character.
107  */
108 TEST_F('CvoxCharacterWalkerUnitTest', 'testSpaces', function() {
109   this.loadDoc(function() {/*!
110     <div id="foo">a <i>b</i> c<input type="text" value="asdf"/></div>
111   */});
112   var node = $('foo');
113   var sel = cvox.CursorSelection.fromNode(node);
114   var ret = this.go(sel, 'next', {descText: 'a'});
115   ret = this.go(ret, 'next', {descText: ' '});
116   ret = this.go(ret, 'next', {descText: 'b'});
117 });