Commit 84369be3 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize selection_test() in selection/modify-up-on-rtl-wrapping-text.html

This patch changes "modify-up-on-rtl-wrapping-text.html" to utilize
|selection_test()| for ease of maintenance and help to implementing EditingNG.

Bug: 707656, 679977
Change-Id: I0306f6f80da87804a739398f3e9201d3ced1c2ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2215542
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772100}
parent 5749e77b
This tests clicking on the left of RTL text puts the caret at the end of the line.
PASS: on ך לכ, caret is at 4 initially
PASS: on ך לכ, caret is at 2 after moving upwards once
PASS: on כ ככ כככ, caret is at 8 initially
PASS: on כ ככ כככ, caret is at 5 after moving upwards once
PASS: on כ ככ כככ, caret is at 2 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 18 initially
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 14 after moving upwards once
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 10 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 6 after moving upwards 3 times
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 3 after moving upwards 4 times
<!DOCTYPE html> <!DOCTYPE html>
<html charset="utf-8"> <script src="../../resources/testharness.js"></script>
<body> <script src="../../resources/testharnessreport.js"></script>
<p>This tests clicking on the left of RTL text puts the caret at the end of the line.</p> <script src="../assert_selection.js"></script>
<pre id="console"></pre>
<script> <script>
// This tests clicking on the left of RTL text puts the caret at the end of the
// line.
const kStyle = [
'font-family: monospace;',
'width: 2ch',
].join(' ');
if (window.testRunner) // 2 lines
testRunner.dumpAsText(); selection_test(
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC|</bdo>',
'</div>',
],
selection => selection.modify('move', 'backward', 'line'),
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A |BC</bdo>',
'</div>',
], '2 lines');
var tests = [ // 3 lines
{content: "&#1498; &#1500;&#1499;", expected: [2, 4]}, selection_test(
{content: "&#1499; &#1499;&#1499; &#1499;&#1499;&#1499;", expected: [2, 5, 8]}, [
{content: "&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;", `<div contenteditable dir="rtl" style="${kStyle}">`,
expected: [3, 6, 10, 14, 18]}, '<bdo dir="rtl">A BC DE|</bdo>',
]; '</div>',
],
function failed(message) { selection => selection.modify('move', 'backward', 'line'),
document.getElementById('console').innerHTML += 'FAIL: ' + message + '\n'; [
} `<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC |DE</bdo>',
function passed(message) { '</div>',
document.getElementById('console').innerHTML += 'PASS: ' + message + '\n'; ], '3 lines-1');
} selection_test(
[
function runTest(container, test) { `<div contenteditable dir="rtl" style="${kStyle}">`,
container.style.width = '100%'; '<bdo dir="rtl">A BC |DE</bdo>',
container.innerHTML = test.content; '</div>',
],
// Starting from 5px, slowly increase the width until each word fits in one selection => selection.modify('move', 'backward', 'line'),
// line. [
var heightOfLine = container.offsetHeight; `<div contenteditable dir="rtl" style="${kStyle}">`,
var width = 5; '<bdo dir="rtl">A |BC DE</bdo>',
do { '</div>',
container.style.width = width + 'px'; ], '3 lines-2');
width++;
} while (
Math.floor(container.offsetHeight / heightOfLine) > test.expected.length);
container.style.width = (width + 1) + 'px';
window.getSelection().collapse(container.lastChild,
container.lastChild.length);
for (var i = 0; i < test.expected.length; i++) {
if (!window.getSelection().isCollapsed)
return failed('the selection was not collapsed');
var range = window.getSelection().getRangeAt(0);
if (range.startContainer != container.firstChild)
return failed('caret was at a wrong container');
var action = 'on ' + test.content + ', caret is at ' + range.startOffset;
if (i == 0) action += ' initially';
else if (i == 1) action += ' after moving upwards once';
else if (i == 2) action += ' after moving upwards twice';
else action += ' after moving upwards ' + i + ' times';
if (range.startOffset != test.expected[test.expected.length - i - 1]) {
return failed(action + ' but expected at ' +
test.expected[test.expected.length - i - 1]);
}
passed(action);
window.getSelection().modify('move', 'backward', 'line')
}
}
var container = document.createElement('div');
container.contentEditable = true;
container.setAttribute('dir', 'rtl');
document.body.appendChild(container);
for (var i = 0; i < tests.length; i++) {
runTest(container, tests[i]);
}
document.body.removeChild(container);
// 5 lines
selection_test(
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC DE FG HI|</bdo>',
'</div>',
],
selection => selection.modify('move', 'backward', 'line'),
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC DE FG |HI</bdo>',
'</div>',
], '5 lines-1');
selection_test(
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC DE FG |HI</bdo>',
'</div>',
],
selection => selection.modify('move', 'backward', 'line'),
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC DE |FG HI</bdo>',
'</div>',
], '5 lines-2');
selection_test(
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC DE |FG HI</bdo>',
'</div>',
],
selection => selection.modify('move', 'backward', 'line'),
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC |DE FG HI</bdo>',
'</div>',
], '5 lines-3');
selection_test(
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A BC |DE FG HI</bdo>',
'</div>',
],
selection => selection.modify('move', 'backward', 'line'),
[
`<div contenteditable dir="rtl" style="${kStyle}">`,
'<bdo dir="rtl">A |BC DE FG HI</bdo>',
'</div>',
], '5 lines-4');
</script> </script>
</body>
</html>
This tests clicking on the left of RTL text puts the caret at the end of the line.
PASS: on ך לכ, caret is at 4 initially
PASS: on ך לכ, caret is at 2 after moving upwards once
PASS: on כ ככ כככ, caret is at 8 initially
PASS: on כ ככ כככ, caret is at 5 after moving upwards once
PASS: on כ ככ כככ, caret is at 2 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 18 initially
FAIL: on גכ יגכ יגכ יגכ יגכ, caret is at 15 after moving upwards once but expected at 14
This tests clicking on the left of RTL text puts the caret at the end of the line.
PASS: on ך לכ, caret is at 4 initially
PASS: on ך לכ, caret is at 2 after moving upwards once
PASS: on כ ככ כככ, caret is at 8 initially
PASS: on כ ככ כככ, caret is at 5 after moving upwards once
PASS: on כ ככ כככ, caret is at 2 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 18 initially
FAIL: on גכ יגכ יגכ יגכ יגכ, caret is at 15 after moving upwards once but expected at 14
This tests clicking on the left of RTL text puts the caret at the end of the line.
PASS: on ך לכ, caret is at 4 initially
PASS: on ך לכ, caret is at 2 after moving upwards once
PASS: on כ ככ כככ, caret is at 8 initially
PASS: on כ ככ כככ, caret is at 5 after moving upwards once
PASS: on כ ככ כככ, caret is at 2 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 18 initially
FAIL: on גכ יגכ יגכ יגכ יגכ, caret is at 15 after moving upwards once but expected at 14
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