1 // Copyright 2015 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 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']);
10 * @extends {ChromeVoxUnitTestBase}
12 function CvoxPanStrategyUnitTest() {}
14 CvoxPanStrategyUnitTest.prototype = {
15 __proto__: ChromeVoxUnitTestBase.prototype,
24 * @param {string} content String representing the content with spaces
25 * representing blank cells and any other character representing
26 * arbitrary non-blank cells.
28 function createArrayBuffer(content) {
29 var result = new ArrayBuffer(content.length);
30 var view = new Uint8Array(result);
31 for (var i = 0; i < content.length; ++i) {
32 view[i] = (content[i] != ' ' ? 1 : 0);
37 TEST_F('CvoxPanStrategyUnitTest', 'FixedPanning', function() {
38 var panner = new cvox.FixedPanStrategy();
40 panner.setDisplaySize(0);
41 panner.setContent(createArrayBuffer(''), 0);
42 assertEqualsJSON({start: 0, end: 0}, panner.viewPort);
43 assertFalse(panner.previous());
44 assertFalse(panner.next());
46 // 25 cells with a blank cell in the first 10 characters.
47 var content = createArrayBuffer('01234567 9012345678901234');
48 panner.setContent(content, 0);
49 assertEqualsJSON({start: 0, end: 0}, panner.viewPort);
50 assertFalse(panner.next());
51 assertFalse(panner.previous());
53 panner.setDisplaySize(10);
54 assertEqualsJSON({start: 0, end: 10}, panner.viewPort);
55 assertTrue(panner.next());
56 assertEqualsJSON({start: 10, end: 20}, panner.viewPort);
57 assertTrue(panner.next());
58 assertEqualsJSON({start: 20, end: 25}, panner.viewPort);
59 assertFalse(panner.next());
60 assertEqualsJSON({start: 20, end: 25}, panner.viewPort);
61 assertTrue(panner.previous());
62 assertEqualsJSON({start: 10, end: 20}, panner.viewPort);
63 assertTrue(panner.previous());
64 assertEqualsJSON({start: 0, end: 10}, panner.viewPort);
66 panner.setContent(content, 19);
67 assertEqualsJSON({start: 10, end: 20}, panner.viewPort);
69 panner.setContent(content, 20);
70 assertEqualsJSON({start: 20, end: 25}, panner.viewPort);
72 panner.setDisplaySize(8);
73 assertEqualsJSON({start: 16, end: 24}, panner.viewPort);
75 panner.viewPort_ = {start: 2, end: 10};
76 assertTrue(panner.previous());
77 assertEqualsJSON({start: 0, end: 8}, panner.viewPort);
80 TEST_F('CvoxPanStrategyUnitTest', 'WrappedPanning', function() {
81 var panner = new cvox.WrappingPanStrategy();
83 // 30 cells with blank cells at positions 8, 22 and 26.
84 var content = createArrayBuffer('01234567 9012345678901 345 789');
85 panner.setContent(content, 0);
86 assertEqualsJSON({start: 0, end: 0}, panner.viewPort);
87 assertFalse(panner.next());
88 assertFalse(panner.previous());
90 panner.setDisplaySize(10);
91 assertEqualsJSON({start: 0, end: 9}, panner.viewPort);
92 assertTrue(panner.next());
93 assertEqualsJSON({start: 9, end: 19}, panner.viewPort);
94 assertTrue(panner.next());
95 assertEqualsJSON({start: 19, end: 27}, panner.viewPort);
96 assertTrue(panner.next());
97 assertEqualsJSON({start: 27, end: 30}, panner.viewPort);
98 assertFalse(panner.next());
99 assertEqualsJSON({start: 27, end: 30}, panner.viewPort);
100 assertTrue(panner.previous());
101 assertEqualsJSON({start: 23, end: 27}, panner.viewPort);
102 assertTrue(panner.previous());
103 assertEqualsJSON({start: 13, end: 23}, panner.viewPort);
104 assertTrue(panner.previous());
105 assertEqualsJSON({start: 9, end: 13}, panner.viewPort);
106 assertTrue(panner.previous());
107 assertEqualsJSON({start: 0, end: 9}, panner.viewPort);
109 panner.setContent(content, 21);
110 assertEqualsJSON({start: 19, end: 27}, panner.viewPort);
112 panner.setContent(content, 30);
113 assertEqualsJSON({start: 27, end: 30}, panner.viewPort);
115 panner.setDisplaySize(8);
116 assertEqualsJSON({start: 23, end: 30}, panner.viewPort);
118 panner.viewPort_ = {start: 2, end: 10};
119 assertTrue(panner.previous());
120 assertEqualsJSON({start: 0, end: 8}, panner.viewPort);