Commit 699f0e72 authored by Fernando Serboncini's avatar Fernando Serboncini Committed by Commit Bot

Clean up modify-up-on-rtl-wrapping-text test

TBR=drott@chromium.org

Change-Id: I9c026944acad5c4783bbed7dcbea262479fbd707
Reviewed-on: https://chromium-review.googlesource.com/1136388
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574933}
parent 3ab73342
...@@ -6,5 +6,8 @@ PASS: on כ ככ כככ, caret is at 8 initially ...@@ -6,5 +6,8 @@ PASS: on כ ככ כככ, caret is at 8 initially
PASS: on כ ככ כככ, caret is at 5 after moving upwards once PASS: on כ ככ כככ, caret is at 5 after moving upwards once
PASS: on כ ככ כככ, caret is at 2 after moving upwards twice PASS: on כ ככ כככ, caret is at 2 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 18 initially PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 18 initially
FAIL: on גכ יגכ יגכ יגכ יגכ, caret is at 15 after moving upwards once but expected at 6 PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 14 after moving upwards once
גכ יגכ יגכ יגכ יגכ PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 10 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 6 after moving upwards 3 times
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 3 after moving upwards 4 times
...@@ -6,69 +6,73 @@ ...@@ -6,69 +6,73 @@
<script> <script>
if (window.testRunner) if (window.testRunner)
testRunner.dumpAsText(); testRunner.dumpAsText();
var tests = [ var tests = [
{content: "&#1498; &#1500;&#1499;", expected: [2, 4]}, {content: "&#1498; &#1500;&#1499;", expected: [2, 4]},
{content: "&#1499; &#1499;&#1499; &#1499;&#1499;&#1499;", expected: [2, 5, 8]}, {content: "&#1499; &#1499;&#1499; &#1499;&#1499;&#1499;", expected: [2, 5, 8]},
{content: "&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;", {content: "&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499; &#1497;&#1490;&#1499;",
expected: [3, 6, 10, 14, 18]}, expected: [3, 6, 10, 14, 18]},
]; ];
function failed(message) { function failed(message) {
console.innerHTML += 'FAIL: ' + message + '\n'; document.getElementById('console').innerHTML += 'FAIL: ' + message + '\n';
} }
function passed(message) { function passed(message) {
console.innerHTML += 'PASS: ' + message + '\n'; document.getElementById('console').innerHTML += 'PASS: ' + message + '\n';
} }
function runTest(container, test) { function runTest(container, test) {
container.style.width = '100%'; container.style.width = '100%';
container.innerHTML = test.content; container.innerHTML = test.content;
// Starting from 5px, slowly increase the width until each word fits in one line. // Starting from 5px, slowly increase the width until each word fits in one
var heightOfLine = container.offsetHeight; // line.
var width = 5; var heightOfLine = container.offsetHeight;
do { var width = 5;
container.style.width = width + 'px'; do {
width++; container.style.width = width + 'px';
} while (container.offsetHeight > heightOfLine * test.expected.length); width++;
container.style.width = (width + 1) + 'px'; } while (
Math.floor(container.offsetHeight / heightOfLine) > test.expected.length);
container.style.width = (width + 1) + 'px';
var lines = ['st', 'nd', 'rd', 'th']; window.getSelection().collapse(container.lastChild,
window.getSelection().collapse(container.lastChild, container.lastChild.length); container.lastChild.length);
for (var i = 0; i < test.expected.length; i++) { for (var i = 0; i < test.expected.length; i++) {
if (!window.getSelection().isCollapsed) if (!window.getSelection().isCollapsed)
return failed('the selection was not collapsed'); return failed('the selection was not collapsed');
var range = window.getSelection().getRangeAt(0); var range = window.getSelection().getRangeAt(0);
if (range.startContainer != container.firstChild) if (range.startContainer != container.firstChild)
return failed('caret was at a wrong container'); return failed('caret was at a wrong container');
var action = 'on ' + test.content + ', caret is at ' + range.startOffset; var action = 'on ' + test.content + ', caret is at ' + range.startOffset;
if (i == 0) action += ' initially'; if (i == 0) action += ' initially';
else if (i == 1) action += ' after moving upwards once'; else if (i == 1) action += ' after moving upwards once';
else if (i == 2) action += ' after moving upwards twice'; else if (i == 2) action += ' after moving upwards twice';
else action += ' after moving upwards ' + i + ' times'; else action += ' after moving upwards ' + i + ' times';
if (range.startOffset != test.expected[test.expected.length - i - 1]) if (range.startOffset != test.expected[test.expected.length - i - 1]) {
return failed(action + ' but expected at ' + test.expected[i]); return failed(action + ' but expected at ' +
passed(action); test.expected[test.expected.length - i - 1]);
window.getSelection().modify('move', 'backward', 'line')
} }
passed(action);
window.getSelection().modify('move', 'backward', 'line')
}
} }
var console = document.getElementById('console');
var container = document.createElement('div'); var container = document.createElement('div');
container.contentEditable = true; container.contentEditable = true;
container.setAttribute('dir', 'rtl'); container.setAttribute('dir', 'rtl');
document.body.appendChild(container); document.body.appendChild(container);
for (var i = 0; i < tests.length; i++) for (var i = 0; i < tests.length; i++) {
runTest(container, tests[i]); runTest(container, tests[i]);
//container.innerHTML = ''; }
document.body.removeChild(container);
</script> </script>
</body> </body>
......
...@@ -6,8 +6,5 @@ PASS: on כ ככ כככ, caret is at 8 initially ...@@ -6,8 +6,5 @@ PASS: on כ ככ כככ, caret is at 8 initially
PASS: on כ ככ כככ, caret is at 5 after moving upwards once PASS: on כ ככ כככ, caret is at 5 after moving upwards once
PASS: on כ ככ כככ, caret is at 2 after moving upwards twice PASS: on כ ככ כככ, caret is at 2 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 18 initially PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 18 initially
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 14 after moving upwards once FAIL: on גכ יגכ יגכ יגכ יגכ, caret is at 15 after moving upwards once but expected at 14
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 10 after moving upwards twice
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 6 after moving upwards 3 times
PASS: on גכ יגכ יגכ יגכ יגכ, caret is at 3 after moving upwards 4 times
גכ יגכ יגכ יגכ יגכ
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