Commit 224c043b authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

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

This patch converts the layout test to use spellcheck_test, so that the
test remains valid after we remove the non-idle-time spellcheck code
path.

This patch also removed editing/spelling/resources/util.js since its
only user is the removed test.

Bug: 757525
Change-Id: I807c029711a5c63b4201c2e5c6ea2e9b7ff16382
Reviewed-on: https://chromium-review.googlesource.com/627169
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496611}
parent f2995c61
......@@ -3128,7 +3128,6 @@ crbug.com/591099 editing/spelling/spellcheck-paste.html [ Failure ]
crbug.com/591099 editing/spelling/spellcheck-queue.html [ Failure ]
crbug.com/591099 editing/spelling/spellcheck_test.html [ Crash Failure ]
crbug.com/591099 editing/spelling/spelling-backward.html [ Failure ]
crbug.com/591099 editing/spelling/spelling-changed-text.html [ Failure ]
crbug.com/591099 editing/spelling/spelling-huge-text.html [ Timeout ]
crbug.com/591099 editing/spelling/spelling-marker-description.html [ Failure ]
crbug.com/591099 editing/style/4916887.html [ Failure ]
function log(msg)
{
document.getElementById("console").innerHTML += (msg + "\n");
}
function verifySpellTest(nretry, opt_doNotFinishTest)
{
var node = window.destination;
if (window.destination.childNodes.length > 0)
node = window.destination.childNodes[0];
if (nretry && !internals.markerCountForNode(node, "spelling")) {
window.setTimeout(function() { verifySpellTest(nretry - 1, opt_doNotFinishTest); }, 0);
return;
}
testFunctionCallback(node);
if (!opt_doNotFinishTest)
finishJSTest();
}
function initSpellTest(testElementId, testText, testFunction, opt_doNotFinishTest)
{
if (!window.internals || !window.testRunner) {
log("FAIL Incomplete test environment");
return;
}
testRunner.setMockSpellCheckerEnabled(true);
testFunctionCallback = testFunction;
jsTestIsAsync = true;
internals.settings.setSmartInsertDeleteEnabled(true);
internals.settings.setSelectTrailingWhitespaceEnabled(false);
internals.settings.setEditingBehavior("win");
window.destination = document.getElementById(testElementId);
window.destination.focus();
document.execCommand("InsertText", false, testText);
window.setTimeout(function() { verifySpellTest(10, opt_doNotFinishTest); }, 0);
}
function findFirstTextNode(node)
{
function iterToFindFirstTextNode(node)
{
if (node instanceof Text)
return node;
var childNodes = node.childNodes;
for (var i = 0; i < childNodes.length; ++i) {
var n = iterToFindFirstTextNode(childNodes[i]);
if (n)
return n;
}
return null;
}
if (node instanceof HTMLInputElement || node instanceof HTMLTextAreaElement) {
return iterToFindFirstTextNode(internals.shadowRoot(node));
} else {
return iterToFindFirstTextNode(node);
}
}
function typeText(elem, text)
{
elem.focus();
for (var i = 0; i < text.length; ++i) {
typeCharacterCommand(text[i]);
}
}
function runNextStep(test, steps, assertions) {
if (!steps.length) {
test.done();
return;
}
var step = steps.shift();
var assertion = assertions.shift();
step();
step_timeout(() => {
test.step(() => assertion());
runNextStep(test, steps, assertions);
}, 50);
}
function runSpellingTest(steps, assertions, opt_title)
{
var t = async_test(opt_title);
if (!window.internals || !window.testRunner) {
t.step(() => assert_unreached('Incomplete test environment'));
t.done();
return;
}
testRunner.setMockSpellCheckerEnabled(true);
runNextStep(t, steps, assertions);
}
Spellcheck should not crash after the text has changed and results are served from cache. To test manually, launch Chromium compiled with Address Sanitizer, enable 'Ask Google for Suggestions', type 'Spell wellcome. Is it broken?', delete the words 'Is it broken?', and context-click on the word 'wellcome'. The test succeeds when the browser does not crash and shows suggestions in the context menu.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS window.getSelection().toString() is " Is it broken?"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/util.js"></script>
</head>
<body>
<div id="container">
<div id="destination" contentEditable></div>
</div>
<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>
spellcheck_test(
'<div contenteditable>|</div>',
'insertText Spell wellcome. Is it broken?',
'<div contenteditable>Spell #wellcome#. Is it broken?</div>',
{
title: 'Setup a content editable div with spelling marker',
callback: sample => spellcheck_test(
sample,
document => {
assert_not_equals(window.eventSender, undefined, 'This test requires eventSender.');
description("Spellcheck should not crash after the text has changed and results are served from cache."
+ " To test manually, launch Chromium compiled with Address Sanitizer, enable 'Ask Google for Suggestions', type 'Spell wellcome. Is it broken?', delete the words 'Is it broken?', and context-click on the word 'wellcome'."
+ " The test succeeds when the browser does not crash and shows suggestions in the context menu.");
const destination = document.querySelector('div');
const textNode = destination.firstChild;
initSpellTest("destination", "Spell wellcome. Is it broken?", function(textNode) {
// Select the text "Is it broken?".
var deleteRange = document.createRange();
const deleteRange = document.createRange();
deleteRange.setStart(textNode, 15);
deleteRange.setEnd(textNode, 29);
window.getSelection().removeAllRanges();
window.getSelection().addRange(deleteRange);
shouldBeEqualToString("window.getSelection().toString()", " Is it broken?");
document.getSelection().removeAllRanges();
document.getSelection().addRange(deleteRange);
// Del key to delete the text "Is it broken?".
eventSender.keyDown("Delete", null);
......@@ -31,12 +33,13 @@ initSpellTest("destination", "Spell wellcome. Is it broken?", function(textNode)
var y = destination.offsetParent.offsetTop + destination.offsetTop + destination.offsetHeight / 2;
eventSender.mouseMoveTo(x, y);
contextMenuElements = eventSender.contextClick();
// Esc key to hide the context menu.
eventSender.keyDown("Escape", null);
document.getElementById("destination").innerHTML = "";
});
},
'<div contenteditable>Spell #wellcome#.</div>',
'Spellcheck should not crash after the text has changed.')
});
</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