blob: 68b9678a6248c8b45a5b96cb353086eb2a3727d6 [file] [log] [blame]
<!DOCTYPE HTML>
<style>
.width-test {
height: 100px;
width: 256px;
background-color: red;
}
.height-test {
width: 100px;
height: 50px;
background-color: red;
}
</style>
<p>
All boxes below should be 100px * 100px and green.
</p>
<div id="test">
<div style="width:100px; height:100px;">control</div>
<div class="width-test" style="width: calc(50px + 50px);">50px + 50px</div>
<div class="width-test" style="width: calc(150px - 50px);">150px - 50px</div>
<div class="width-test" style="width: calc(50px + 50px);">50px + 50px (2 spaces around operator)</div>
<div class="width-test" style="width: calc(150px - 50px);">150px - 50px (2 spaces around operator)</div>
<div class="width-test" style="width: calc(50px*2);">50px*2</div>
<div class="width-test" style="width: calc(50px *2);">50px *2</div>
<div class="width-test" style="width: calc(50px* 2);">50px* 2</div>
<div class="width-test" style="width: calc(200px/2);">200px/2</div>
<div class="width-test" style="width: calc(200px /2);">200px /2</div>
<div class="width-test" style="width: calc(200px/ 2);">200px/ 2</div>
<div class="width-test" style="width: calc(50px*(2));">50px*(2)</div>
<div class="width-test" style="width: calc(50px *(2));">50px *(2)</div>
<div class="width-test" style="width: calc(50px* (2));">50px* (2)</div>
<div class="width-test" style="width: calc(50px*(1 + 1));">50px*(1 + 1)</div>
<div class="width-test" style="width: calc(50px*(12 - 10));">50px*(12 - 10)</div>
<div class="width-test" style="width: calc(50px*(10 / 5));">50px*(10 / 5)</div>
<div class="width-test" style="width: calc(10px* (5 * 2));">10px* (5 * 2)</div>
<div class="width-test" style="width: calc(50px + 10px * 5);">50px + 10px * 5 (operation order)</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(100%/2);">100%/2 (where 100% is 200px)</div>
</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(100% + -100px);">100% + -100px (where 100% is 200px)</div>
</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(80% - 60px);">80% - 60px (where 100% is 200px)</div>
</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(300px - 100%);">300px - 100% (where 100% is 200px)</div>
</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(-100px + 100%);">-100px + 100% (where 100% is 200px)</div>
</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(20% + 30%);">20% + 30% (where 100% is 200px)</div>
</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(80% - 30%);">80% - 30% (where 100% is 200px)</div>
</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(10% * 5);">10% * 5 (where 100% is 200px)</div>
</div>
<div style="width: 200px; background-color: white;" class="wrapper">
<div class="width-test" style="width: calc(5 * 10%);">5 * 10% (where 100% is 200px)</div>
</div>
<div class="width-test" style="width: calc((100px));">(100px)</div>
<div class="width-test" style="width: calc((50px + 50px));">(50px + 50px)</div>
<div class="width-test" style="width: calc((50px) + 50px);">(50px) + 50px</div>
<div class="width-test" style="width: calc(50px + (50px));">50px + (50px)</div>
<div class="width-test" style="width: calc( 50px + 50px );"> 50px + 50px </div>
<div class="width-test" style="width: calc( 50px + 25px * 2 );"> 50px + 25px * 2 </div>
<div class="width-test" style="width: calc( (25px + 25px) * 2 );"> (25px + 25px) * 2 </div>
<div class="width-test" style="width: calc(2 * 50px);">2 * 50px</div>
<div class="width-test" style="width: calc(2 * 100px / 2);">2 * 100px / 2</div>
<div class="width-test" style="width: calc((1em - 1em) + 100px);">(1em - 1em) + 100px</div>
<div class="width-test" style="width: calc(50px + +50px);">50px + +50px</div>
<div class="width-test" style="width: calc(-50px + 150px);">-50px + 150px</div>
<div class="width-test" style="width: calc(-50px - -150px);">-50px - -150px</div>
<div class="width-test" style="width: calc((((((((100px))))))));">(((((((100px)))))))</div>
<div class="width-test" style="width: calc(( 50px + 50px ));"> 50px + 50px </div>
<div class="height-test" style="height: calc(100px);">100px</div>
<div style="height: 50px; background-color: white;" class="wrapper">
<div class="height-test" style="height: calc(100% * 2);">100% * 2</div>
</div>
</div>
<script>
if (window.testRunner)
testRunner.dumpAsText();
var tolerance = 0.1;
zoomLevels = [1, 1.2, 2];
var test = document.getElementById("test");
for (var child = test.firstElementChild; child; child = child.nextElementSibling) {
var element = child;
if (element.className == "wrapper") {
element = element.firstChild;
while (element.tagName != "DIV") element = element.nextElementSibling;
}
var error = [];
for (var z = 0; z < zoomLevels.length; z++) {
var zoom = zoomLevels[z];
document.body.style.zoom = zoom;
var width = element.offsetWidth;
if (Math.abs(100 - width) > tolerance)
error.push("@zoom=" + zoom + " expected width of 100, but was " + width);
var height = element.offsetHeight;
if (Math.abs(100 - height) > tolerance)
error.push("@zoom=" + zoom + " expected height of 100, but was " + height);
}
if (error == "") {
element.style.backgroundColor = "green";
element.innerHTML += " => PASS";
} else
element.innerHTML += " => FAIL: " + error.join("; ");
}
document.body.style.zoom = 1;
</script>