Commit a00d926f authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Convert editing/spelling/spelling-huge-text.html with spellcheck_test

This patch converts the layout test with spellcheck_test as a
preparation for implementing idle time spellchecker.

This patch also contains a performance optimization to spellcheck_test
in handling CharacterData nodes with long text.

BUG=517298

Review-Url: https://codereview.chromium.org/2455883003
Cr-Commit-Position: refs/heads/master@{#430211}
parent a5d5e38d
...@@ -113,20 +113,21 @@ class MarkerSerializer { ...@@ -113,20 +113,21 @@ class MarkerSerializer {
/** /**
* @private * @private
* @param {!Node} node * @param {!CharacterData} node
* @param {number} offset * @param {number} offset
* @return {number} The next offset at which a current active marker ends or
* a new marker starts. Returns node.data.length if there is
* no more markers.
*/ */
advancedTo(node, offset) { advancedTo(node, offset) {
var nextCheckPoint = node.data.length;
for (let type in this.markerTypes_) { for (let type in this.markerTypes_) {
// Handle the ending of the current active marker. // Handle the ending of the current active marker.
if (isAtRangeEnd(this.activeMarkerRanges_[type], node, offset)) { if (isAtRangeEnd(this.activeMarkerRanges_[type], node, offset))
this.activeMarkerRanges_[type] = null;
this.emit(this.markerTypes_[type]); this.emit(this.markerTypes_[type]);
}
// Handle the starting of the next active marker. // Recompute the current active marker and the next check point
if (this.activeMarkerRanges_[type]) this.activeMarkerRanges_[type] = null;
return;
/** @type {number} */ /** @type {number} */
const markerCount = window.internals.markerCountForNode(node, type); const markerCount = window.internals.markerCountForNode(node, type);
for (let i = 0; i < markerCount; ++i) { for (let i = 0; i < markerCount; ++i) {
...@@ -137,15 +138,20 @@ class MarkerSerializer { ...@@ -137,15 +138,20 @@ class MarkerSerializer {
assert_equals( assert_equals(
marker.endContainer, node, marker.endContainer, node,
'Internal error: marker range not ending in the annotated node.'); 'Internal error: marker range not ending in the annotated node.');
if (marker.startOffset === offset) { assert_greater_than(marker.endOffset, marker.startOffset,
assert_greater_than(marker.endOffset, offset, 'Internal error: marker range is collapsed.');
'Internal error: marker range is collapsed.'); if (marker.startOffset <= offset && offset < marker.endOffset) {
this.activeMarkerRanges_[type] = marker; this.activeMarkerRanges_[type] = marker;
this.emit(this.markerTypes_[type]); nextCheckPoint = Math.min(nextCheckPoint, marker.endOffset);
break; // Handle the starting of the current active marker.
if (offset === marker.startOffset)
this.emit(this.markerTypes_[type]);
} else if (marker.startOffset > offset) {
nextCheckPoint = Math.min(nextCheckPoint, marker.startOffset);
} }
} }
} }
return nextCheckPoint;
} }
/** /**
...@@ -157,9 +163,10 @@ class MarkerSerializer { ...@@ -157,9 +163,10 @@ class MarkerSerializer {
const text = node.nodeValue; const text = node.nodeValue;
/** @type {number} */ /** @type {number} */
const length = text.length; const length = text.length;
for (let offset = 0; offset < length; ++offset) { for (let offset = 0; offset < length;) {
this.advancedTo(node, offset); const nextCheckPoint = this.advancedTo(node, offset);
this.emit(text[offset]); this.emit(text.substring(offset, nextCheckPoint));
offset = nextCheckPoint;
} }
this.advancedTo(node, length); this.advancedTo(node, length);
} }
......
Text to check is divided into chunks to make sure checking some huge text does not freeze the page/UI. With the asynchronous spell checker the whole text is checked. To test manaully trigger spell checking of the editable (e.g. by copy+paste) with unified and asynchronous checker on. There should be 6 misspellings marked.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS internals.markerCountForNode(testEditable.childNodes[0], "spelling") became 6
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html> <!doctype html>
<html> <script src="../../resources/testharness.js"></script>
<head> <script src="../../resources/testharnessreport.js"></script>
<script src="../../resources/js-test.js"></script> <script src="../assert_selection.js"></script>
</head> <script src="spellcheck_test.js"></script>
<body onload="test();">
<div id="console"></div>
<div id="editable" contenteditable></div>
<script> <script>
description("Text to check is divided into chunks to make sure checking some huge text " + const longText = 'Good good good good good good good good good good good good good. '.repeat(600);
"does not freeze the page/UI. With the asynchronous spell checker the whole text is checked. " + spellcheck_test(
"To test manaully trigger spell checking of the editable (e.g. by copy+paste) with unified " + `<div contenteditable>zz zz zz. ${longText}zz zz zz.</div>`,
"and asynchronous checker on. There should be 6 misspellings marked."); document => document.querySelector('div').focus(),
`<div contenteditable>#zz# #zz# #zz#. ${longText}#zz# #zz# #zz#.</div>`,
jsTestIsAsync = true; 'Spellchecking long text does not freeze the page.');
if (window.testRunner)
testRunner.setMockSpellCheckerEnabled(true);
var testEditable = null;
function test()
{
testEditable = document.getElementById("editable");
var loopCount = 150;
var longText = "Good good good good good good good good good good good good good. " +
"Good good good good good good good good good good good good good. " +
"Good good good good good good good good good good good good good. " +
"Good good good good good good good good good good good good good.";
var testLongText = "";
for (var i = 0; i < loopCount; ++i)
testLongText += longText;
testLongText = "zz zz zz. " + testLongText + " zz zz zz.";
testEditable.innerText = testLongText;
if (!window.internals) {
log("Test manually. See the description for steps");
return;
}
internals.setSpellCheckingEnabled(false);
testEditable.focus();
internals.setSpellCheckingEnabled(true);
shouldBecomeEqual('internals.markerCountForNode(testEditable.childNodes[0], "spelling")', '6', function() {
testEditable.removeChild(testEditable.childNodes[0]);
finishJSTest();
}, 5000 /* huge text needs more time to be spell checked */);
}
</script> </script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment