Commit ffe5bf62 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Convert editing/inserting/caret-position.html with W3C testharness

This patch converts the web test with testharness to reduce usage of
legacy editing.js. This is also a preparation for implementing bidi
caret affinity.

Bug: 917165
Change-Id: I84bbcba69f6a9dc768e92081b274146689635e28
Reviewed-on: https://chromium-review.googlesource.com/c/1388026
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618395}
parent 246d8566
Right aligned div.
x
RTL div.
a
0px right padding RTL textarea.
LTR div and textarea.
a
NO WRAPPING
No wrapping right aligned div.
No wrapping RTL div.
a
No wrapping 0px right padding RTL textarea.
No wrapping LTR div and textarea.
a
<html>
<head>
<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
function assertEqual(test_name, actual, expected)
{
if (actual != expected) {
log("==================================");
log("FAILED: " + test_name);
log("actual: " + actual);
log("expected: " + expected);
}
}
function testCaretPosition(elementId, caretPosition)
{
e = document.getElementById(elementId, caretPosition);
function testCaretPosition(elementId, caretPosition) {
test(() => {
assert_own_property(window, 'textInputController');
e = document.getElementById(elementId);
e.focus();
if (window.textInputController) {
var caretRect = textInputController.firstRectForCharacterRange(0, 0);
assertEqual(elementId, caretRect[0], caretPosition);
}
assert_equals(caretRect[0], caretPosition);
}, `${elementId} ${caretPosition}`);
}
function runTest()
{
if (window.testRunner)
testRunner.dumpAsText();
function runTest() {
test(() => {
assert_own_property(window, 'textInputController');
var e = document.getElementById("right-align-div");
e.focus();
selectAllCommand();
typeCharacterCommand();
if (window.textInputController) {
document.execCommand('selectAll');
document.execCommand('insertText', false, 'x');
var caretRect = textInputController.firstRectForCharacterRange(1, 0);
assertEqual("right-align-div", caretRect[0], 208);
}
assert_equals(caretRect[0], 208);
}, 'right-align-div 208 after typing');
testCaretPosition("rtl-div", 208);
testCaretPosition("0-right-padding-rtl-textarea", 206);
......
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