Commit 5749e77b authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize selection_test() in selection/extend-to-line-boundary.html

This patch changes "extend-to-line-boundary.html" to utilize |selection_test()|
for ease of maintenance and help to implementing EditingNG.

Bug: 707656, 679977
Change-Id: I3c31e572b3f4ba3e2eb5a72e62857c054b4a56b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214738
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772099}
parent 5767799d
PASS for LTR
PASS for RTL
the quick brown fox jumps the quick brown fox jumps the quick brown fox jumps
שוּרה שוּרה שוּרה שוּרה שוּרה שוּרה שוּרה שוּרה שוּרה
<!DOCTYPE html> <!DOCTYPE html>
<body> <script src="../../resources/testharness.js"></script>
<pre id="console"></pre> <script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script> <script>
function log(s) { const kStyle = [
document.getElementById("console").innerHTML += s + "\n"; 'font-family: monospace;',
} 'width: 4ch',
].join(' ');
function createEditableMultilineDiv(text, numLines) { // LTR
// Put text in a span so that the width can be measured. selection_test(
var span = document.createElement("span"); [
span.innerHTML = text; `<div contenteditable style="${kStyle}">`,
document.body.appendChild(span); '|abc def ghi jkl',
var widthPx = Math.ceil(span.getBoundingClientRect().width); '</div>',
document.body.removeChild(span); ],
selection => selection.modify("move", "forward", "line"),
[
`<div contenteditable style="${kStyle}">`,
'abc |def ghi jkl',
'</div>',
], 'LTR move forward line');
selection_test(
[
`<div contenteditable style="${kStyle}">`,
'abc |def ghi jkl',
'</div>',
],
selection => selection.modify("extend", "forward", "lineboundary"),
[
`<div contenteditable style="${kStyle}">`,
'abc ^def |ghi jkl',
'</div>',
], 'LTR extend forward lineboundary');
// Make div with those dimensions so that the text wraps predictably regardless of platform. // RTL-BDO
var lines = text; selection_test(
for (var i = 1; i < numLines; i++) [
lines += " " + text; `<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">|abc def ghi jkl</bdo>',
'</div>',
],
selection => selection.modify("move", "forward", "line"),
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">abc |def ghi jkl</bdo>',
'</div>',
], 'RTL-BDO move forward line');
selection_test(
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">abc |def ghi jkl</bdo>',
'</div>',
],
selection => selection.modify("extend", "forward", "lineboundary"),
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">abc ^def |ghi jkl</bdo>',
'</div>',
], 'RTL-BDO extend forward lineboundary');
var div = document.createElement("div"); // RTL
div.setAttribute("style", "width: " + widthPx + "px"); selection_test(
div.contentEditable = true; [
div.innerHTML = lines; `<div contenteditable dir="rtl" style="${kStyle}">`,
'|\u05D0\u05D1\u05D2 \u05E0\u05E1\u05E2 \u05E5\u05E6\u05E7 \u05D5\u05D6\u05D7',
return div; '</div>',
} ],
selection => selection.modify("move", "forward", "line"),
function selectSecondLine(element) { [
getSelection().collapse(element.childNodes[0], 0); `<div contenteditable dir="rtl" style="${kStyle}">`,
getSelection().modify("move", "forward", "line"); '\u05D0\u05D1\u05D2 |\u05E0\u05E1\u05E2 \u05E5\u05E6\u05E7 \u05D5\u05D6\u05D7',
getSelection().modify("extend", "forward", "lineboundary"); '</div>',
} ], 'RTL move forward line');
selection_test(
function unescapeRtl(rtlText) { [
var e = document.createElement("span"); `<div contenteditable dir="rtl" style="${kStyle}">`,
e.innerHTML = rtlText; '\u05D0\u05D1\u05D2 |\u05E0\u05E1\u05E2 \u05E5\u05E6\u05E7 \u05D5\u05D6\u05D7',
return e.innerHTML; '</div>',
} ],
selection => selection.modify("extend", "forward", "lineboundary"),
ltrText = "the quick brown fox jumps"; [
ltrTextContainer = createEditableMultilineDiv(ltrText, 3); `<div contenteditable dir="rtl" style="${kStyle}">`,
document.body.appendChild(ltrTextContainer); '\u05D0\u05D1\u05D2 ^\u05E0\u05E1\u05E2 |\u05E5\u05E6\u05E7 \u05D5\u05D6\u05D7',
selectSecondLine(ltrTextContainer); '</div>',
], 'RTL extend forward lineboundary');
if (getSelection().toString() === ltrText + " ")
log("PASS for LTR");
else
log("FAIL for LTR, selection is '" + getSelection() + "' but should be '" + ltrText + " '");
rtlText = unescapeRtl("&#x05E9;&#x05D5;&#x05BC;&#x05E8;&#x05D4; " +
"&#x05E9;&#x05D5;&#x05BC;&#x05E8;&#x05D4; " +
"&#x05E9;&#x05D5;&#x05BC;&#x05E8;&#x05D4;");
rtlTextContainer = createEditableMultilineDiv(rtlText, 3);
rtlTextContainer.setAttribute("dir", "rtl");
document.body.appendChild(rtlTextContainer);
selectSecondLine(rtlTextContainer);
if (getSelection().toString() === rtlText + " ")
log("PASS for RTL");
else
log("FAIL for RTL, selection is '" + getSelection() + "' but should be '" + rtlText + " '");
log("");
if (window.testRunner)
testRunner.dumpAsText();
</script> </script>
</body>
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