Commit 0c2577be authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize selection_test() in editing/selection/extend-after-mouse-selection.html

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

Bug: 707656, 679977
Change-Id: Ife7382b8e1dfe4a24bd458b5aff0248d818db698
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214866
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771669}
parent 18258653
a bc
d ef
ghi
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 2 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](ef) anchorOffset: 2 focusNode: [object Text](a ) focusOffset: 1 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](ef) anchorOffset: 2 focusNode: [object Text](bc) focusOffset: 0 isCollapsed: false]
PASS Selection is [anchorNode: [object Text]( ) anchorOffset: 1 focusNode: [object Text](bc) focusOffset: 0 isCollapsed: false]
PASS Selection is [anchorNode: [object Text]( ) anchorOffset: 1 focusNode: [object Text](a ) focusOffset: 0 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 2 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 1 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 2 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text]( ) focusOffset: 1 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object HTMLSpanElement](null) focusOffset: 4 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 2 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 1 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 2 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text]( ) focusOffset: 1 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object HTMLSpanElement](null) focusOffset: 4 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 2 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 1 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text](ef) focusOffset: 2 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object Text]( ) focusOffset: 1 isCollapsed: false]
PASS Selection is [anchorNode: [object Text](bc) anchorOffset: 0 focusNode: [object HTMLSpanElement](null) focusOffset: 4 isCollapsed: false]
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<style>
.editing {
border: 2px solid red;
font-size: 24px;
}
</style>
<script src="../editing.js"></script>
<script src="../../resources/js-test.js"></script>
<script src="resources/js-test-selection-shared.js"></script>
<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
function editingTest(editingBehavior) {
if (window.internals)
internals.settings.setEditingBehavior(editingBehavior);
var startTarget = document.getElementById('start');
var endTarget = document.getElementById('end');
eventSender.mouseMoveTo(startTarget.offsetLeft, startTarget.offsetTop + 10);
// Double-click to select at word-granularity to workaround eventSender bug with selecting text at
// character granularity (i.e. that it just doesn't work).
function doubleClick(selection) {
const start = selection.document.querySelector('s');
const end = selection.document.querySelector('e');
eventSender.mouseMoveTo(
selection.computeLeft(start),
selection.computeTop(start) + 3);
// Double-click to select at word-granularity to workaround eventSender
// bug with selecting text at character granularity (i.e. that it just
// doesn't work).
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.mouseDown();
eventSender.mouseMoveTo(endTarget.offsetLeft, endTarget.offsetTop + 10);
eventSender.mouseMoveTo(
selection.computeLeft(end),
selection.computeTop(end) + 3);
eventSender.mouseUp();
assertSelectionAt(startTarget.firstChild, 0, endTarget.firstChild, 2);
extendSelectionBackwardByCharacterCommand();
// On Win/Linux the anchor is be fixed after the mouse-selection and never changes.
// On Mac, the first character-granularity selection after a mouse-selection resets the anchor/focus.
if (editingBehavior == "mac")
assertSelectionAt(endTarget.firstChild, 2, startTarget.previousSibling, 1);
else
assertSelectionAt(startTarget.firstChild, 0, endTarget.firstChild, 1);
extendSelectionForwardByCharacterCommand();
if (editingBehavior == "mac")
assertSelectionAt(endTarget.firstChild, 2, startTarget.firstChild, 0);
else
assertSelectionAt(startTarget.firstChild, 0, endTarget.firstChild, 2);
extendSelectionForwardByLineBoundaryCommand();
if (editingBehavior == "mac")
assertSelectionAt(endTarget.nextSibling, 1, startTarget.firstChild, 0);
else
assertSelectionAt(startTarget.firstChild, 0, endTarget.nextSibling, 1);
extendSelectionBackwardByLineBoundaryCommand();
if (editingBehavior == "mac")
assertSelectionAt(endTarget.nextSibling, 1, startTarget.previousSibling, 0);
else
assertSelectionAt(startTarget.firstChild, 0, document.getElementById('test'), 4);
}
</script>
<title>Editing Test</title>
</head>
<body>
<div contenteditable id="root" class="editing">
<span id="test">a <span id="start">bc</span> <br>d <span id="end">ef</span> <br>ghi</span>
</div>
<div id="console"></div>
function extend(selection, direction, unit) {
selection.modify('extend', direction, unit);
}
<script>
editingTest("mac");
editingTest("win");
editingTest("unix");
editingTest("android");
for (const behavior of ['android', 'mac', /*'unix', 'win'*/]) {
const steps = [
{ input: 'a <s>bc</s><br>d <e>ef</e><br>ghi' },
{
// step 1
action: selection => doubleClick(selection),
mac: 'a <s>^bc</s><br>d <e>ef|</e><br>ghi',
others: 'a <s>^bc</s><br>d <e>ef|</e><br>ghi',
},
{
// step 2
action: selection => extend(selection, 'backward', 'character'),
mac: 'a| <s>bc</s><br>d <e>ef^</e><br>ghi',
others: 'a <s>^bc</s><br>d <e>e|f</e><br>ghi',
},
{
// step 3
action: selection => extend(selection, 'forward', 'character'),
mac: 'a <s>|bc</s><br>d <e>ef^</e><br>ghi',
others: 'a <s>^bc</s><br>d <e>ef|</e><br>ghi',
},
{
// step 4
action: selection => extend(selection, 'forward', 'line'),
mac: 'a <s>bc</s><br>d <e>|ef^</e><br>ghi',
others: 'a <s>^bc</s><br>d <e>ef</e><br>ghi|',
},
{
// step 5
action: selection => extend(selection, 'backward', 'line'),
mac: 'a <s>|bc</s><br>d <e>ef^</e><br>ghi',
others: 'a <s>^bc</s><br>d <e>ef|</e><br>ghi',
},
];
for (let step = 1; step < steps.length; ++step) {
selection_test(
`<div>${steps[0].input}</div>`,
selection => {
if (!window.eventSender)
throw 'This test requires eventSender.';
if (!window.internals)
throw 'This test requires internals.';
internals.settings.setEditingBehavior(behavior);
for (let i = 1; i <= step; ++i)
steps[i].action(selection);
},
behavior === 'mac'
? `<div>${steps[step].mac}</div>`
: `<div>${steps[step].others}</div>`,
`${behavior}: step ${step} ${steps[step].action}`);
}
}
</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