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 {
/**
* @private
* @param {!Node} node
* @param {!CharacterData} node
* @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) {
var nextCheckPoint = node.data.length;
for (let type in this.markerTypes_) {
// Handle the ending of the current active marker.
if (isAtRangeEnd(this.activeMarkerRanges_[type], node, offset)) {
this.activeMarkerRanges_[type] = null;
if (isAtRangeEnd(this.activeMarkerRanges_[type], node, offset))
this.emit(this.markerTypes_[type]);
}
// Handle the starting of the next active marker.
if (this.activeMarkerRanges_[type])
return;
// Recompute the current active marker and the next check point
this.activeMarkerRanges_[type] = null;
/** @type {number} */
const markerCount = window.internals.markerCountForNode(node, type);
for (let i = 0; i < markerCount; ++i) {
......@@ -137,15 +138,20 @@ class MarkerSerializer {
assert_equals(
marker.endContainer, node,
'Internal error: marker range not ending in the annotated node.');
if (marker.startOffset === offset) {
assert_greater_than(marker.endOffset, offset,
assert_greater_than(marker.endOffset, marker.startOffset,
'Internal error: marker range is collapsed.');
if (marker.startOffset <= offset && offset < marker.endOffset) {
this.activeMarkerRanges_[type] = marker;
nextCheckPoint = Math.min(nextCheckPoint, marker.endOffset);
// Handle the starting of the current active marker.
if (offset === marker.startOffset)
this.emit(this.markerTypes_[type]);
break;
} else if (marker.startOffset > offset) {
nextCheckPoint = Math.min(nextCheckPoint, marker.startOffset);
}
}
}
return nextCheckPoint;
}
/**
......@@ -157,9 +163,10 @@ class MarkerSerializer {
const text = node.nodeValue;
/** @type {number} */
const length = text.length;
for (let offset = 0; offset < length; ++offset) {
this.advancedTo(node, offset);
this.emit(text[offset]);
for (let offset = 0; offset < length;) {
const nextCheckPoint = this.advancedTo(node, offset);
this.emit(text.substring(offset, nextCheckPoint));
offset = nextCheckPoint;
}
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>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body onload="test();">
<div id="console"></div>
<div id="editable" contenteditable></div>
<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script src="spellcheck_test.js"></script>
<script>
description("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.");
jsTestIsAsync = true;
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 */);
}
const longText = 'Good good good good good good good good good good good good good. '.repeat(600);
spellcheck_test(
`<div contenteditable>zz zz zz. ${longText}zz zz zz.</div>`,
document => document.querySelector('div').focus(),
`<div contenteditable>#zz# #zz# #zz#. ${longText}#zz# #zz# #zz#.</div>`,
'Spellchecking long text does not freeze the page.');
</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