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

Convert edtitng/text-iterator/first-letter-word-boundary.html with assert_selection

This patch converts the layout test with assert_selection to improve
code health and also increase the usage of w3c testharness.

Note: Chrome's current behavior is incorrect. It will be fixed by
https://codereview.chromium.org/2541163003

BUG=n/a

Review-Url: https://codereview.chromium.org/2534423003
Cr-Commit-Position: refs/heads/master@{#436224}
parent d177fe1e
This tests moving caret around a word with a first-letter rule. WebKit should not crash. This test also demonstrates a bug that word position is incorrectly reported.
hello world'
white-space: normal;
FAIL: moving forward by word from offset 4 put caret at offset 10 but expected 6
PASS: moving backward by word from offset 4 put caret at offset 1
white-space: pre;
FAIL: moving forward by word from offset 4 put caret at offset 10 but expected 6
PASS: moving backward by word from offset 4 put caret at offset 1
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
#test:first-letter {
color: red;
}
</style>
</head>
<body>
<p>This tests moving caret around a word with a first-letter rule. WebKit should not crash.
This test also demonstrates a bug that word position is incorrectly reported.</p>
<div id="test" contenteditable> hello world'</div>
<pre id="console"></pre>
<script>
if (window.testRunner)
testRunner.dumpAsText();
if (window.internals)
internals.settings.setEditingBehavior("mac");
function runTest(actor, expectedOffset) {
window.getSelection().collapse(test.firstChild, 4);
var action = actor() + ' from offset ' + 4 + ' put caret at offset ';
var startOffset = window.getSelection().getRangeAt(0).startOffset;
action += startOffset;
if (startOffset == expectedOffset)
console.innerHTML += 'PASS: ' + action + '\n';
else
console.innerHTML += 'FAIL: ' + action + ' but expected ' + expectedOffset + '\n';
}
var test = document.getElementById('test');
var console = document.getElementById('console');
console.innerHTML += 'white-space: normal;\n';
runTest(function () {window.getSelection().modify('move', 'forward', 'word'); return 'moving forward by word';}, 6);
runTest(function () {window.getSelection().modify('move', 'backward', 'word'); return 'moving backward by word';}, 1);
console.innerHTML += 'white-space: pre;\n';
test.style.whiteSpace = 'pre';
runTest(function () {window.getSelection().modify('move', 'forward', 'word'); return 'moving forward by word';}, 6);
runTest(function () {window.getSelection().modify('move', 'backward', 'word'); return 'moving backward by word';}, 1);
const isMac = navigator.platform.indexOf('Mac') !== -1;
// The current behavior is wrong. The correct expectation should be
// 'hello |world' on Windows and 'hello| world' on other platforms.
test(() => assert_selection(
[
'<style>:first-letter{color:red;}</style>',
'<div contenteditable> hel|lo world\'</div>'
].join(''),
selection => selection.modify('move', 'forward', 'word'),
[
'<style>:first-letter{color:red;}</style>',
isMac ? '<div contenteditable> hello wor|ld\'</div>'
: '<div contenteditable> hello world\'|</div>'
].join('')), 'Move forward by word');
test(() => assert_selection(
[
'<style>:first-letter{color:red;}</style>',
'<div contenteditable> hel|lo world\'</div>'
].join(''),
selection => selection.modify('move', 'backward', 'word'),
[
'<style>:first-letter{color:red;}</style>',
'<div contenteditable> |hello world\'</div>'
].join('')), 'Move backward by word');
// The current behavior is wrong. The correct expectation should be
// 'hello |world' on Windows and 'hello| world' on other platforms.
test(() => assert_selection(
[
'<style>:first-letter{color:red;}</style>',
'<div contenteditable style="white-space:pre"> hel|lo world\'</div>'
].join(''),
selection => selection.modify('move', 'forward', 'word'),
[
'<style>:first-letter{color:red;}</style>',
isMac ? '<div contenteditable style="white-space:pre"> hello wor|ld\'</div>'
: '<div contenteditable style="white-space:pre"> hello world\'|</div>'
].join('')), 'Move forward by word with white-space:pre');
test(() => assert_selection(
[
'<style>:first-letter{color:red;}</style>',
'<div contenteditable style="white-space:pre"> hel|lo world\'</div>'
].join(''),
selection => selection.modify('move', 'backward', 'word'),
[
'<style>:first-letter{color:red;}</style>',
'<div contenteditable style="white-space:pre"> |hello world\'</div>'
].join('')), 'Move backward by word with white-space:pre');
</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