Bug 537890. Part 7: Tests for pt/pc/mm/cm/in not being physical units, and for mozmm being physical units. r=dbaron
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 13 Aug 2010 21:58:02 +1200
changeset 50789 46d18f2dabe955ce721f8b021b4f268439ca4c97
parent 50788 49429c0426d1a3e0dedbe5d2fd05da9a87150456
child 50790 a9982342b435e70b2243b4e5dbb34daf771483c2
push id15159
push userrocallahan@mozilla.com
push dateWed, 18 Aug 2010 06:06:20 +0000
treeherdermozilla-central@a27043cd19ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs537890
milestone2.0b5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 537890. Part 7: Tests for pt/pc/mm/cm/in not being physical units, and for mozmm being physical units. r=dbaron
layout/style/test/Makefile.in
layout/style/test/test_pixel_lengths.html
--- a/layout/style/test/Makefile.in
+++ b/layout/style/test/Makefile.in
@@ -153,16 +153,17 @@ GARBAGE += css_properties.js
 		test_initial_storage.html \
 		test_media_queries.html \
 		test_media_queries_dynamic.html \
 		test_media_queries_dynamic_xbl.html \
 		test_namespace_rule.html \
 		test_of_type_selectors.xhtml \
 		test_parse_rule.html \
 		test_parse_url.html \
+		test_pixel_lengths.html \
 		test_pointer-events.html \
 		test_property_database.html \
 		test_priority_preservation.html \
 		test_property_syntax_errors.html \
 		test_rem_unit.html \
 		test_selectors.html \
 		test_selectors_on_anonymous_content.html \
 		test_shorthand_property_getters.html \
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_pixel_lengths.html
@@ -0,0 +1,71 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test that pixel lengths don't change based on DPI</title>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<div id="display">
+
+<div id="pt" style="width:90pt; height:90pt; background:lime;">pt</div>
+<div id="pc" style="width:5pc; height:5pc; background:yellow;">pc</div>
+<div id="mm" style="width:25.4mm; height:25.4mm; background:orange;">mm</div>
+<div id="cm" style="width:2.54cm; height:2.54cm; background:purple;">cm</div>
+<div id="in" style="width:1in; height:1in; background:magenta;">in</div>
+
+<div id="mozmm" style="width:25.4mozmm; height:25.4mozmm; background:cyan;">mozmm</div>
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+var prefService = Components.classes["@mozilla.org/preferences-service;1"].
+                    getService(Components.interfaces.nsIPrefService);
+var branch = prefService.getBranch("layout.");
+var oldDPI = branch.getIntPref("css.dpi");
+var dpi = oldDPI;
+
+function check(id, val) {
+  var e = document.getElementById(id);
+  is(Math.round(e.getBoundingClientRect().width), Math.round(val),
+     "Checking width in " + id + " at " + dpi + " DPI");
+  is(Math.round(e.getBoundingClientRect().height), Math.round(val),
+     "Checking height in " + id + " at " + dpi + " DPI");
+}
+
+function checkPixelRelativeUnits() {
+  check("pt", 120);
+  check("pc", 80);
+  check("mm", 96);
+  check("cm", 96);
+  check("in", 96);
+}
+
+checkPixelRelativeUnits();
+
+branch.setIntPref("css.dpi", dpi = 96);
+
+var mozmm = document.getElementById("mozmm");
+var mozmmSize = mozmm.getBoundingClientRect().width;
+is(Math.round(mozmmSize), Math.round(mozmm.getBoundingClientRect().height),
+   "mozmm div should be square");
+
+checkPixelRelativeUnits();
+
+branch.setIntPref("css.dpi", dpi = 192);
+
+// At 192 dpi, a one-inch box should be twice the number of device pixels,
+// and since we haven't changed the device-pixels-per-CSS-pixel ratio, the
+// mozmm box should be twice the size in CSS pixels.
+check("mozmm", mozmmSize*2);
+checkPixelRelativeUnits();
+
+branch.setIntPref("css.dpi", oldDPI);
+
+</script>
+</pre>
+</body>
+</html>