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

Side by Side Diff: third_party/WebKit/LayoutTests/editing/spelling/spellcheck_test.js

Issue 2455883003: Convert editing/spelling/spelling-huge-text.html with spellcheck_test (Closed)
Patch Set: Optimize spellcheck_test's handleCharacterData Created 4 years, 1 month 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/spelling/spelling-huge-text.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 7 // This file provides
8 // |spellcheck_test(sample, tester, expectedText, opt_title)| asynchronous test 8 // |spellcheck_test(sample, tester, expectedText, opt_title)| asynchronous test
9 // to W3C test harness for easier writing of spellchecker test cases. 9 // to W3C test harness for easier writing of spellchecker test cases.
10 // 10 //
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 /** 108 /**
109 * @private 109 * @private
110 * @param {string} string 110 * @param {string} string
111 */ 111 */
112 emit(string) { this.strings_.push(string); } 112 emit(string) { this.strings_.push(string); }
113 113
114 /** 114 /**
115 * @private 115 * @private
116 * @param {!Node} node 116 * @param {!CharacterData} node
117 * @param {number} offset 117 * @param {number} offset
118 * @return {number} The next offset at which a current active marker ends or
119 * a new marker starts. Returns node.data.length if there is
120 * no more markers.
118 */ 121 */
119 advancedTo(node, offset) { 122 advancedTo(node, offset) {
123 var nextCheckPoint = node.data.length;
120 for (let type in this.markerTypes_) { 124 for (let type in this.markerTypes_) {
121 // Handle the ending of the current active marker. 125 // Handle the ending of the current active marker.
122 if (isAtRangeEnd(this.activeMarkerRanges_[type], node, offset)) { 126 if (isAtRangeEnd(this.activeMarkerRanges_[type], node, offset))
123 this.activeMarkerRanges_[type] = null;
124 this.emit(this.markerTypes_[type]); 127 this.emit(this.markerTypes_[type]);
125 }
126 128
127 // Handle the starting of the next active marker. 129 // Recompute the current active marker and the next check point
128 if (this.activeMarkerRanges_[type]) 130 this.activeMarkerRanges_[type] = null;
129 return;
130 /** @type {number} */ 131 /** @type {number} */
131 const markerCount = window.internals.markerCountForNode(node, type); 132 const markerCount = window.internals.markerCountForNode(node, type);
132 for (let i = 0; i < markerCount; ++i) { 133 for (let i = 0; i < markerCount; ++i) {
133 const marker = window.internals.markerRangeForNode(node, type, i); 134 const marker = window.internals.markerRangeForNode(node, type, i);
134 assert_equals( 135 assert_equals(
135 marker.startContainer, node, 136 marker.startContainer, node,
136 'Internal error: marker range not starting in the annotated node.'); 137 'Internal error: marker range not starting in the annotated node.');
137 assert_equals( 138 assert_equals(
138 marker.endContainer, node, 139 marker.endContainer, node,
139 'Internal error: marker range not ending in the annotated node.'); 140 'Internal error: marker range not ending in the annotated node.');
140 if (marker.startOffset === offset) { 141 assert_greater_than(marker.endOffset, marker.startOffset,
141 assert_greater_than(marker.endOffset, offset, 142 'Internal error: marker range is collapsed.');
142 'Internal error: marker range is collapsed.'); 143 if (marker.startOffset <= offset && offset < marker.endOffset) {
143 this.activeMarkerRanges_[type] = marker; 144 this.activeMarkerRanges_[type] = marker;
144 this.emit(this.markerTypes_[type]); 145 nextCheckPoint = Math.min(nextCheckPoint, marker.endOffset);
145 break; 146 // Handle the starting of the current active marker.
147 if (offset === marker.startOffset)
148 this.emit(this.markerTypes_[type]);
149 } else if (marker.startOffset > offset) {
150 nextCheckPoint = Math.min(nextCheckPoint, marker.startOffset);
146 } 151 }
147 } 152 }
148 } 153 }
154 return nextCheckPoint;
149 } 155 }
150 156
151 /** 157 /**
152 * @private 158 * @private
153 * @param {!CharacterData} node 159 * @param {!CharacterData} node
154 */ 160 */
155 handleCharacterData(node) { 161 handleCharacterData(node) {
156 /** @type {string} */ 162 /** @type {string} */
157 const text = node.nodeValue; 163 const text = node.nodeValue;
158 /** @type {number} */ 164 /** @type {number} */
159 const length = text.length; 165 const length = text.length;
160 for (let offset = 0; offset < length; ++offset) { 166 for (let offset = 0; offset < length;) {
161 this.advancedTo(node, offset); 167 const nextCheckPoint = this.advancedTo(node, offset);
162 this.emit(text[offset]); 168 this.emit(text.substring(offset, nextCheckPoint));
169 offset = nextCheckPoint;
163 } 170 }
164 this.advancedTo(node, length); 171 this.advancedTo(node, length);
165 } 172 }
166 173
167 /** 174 /**
168 * @private 175 * @private
169 * @param {!HTMLElement} element 176 * @param {!HTMLElement} element
170 */ 177 */
171 handleInnerEditorOf(element) { 178 handleInnerEditorOf(element) {
172 /** @type {!ShadowRoot} */ 179 /** @type {!ShadowRoot} */
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 expectedText: expectedText, args: args}); 435 expectedText: expectedText, args: args});
429 return; 436 return;
430 } 437 }
431 438
432 invokeSpellcheckTest(input, tester, expectedText, args); 439 invokeSpellcheckTest(input, tester, expectedText, args);
433 } 440 }
434 441
435 // Export symbols 442 // Export symbols
436 window.spellcheck_test = spellcheckTest; 443 window.spellcheck_test = spellcheckTest;
437 })(); 444 })();
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/editing/spelling/spelling-huge-text.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698