| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 // This file provides |assert_selection(sample, tester, expectedText)| assertion | 7 // This file provides |assert_selection(sample, tester, expectedText)| assertion |
| 8 // to W3C test harness to write editing test cases easier. | 8 // to W3C test harness to write editing test cases easier. |
| 9 // | 9 // |
| 10 // |sample| is an HTML fragment text which is inserted as |innerHTML|. It should | 10 // |sample| is an HTML fragment text which is inserted as |innerHTML|. It should |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 * @param {string} string | 363 * @param {string} string |
| 364 */ | 364 */ |
| 365 emit(string) { this.strings_.push(string); } | 365 emit(string) { this.strings_.push(string); } |
| 366 | 366 |
| 367 /** | 367 /** |
| 368 * @private | 368 * @private |
| 369 * @param {!HTMLElement} parentNode | 369 * @param {!HTMLElement} parentNode |
| 370 * @param {number} childIndex | 370 * @param {number} childIndex |
| 371 */ | 371 */ |
| 372 handleSelection(parentNode, childIndex) { | 372 handleSelection(parentNode, childIndex) { |
| 373 if (this.selection_.isNone) |
| 374 return; |
| 373 if (parentNode === this.selection_.focusNode && | 375 if (parentNode === this.selection_.focusNode && |
| 374 childIndex === this.selection_.focusOffset) { | 376 childIndex === this.selection_.focusOffset) { |
| 375 this.emit('|'); | 377 this.emit('|'); |
| 376 return; | 378 return; |
| 377 } | 379 } |
| 378 if (parentNode === this.selection_.anchorNode && | 380 if (parentNode === this.selection_.anchorNode && |
| 379 childIndex === this.selection_.anchorOffset) { | 381 childIndex === this.selection_.anchorOffset) { |
| 380 this.emit('^'); | 382 this.emit('^'); |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 | 385 |
| 384 /** | 386 /** |
| 385 * @private | 387 * @private |
| 386 * @param {!CharacterData} node | 388 * @param {!CharacterData} node |
| 387 */ | 389 */ |
| 388 handleCharacterData(node) { | 390 handleCharacterData(node) { |
| 389 /** @type {string} */ | 391 /** @type {string} */ |
| 390 const text = node.nodeValue; | 392 const text = node.nodeValue; |
| 393 if (this.selection_.isNone) |
| 394 return this.emit(text); |
| 391 /** @type {number} */ | 395 /** @type {number} */ |
| 392 const anchorOffset = this.selection_.anchorOffset; | 396 const anchorOffset = this.selection_.anchorOffset; |
| 393 /** @type {number} */ | 397 /** @type {number} */ |
| 394 const focusOffset = this.selection_.focusOffset; | 398 const focusOffset = this.selection_.focusOffset; |
| 395 if (node === this.selection_.focusNode && | 399 if (node === this.selection_.focusNode && |
| 396 node === this.selection_.anchorNode) { | 400 node === this.selection_.anchorNode) { |
| 397 if (anchorOffset === focusOffset) { | 401 if (anchorOffset === focusOffset) { |
| 398 this.emit(text.substr(0, focusOffset)); | 402 this.emit(text.substr(0, focusOffset)); |
| 399 this.emit('|'); | 403 this.emit('|'); |
| 400 this.emit(text.substr(focusOffset)); | 404 this.emit(text.substr(focusOffset)); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 // case. | 658 // case. |
| 655 if (actualText === expectedText) | 659 if (actualText === expectedText) |
| 656 sample.remove(); | 660 sample.remove(); |
| 657 assert_equals(actualText, expectedText, description); | 661 assert_equals(actualText, expectedText, description); |
| 658 } | 662 } |
| 659 | 663 |
| 660 // Export symbols | 664 // Export symbols |
| 661 window.Sample = Sample; | 665 window.Sample = Sample; |
| 662 window.assert_selection = assertSelection; | 666 window.assert_selection = assertSelection; |
| 663 })(); | 667 })(); |
| OLD | NEW |