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.
5 // Include test fixture.
6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']);
11 * @extends {ChromeVoxUnitTestBase}
13 function CvoxCursorSelectionUnitTest() {}
15 CvoxCursorSelectionUnitTest.prototype = {
16 __proto__: ChromeVoxUnitTestBase.prototype,
20 'cvox.CursorSelection'
24 TEST_F('CvoxCursorSelectionUnitTest', 'Reverse', function() {
25 this.loadDoc(function() {/*!
31 var a = new cvox.Cursor($('a'), 0, '');
32 var b = new cvox.Cursor($('b'), 0, '');
34 var aa = new cvox.CursorSelection(a, a);
35 assertEquals(false, aa.isReversed());
37 assertEquals(true, aa.isReversed());
39 var ab = new cvox.CursorSelection(a, b);
40 assertEquals(false, ab.isReversed());
42 assertEquals(true, ab.isReversed());
43 assertEquals(true, ab.start.equals(b));
44 assertEquals(true, ab.end.equals(a));
45 ab.setReversed(false);
46 assertEquals(false, ab.isReversed());
47 assertEquals(true, ab.start.equals(a));
48 assertEquals(true, ab.end.equals(b));
50 ab = new cvox.CursorSelection(b, a);
51 assertEquals(false, ab.isReversed());
52 assertEquals(true, ab.start.equals(a));
53 assertEquals(true, ab.end.equals(b));
55 var ba = new cvox.CursorSelection(b, a, true);
56 assertEquals(true, ba.isReversed());
57 assertEquals(true, ba.start.equals(b));
58 assertEquals(true, ba.end.equals(a));
60 ba = new cvox.CursorSelection(a, b, true);
61 assertEquals(true, ba.isReversed());
62 assertEquals(true, ba.start.equals(b));
63 assertEquals(true, ba.end.equals(a));
67 /** Tests correctness of collapsing selections. */
68 TEST_F('CvoxCursorSelectionUnitTest', 'Collapse', function() {
69 this.loadDoc(function() {/*!
70 <p id='1'>This is a test.</p>
72 var text = $('1').firstChild;
73 var a = new cvox.Cursor(text, 0, 'This is a test.');
74 var b = new cvox.Cursor(text, 13, 'This is a test.');
75 var c = new cvox.Cursor(text, 5, 'This is a test.');
76 var d = new cvox.Cursor(text, 8, 'This is a test.');
78 var aa = new cvox.CursorSelection(a, a).collapse();
79 assertEquals(0, aa.start.index);
80 assertEquals(0, aa.end.index);
82 var ab = new cvox.CursorSelection(a, b).collapse();
83 assertEquals(0, ab.start.index);
84 assertEquals(1, ab.end.index);
86 var ba = new cvox.CursorSelection(b, a, true).collapse();
87 assertEquals(12, ba.absStart().index);
88 assertEquals(13, ba.absEnd().index);
90 var cd = new cvox.CursorSelection(c, d).collapse();
91 assertEquals(5, cd.start.index);
92 assertEquals(6, cd.end.index);
94 var dc = new cvox.CursorSelection(d, c, true).collapse();
95 assertEquals(7, dc.absStart().index);
96 assertEquals(8, dc.absEnd().index);