Commit b4557dc3 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Utilize selection_test() in...

Utilize selection_test() in editing/selection/modify-by-lineboundary-in-inline-editable-contexts.html

This patch changes "modify-by-lineboundary-in-inline-editable-contexts.html" to
utilize |selection_test()| for ease of maintenance and help to implementing
EditingNG.

Bug: 707656, 679977
Change-Id: Iec04294c7960073945badcbfff1afa43beffdac3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2220412
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773091}
parent 85095e5e
This test ensures that modifying the selection by line boundary granularity (like home/end do) functions properly in an inline editable context.
You can run this test manually by placing the caret in the middle of the both of the shaded editable spans below and ensuring home/end (command left/right on Mac) moves the caret to the boundaries of the shaded area.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS Modify moving forward in adjacent, editable spans
PASS Modify moving backward in adjacent, editable spans
PASS Modify moving forward in editable span in non-editable content
PASS Modify moving backward in editable span in non-editable content
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/js-test-selection-shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="script-tests/modify-by-lineboundary-in-inline-editable-contexts.js"></script>
</body>
</html>
<!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 test ensures that modifying the selection by line boundary granularity
// (like home/end do) functions properly in an inline editable context.
// adjacent, editable spans
selection_test(
'<span contenteditable>a|bc</span><span contenteditable>xyz</span>',
selection => selection.modify('move', 'forward', 'lineboundary'),
'<span contenteditable>abc|</span><span contenteditable>xyz</span>',
'1 End key: adjacent, editable spans');
selection_test(
'<span contenteditable>a|bc</span><span contenteditable>xyz</span>',
selection => selection.modify('move', 'backward', 'lineboundary'),
'<span contenteditable>|abc</span><span contenteditable>xyz</span>',
'2 Home key: adjacent, editable spans');
// editable span in non-editable content
selection_test(
'abc <span contenteditable>X|YZ</span> def',
selection => selection.modify('move', 'forward', 'lineboundary'),
'abc <span contenteditable>XYZ|</span> def',
'1 End key: editable span in non-editable content');
selection_test(
'abc <span contenteditable>X|YZ</span> def',
selection => selection.modify('move', 'backward', 'lineboundary'),
'abc <span contenteditable>|XYZ</span> def',
'2 Home key: editable span in non-editable content');
</script>
description("This test ensures that modifying the selection by line boundary granularity (like home/end do) functions properly in an inline editable context.<br>" +
"You can run this test manually by placing the caret in the middle of the both of the shaded editable spans below and ensuring home/end (command left/right" +
" on Mac) moves the caret to the boundaries of the shaded area.");
function testModifyByLine(root, direction, expectedOffset, description) {
root.focus();
var sel = window.getSelection();
var initialOffset = 2;
sel.setBaseAndExtent(root.firstChild, initialOffset, root.firstChild, initialOffset);
sel.modify("move", direction, "lineboundary");
var testName = "Modify moving " + direction + " in " + description;
if (sel.baseOffset == expectedOffset)
testPassed(testName);
else if (sel.baseOffset == initialOffset)
testFailed(testName + " had no effect.");
else
testFailed(testName + " resulted in an unexpected offset of " + sel.baseOffset);
}
var container = document.createElement('div');
document.body.appendChild(container);
container.innerHTML = '<span contentEditable="true" style="background-color: lightgrey">adjacent editable</span><span contentEditable="true">spans</span>';
var name = "adjacent, editable spans";
testModifyByLine(container.firstChild, "forward", 17, name);
testModifyByLine(container.firstChild, "backward", 0, name);
if (window.testRunner)
container.innerHTML = '';
container = document.createElement('div')
document.body.appendChild(container);
container.innerHTML = 'This is a non-editable paragraph with <span contentEditable="true" style="background-color: lightgrey" id="root">an editable span</span> inside it.';
name = "editable span in non-editable content"
var root = document.getElementById('root');
testModifyByLine(root, "forward", 16, name);
testModifyByLine(root, "backward", 0, name);
if (window.testRunner)
container.innerHTML = '';
var successfullyParsed = true;
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