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> <!DOCTYPE html>
<html> <script src="../../resources/testharness.js"></script>
<head> <script src="../../resources/testharnessreport.js"></script>
<style type="text/css"> <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> <script>
const isMac = navigator.platform.indexOf('Mac') !== -1;
if (window.testRunner)
testRunner.dumpAsText(); // The current behavior is wrong. The correct expectation should be
if (window.internals) // 'hello |world' on Windows and 'hello| world' on other platforms.
internals.settings.setEditingBehavior("mac"); test(() => assert_selection(
[
function runTest(actor, expectedOffset) { '<style>:first-letter{color:red;}</style>',
window.getSelection().collapse(test.firstChild, 4); '<div contenteditable> hel|lo world\'</div>'
var action = actor() + ' from offset ' + 4 + ' put caret at offset '; ].join(''),
var startOffset = window.getSelection().getRangeAt(0).startOffset; selection => selection.modify('move', 'forward', 'word'),
action += startOffset; [
if (startOffset == expectedOffset) '<style>:first-letter{color:red;}</style>',
console.innerHTML += 'PASS: ' + action + '\n'; isMac ? '<div contenteditable> hello wor|ld\'</div>'
else : '<div contenteditable> hello world\'|</div>'
console.innerHTML += 'FAIL: ' + action + ' but expected ' + expectedOffset + '\n'; ].join('')), 'Move forward by word');
}
test(() => assert_selection(
var test = document.getElementById('test'); [
var console = document.getElementById('console'); '<style>:first-letter{color:red;}</style>',
'<div contenteditable> hel|lo world\'</div>'
console.innerHTML += 'white-space: normal;\n'; ].join(''),
runTest(function () {window.getSelection().modify('move', 'forward', 'word'); return 'moving forward by word';}, 6); selection => selection.modify('move', 'backward', 'word'),
runTest(function () {window.getSelection().modify('move', 'backward', 'word'); return 'moving backward by word';}, 1); [
'<style>:first-letter{color:red;}</style>',
console.innerHTML += 'white-space: pre;\n'; '<div contenteditable> |hello world\'</div>'
test.style.whiteSpace = 'pre'; ].join('')), 'Move backward by word');
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); // 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> </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