Commit 24622cfc authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Convert editing/undo/undo-{combined-,forward-,}delete.html to use assert_selection()

This patch changes "undo-{combined-,forward-,}delete.html" to use
|assert_selection()| and integrate into "undo-delete.html" since
these test are similar for improving readability.

Note: This patch similar to the patch[1] which convert 
"undo-delete-boundary.html".

[1] http://crrev.com/c/567615 Convert 
editing/undo/undo-{combined-,forward-,}delete-boundary.html to use
assert_selection()

Bug: 230267, 679977
Change-Id: I7e21fae9a023cc70577d373161ac0e8e7beafc66
Reviewed-on: https://chromium-review.googlesource.com/571205Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486705}
parent b9fbd971
mac
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 5
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 9
PASS selection.toString() is "word"
win
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 7
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 7
PASS selection.toString() is ""
unix
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 7
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 7
PASS selection.toString() is ""
android
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 7
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 7
PASS selection.toString() is ""
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<body>
<div id="container">
<p id="description"></p>
<p>To test manually, place the cursor after 'o' in 'word' and delete it completely character by character. Do ctrl+z. On Mac, 'word' should be selected. On other platforms 'word' should not be selected and the cursor should be placed after 'o' in 'word'.</p>
<div id="test" style="border: 2px solid red;" contenteditable>This word should be selected only on mac.</div>
</div>
<div id="console"></div>
<script src="../../resources/js-test.js"></script>
<script>
description('Verifies the selection behavior on undoing a text deletion.');
var selectionNode = document.getElementById('test').firstChild;
var selectionOffset = selectionNode.data.indexOf('o') + 1;
var startOffsetMac = selectionNode.data.indexOf(' ') + 1;
var endOffsetMac = selectionNode.data.indexOf('d') + 1;
var selection = window.getSelection();
function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndNode, expectedEndOffset, selectedText) {
debug(platform);
internals.settings.setEditingBehavior(platform);
selection.collapse(selectionNode, selectionOffset);
for (var i = 0; i < 2; i++)
document.execCommand('delete');
for (var i = 0; i < 2; i++)
document.execCommand('forwarddelete');
document.execCommand('undo');
shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data);
shouldBe('selection.anchorOffset', expectedStartOffset + '');
shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data);
shouldBe('selection.focusOffset', expectedEndOffset + '');
shouldBeEqualToString('selection.toString()', selectedText);
}
if (window.internals) {
undoTest('mac', selectionNode, startOffsetMac, selectionNode, endOffsetMac, 'word');
undoTest('win', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
undoTest('unix', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
undoTest('android', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
}
if (window.testRunner)
document.getElementById('container').outerHTML = '';
</script>
</body>
</html>
mac
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 9
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 5
PASS selection.toString() is "word"
win
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 9
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 9
PASS selection.toString() is ""
unix
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 9
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 9
PASS selection.toString() is ""
android
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 9
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 9
PASS selection.toString() is ""
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html> <!doctype html>
<html> <script src="../../resources/testharness.js"></script>
<body> <script src="../../resources/testharnessreport.js"></script>
<div id="container"> <script src="../assert_selection.js"></script>
<p id="description"></p>
<p>To test manually, place the cursor at the end of 'word' and delete it completely character by character. Do ctrl+z. On Mac, 'word' should be selected. On other platforms 'word' should not be selected and the cursor should be placed at the end of 'word'.</p>
<div id="test" style="border: 2px solid red;" contenteditable>This word should be selected only on mac.</div>
</div>
<div id="console"></div>
<script src="../../resources/js-test.js"></script>
<script> <script>
description('Verifies the selection behavior on undoing a text deletion.'); function undoTest(behavior) {
var selectionNode = document.getElementById('test').firstChild; if (window.internals)
var selectionOffset = selectionNode.data.indexOf('d') + 1; internals.settings.setEditingBehavior(behavior);
var endOffsetMac = selectionNode.data.indexOf(' ') + 1; test(() => assert_selection(
var selection = window.getSelection(); [
'<div contenteditable>',
'This word| should be selected only on mac.',
'</div>'
].join(''),
selection => {
for (let i = 0; i < 4; ++i)
selection.document.execCommand('delete');
selection.document.execCommand('undo');
},
[
'<div contenteditable>',
behavior === 'mac'
? 'This |word^ should be selected only on mac.'
: 'This word| should be selected only on mac.',
'</div>',
].join('')),
`${behavior}: backward delete`);
function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndNode, expectedEndOffset, selectedText) { test(() => assert_selection(
debug(platform); [
internals.settings.setEditingBehavior(platform); '<div contenteditable>',
'This |word should be selected only on mac.',
'</div>'
].join(''),
selection => {
for (let i = 0; i < 4; ++i)
selection.document.execCommand('forwardDelete');
selection.document.execCommand('undo');
},
[
'<div contenteditable>',
behavior === 'mac'
? 'This ^word| should be selected only on mac.'
: 'This |word should be selected only on mac.',
'</div>',
].join('')),
`${behavior}: forward delete`);
selection.collapse(selectionNode, selectionOffset); test(() => assert_selection(
for (var i = 0; i < 4; i++) [
document.execCommand('delete'); '<div contenteditable>',
document.execCommand('undo'); 'This wo|rd should be selected only on mac.',
'</div>'
shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data); ].join(''),
shouldBe('selection.anchorOffset', expectedStartOffset + ''); selection => {
shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data); for (let i = 0; i < 2; ++i)
shouldBe('selection.focusOffset', expectedEndOffset + ''); selection.document.execCommand('delete');
shouldBeEqualToString('selection.toString()', selectedText); for (let i = 0; i < 2; ++i)
} selection.document.execCommand('forwardDelete');
selection.document.execCommand('undo');
if (window.internals) { },
undoTest('mac', selectionNode, selectionOffset, selectionNode, endOffsetMac, 'word'); [
undoTest('win', selectionNode, selectionOffset, selectionNode, selectionOffset, ''); '<div contenteditable>',
undoTest('unix', selectionNode, selectionOffset, selectionNode, selectionOffset, ''); behavior === 'mac'
undoTest('android', selectionNode, selectionOffset, selectionNode, selectionOffset, ''); ? 'This ^word| should be selected only on mac.'
: 'This wo|rd should be selected only on mac.',
'</div>',
].join('')),
`${behavior}: backward and forward delete`);
} }
if (window.testRunner) for (let behavior of ['android', 'mac', 'unix', 'win'])
document.getElementById('container').outerHTML = ''; undoTest(behavior);
</script> </script>
</body>
</html>
mac
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 5
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 9
PASS selection.toString() is "word"
win
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 5
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 5
PASS selection.toString() is ""
unix
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 5
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 5
PASS selection.toString() is ""
android
PASS selection.anchorNode.data is "This word should be selected only on mac."
PASS selection.anchorOffset is 5
PASS selection.focusNode.data is "This word should be selected only on mac."
PASS selection.focusOffset is 5
PASS selection.toString() is ""
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<body>
<div id="container">
<p id="description"></p>
<p>To test manually, place the cursor before 'w' of 'word' and delete it completely character by character. Do ctrl+z. On Mac, 'word' should be selected. On other platforms 'word' should not be selected and the cursor should be placed before 'w' of 'word'.</p>
<div id="test" style="border: 2px solid red;" contenteditable>This word should be selected only on mac.</div>
</div>
<div id="console"></div>
<script src="../../resources/js-test.js"></script>
<script>
description('Verifies the selection behavior on undoing a text deletion.');
var selectionNode = document.getElementById('test').firstChild;
var selectionOffset = selectionNode.data.indexOf(' ') + 1;
var endOffsetMac = selectionNode.data.indexOf('d') + 1;
var selection = window.getSelection();
function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndNode, expectedEndOffset, selectedText) {
debug(platform);
internals.settings.setEditingBehavior(platform);
selection.collapse(selectionNode, selectionOffset);
for (var i = 0; i < 4; i++)
document.execCommand('forwarddelete');
document.execCommand('undo');
shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data);
shouldBe('selection.anchorOffset', expectedStartOffset + '');
shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data);
shouldBe('selection.focusOffset', expectedEndOffset + '');
shouldBeEqualToString('selection.toString()', selectedText);
}
if (window.internals) {
undoTest('mac', selectionNode, selectionOffset, selectionNode, endOffsetMac, 'word');
undoTest('win', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
undoTest('unix', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
undoTest('android', selectionNode, selectionOffset, selectionNode, selectionOffset, '');
}
if (window.testRunner)
document.getElementById('container').outerHTML = '';
</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