Commit 42ed4b41 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize selection_test() in editing/selection/directionality-after-undo-replace.html

This patch changes "directionality-after-undo-replace.html" to utilize
|selection_test()| for ease of maintenance and help to implementing EditingNG.

Bug: 707656, 679977
Change-Id: Ib3b187db88c54a79ba44023f1e2b1c655534232f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2226323
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@{#774054}
parent 90c6a6c6
This tests WebKit preserves non-directional selection after unapplying replacement on Mac. To manually test on Mac,
Select "world" by double-clicking the word
Replace "world" by a character by pressing a key
Undo
Extend selection to the left
" world" should be selected.
hello world WebKit
PASS
<!DOCTYPE html>
<html>
<body>
<p>This tests WebKit preserves non-directional selection after unapplying replacement on Mac. To manually test on Mac,</p>
<ol>
<li>Select "world" by double-clicking the word</li>
<li>Replace "world" by a character by pressing a key</li>
<li>Undo</li>
<li>Extend selection to the left</li>
</ol>
<p>" world" should be selected.</p>
<div contenteditable>hello wo<span id="target">r</span>ld WebKit</div>
<!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>
// This tests Blink preserves non-directional selection after unapplying
// replacement on Mac.
//
// This tests do following steps:
// 1. Select "world" by double-clicking the word
// 2. Replace "world" by a character by pressing a key
// 3. Undo
// 4. Extend selection to the left
if (window.testRunner && window.internals) {
testRunner.dumpAsText();
const kStyle = [
'font: 30px/1 monospace;',
].join('');
function doubleClick(selection) {
if (!window.eventSender)
document.writeln('FAIL - this test requires eventSender');
else {
internals.settings.setEditingBehavior('mac');
throw 'This test requires eventSender.';
const target = selection.document.getElementById('target');
var test = document.getElementById('target');
eventSender.mouseMoveTo(target.offsetLeft + target.offsetWidth / 2, target.offsetTop + target.offsetHeight / 2);
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.leapForward(9999); // reset mouse button state
eventSender.mouseMoveTo(
selection.computeLeft(target) + target.offsetWidth / 2,
selection.computeTop(target) + target.offsetHeight / 2);
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.leapForward(200);
eventSender.leapForward(200);
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.mouseDown();
eventSender.mouseUp();
}
const kSample = [
`<style>${kStyle}</style>`,
'<div contenteditable>',
'ABC wo<b id="target">r</b>ld XYZ',
'</div>',
];
const steps = [
{
title: '1. Select "world" by double-clicking the word',
action: doubleClick,
expected: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
'ABC ^wo<b id="target">r</b>ld| XYZ',
'</div>',
],
win: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
// Windoews selects word with a trailing space.
'ABC ^wo<b id="target">r</b>ld |XYZ',
'</div>',
],
},
{
title: '2. Replace "world" by a character by pressing a key',
action: selection => {
selection.document.execCommand('InsertText', false, 'a');
},
expected: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
'ABC a|\u00A0XYZ',
'</div>',
],
win: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
'ABC a|XYZ',
'</div>',
],
},
{
title: '3. Undo',
action: selection => {
selection.document.execCommand('Undo');
},
expected: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
'ABC ^wo<b id="target">r</b>ld| XYZ',
'</div>',
],
win: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
'ABC ^wo<b id="target">r</b>ld |XYZ',
'</div>',
],
},
document.execCommand('InsertText', false, 'a');
document.execCommand('Undo');
window.getSelection().modify('extend', 'left', 'character');
{
title: '4. Extend selection to the left',
action: selection => selection.modify('extend', 'left', 'character'),
expected: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
'ABC ^wo<b id="target">r</b>l|d XYZ',
'</div>',
],
mac: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
// Mac keeps non-directional selection made by double click.
'ABC| wo<b id="target">r</b>ld^ XYZ',
'</div>',
],
win: [
`<style>${kStyle}</style>`,
'<div contenteditable>',
'ABC ^wo<b id="target">r</b>ld| XYZ',
'</div>',
],
},
];
var actual = window.getSelection().toString();
// Windows has a trailing whitespace, other platforms don't.
document.writeln((actual == ' world' || actual == ' world ') ? 'PASS' : 'FAIL - expected " world" but got "' + actual + '"');
for (const platform of ['android', 'mac', 'unix', 'win']) {
if (window.internals) {
internals.settings.setEditingBehavior(platform);
internals.settings.setSelectTrailingWhitespaceEnabled(
platform === 'win');
}
for (const step of steps) {
if (platform in step)
continue;
step[platform] = step.expected;
}
}
for (let nth = 0; nth < steps.length; ++nth) {
selection_test(
kSample,
selection => {
for (const step of steps.slice(0, nth + 1))
step.action(selection);
},
steps[nth][platform],
`${platform} ${steps[nth].title}`);
}
}
</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