Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / chromevox / walkers / math_shifter_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(['../testing/chromevox_unittest_base.js']);
7
8 /**
9  * Test fixture.
10  * @constructor
11  * @extends {ChromeVoxUnitTestBase}
12  */
13 function CvoxMathShifterUnitTest() {}
14
15 CvoxMathShifterUnitTest.prototype = {
16   __proto__: ChromeVoxUnitTestBase.prototype,
17
18   closureModuleDeps: [
19     'cvox.ChromeVoxTester',
20     'cvox.CursorSelection',
21     'cvox.DescriptionUtil',
22     'cvox.MathmlStoreRules'
23   ],
24
25   /** @override */
26   setUp: function() {
27     cvox.ChromeVoxTester.setUp(document);
28   },
29
30   /** @override */
31   tearDown: function() {
32     cvox.ChromeVoxTester.tearDown(document);
33   },
34
35   /**
36    * Simulates speaking the node (only text, no annotations!).
37    * @param {Node} node The node to be described.
38    * @return {!string} The resulting string.
39    */
40   getNodeDescription: function(node) {
41     if (node) {
42       var descs = cvox.DescriptionUtil.getMathDescription(node);
43       var descs_str = descs.map(function(desc) {return desc.text;});
44       return descs_str.filter(function(str) {return str;}).join(' ');
45     }
46     return '';
47   }
48 };
49
50 TEST_F('CvoxMathShifterUnitTest', 'MathmlMtext', function() {
51   this.loadHtml(
52       '<div><math xmlns="http://www.w3.org/1998/Math/MathML" id="m0">' +
53       '<mtext>Quod erat demonstrandum</mtext>' +
54       '</math></div>'
55       );
56   var node = $('m0');
57   assertEquals('Quod erat demonstrandum', this.getNodeDescription(node));
58 });
59
60
61 /** Test MathML individual.
62  * @export
63  */
64 TEST_F('CvoxMathShifterUnitTest', 'MathmlMi', function() {
65   this.loadHtml(
66       '<div><math xmlns="http://www.w3.org/1998/Math/MathML" id="m1">' +
67       '<mi>x</mi>' +
68       '</math></div>');
69   var node = $('m1');
70   assertEquals('x', this.getNodeDescription(node));
71 });
72
73
74 /** Test MathML numeral.
75  * @export
76  */
77 TEST_F('CvoxMathShifterUnitTest', 'MathmlMn', function() {
78   this.loadHtml(
79       '<div><math xmlns="http://www.w3.org/1998/Math/MathML" id="m2">' +
80       '<mn>123</mn>' +
81       '</math></div>');
82   var node = $('m2');
83   assertEquals('123', this.getNodeDescription(node));
84 });
85
86
87 /** Test MathML operator
88  * @export
89  */
90 TEST_F('CvoxMathShifterUnitTest', 'MathmlMo', function() {
91   this.loadHtml(
92       '<div><math xmlns="http://www.w3.org/1998/Math/MathML" id="m3">' +
93       '<mo>+</mo>' +
94       '</math></div>');
95   var node = $('m3');
96   assertEquals('+', this.getNodeDescription(node));
97 });
98
99
100 /** Test MathML superscript.
101  * @export
102  */
103 TEST_F('CvoxMathShifterUnitTest', 'MathmlMsup', function() {
104   this.loadHtml(
105       '<div><math xmlns="http://www.w3.org/1998/Math/MathML" id="m4">' +
106       '<msup><mi>x</mi><mn>4</mn></msup>' +
107       '</math></div>');
108   var node = $('m4');
109   assertEquals('x super 4', this.getNodeDescription(node));
110 });
111
112
113 /** Test MathML subscript.
114  * @export
115  */
116 TEST_F('CvoxMathShifterUnitTest', 'MathmlMsub', function() {
117   this.loadHtml(
118       '<div><math xmlns="http://www.w3.org/1998/Math/MathML" id="m5">' +
119       '<msub><mi>x</mi><mn>3</mn></msub>' +
120       '</math></div>');
121   var node = $('m5');
122   assertEquals('x sub 3', this.getNodeDescription(node));
123 });
124
125
126 /** Test MathML subsupscript.
127  * @export
128  */
129 TEST_F('CvoxMathShifterUnitTest', 'MathmlMsubsup', function() {
130   this.loadHtml(
131       '<div><math xmlns="http://www.w3.org/1998/Math/MathML" id="m6">' +
132       '<msubsup><mi>x</mi><mn>3</mn><mn>4</mn></msubsup>' +
133       '</math></div>');
134   var node = $('m6');
135   assertEquals('x sub 3 super 4', this.getNodeDescription(node));
136 });