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> <html>
<head> <head>
<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script> <script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script> <script>
function log(str) { function testCaretPosition(elementId, caretPosition) {
var li = document.createElement("li"); test(() => {
li.appendChild(document.createTextNode(str)); assert_own_property(window, 'textInputController');
var console = document.getElementById("console"); e = document.getElementById(elementId);
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);
e.focus(); e.focus();
if (window.textInputController) { var caretRect = textInputController.firstRectForCharacterRange(0, 0);
var caretRect = textInputController.firstRectForCharacterRange(0, 0); assert_equals(caretRect[0], caretPosition);
assertEqual(elementId, caretRect[0], caretPosition); }, `${elementId} ${caretPosition}`);
}
} }
function runTest() function runTest() {
{ test(() => {
if (window.testRunner) assert_own_property(window, 'textInputController');
testRunner.dumpAsText();
var e = document.getElementById("right-align-div"); var e = document.getElementById("right-align-div");
e.focus(); e.focus();
selectAllCommand(); document.execCommand('selectAll');
typeCharacterCommand(); document.execCommand('insertText', false, 'x');
if (window.textInputController) { var caretRect = textInputController.firstRectForCharacterRange(1, 0);
var caretRect = textInputController.firstRectForCharacterRange(1, 0); assert_equals(caretRect[0], 208);
assertEqual("right-align-div", caretRect[0], 208); }, 'right-align-div 208 after typing');
}
testCaretPosition("rtl-div", 208); testCaretPosition("rtl-div", 208);
testCaretPosition("0-right-padding-rtl-textarea", 206); testCaretPosition("0-right-padding-rtl-textarea", 206);
testCaretPosition("ltr-div", 9); testCaretPosition("ltr-div", 9);
testCaretPosition("ltr-textarea", 10); testCaretPosition("ltr-textarea", 10);
testCaretPosition("no-wrapping-right-align-div", 208); testCaretPosition("no-wrapping-right-align-div", 208);
testCaretPosition("no-wrapping-rtl-div", 208); testCaretPosition("no-wrapping-rtl-div", 208);
testCaretPosition("no-wrapping-0-right-padding-rtl-textarea", 206); testCaretPosition("no-wrapping-0-right-padding-rtl-textarea", 206);
testCaretPosition("no-wrapping-ltr-div", 9); testCaretPosition("no-wrapping-ltr-div", 9);
testCaretPosition("no-wrapping-ltr-textarea", 10); testCaretPosition("no-wrapping-ltr-textarea", 10);
} }
</script> </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