OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 GEN_INCLUDE([ | 5 GEN_INCLUDE([ |
6 'chrome/browser/resources/chromeos/chromevox/testing/assert_additions.js']); | 6 'chrome/browser/resources/chromeos/chromevox/testing/assert_additions.js']); |
7 | 7 GEN_INCLUDE([ |
8 /** | 8 'chrome/browser/resources/chromeos/chromevox/testing/common.js']); |
9 * Shortcut for document.getElementById. | |
10 * @param {string} id of the element. | |
11 * @return {HTMLElement} with the id. | |
12 */ | |
13 function $(id) { | |
14 return document.getElementById(id); | |
15 } | |
16 | 9 |
17 /** | 10 /** |
18 * Base test fixture for ChromeVox unit tests. | 11 * Base test fixture for ChromeVox unit tests. |
19 * | 12 * |
20 * Note that while conceptually these are unit tests, these tests need | 13 * Note that while conceptually these are unit tests, these tests need |
21 * to run in a full web page, so they're actually run as WebUI browser | 14 * to run in a full web page, so they're actually run as WebUI browser |
22 * tests. | 15 * tests. |
23 * | 16 * |
24 * @constructor | 17 * @constructor |
25 * @extends {testing.Test} | 18 * @extends {testing.Test} |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 * encoded as a comment inside a function, so you can use it like this: | 60 * encoded as a comment inside a function, so you can use it like this: |
68 * | 61 * |
69 * this.loadDoc(function() {/*! | 62 * this.loadDoc(function() {/*! |
70 * <p>Html goes here</p> | 63 * <p>Html goes here</p> |
71 * * /}); | 64 * * /}); |
72 * | 65 * |
73 * @param {Function} commentEncodedHtml The html to load, embedded as a | 66 * @param {Function} commentEncodedHtml The html to load, embedded as a |
74 * comment inside an anonymous function - see example, above. | 67 * comment inside an anonymous function - see example, above. |
75 */ | 68 */ |
76 loadDoc: function(commentEncodedHtml) { | 69 loadDoc: function(commentEncodedHtml) { |
77 var html = this.extractHtmlFromCommentEncodedString_(commentEncodedHtml); | 70 var html = |
| 71 TestUtils.extractHtmlFromCommentEncodedString(commentEncodedHtml); |
78 this.loadHtml(html); | 72 this.loadHtml(html); |
79 }, | 73 }, |
80 | 74 |
81 /** | 75 /** |
82 * Appends some inlined html into the current document, at the end of | 76 * Appends some inlined html into the current document, at the end of |
83 * the body element. Takes the html encoded as a comment inside a function, | 77 * the body element. Takes the html encoded as a comment inside a function, |
84 * so you can use it like this: | 78 * so you can use it like this: |
85 * | 79 * |
86 * this.appendDoc(function() {/*! | 80 * this.appendDoc(function() {/*! |
87 * <p>Html goes here</p> | 81 * <p>Html goes here</p> |
88 * * /}); | 82 * * /}); |
89 * | 83 * |
90 * @param {Function} commentEncodedHtml The html to load, embedded as a | 84 * @param {Function} commentEncodedHtml The html to load, embedded as a |
91 * comment inside an anonymous function - see example, above. | 85 * comment inside an anonymous function - see example, above. |
92 */ | 86 */ |
93 appendDoc: function(commentEncodedHtml) { | 87 appendDoc: function(commentEncodedHtml) { |
94 var html = this.extractHtmlFromCommentEncodedString_(commentEncodedHtml); | 88 var html = |
| 89 TestUtils.extractHtmlFromCommentEncodedString(commentEncodedHtml); |
95 this.appendHtml(html); | 90 this.appendHtml(html); |
96 }, | 91 }, |
97 | 92 |
98 /** | 93 /** |
99 * Appends some inlined html into the current document, at the end of | 94 * Appends some inlined html into the current document, at the end of |
100 * the body element. | 95 * the body element. |
101 * @param {string} html The html to load as a string. | 96 * @param {string} html The html to load as a string. |
102 */ | 97 */ |
103 appendHtml: function(html) { | 98 appendHtml: function(html) { |
104 var div = document.createElement('div'); | 99 var div = document.createElement('div'); |
105 div.innerHTML = html; | 100 div.innerHTML = html; |
106 var fragment = document.createDocumentFragment(); | 101 var fragment = document.createDocumentFragment(); |
107 while (div.firstChild) { | 102 while (div.firstChild) { |
108 fragment.appendChild(div.firstChild); | 103 fragment.appendChild(div.firstChild); |
109 } | 104 } |
110 document.body.appendChild(fragment); | 105 document.body.appendChild(fragment); |
111 }, | 106 }, |
112 | 107 |
113 /** | 108 /** |
114 * Extracts some inlined html encoded as a comment inside a function, | |
115 * so you can use it like this: | |
116 * | |
117 * this.appendDoc(function() {/*! | |
118 * <p>Html goes here</p> | |
119 * * /}); | |
120 * | |
121 * @param {Function} commentEncodedHtml The html , embedded as a | |
122 * comment inside an anonymous function - see example, above. | |
123 @ @return {String} The html text. | |
124 */ | |
125 extractHtmlFromCommentEncodedString_: function(commentEncodedHtml) { | |
126 return commentEncodedHtml.toString(). | |
127 replace(/^[^\/]+\/\*!?/, ''). | |
128 replace(/\*\/[^\/]+$/, ''); | |
129 }, | |
130 | |
131 /** | |
132 * Waits for the queued events in ChromeVoxEventWatcher to be | 109 * Waits for the queued events in ChromeVoxEventWatcher to be |
133 * handled, then calls a callback function with provided arguments | 110 * handled, then calls a callback function with provided arguments |
134 * in the test case scope. Very useful for asserting the results of events. | 111 * in the test case scope. Very useful for asserting the results of events. |
135 * | 112 * |
136 * @param {function()} func A function to call when ChromeVox is ready. | 113 * @param {function()} func A function to call when ChromeVox is ready. |
137 * @param {*} var_args Additional arguments to pass through to the function. | 114 * @param {*} var_args Additional arguments to pass through to the function. |
138 * @return {ChromeVoxUnitTestBase} this. | 115 * @return {ChromeVoxUnitTestBase} this. |
139 */ | 116 */ |
140 waitForCalm: function(func, var_args) { | 117 waitForCalm: function(func, var_args) { |
141 var me = this; | 118 var me = this; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return this; // for chaining. | 185 return this; // for chaining. |
209 }, | 186 }, |
210 | 187 |
211 /** | 188 /** |
212 * @return {cvox.SpokenListBuilder} A new builder. | 189 * @return {cvox.SpokenListBuilder} A new builder. |
213 */ | 190 */ |
214 spokenList: function() { | 191 spokenList: function() { |
215 return new cvox.SpokenListBuilder(); | 192 return new cvox.SpokenListBuilder(); |
216 } | 193 } |
217 }; | 194 }; |
OLD | NEW |