layout/style/test/test_computed_style.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for miscellaneous computed style issues</title>
michael@0 5 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 7 </head>
michael@0 8 <body>
michael@0 9 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
michael@0 10 <p id="display"></p>
michael@0 11 <div id="content" style="display: none">
michael@0 12
michael@0 13 </div>
michael@0 14 <pre id="test">
michael@0 15 <script type="application/javascript">
michael@0 16
michael@0 17 /** Test for miscellaneous computed style issues **/
michael@0 18
michael@0 19 var frame_container = document.getElementById("display");
michael@0 20 var noframe_container = document.getElementById("content");
michael@0 21
michael@0 22 (function test_bug_595650() {
michael@0 23 // Test handling of horizontal and vertical percentages for border-radius
michael@0 24 // and -moz-outline-radius.
michael@0 25 var p = document.createElement("p");
michael@0 26 p.setAttribute("style", "width: 256px; height: 128px");
michael@0 27 p.style.borderTopLeftRadius = "1.5625%"; /* 1/64 == 4px 2px */
michael@0 28 p.style.borderTopRightRadius = "5px";
michael@0 29 p.style.borderBottomRightRadius = "5px 3px";
michael@0 30 p.style.borderBottomLeftRadius = "1.5625% 3.125%" /* 1/64 1/32 == 4px 4px */
michael@0 31 p.style.MozOutlineRadiusTopleft = "1.5625%"; /* 1/64 == 4px 2px */
michael@0 32 p.style.MozOutlineRadiusTopright = "5px";
michael@0 33 p.style.MozOutlineRadiusBottomright = "5px 3px";
michael@0 34 p.style.MozOutlineRadiusBottomleft = "1.5625% 3.125%" /* 1/64 1/32 == 4px 4px */
michael@0 35 var cs = getComputedStyle(p, "");
michael@0 36
michael@0 37 frame_container.appendChild(p);
michael@0 38 is(cs.borderTopLeftRadius, "4px 2px",
michael@0 39 "computed value of % border-radius, with frame");
michael@0 40 is(cs.borderTopRightRadius, "5px",
michael@0 41 "computed value of px border-radius, with frame");
michael@0 42 is(cs.borderBottomRightRadius, "5px 3px",
michael@0 43 "computed value of px border-radius, with frame");
michael@0 44 is(cs.borderBottomLeftRadius, "4px",
michael@0 45 "computed value of % border-radius, with frame");
michael@0 46 is(cs.MozOutlineRadiusTopleft, "4px 2px",
michael@0 47 "computed value of % outline-radius, with frame");
michael@0 48 is(cs.MozOutlineRadiusTopright, "5px",
michael@0 49 "computed value of px outline-radius, with frame");
michael@0 50 is(cs.MozOutlineRadiusBottomright, "5px 3px",
michael@0 51 "computed value of px outline-radius, with frame");
michael@0 52 is(cs.MozOutlineRadiusBottomleft, "4px",
michael@0 53 "computed value of % outline-radius, with frame");
michael@0 54
michael@0 55 noframe_container.appendChild(p);
michael@0 56 is(cs.borderTopLeftRadius, "1.5625%",
michael@0 57 "computed value of % border-radius, without frame");
michael@0 58 is(cs.borderTopRightRadius, "5px",
michael@0 59 "computed value of px border-radius, without frame");
michael@0 60 is(cs.borderBottomRightRadius, "5px 3px",
michael@0 61 "computed value of px border-radius, without frame");
michael@0 62 is(cs.borderBottomLeftRadius, "1.5625% 3.125%",
michael@0 63 "computed value of % border-radius, without frame");
michael@0 64 is(cs.MozOutlineRadiusTopleft, "1.5625%",
michael@0 65 "computed value of % outline-radius, without frame");
michael@0 66 is(cs.MozOutlineRadiusTopright, "5px",
michael@0 67 "computed value of px outline-radius, without frame");
michael@0 68 is(cs.MozOutlineRadiusBottomright, "5px 3px",
michael@0 69 "computed value of px outline-radius, without frame");
michael@0 70 is(cs.MozOutlineRadiusBottomleft, "1.5625% 3.125%",
michael@0 71 "computed value of % outline-radius, without frame");
michael@0 72
michael@0 73 p.parentNode.removeChild(p);
michael@0 74 })();
michael@0 75
michael@0 76 (function test_bug_595651() {
michael@0 77 // Test that clamping of border-radius is reflected in computed style.
michael@0 78 var p = document.createElement("p");
michael@0 79 p.setAttribute("style", "width: 190px; height: 90px; border: 5px solid;");
michael@0 80 p.style.borderRadius = "1000px";
michael@0 81 var cs = getComputedStyle(p, "");
michael@0 82
michael@0 83 frame_container.appendChild(p);
michael@0 84 is(cs.borderTopLeftRadius, "50px",
michael@0 85 "computed value of clamped border radius (top left)");
michael@0 86 is(cs.borderTopRightRadius, "50px",
michael@0 87 "computed value of clamped border radius (top right)");
michael@0 88 is(cs.borderBottomRightRadius, "50px",
michael@0 89 "computed value of clamped border radius (bottom right)");
michael@0 90 is(cs.borderBottomLeftRadius, "50px",
michael@0 91 "computed value of clamped border radius (bottom left)");
michael@0 92
michael@0 93 p.style.overflowY = "scroll";
michael@0 94 is(cs.borderTopLeftRadius, "50px",
michael@0 95 "computed value of clamped border radius (top left, overflow-y)");
michael@0 96 // Fennec doesn't have scrollbars for overflow:scroll content
michael@0 97 if (p.clientWidth == p.offsetWidth - 10) {
michael@0 98 is(cs.borderTopRightRadius, "50px",
michael@0 99 "computed value of border radius (top right, overflow-y)");
michael@0 100 is(cs.borderBottomRightRadius, "50px",
michael@0 101 "computed value of border radius (bottom right, overflow-y)");
michael@0 102 } else {
michael@0 103 is(cs.borderTopRightRadius, "5px",
michael@0 104 "computed value of clamped border radius (top right, overflow-y)");
michael@0 105 is(cs.borderBottomRightRadius, "5px",
michael@0 106 "computed value of clamped border radius (bottom right, overflow-y)");
michael@0 107 }
michael@0 108 is(cs.borderBottomLeftRadius, "50px",
michael@0 109 "computed value of clamped border radius (bottom left, overflow-y)");
michael@0 110
michael@0 111 p.style.overflowY = "hidden";
michael@0 112 p.style.overflowX = "scroll";
michael@0 113 is(cs.borderTopLeftRadius, "50px",
michael@0 114 "computed value of clamped border radius (top left, overflow-x)");
michael@0 115 is(cs.borderTopRightRadius, "50px",
michael@0 116 "computed value of clamped border radius (top right, overflow-x)");
michael@0 117 // Fennec doesn't have scrollbars for overflow:scroll content
michael@0 118 if (p.clientHeight == p.offsetHeight - 10) {
michael@0 119 is(cs.borderBottomRightRadius, "50px",
michael@0 120 "computed value of border radius (bottom right, overflow-x)");
michael@0 121 is(cs.borderBottomLeftRadius, "50px",
michael@0 122 "computed value of border radius (bottom left, overflow-x)");
michael@0 123 } else {
michael@0 124 is(cs.borderBottomRightRadius, "5px",
michael@0 125 "computed value of clamped border radius (bottom right, overflow-x)");
michael@0 126 is(cs.borderBottomLeftRadius, "5px",
michael@0 127 "computed value of clamped border radius (bottom left, overflow-x)");
michael@0 128 }
michael@0 129
michael@0 130 p.parentNode.removeChild(p);
michael@0 131 })();
michael@0 132
michael@0 133 (function test_bug_647885_1() {
michael@0 134 // Test that various background-position styles round-trip correctly
michael@0 135 var backgroundPositions = [
michael@0 136 [ "0 0", "0px 0px", "unitless 0" ],
michael@0 137 [ "0px 0px", "0px 0px", "0 with units" ],
michael@0 138 [ "0% 0%", "0% 0%", "0%" ],
michael@0 139 [ "calc(0px) 0", "0px 0px", "0 calc with units x" ],
michael@0 140 [ "0 calc(0px)", "0px 0px", "0 calc with units y" ],
michael@0 141 [ "calc(3px - 3px) 0", "0px 0px", "computed 0 calc with units x" ],
michael@0 142 [ "0 calc(3px - 3px)", "0px 0px", "computed 0 calc with units y" ],
michael@0 143 [ "calc(0%) 0", "0% 0px", "0% calc x"],
michael@0 144 [ "0 calc(0%)", "0px 0%", "0% calc y"],
michael@0 145 [ "calc(3px + 2% - 2%) 0", "calc(3px + 0%) 0px",
michael@0 146 "computed 0% calc x"],
michael@0 147 [ "0 calc(3px + 2% - 2%)", "0px calc(3px + 0%)",
michael@0 148 "computed 0% calc y"],
michael@0 149 [ "calc(3px - 5px) calc(6px - 7px)", "-2px -1px",
michael@0 150 "negative pixel width"],
michael@0 151 [ "", "0% 0%", "initial value" ],
michael@0 152 ];
michael@0 153
michael@0 154 var p = document.createElement("p");
michael@0 155 var cs = getComputedStyle(p, "");
michael@0 156 frame_container.appendChild(p);
michael@0 157
michael@0 158 for (var i = 0; i < backgroundPositions.length; ++i) {
michael@0 159 var test = backgroundPositions[i];
michael@0 160 p.style.backgroundPosition = test[0];
michael@0 161 is(cs.backgroundPosition, test[1], "computed value of " + test[2] + " background-position");
michael@0 162 }
michael@0 163
michael@0 164 p.parentNode.removeChild(p);
michael@0 165 })();
michael@0 166
michael@0 167 (function test_bug_647885_2() {
michael@0 168 // Test that various background-size styles round-trip correctly
michael@0 169 var backgroundSizes = [
michael@0 170 [ "0 0", "0px 0px", "unitless 0" ],
michael@0 171 [ "0px 0px", "0px 0px", "0 with units" ],
michael@0 172 [ "0% 0%", "0% 0%", "0%" ],
michael@0 173 [ "calc(0px) 0", "0px 0px", "0 calc with units horizontal" ],
michael@0 174 [ "0 calc(0px)", "0px 0px", "0 calc with units vertical" ],
michael@0 175 [ "calc(3px - 3px) 0", "0px 0px", "computed 0 calc with units horizontal" ],
michael@0 176 [ "0 calc(3px - 3px)", "0px 0px", "computed 0 calc with units vertical" ],
michael@0 177 [ "calc(0%) 0", "0% 0px", "0% calc horizontal"],
michael@0 178 [ "0 calc(0%)", "0px 0%", "0% calc vertical"],
michael@0 179 [ "calc(3px + 2% - 2%) 0", "calc(3px + 0%) 0px",
michael@0 180 "computed 0% calc horizontal"],
michael@0 181 [ "0 calc(3px + 2% - 2%)", "0px calc(3px + 0%)",
michael@0 182 "computed 0% calc vertical"],
michael@0 183 [ "calc(3px - 5px) calc(6px - 9px)",
michael@0 184 "calc(-2px) calc(-3px)", "negative pixel width" ],
michael@0 185 [ "", "auto auto", "initial value" ],
michael@0 186 ];
michael@0 187
michael@0 188 var p = document.createElement("p");
michael@0 189 var cs = getComputedStyle(p, "");
michael@0 190 frame_container.appendChild(p);
michael@0 191
michael@0 192 for (var i = 0; i < backgroundSizes.length; ++i) {
michael@0 193 var test = backgroundSizes[i];
michael@0 194 p.style.backgroundSize = test[0];
michael@0 195 is(cs.backgroundSize, test[1], "computed value of " + test[2] + " background-size");
michael@0 196 }
michael@0 197
michael@0 198 p.parentNode.removeChild(p);
michael@0 199 })();
michael@0 200
michael@0 201 (function test_bug_716628() {
michael@0 202 // Test that various gradient styles round-trip correctly
michael@0 203 var backgroundImages = [
michael@0 204 [ "-moz-radial-gradient(10% bottom, #ffffff, black)",
michael@0 205 "radial-gradient(at 10% 100%, rgb(255, 255, 255), rgb(0, 0, 0))",
michael@0 206 "radial gradient 1" ],
michael@0 207 [ "-moz-radial-gradient(#ffffff, black)",
michael@0 208 "radial-gradient(rgb(255, 255, 255), rgb(0, 0, 0))",
michael@0 209 "radial gradient 2" ],
michael@0 210 [ "-moz-radial-gradient(cover, #ffffff, black)",
michael@0 211 "radial-gradient(rgb(255, 255, 255), rgb(0, 0, 0))",
michael@0 212 "radial gradient 3" ],
michael@0 213 [ "-moz-radial-gradient(top left -45deg, #ffffff, black)",
michael@0 214 "-moz-radial-gradient(0% 0% -45deg, rgb(255, 255, 255), rgb(0, 0, 0))",
michael@0 215 "radial gradient with angle in degrees" ],
michael@0 216 [ "-moz-linear-gradient(red, blue)",
michael@0 217 "linear-gradient(rgb(255, 0, 0), rgb(0, 0, 255))",
michael@0 218 "linear gradient 1" ],
michael@0 219 [ "-moz-linear-gradient(to bottom, red, blue)",
michael@0 220 "linear-gradient(rgb(255, 0, 0), rgb(0, 0, 255))",
michael@0 221 "linear gradient 2" ],
michael@0 222 [ "-moz-linear-gradient(to right, red, blue)",
michael@0 223 "linear-gradient(to right, rgb(255, 0, 0), rgb(0, 0, 255))",
michael@0 224 "linear gradient 3" ],
michael@0 225 [ "-moz-linear-gradient(10px 10px -45deg, red, blue)",
michael@0 226 "-moz-linear-gradient(10px 10px -45deg, rgb(255, 0, 0), rgb(0, 0, 255))",
michael@0 227 "linear gradient with angle in degrees" ],
michael@0 228 [ "-moz-linear-gradient(10px 10px -0.125turn, red, blue)",
michael@0 229 "-moz-linear-gradient(10px 10px -0.125turn, rgb(255, 0, 0), rgb(0, 0, 255))",
michael@0 230 "linear gradient with angle in turns" ],
michael@0 231 ];
michael@0 232
michael@0 233 var p = document.createElement("p");
michael@0 234 var cs = getComputedStyle(p, "");
michael@0 235 frame_container.appendChild(p);
michael@0 236
michael@0 237 for (var i = 0; i < backgroundImages.length; ++i) {
michael@0 238 var test = backgroundImages[i];
michael@0 239 p.style.backgroundImage = test[0];
michael@0 240 is(cs.backgroundImage, test[1], "computed value of " + test[2] + " background-image");
michael@0 241 }
michael@0 242
michael@0 243 p.parentNode.removeChild(p);
michael@0 244 })();
michael@0 245 </script>
michael@0 246 </pre>
michael@0 247 </body>
michael@0 248 </html>

mercurial