Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: third_party/WebKit/LayoutTests/editing/assert_selection.js

Issue 2686663004: Selection API: Selection.extend() should throw if rangeCount is 0. (Closed)
Patch Set: focus() -> collapse() Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/editing/execCommand/transpose-backslash-with-euc.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 })();
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/editing/execCommand/transpose-backslash-with-euc.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698