| 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 // Include test fixture. | 5 // Include test fixture. |
| 6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']); | 6 GEN_INCLUDE(['../testing/chromevox_unittest_base.js']); |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Test fixture. | 9 * Test fixture. |
| 10 * @constructor | 10 * @constructor |
| 11 * @extends {ChromeVoxUnitTestBase} | 11 * @extends {ChromeVoxUnitTestBase} |
| 12 */ | 12 */ |
| 13 function CvoxContentEditableExtractorUnitTest() {} | 13 function CvoxContentEditableExtractorUnitTest() {} |
| 14 | 14 |
| 15 CvoxContentEditableExtractorUnitTest.prototype = { | 15 CvoxContentEditableExtractorUnitTest.prototype = { |
| 16 __proto__: ChromeVoxUnitTestBase.prototype, | 16 __proto__: ChromeVoxUnitTestBase.prototype, |
| 17 | 17 |
| 18 /** @override */ | 18 /** @override */ |
| 19 closureModuleDeps: [ | 19 closureModuleDeps: [ |
| 20 'cvox.ContentEditableExtractor', | 20 'cvox.ContentEditableExtractor', |
| 21 ] | 21 ] |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 /** |
| 25 * Helper function to set the selection |
| 26 * @param {Node} startNode The base/start node of the range. |
| 27 * @param {number} startOffset The 0-based character index of the start. |
| 28 * @param {Node} endNode The extent/end node of the range. |
| 29 * @param {number} endOffset The 0-based character index of the end. |
| 30 */ |
| 31 function setSelection(startNode, startOffset, endNode, endOffset) { |
| 32 var r = document.createRange(); |
| 33 r.setStart(startNode, startOffset); |
| 34 r.setEnd(endNode, endOffset); |
| 35 var sel = window.getSelection(); |
| 36 sel.removeAllRanges(); |
| 37 sel.addRange(r); |
| 38 } |
| 39 |
| 24 TEST_F('CvoxContentEditableExtractorUnitTest', 'EmptyElement', function() { | 40 TEST_F('CvoxContentEditableExtractorUnitTest', 'EmptyElement', function() { |
| 25 this.loadDoc(function() {/*! | 41 this.loadDoc(function() {/*! |
| 26 <div> | 42 <div> |
| 27 <div id="textbox" contentEditable="true"></div> | 43 <div id="textbox" contentEditable="true"></div> |
| 28 </div> | 44 </div> |
| 29 */}); | 45 */}); |
| 30 | 46 |
| 31 var textbox = $('textbox'); | 47 var textbox = $('textbox'); |
| 32 var extractor = new cvox.ContentEditableExtractor(); | 48 var extractor = new cvox.ContentEditableExtractor(); |
| 33 extractor.update(textbox); | 49 extractor.update(textbox); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 extractor.update(textbox); | 317 extractor.update(textbox); |
| 302 assertEquals(7, extractor.getStartIndex()); | 318 assertEquals(7, extractor.getStartIndex()); |
| 303 assertEquals(7, extractor.getEndIndex()); | 319 assertEquals(7, extractor.getEndIndex()); |
| 304 | 320 |
| 305 // Beginning of third line. | 321 // Beginning of third line. |
| 306 setSelection(threeTextNode, 0, threeTextNode, 0); | 322 setSelection(threeTextNode, 0, threeTextNode, 0); |
| 307 extractor.update(textbox); | 323 extractor.update(textbox); |
| 308 assertEquals(8, extractor.getStartIndex()); | 324 assertEquals(8, extractor.getStartIndex()); |
| 309 assertEquals(8, extractor.getEndIndex()); | 325 assertEquals(8, extractor.getEndIndex()); |
| 310 }); | 326 }); |
| OLD | NEW |