Fix mixed directional tests from bug 396392. Bug 525788, r=roc

This commit is contained in:
Simon Montagu 2009-12-21 00:56:14 -08:00
parent d84ebba607
commit d854f924d8

View File

@ -5,6 +5,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=421640
--> -->
<head> <head>
<title>Test for Bug 396392</title> <title>Test for Bug 396392</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="/MochiKit/packed.js"></script> <script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
@ -15,10 +16,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=421640
<div id="content" style="font-face:monospace;font-size:12px;width:100px"> <div id="content" style="font-face:monospace;font-size:12px;width:100px">
<p>000000<span>0</span></p><div>00000<span>0</span></div><p>0000<span>0000</span>0000</p> <p>000000<span>0</span></p><div>00000<span>0</span></div><p>0000<span>0000</span>0000</p>
</div> </div>
<div id="mixeddir" style="font-face:monospace;font-size:12px;width:100px"><span>english &#x202e;rtl-overide english&#x202c; word</span></div>
<pre id="test"> <pre id="test">
<script class="testbody" type="text/javascript"> <script class="testbody" type="text/javascript">
var isLTR=true;
function isEmptyRect(rect, name) { function isEmptyRect(rect, name) {
name = (isLTR ? 'isLTR ' : 'isRTL ') + name;
is(rect.left, 0, name+'empty rect should have left = 0'); is(rect.left, 0, name+'empty rect should have left = 0');
is(rect.right, 0, name+'empty rect should have right = 0'); is(rect.right, 0, name+'empty rect should have right = 0');
is(rect.top, 0, name+'empty rect should have top = 0'); is(rect.top, 0, name+'empty rect should have top = 0');
@ -28,6 +32,7 @@ function isEmptyRect(rect, name) {
} }
function isEmptyRectList(rectlist, name) { function isEmptyRectList(rectlist, name) {
name = (isLTR ? 'isLTR ' : 'isRTL ') + name;
is(rectlist.length, 0, name + 'empty rectlist should have zero rects'); is(rectlist.length, 0, name + 'empty rectlist should have zero rects');
} }
@ -49,7 +54,8 @@ function runATest(obj) {
} }
//test getBoundingClientRect() //test getBoundingClientRect()
var rect = range.getBoundingClientRect(); var rect = range.getBoundingClientRect();
var testname = 'range.getBoundingClientRect for ' + obj.name; var testname = (isLTR ? 'isLTR ' : 'isRTL ') +
'range.getBoundingClientRect for ' + obj.name;
if (obj.rect) { if (obj.rect) {
is(_getRect(rect),_getRect(obj.rect), testname); is(_getRect(rect),_getRect(obj.rect), testname);
} else { } else {
@ -57,7 +63,8 @@ function runATest(obj) {
} }
//test getClientRects() //test getClientRects()
var rectlist = range.getClientRects(); var rectlist = range.getClientRects();
testname = 'range.getClientRects for '+obj.name; testname = (isLTR ? 'isLTR ' : 'isRTL ') +
'range.getClientRects for '+obj.name;
if (!obj.rectList) { if (!obj.rectList) {
//rectList is not specified, use obj.rect to figure out rectList //rectList is not specified, use obj.rect to figure out rectList
obj.rectList = obj.rect?[obj.rect]:[]; obj.rectList = obj.rect?[obj.rect]:[];
@ -66,6 +73,10 @@ function runATest(obj) {
isEmptyRectList(rectlist, testname+": "); isEmptyRectList(rectlist, testname+": ");
} else { } else {
is(rectlist.length, obj.rectList.length, testname+' should return '+obj.rectList.length+' rects.'); is(rectlist.length, obj.rectList.length, testname+' should return '+obj.rectList.length+' rects.');
if(!obj.rectList.forEach){
//convert RectList to a real array
obj.rectList=Array.prototype.slice.call(obj.rectList, 0);
}
obj.rectList.forEach(function(rect,i) { obj.rectList.forEach(function(rect,i) {
is(_getRect(rectlist[i]),_getRect(rect),testname+": item at "+i); is(_getRect(rectlist[i]),_getRect(rect),testname+": item at "+i);
}); });
@ -75,7 +86,7 @@ function runATest(obj) {
} }
} }
/** Test for Bug 396392 **/ /** Test for Bug 396392 **/
function test() { function doTest(){
var root = document.getElementById('content'); var root = document.getElementById('content');
var firstP = root.firstElementChild, spanInFirstP = firstP.childNodes[1], var firstP = root.firstElementChild, spanInFirstP = firstP.childNodes[1],
firstDiv = root.childNodes[2], spanInFirstDiv = firstDiv.childNodes[1], firstDiv = root.childNodes[2], spanInFirstDiv = firstDiv.childNodes[1],
@ -92,13 +103,15 @@ function test() {
rect:null}, rect:null},
{name:'collapsedInBlockNode', range:[firstP, 2], rect:null}, {name:'collapsedInBlockNode', range:[firstP, 2], rect:null},
{name:'collapsedAtBeginningOfTextNode', range:[firstP.firstChild, 0], {name:'collapsedAtBeginningOfTextNode', range:[firstP.firstChild, 0],
rect:[firstPRect.left, firstPRect.left, spanInFirstPRect.top, rect:[spanInFirstPRect.left - 6 * widthPerchar,
spanInFirstPRect.left - 6 * widthPerchar, spanInFirstPRect.top,
spanInFirstPRect.bottom, 0, spanInFirstPRect.height]}, spanInFirstPRect.bottom, 0, spanInFirstPRect.height]},
{name:'collapsedWithinTextNode', range:[firstP.firstChild, 1], {name:'collapsedWithinTextNode', range:[firstP.firstChild, 1],
rect:[firstPRect.left+widthPerchar, firstPRect.left+widthPerchar, rect:[spanInFirstPRect.left - 5 * widthPerchar,
spanInFirstPRect.left - 5 * widthPerchar,
spanInFirstPRect.top, spanInFirstPRect.bottom, 0, spanInFirstPRect.height]}, spanInFirstPRect.top, spanInFirstPRect.bottom, 0, spanInFirstPRect.height]},
{name:'collapsedAtEndOfTextNode', range:[firstP.firstChild, 6], {name:'collapsedAtEndOfTextNode', range:[firstP.firstChild, 6],
rect:[firstPRect.left + 6*widthPerchar, firstPRect.left + 6*widthPerchar, rect:[spanInFirstPRect.left, spanInFirstPRect.left,
spanInFirstPRect.top, spanInFirstPRect.bottom, 0, spanInFirstPRect.height]}, spanInFirstPRect.top, spanInFirstPRect.bottom, 0, spanInFirstPRect.height]},
{name:'singleBlockNode', range:[root, 1, root, 2], rect:firstPRect}, {name:'singleBlockNode', range:[root, 1, root, 2], rect:firstPRect},
{name:'twoBlockNodes', range:[root, 1, root, 3], {name:'twoBlockNodes', range:[root, 1, root, 3],
@ -108,7 +121,7 @@ function test() {
rectList:[firstPRect, firstDivRect]}, rectList:[firstPRect, firstDivRect]},
{name:'endOfTextNodeToEndOfAnotherTextNodeInAnotherBlock', {name:'endOfTextNodeToEndOfAnotherTextNodeInAnotherBlock',
range:[spanInFirstP.firstChild, 1, firstDiv.firstChild, 5], range:[spanInFirstP.firstChild, 1, firstDiv.firstChild, 5],
rect:[firstDivRect.left, firstDivRect.left + 5*widthPerchar, rect:[spanInFirstDivRect.left - 5*widthPerchar, spanInFirstDivRect.left,
spanInFirstDivRect.top, spanInFirstDivRect.bottom, 5 * widthPerchar, spanInFirstDivRect.top, spanInFirstDivRect.bottom, 5 * widthPerchar,
spanInFirstDivRect.height]}, spanInFirstDivRect.height]},
{name:'startOfTextNodeToStartOfAnotherTextNodeInAnotherBlock', {name:'startOfTextNodeToStartOfAnotherTextNodeInAnotherBlock',
@ -117,17 +130,18 @@ function test() {
spanInFirstPRect.bottom, widthPerchar, spanInFirstPRect.height]}, spanInFirstPRect.bottom, widthPerchar, spanInFirstPRect.height]},
{name:'endPortionOfATextNode', range:[firstP.firstChild, 3, {name:'endPortionOfATextNode', range:[firstP.firstChild, 3,
firstP.firstChild, 6], firstP.firstChild, 6],
rect:[firstPRect.left + 3*widthPerchar, firstPRect.left + 6*widthPerchar, rect:[spanInFirstPRect.left - 3*widthPerchar, spanInFirstPRect.left,
spanInFirstPRect.top, spanInFirstPRect.bottom, 3*widthPerchar, spanInFirstPRect.height]}, spanInFirstPRect.top, spanInFirstPRect.bottom, 3*widthPerchar, spanInFirstPRect.height]},
{name:'startPortionOfATextNode', range:[firstP.firstChild, 0, {name:'startPortionOfATextNode', range:[firstP.firstChild, 0,
firstP.firstChild, 3], firstP.firstChild, 3],
rect:[firstPRect.left, firstPRect.left + 3*widthPerchar, spanInFirstPRect.top, rect:[spanInFirstPRect.left - 6*widthPerchar,
spanInFirstPRect.left - 3*widthPerchar, spanInFirstPRect.top,
spanInFirstPRect.bottom, 3 * widthPerchar, spanInFirstPRect.height]}, spanInFirstPRect.bottom, 3 * widthPerchar, spanInFirstPRect.height]},
{name:'spanTextNodes', range:[secondP.firstChild, 1, secondP.lastChild, 1], {name:'spanTextNodes', range:[secondP.firstChild, 1, secondP.lastChild, 1],
rect:[secondPRect.left + widthPerchar, spanInSecondPRect.right + rect:[spanInSecondPRect.left - 3*widthPerchar, spanInSecondPRect.right +
widthPerchar, spanInSecondPRect.top, spanInSecondPRect.bottom, widthPerchar, spanInSecondPRect.top, spanInSecondPRect.bottom,
spanInSecondPRect.width + 4*widthPerchar, spanInSecondPRect.height], spanInSecondPRect.width + 4*widthPerchar, spanInSecondPRect.height],
rectList:[[secondPRect.left + widthPerchar, spanInSecondPRect.left, rectList:[[spanInSecondPRect.left - 3*widthPerchar, spanInSecondPRect.left,
spanInSecondPRect.top, spanInSecondPRect.bottom, 3 * widthPerchar, spanInSecondPRect.top, spanInSecondPRect.bottom, 3 * widthPerchar,
spanInSecondPRect.height], spanInSecondPRect.height],
spanInSecondPRect, spanInSecondPRect,
@ -135,10 +149,27 @@ function test() {
spanInSecondPRect.top, spanInSecondPRect.bottom, widthPerchar, spanInSecondPRect.top, spanInSecondPRect.bottom, widthPerchar,
spanInSecondPRect.height]]} spanInSecondPRect.height]]}
]; ];
testcases.forEach(function(tc) { testcases.forEach(runATest);
runATest(tc); }
}); function testMixedDir(){
//alert(_getRect(rect)); var root = document.getElementById('mixeddir');
var firstSpan = root.firstElementChild, firstSpanRect=firstSpan.getBoundingClientRect(),
firstSpanRectList = firstSpan.getClientRects();
runATest({name:'mixeddir',range:[firstSpan.firstChild,0,firstSpan.firstChild,firstSpan.firstChild.length],
rect: firstSpanRect, rectList:firstSpanRectList});
}
function test(){
//test ltr
doTest();
testMixedDir();
isLTR = false;
var root = document.getElementById('content');
root.dir = 'rtl';
//test rtl
doTest();
testMixedDir();
SimpleTest.finish(); SimpleTest.finish();
} }