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

Convert fast/dom/Range/range-expand.html with testharness

This patch converts the layout test with W3C testharness to allow
cross-platform evaluation of the test cases.

Change-Id: Ifba919b388f8a6c6de062f8615d0547fac2d2ca6
Reviewed-on: https://chromium-review.googlesource.com/c/1336661Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608259}
parent 6b0ab168
CONSOLE WARNING: line 57: 'Range.expand()' is deprecated. Please use 'Selection.modify()' instead.
This is the begin of a block. A block is a collection of sentences. Each sentence begins with capital letter and ends with a punctuation.
Now, a sentence is divided into multiple lines.
Roll the mouse around the page. The coordinates of the mouse pointer are currently atop an element
whose ID is:"".
Cell A1 Cell B1
Cell A2 Cell B2
Section 1
text.
Section 2
text.
Here is a positioned element.
在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。
בלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"
<!doctype html>
<html> <html>
<head> <head>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8"> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">
<title>Test for Range.expand()</title> <title>Test for Range.expand()</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script> <script>
function log(str) function expandRangeString(startId, startOffset, endId, endOffset, expandUnit, firstChild) {
{ const range = document.createRange();
var li = document.createElement("li"); let startNode = document.getElementById(startId);
li.appendChild(document.createTextNode(str)); if (firstChild == true)
var console = document.getElementById("console"); startNode = startNode.firstChild;
console.appendChild(li); let endNode = document.getElementById(endId);
if (firstChild == true)
endNode = endNode.firstChild;
range.setStart(startNode, startOffset);
range.setEnd(endNode, endOffset);
range.expand(expandUnit);
return range.toString();
} }
function assertEqual(test_name, actual, expected) function runTests() {
{ // test 1 - Expand to document.
if (actual != expected) { test(() => {
log("=================================="); const actual = expandRangeString('myspan', 0, 'myspan', 0, 'document', false);
log("FAILED test " + test_name); const expected = 'This is the begin of a block. A block is a collection of sentences. Each sentence begins with capital\x0Aletter and ends with a punctuation.\x0A\x0ANow, a sentence\x0Ais divided into\x0Amultiple lines.\x0A\x0ARoll the mouse around the page. The coordinates\x0Aof the mouse pointer are currently atop an elementwhose ID \x0Ais:"".\x0A\x0A\x0A\x0A Cell A1\x0A Cell B1\x0A\x0A\x0A Cell A2\x0A Cell B2\x0A\x0A\x0ASection 1\x0Atext.\x0ASection 2\x0Atext.\x0A\x0AHere is a positioned element.\x0A在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。\x0Aבלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"'
log("actual: " + actual); assert_equals(actual, expected);
log("expected: " + expected); }, 'document1');
if (actual.length != expected.length) {
log("length !=" + "; actual.length: " + actual.length + "; expected.length: " + expected.length); // test 2 - Expand to block.
log("escaped actual: " + escape(actual)); test(() => {
log("escaped expected: " + escape(expected)); const actual = expandRangeString('td_A1', 0, 'td_A1', 0, 'block', false);
var length = actual.length; assert_equals(actual, 'Cell A1');
if (actual.length > expected.length) }, 'block2');
length = expected.length;
for (var i=0; i<length; ++i) { // test 3 - Expand to block, different range start and end offset.
log("i: " + i + "; actual: " + actual[i] + "; expected: " + expected[i]); test(() => {
if (actual[i] != expected[i]) const actual = expandRangeString('td_A1', 1, 'td_A1', 2, 'block', true);
log("!="); assert_equals(actual, 'Cell A1');
} }, 'block3');
}
else { // test 4 - Expand to block, different range start and end node.
log("actual: " + escape(actual)); test(() => {
log("expected: " + escape(expected)); const actual = expandRangeString('td_A1', 0, 'td_B1', 0, 'block', false);
for (var i=0; i<actual.length; ++i) { assert_equals(actual, 'Cell A1\x0A Cell B1');
log("i: " + i + "; actual: " + actual[i] + "; expected: " + expected[i]); }, 'block4');
if (actual[i] != expected[i])
log("!="); // test 5 - Expand to sentence.
} test(() => {
const actual = expandRangeString('instructions', 0, 'instructions', 0, 'sentence', false);
} assert_equals(actual, 'Roll the mouse around the page. ');
} }, 'sentence5');
}
// test 6 - Expand to sentence, different range start and end offset.
function expandRangeString(range, startId, startOffset, endId, endOffset, expandUnit, firstChild) test(() => {
{ const actual = expandRangeString('instructions', 1, 'instructions', 2, 'sentence', true);
var startNode = document.getElementById(startId); assert_equals(actual, 'Roll the mouse around the page. ');
if (firstChild == true) }, 'sentence6');
startNode = startNode.firstChild;
var endNode = document.getElementById(endId); // test 7 - Expand to sentence, different range start and end node.
if (firstChild == true) test(() => {
endNode = endNode.firstChild; const actual = expandRangeString('instructions', 0, 'mybr', 0, 'sentence', false);
range.setStart(startNode, startOffset); assert_equals(actual, 'Roll the mouse around the page. The coordinates\x0Aof the mouse pointer are currently atop an element');
range.setEnd(endNode, endOffset); }, 'sentence7');
range.expand(expandUnit);
return range.toString(); // test 8 - Sentence does not go upstream?
} test(() => {
const actual = expandRangeString('multilineSentence', 0, 'multilineSentence', 0, 'sentence', false);
function test() assert_equals(actual, 'Now, a sentence\x0Ais divided into\x0Amultiple lines.');
{ }, 'sentence8');
if (window.testRunner)
testRunner.dumpAsText(); test(() => {
const actual = expandRangeString('multilineSentence', 1, 'multilineSentence', 5, 'sentence', true);
// test 1 - Expand to document. assert_equals(actual, 'Now, a sentence\x0Ais divided into\x0Amultiple lines.');
var range = document.createRange(); }, 'sentence9');
var actual = expandRangeString(range, 'myspan', 0, 'myspan', 0, 'document', false);
var expected = 'This is the begin of a block. A block is a collection of sentences. Each sentence begins with capital\x0Aletter and ends with a punctuation.\x0A\x0ANow, a sentence\x0Ais divided into\x0Amultiple lines.\x0A\x0ARoll the mouse around the page. The coordinates\x0Aof the mouse pointer are currently atop an elementwhose ID \x0Ais:"".\x0A\x0A\x0A\x0A Cell A1\x0A Cell B1\x0A\x0A\x0A Cell A2\x0A Cell B2\x0A\x0A\x0ASection 1\x0Atext.\x0ASection 2\x0Atext.\x0A\x0AHere is a positioned element.\x0A在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。\x0Aבלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"' test(() => {
assertEqual("document1", actual, expected); const actual = expandRangeString('multilineSentence', 20, 'multilineSentence', 20, 'sentence', true);
assert_equals(actual, 'is divided into\x0Amultiple lines.');
// test 2 - Expand to block. }, 'sentence10');
actual = expandRangeString(range, 'td_A1', 0, 'td_A1', 0, 'block', false);
assertEqual("block2", actual, "Cell A1"); test(() => {
const actual = expandRangeString('multilineSentence', 40, 'multilineSentence', 40, 'sentence', true);
// test 3 - Expand to block, different range start and end offset. assert_equals(actual, 'multiple lines.');
actual = expandRangeString(range, 'td_A1', 1, 'td_A1', 2, 'block', true); }, 'sentence11');
assertEqual("block3", actual, "Cell A1");
// Expand word.
// test 4 - Expand to block, different range start and end node. // Same range start and end, both at the begin of word.
actual = expandRangeString(range, 'td_A1', 0, 'td_B1', 0, 'block', false); test(() => {
assertEqual("block4", actual, "Cell A1\x0A Cell B1"); const actual = expandRangeString('mydiv', 0, 'mydiv', 0, 'word', false);
assert_equals(actual, 'Here');
// test 5 - Expand to sentence. }, 'word1');
actual = expandRangeString(range, 'instructions', 0, 'instructions', 0, 'sentence', false);
assertEqual("sentence5", actual, "Roll the mouse around the page. "); // Same range start and end, both at the begin of a word.
test(() => {
// test 6 - Expand to sentence, different range start and end offset. const actual = expandRangeString('mydiv', 1, 'mydiv', 1, 'word', true);
actual = expandRangeString(range, 'instructions', 1, 'instructions', 2, 'sentence', true); assert_equals(actual, 'Here');
assertEqual("sentence6", actual, "Roll the mouse around the page. "); }, 'word2');
// test 7 - Expand to sentence, different range start and end node. // Same range start and end, both at the middle of a word.
actual = expandRangeString(range, 'instructions', 0, 'mybr', 0, 'sentence', false); test(() => {
assertEqual("sentence7", actual, "Roll the mouse around the page. The coordinates\x0Aof the mouse pointer are currently atop an element"); const actual = expandRangeString('mydiv', 3, 'mydiv', 3, 'word', true);
assert_equals(actual, 'Here');
// test 8 - Sentence does not go upstream? }, 'word3');
actual = expandRangeString(range, 'multilineSentence', 0, 'multilineSentence', 0, 'sentence', false);
assertEqual("sentence8", actual, "Now, a sentence\x0Ais divided into\x0Amultiple lines."); // Same range start and end, both at the end of a word.
test(() => {
actual = expandRangeString(range, 'multilineSentence', 1, 'multilineSentence', 5, 'sentence', true); const actual = expandRangeString('mydiv', 4, 'mydiv', 4, 'word', true);
assertEqual("sentence9", actual, "Now, a sentence\x0Ais divided into\x0Amultiple lines."); assert_equals(actual, 'Here');
}, 'word4');
actual = expandRangeString(range, 'multilineSentence', 20, 'multilineSentence', 20, 'sentence', true);
assertEqual("sentence10", actual, "is divided into\x0Amultiple lines."); // Different range start and end offset, both at the middle of a word.
test(() => {
actual = expandRangeString(range, 'multilineSentence', 40, 'multilineSentence', 40, 'sentence', true); const actual = expandRangeString('mydiv', 2, 'mydiv', 3, 'word', true);
assertEqual("sentence11", actual, "multiple lines."); assert_equals(actual, 'Here');
}, 'word5');
// Expand word.
// Same range start and end, both at the begin of word. // Different range start and end offset, start at the begin of a word,
actual = expandRangeString(range, 'mydiv', 0, 'mydiv', 0, 'word', false); // and end at the end of a word.
assertEqual("word1", actual, "Here"); test(() => {
const actual = expandRangeString('mydiv', 5, 'mydiv', 4, 'word', true);
// Same range start and end, both at the begin of a word. assert_equals(actual, 'Here');
actual = expandRangeString(range, 'mydiv', 1, 'mydiv', 1, 'word', true); }, 'word6');
assertEqual("word2", actual, "Here");
// Different range start and end offset, start at the begin of a word,
// Same range start and end, both at the middle of a word. // and end at the middle of a word.
actual = expandRangeString(range, 'mydiv', 3, 'mydiv', 3, 'word', true); test(() => {
assertEqual("word3", actual, "Here"); const actual = expandRangeString('mydiv', 1, 'mydiv', 3, 'word', true);
assert_equals(actual, 'Here');
// Same range start and end, both at the end of a word. }, 'word7');
actual = expandRangeString(range, 'mydiv', 4, 'mydiv', 4, 'word', true);
assertEqual("word4", actual, "Here"); // Different range start and end offset, start at the middle of a word,
// and end at the end of a word.
// Different range start and end offset, both at the middle of a word. test(() => {
actual = expandRangeString(range, 'mydiv', 2, 'mydiv', 3, 'word', true); const actual = expandRangeString('mydiv', 2, 'mydiv', 4, 'word', true);
assertEqual("word5", actual, "Here"); assert_equals(actual, 'Here');
}, 'word8');
// Different range start and end offset, start at the begin of a word,
// and end at the end of a word. // Across more than 1 word.
actual = expandRangeString(range, 'mydiv', 5, 'mydiv', 4, 'word', true); // Start at the begin of 1st word, end at the end of last word.
assertEqual("word6", actual, "Here"); test(() => {
const actual = expandRangeString('mydiv', 1, 'mydiv', 7, 'word', true);
// Different range start and end offset, start at the begin of a word, assert_equals(actual, 'Here is');
// and end at the middle of a word. }, 'word9');
actual = expandRangeString(range, 'mydiv', 1, 'mydiv', 3, 'word', true);
assertEqual("word7", actual, "Here"); // Start at the middle of 1st word, end at the middle of last word.
test(() => {
// Different range start and end offset, start at the middle of a word, const actual = expandRangeString('mydiv', 2, 'mydiv', 6, 'word', true);
// and end at the end of a word. assert_equals(actual, 'Here is');
actual = expandRangeString(range, 'mydiv', 2, 'mydiv', 4, 'word', true); }, 'word10');
assertEqual("word8", actual, "Here");
// Start at the begin of 1st word, end at the middle of last word.
// Across more than 1 word. test(() => {
// Start at the begin of 1st word, end at the end of last word. const actual = expandRangeString('mydiv', 1, 'mydiv', 6, 'word', true);
actual = expandRangeString(range, 'mydiv', 1, 'mydiv', 7, 'word', true); assert_equals(actual, 'Here is');
assertEqual("word9", actual, "Here is"); }, 'word11');
// Start at the middle of 1st word, end at the middle of last word. // Start at the middle of 1st word, end at the end of last word.
actual = expandRangeString(range, 'mydiv', 2, 'mydiv', 6, 'word', true); test(() => {
assertEqual("word10", actual, "Here is"); const actual = expandRangeString('mydiv', 2, 'mydiv', 7, 'word', true);
assert_equals(actual, 'Here is');
// Start at the begin of 1st word, end at the middle of last word. }, 'word12');
actual = expandRangeString(range, 'mydiv', 1, 'mydiv', 6, 'word', true);
assertEqual("word11", actual, "Here is"); // Word and space.
test(() => {
// Start at the middle of 1st word, end at the end of last word. const actual = expandRangeString('mydiv', 4, 'mydiv', 5, 'word', true);
actual = expandRangeString(range, 'mydiv', 2, 'mydiv', 7, 'word', true); assert_equals(actual, 'Here ');
assertEqual("word12", actual, "Here is"); }, 'word13');
// Word and space. // Word across different nodes.
actual = expandRangeString(range, 'mydiv', 4, 'mydiv', 5, 'word', true); test(() => {
assertEqual("word13", actual, "Here "); const actual = expandRangeString('mydiv', 1, 'he-div', 0, 'word', true);
assert_equals(actual, 'Here is a positioned element.\x0A在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。\x0Aבלשכת');
// Word across different nodes. }, 'word14');
actual = expandRangeString(range, 'mydiv', 1, 'he-div', 0, 'word', true);
assertEqual("word14", actual, "Here is a positioned element.\x0A在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。\x0Aבלשכת"); // Test for Chinese. No Chinese segmentation in platform/mac.
test(() => {
// Test for Chinese. No Chinese segmentation in platform/mac. const actual = expandRangeString('zh-CN-div', 0, 'zh-CN-div', 0, 'word', true);
actual = expandRangeString(range, 'zh-CN-div', 0, 'zh-CN-div', 0, 'word', true); assert_equals(actual, '');
assertEqual("Chinese word0", actual, ""); }, 'Chinese word0');
actual = expandRangeString(range, 'zh-CN-div', 1, 'zh-CN-div', 1, 'word', true);
assertEqual("Chinese word1", actual, ""); test(() => {
actual = expandRangeString(range, 'zh-CN-div', 2, 'zh-CN-div', 2, 'word', true); const actual = expandRangeString('zh-CN-div', 1, 'zh-CN-div', 1, 'word', true);
assertEqual("Chinese word1", actual, ""); assert_equals(actual, '');
}, 'Chinese word1');
actual = expandRangeString(range, 'zh-CN-div', 3, 'zh-CN-div', 3, 'sentence', true);
assertEqual("Chinese sentence: ", actual, "在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。"); test(() => {
const actual = expandRangeString('zh-CN-div', 2, 'zh-CN-div', 2, 'word', true);
actual = expandRangeString(range, 'zh-CN-div', 3, 'zh-CN-div', 3, 'block', true); assert_equals(actual, '');
assertEqual("Chinese block: ", actual, "在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。"); }, 'Chinese word2');
// Test for Hebrew. test(() => {
actual = expandRangeString(range, 'he-div', 1, 'he-div', 1, 'word', true); const actual = expandRangeString('zh-CN-div', 3, 'zh-CN-div', 3, 'sentence', true);
assertEqual("Hebrew word", actual, "בלשכת"); assert_equals(actual, '在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。');
}, 'Chinese sentence');
actual = expandRangeString(range, 'he-div', 1, 'he-div', 1, 'sentence', true);
assertEqual("Hebrew sentence", actual, 'בלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"' ); test(() => {
const actual = expandRangeString('zh-CN-div', 3, 'zh-CN-div', 3, 'block', true);
actual = expandRangeString(range, 'he-div', 0, 'he-div', 0, 'sentence', false); assert_equals(actual, '在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。');
assertEqual("Hebrew block", actual, 'בלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"' ); }, 'Chinese block');
// Test for Hebrew.
test(() => {
const actual = expandRangeString('he-div', 1, 'he-div', 1, 'word', true);
assert_equals(actual, 'בלשכת');
}, 'Hebrew word');
test(() => {
const actual = expandRangeString('he-div', 1, 'he-div', 1, 'sentence', true);
assert_equals(actual, 'בלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"' );
}, 'Hebrew sentence');
test(() => {
const actual = expandRangeString('he-div', 0, 'he-div', 0, 'sentence', false);
assert_equals(actual, 'בלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"' );
}, 'Hebrew block');
} }
</script> </script>
<body onload="test()"> <body>
<p>This is the begin of a block. A block is a collection of sentences. Each sentence begins with capital <p>This is the begin of a block. A block is a collection of sentences. Each sentence begins with capital
letter and ends with a punctuation. letter and ends with a punctuation.
</p> </p>
...@@ -222,7 +247,9 @@ is:"<span id="myspan" style="font-weight:bold"></span>".</p> ...@@ -222,7 +247,9 @@ is:"<span id="myspan" style="font-weight:bold"></span>".</p>
Here is a positioned element.</div> Here is a positioned element.</div>
<div id="zh-CN-div">在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。</div> <div id="zh-CN-div">在甲型H1N1流感可能出现大流行的警告声中,昨天召开的江苏省2009-2010年度流感防制研讨会注定与往年不同。每年都会召开的一次例会,今年足足提前了一个月;会上研讨的主题,已从以前的季节性流感,变成以甲型H1N1流感为重点。</div>
<div id="he-div">בלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"</div> <div id="he-div">בלשכת שר החוץ הגיבו להתקפות עליו בעקבות הנחייתו לדרוש מהמועמדים לקורס צוערים שירות צבאי או לאומי: "המתקיפים צבועים, מי שרוצה לייצג את המדינה רוצה גם לשרת אותה"</div>
<ul id="console"></ul>
<script>
runTests();
</script>
</body> </body>
</html> </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