blob: adc5072c7eb677599f738dda62080c21fbfda569 [file] [log] [blame]
<script src="../../../resources/js-test-pre.js"></script>
<style>
body {
font: 16px Ahem;
}
#base {
width: 300px;
height: 100px;
}
#border {
border: 10px solid #999;
width: 300px;
height: 100px;
}
#margin {
margin: 10px;
width: 300px;
height: 100px;
}
#transform {
-webkit-transform: translateX(50px) rotate(45deg);
width: 100px;
height: 100px;
}
#columns {
-webkit-column-count: 3;
width: 300px;
}
#inline {
display: inline;
}
#outer {
width: 100px;
height: 100px;
}
#inner {
width: 200px;
height: 200px;
}
table {
width: 300px;
}
img {
width: 100px;
height: 100px;
}
.testBox {
background-color: green;
}
#testArea {
width: 300px;
}
.bbox {
position: absolute;
outline: 5px solid rgba(255, 0, 0, .75);
}
#console {
position: absolute;
left: 500px;
}
</style>
<div id="console"></div>
<div id="testArea">
<p>1. Base</p> <div id="base" class="testBox"></div>
<p>2. Border</p> <div id="border" class="testBox"></div>
<p>3. Margin</p> <div id="margin" class="testBox"></div>
<p>4. Transform</p> <div id="transform" class="testBox"></div>
<p>5. Column</p> <div id="columns" class="testBox">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<p>6. In a column</p> <div id="columns">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.<span id="in-columns" class="testBox knownFailure">In columns</span> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<p>7. Inline</p> <div id="inline" class="testBox">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<p>8. Table</p> <table class="testBox"><tr><td>table data</td><td>table data</td></tr><tr><td>table data</td><td>table data</td></tr></table>
<p>9. Table with Caption</p> <table class="testBox"><caption>caption</caption><tr><td>table data</td><td>table data</td></tr><tr><td>table data</td><td>table data</td></tr></table>
<p>10. Table Row</p> <table><tr class="testBox"><td>table data</td><td>table data</td></tr><tr><td>table data</td><td>table data</td></tr></table>
<p>11. Table Cell</p> <table><tr><td class="testBox">table data</td><td>table data</td></tr><tr><td>table data</td><td>table data</td></tr></table>
<p>12. Big block in little</p> <div id="outer" class="testBox"><div id="inner"></div></div>
<p>13. Replaced in inline</p> <span class="testBox">Lorem<img>ipsum</span>
<p>14. Block in inline</p> <span class="testBox">Lorem<div id="inner"></div>ipsum</span>
<p>15. Float in inline</p> <span class="testBox"><img style="float:right"></span>
</div>
<script>
if (window.testRunner)
testRunner.dumpAsText();
else
alert("WARNING:\nThis test may show bogus FAILures if not run in DumpRenderTree, due to platform-specific differences in font metrics.");
function testClientRect(toTest, expectedRect)
{
rect = toTest;
shouldBeEqualToString("rect.left.toFixed(3)", expectedRect.left.toFixed(3));
shouldBeEqualToString("rect.top.toFixed(3)", expectedRect.top.toFixed(3));
shouldBeEqualToString("rect.width.toFixed(3)", expectedRect.width.toFixed(3));
shouldBeEqualToString("rect.height.toFixed(3)", expectedRect.height.toFixed(3));
shouldBe("rect.right", "rect.left + rect.width");
shouldBe("rect.bottom", "rect.top + rect.height");
debug("");
}
function addBBoxOverClientRect(rect)
{
var bbox = document.createElement('div');
bbox.className = "bbox";
var style = "";
style += "left: " + rect.left + "px;";
style += "top: " + rect.top + "px;";
style += "width: " + (rect.right - rect.left) + "px;";
style += "height: " + (rect.bottom - rect.top) + "px;";
bbox.setAttribute("style", style);
document.documentElement.appendChild(bbox);
}
var fail = undefined;
var expectedResults = [
/*1*/ { left: 8, top: 40, width: 300, height: 100 },
/*2*/ { left: 8, top: 188, width: 320, height: 120 },
/*3*/ { left: 18, top: 356, width: 300, height: 100 },
/*4*/ { left: 37.289, top: 483.289, width: 141.421, height: 141.421 },
/*5*/ { left: 8, top: 652, width: 300, height: 368 },
/*6*/ { left: fail, top: fail, width: fail, height: fail },
/*7*/ { left: 8, top: 1484, width: 288, height: 464 },
/*8*/ { left: 8, top: 1996, width: 300, height: 74 },
/*9*/ { left: 8, top: 2134, width: 300, height: 90 },
/*10*/ { left: 8, top: 2274, width: 300, height: 34 },
/*11*/ { left: 10, top: 2396, width: 147, height: 34 },
/*12*/ { left: 8, top: 2532, width: 100, height: 100 },
/*13*/ { left: 8, top: 2783, width: 260, height: 16 },
/*14*/ { left: 8, top: 2863, width: 300, height: 232 },
/*15*/ { left: 8, top: 3159, width: 0, height: 0 }
];
function test(number, element)
{
debug("Test " + number);
if (element.className.match("knownFailure")) {
debug("Known failure. Skipping.");
debug("");
return;
}
var boundingRect = element.getBoundingClientRect();
addBBoxOverClientRect(boundingRect);
testClientRect(boundingRect, expectedResults[number - 1]);
}
var tests = document.getElementsByClassName("testBox");
for (var i = 0; i < tests.length; ++i)
test(i + 1, tests[i]);
if (window.testRunner) {
var area = document.getElementById('testArea');
area.parentNode.removeChild(area);
}
</script>
<script src="../../../resources/js-test-post.js"></script>