summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/chromeos/chromevox/walkers/structural_line_walker_test.unitjs
blob: 7dc9b159605278f7ab90caaba5e0c6d588cb13bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// 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(['../testing/chromevox_unittest_base.js']);

/**
 * Test fixture.
 * @constructor
 * @extends {ChromeVoxUnitTestBase}
 */
function CvoxStructuralLineWalkerUnitTest() {}

CvoxStructuralLineWalkerUnitTest.prototype = {
  __proto__: ChromeVoxUnitTestBase.prototype,

  /** @override */
  closureModuleDeps: [
    'cvox.StructuralLineWalker',
    'cvox.TestMsgs',
  ],

  /** @override */
  setUp: function() {
    this.loadDoc(function() {/*!
      <a id='1' href='google.com'>Click Here</a>
      <pre id='2'>This text will break
        immediately here!
        <a href='google.com'>And here!</a>
      </p>
      */});
  
    cvox.ChromeVox.msgs = new cvox.TestMsgs();
  
    this.walker_ = new cvox.StructuralLineWalker();
  },
};

TEST_F('CvoxStructuralLineWalkerUnitTest', 'BrailleLine', function() {
  var aLink = $('1');
  var aLinkSel1 = this.walker_.sync(cvox.CursorSelection.fromNode(aLink));
  assertEquals('Click Here lnk',
               this.walker_.getBraille(aLinkSel1, aLinkSel1).text.toString());

  var aPSel1 = this.walker_.next(aLinkSel1);
  assertEquals('This text will break',
               this.walker_.getBraille(aLinkSel1, aPSel1).text.toString());

  var aPSel2 = this.walker_.next(aPSel1);
  assertEquals('immediately here!',
               this.walker_.getBraille(aPSel1, aPSel2).text.toString());

  aLinkSel2 = this.walker_.next(aPSel2);
  assertEquals('And here! lnk',
               this.walker_.getBraille(aPSel2, aLinkSel2).text.toString());
});


/** Tests sync'ing to a line in the middle of a paragraph. */
TEST_F('CvoxStructuralLineWalkerUnitTest', 'Sync', function() {
  var p1Sel = this.walker_.sync(
      cvox.CursorSelection.fromNode($('2')));

  // The second structural line of the paragraph.
  var p2Sel = this.walker_.next(p1Sel);
  assertEquals(29, p2Sel.start.index);
  assertEquals(46, p2Sel.end.index);

  // Sync should never mutate a previously synced selection.
  assertTrue(p2Sel.equals(this.walker_.sync(p2Sel)));
});

/** Tests syncing into an element treated as a leaf by TraverseUtil. */
TEST_F('CvoxStructuralLineWalkerUnitTest', 'SyncTraverseUtil', function() {
  this.loadDoc(function() {/*!
    <select id='leaf'>
      <option>apple
      <option>orange
    </select>
  */});
  var leaf = $('leaf');
  assertEquals('leaf',
      this.walker_.sync(cvox.CursorSelection.fromNode(leaf)).start.node.id);
});


/** Tests specialized name calc with listitems with prefixes. */
TEST_F('CvoxStructuralLineWalkerUnitTest', 'ListitemPrefixes', function() {
  this.loadDoc(function() {/*!
    <ol>
      <li id='li_orange'>orange
      <li id='li_apple'>apple
      <li id='li_long'>hi broken<br>line here
    </ol>
  */});
  var li1 = $('li_orange');
  var li2 = $('li_apple');
  var li3 = $('li_long');
  var li1Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li1));
  var li2Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li2));
  var li3Sel = this.walker_.sync(cvox.CursorSelection.fromNode(li3));
  var li3SelNext = this.walker_.next(li3Sel);

  assertEquals('1. orange',
               this.walker_.getDescription(li1Sel, li1Sel)[0].text);
  assertEquals('2. apple', this.walker_.getDescription(li2Sel, li2Sel)[0].text);
  assertEquals(
          '3. hi broken',
      this.walker_.getDescription(li3Sel, li3Sel)[0].text);
  assertEquals('line here', this.walker_.getDescription(
      li3SelNext, li3SelNext)[0].text.toString());

  assertEquals('1. orange',
               this.walker_.getBraille(li1Sel, li1Sel).text.toString());
  assertEquals('2. apple',
               this.walker_.getBraille(li2Sel, li2Sel).text.toString());
  assertEquals(
          '3. hi broken',
      this.walker_.getBraille(li3Sel, li3Sel).text.toString());
  assertEquals('line here',
               this.walker_.getBraille(li3SelNext, li3SelNext).text.toString());
});