Commit 1555e9e2 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize selection_test() in editing/selection/mouse/click-left-of-rtl-wrapping-text.html

This patch changes |selection_test()| in "click-left-of-rtl-wrapping-text.html"
for ease of maintenance and help to enable EditingNG.

Bug: 679977, 707656
Change-Id: I6c1992fca70d585ed1b27d271085dbbcea87b83c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2249399
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779239}
parent 7605b9a7
<!doctype html>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<!doctype html>
<script src="../../../resources/ahem.js"></script>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
test(() => {
if (!window.eventSender) {
assert_no_reached('This test requires eventSender.');
return;
}
function testClickLeft(selection, lines, rowIndexToClick) {
const doc = selection.document;
const container = doc.querySelector('div');
// Adjust width to have |lines| of lines.
// Since the Ahem font doesn't cover characters used in test,
// we need to calc width depending on each platform.
const heightOfLine = container.offsetHeight;
let width = 5;
do {
container.style.width = `${width}px`;
width++;
} while (container.offsetHeight > heightOfLine * lines);
container.style.width = `${width + 1}px`;
// Click left of the |rowIndexToClick|th line.
eventSender.mouseMoveTo(
doc.offsetLeft + container.offsetLeft + 3,
doc.offsetTop + container.offsetTop + heightOfLine/2 + rowIndexToClick * heightOfLine);
eventSender.mouseDown();
eventSender.mouseUp();
// Remove width from style to clean result DOM.
container.style.removeProperty('width');
return heightOfLine;
}
assert_selection(
'<div contenteditable dir="rtl">&#1498; &#1500;&#1499;</div>',
selection => testClickLeft(selection, 2, 0),
'<div contenteditable dir="rtl" style>ך |לכ</div>');
assert_selection(
'<div contenteditable dir="rtl">&#1498; &#1500;&#1499;</div>',
selection => testClickLeft(selection, 2, 1),
'<div contenteditable dir="rtl" style>ך לכ|</div>');
assert_selection(
[
'<div contenteditable dir="rtl">',
'&#1499;&#1499; &#1499;&#1499;&#1499;&#1499; &#1499;&#1499;&#1499;',
'</div>'
].join(''),
selection => testClickLeft(selection, 3, 0),
[
'<div contenteditable dir="rtl" style>',
'ככ |ככככ כככ',
'</div>'
].join(''));
assert_selection(
[
'<div contenteditable dir="rtl">',
'&#1499;&#1499; &#1499;&#1499;&#1499;&#1499; &#1499;&#1499;&#1499;',
'</div>'
].join(''),
selection => testClickLeft(selection, 3, 1),
[
'<div contenteditable dir="rtl" style>',
'ככ ככככ |כככ',
'</div>'
].join(''));
assert_selection(
[
'<div contenteditable dir="rtl">',
'&#1499;&#1499; &#1499;&#1499;&#1499;&#1499; &#1499;&#1499;&#1499;',
'</div>'
].join(''),
selection => testClickLeft(selection, 3, 2),
[
'<div contenteditable dir="rtl" style>',
'ככ ככככ כככ|',
'</div>'
].join(''));
assert_selection(
[
'<div contenteditable dir="rtl">',
'&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;',
'</div>'
].join(''),
selection => testClickLeft(selection, 5, 0),
[
'<div contenteditable dir="rtl" style>',
'גכ |יגכ יגכ יגכ יגכ',
'</div>'
].join(''));
assert_selection(
[
'<div contenteditable dir="rtl">',
'&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;',
'</div>'
].join(''),
selection => testClickLeft(selection, 5, 1),
[
'<div contenteditable dir="rtl" style>',
'גכ יגכ |יגכ יגכ יגכ',
'</div>'
].join(''));
assert_selection(
[
'<div contenteditable dir="rtl">',
'&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;',
'</div>'
].join(''),
selection => testClickLeft(selection, 5, 2),
[
'<div contenteditable dir="rtl" style>',
'גכ יגכ יגכ |יגכ יגכ',
'</div>'
].join(''));
assert_selection(
[
'<div contenteditable dir="rtl">',
'&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;',
'</div>'
].join(''),
selection => testClickLeft(selection, 5, 3),
[
'<div contenteditable dir="rtl" style>',
'גכ יגכ יגכ יגכ |יגכ',
'</div>'
].join(''));
assert_selection(
[
'<div contenteditable dir="rtl">',
'&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;',
'</div>'
].join(''),
selection => testClickLeft(selection, 5, 4),
[
'<div contenteditable dir="rtl" style>',
'גכ יגכ יגכ יגכ יגכ|',
'</div>'
].join(''));
}, 'This tests clicking on the left of RTL text puts the caret at the end of the line');
// Test clicking on the left of RTL text puts the caret at the end of the line.
function testClickLeft(lineNumber, numberOfLines, width, sample, expected) {
const kLineHeight = 20;
const kStyle = [
'direction: rtl;',
`font: 10px/${kLineHeight}px Ahem;`,
'line-break: normal;',
`width: ${width}ch;`,
].join('');
selection_test(
[
`<style>div {${kStyle}}</style>`,
`<div contenteditable><bdo dir="rtl">${sample}</bdo></div>`,
],
selection => {
const target = selection.document.querySelector('div');
if (!window.eventSender)
throw 'This test requires eventSender.';
assert_equals(target.offsetHeight, numberOfLines * kLineHeight);
const offsetY = (lineNumber - 1) * kLineHeight;
eventSender.leapForward(9999); // reset mouse click
eventSender.mouseMoveTo(
selection.computeLeft(target) + 3,
selection.computeTop(target) + offsetY + kLineHeight / 2);
eventSender.mouseDown();
eventSender.mouseUp();
},
[
`<style>div {${kStyle}}</style>`,
`<div contenteditable><bdo dir="rtl">${expected}</bdo></div>`,
],
`Click left at line ${lineNumber}/${numberOfLines}`);
}
// 2 lines
testClickLeft(1, 2, 2, 'A BC', 'A| BC');
testClickLeft(2, 2, 2, 'A BC', 'A BC|');
// 3 lines
testClickLeft(1, 3, 4, 'AB CDEF GHI', 'AB| CDEF GHI');
testClickLeft(2, 3, 4, 'AB CDEF GHI', 'AB CDEF| GHI');
testClickLeft(3, 3, 4, 'AB CDEF GHI', 'AB CDEF GHI|');
// 5 lines
testClickLeft(1, 5, 4, 'AB CDE FGH IJK LMN', 'AB| CDE FGH IJK LMN');
testClickLeft(2, 5, 4, 'AB CDE FGH IJK LMN', 'AB CDE| FGH IJK LMN');
testClickLeft(3, 5, 4, 'AB CDE FGH IJK LMN', 'AB CDE FGH| IJK LMN');
testClickLeft(4, 5, 4, 'AB CDE FGH IJK LMN', 'AB CDE FGH IJK| LMN');
testClickLeft(5, 5, 4, 'AB CDE FGH IJK LMN', 'AB CDE FGH IJK LMN|');
</script>
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