| 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, options)| | 7 // This file provides |assert_selection(sample, tester, expectedText, options)| |
| 8 // assertion to W3C test harness to write editing test cases easier. | 8 // assertion 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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 `You should have focus marker and should not have anchor marker if and
only if selection is a caret in "${sampleText}".`); | 743 `You should have focus marker and should not have anchor marker if and
only if selection is a caret in "${sampleText}".`); |
| 744 } | 744 } |
| 745 this.document_.body.innerHTML = sampleText; | 745 this.document_.body.innerHTML = sampleText; |
| 746 /** @type {!SampleSelection} */ | 746 /** @type {!SampleSelection} */ |
| 747 const selection = Parser.parse(this.document_.body); | 747 const selection = Parser.parse(this.document_.body); |
| 748 if (selection.isNone) | 748 if (selection.isNone) |
| 749 return; | 749 return; |
| 750 if (this.loadSelectionInTextArea(selection)) | 750 if (this.loadSelectionInTextArea(selection)) |
| 751 return; | 751 return; |
| 752 this.selection_.collapse(selection.anchorNode, selection.anchorOffset); | 752 this.selection_.collapse(selection.anchorNode, selection.anchorOffset); |
| 753 this.selection_.extend(selection.focusNode, selection.focusOffset); | 753 if (this.selection_.rangeCount > 0) |
| 754 this.selection_.extend(selection.focusNode, selection.focusOffset); |
| 754 } | 755 } |
| 755 | 756 |
| 756 /** | 757 /** |
| 757 * @private | 758 * @private |
| 758 * @param {!SampleSelection} selection | 759 * @param {!SampleSelection} selection |
| 759 * @return {boolean} Returns true if selection is in TEXTAREA. | 760 * @return {boolean} Returns true if selection is in TEXTAREA. |
| 760 */ | 761 */ |
| 761 loadSelectionInTextArea(selection) { | 762 loadSelectionInTextArea(selection) { |
| 762 /** @type {Node} */ | 763 /** @type {Node} */ |
| 763 const enclosingNode = selection.anchorNode.parentNode; | 764 const enclosingNode = selection.anchorNode.parentNode; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 throw new Error(`${description}\n` + | 924 throw new Error(`${description}\n` + |
| 924 `\t expected ${expectedText},\n` + | 925 `\t expected ${expectedText},\n` + |
| 925 `\t but got ${actualText},\n` + | 926 `\t but got ${actualText},\n` + |
| 926 `\t sameupto ${commonPrefixOf(expectedText, actualText)}`); | 927 `\t sameupto ${commonPrefixOf(expectedText, actualText)}`); |
| 927 } | 928 } |
| 928 | 929 |
| 929 // Export symbols | 930 // Export symbols |
| 930 window.Sample = Sample; | 931 window.Sample = Sample; |
| 931 window.assert_selection = assertSelection; | 932 window.assert_selection = assertSelection; |
| 932 })(); | 933 })(); |
| OLD | NEW |