test_computed_style.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Test for miscellaneous computed style issues</title>
  5. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  6. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  7. </head>
  8. <body>
  9. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
  10. <p id="display"></p>
  11. <div id="content" style="display: none">
  12. </div>
  13. <pre id="test">
  14. <script type="application/javascript">
  15. /** Test for miscellaneous computed style issues **/
  16. var frame_container = document.getElementById("display");
  17. var noframe_container = document.getElementById("content");
  18. (function test_bug_595650() {
  19. // Test handling of horizontal and vertical percentages for border-radius
  20. // and -moz-outline-radius.
  21. var p = document.createElement("p");
  22. p.setAttribute("style", "width: 256px; height: 128px");
  23. p.style.borderTopLeftRadius = "1.5625%"; /* 1/64 == 4px 2px */
  24. p.style.borderTopRightRadius = "5px";
  25. p.style.borderBottomRightRadius = "5px 3px";
  26. p.style.borderBottomLeftRadius = "1.5625% 3.125%" /* 1/64 1/32 == 4px 4px */
  27. p.style.MozOutlineRadiusTopleft = "1.5625%"; /* 1/64 == 4px 2px */
  28. p.style.MozOutlineRadiusTopright = "5px";
  29. p.style.MozOutlineRadiusBottomright = "5px 3px";
  30. p.style.MozOutlineRadiusBottomleft = "1.5625% 3.125%" /* 1/64 1/32 == 4px 4px */
  31. var cs = getComputedStyle(p, "");
  32. frame_container.appendChild(p);
  33. is(cs.borderTopLeftRadius, "1.5625%",
  34. "computed value of % border-radius, with frame");
  35. is(cs.borderTopRightRadius, "5px",
  36. "computed value of px border-radius, with frame");
  37. is(cs.borderBottomRightRadius, "5px 3px",
  38. "computed value of px border-radius, with frame");
  39. is(cs.borderBottomLeftRadius, "1.5625% 3.125%",
  40. "computed value of % border-radius, with frame");
  41. is(cs.MozOutlineRadiusTopleft, "1.5625%",
  42. "computed value of % outline-radius, with frame");
  43. is(cs.MozOutlineRadiusTopright, "5px",
  44. "computed value of px outline-radius, with frame");
  45. is(cs.MozOutlineRadiusBottomright, "5px 3px",
  46. "computed value of px outline-radius, with frame");
  47. is(cs.MozOutlineRadiusBottomleft, "1.5625% 3.125%",
  48. "computed value of % outline-radius, with frame");
  49. noframe_container.appendChild(p);
  50. is(cs.borderTopLeftRadius, "1.5625%",
  51. "computed value of % border-radius, without frame");
  52. is(cs.borderTopRightRadius, "5px",
  53. "computed value of px border-radius, without frame");
  54. is(cs.borderBottomRightRadius, "5px 3px",
  55. "computed value of px border-radius, without frame");
  56. is(cs.borderBottomLeftRadius, "1.5625% 3.125%",
  57. "computed value of % border-radius, without frame");
  58. is(cs.MozOutlineRadiusTopleft, "1.5625%",
  59. "computed value of % outline-radius, without frame");
  60. is(cs.MozOutlineRadiusTopright, "5px",
  61. "computed value of px outline-radius, without frame");
  62. is(cs.MozOutlineRadiusBottomright, "5px 3px",
  63. "computed value of px outline-radius, without frame");
  64. is(cs.MozOutlineRadiusBottomleft, "1.5625% 3.125%",
  65. "computed value of % outline-radius, without frame");
  66. p.parentNode.removeChild(p);
  67. })();
  68. (function test_bug_1292447() {
  69. // Was for bug 595651 which tests that clamping of border-radius
  70. // is reflected in computed style.
  71. // For compatibility issue, resolved value is computed value now.
  72. var p = document.createElement("p");
  73. p.setAttribute("style", "width: 190px; height: 90px; border: 5px solid;");
  74. p.style.borderRadius = "1000px";
  75. var cs = getComputedStyle(p, "");
  76. frame_container.appendChild(p);
  77. is(cs.borderTopLeftRadius, "1000px",
  78. "computed value of clamped border radius (top left)");
  79. is(cs.borderTopRightRadius, "1000px",
  80. "computed value of clamped border radius (top right)");
  81. is(cs.borderBottomRightRadius, "1000px",
  82. "computed value of clamped border radius (bottom right)");
  83. is(cs.borderBottomLeftRadius, "1000px",
  84. "computed value of clamped border radius (bottom left)");
  85. p.style.overflowY = "scroll";
  86. is(cs.borderTopLeftRadius, "1000px",
  87. "computed value of clamped border radius (top left, overflow-y)");
  88. // Fennec doesn't have scrollbars for overflow:scroll content
  89. if (p.clientWidth == p.offsetWidth - 10) {
  90. is(cs.borderTopRightRadius, "1000px",
  91. "computed value of border radius (top right, overflow-y)");
  92. is(cs.borderBottomRightRadius, "1000px",
  93. "computed value of border radius (bottom right, overflow-y)");
  94. } else {
  95. is(cs.borderTopRightRadius, "1000px",
  96. "computed value of clamped border radius (top right, overflow-y)");
  97. is(cs.borderBottomRightRadius, "1000px",
  98. "computed value of clamped border radius (bottom right, overflow-y)");
  99. }
  100. is(cs.borderBottomLeftRadius, "1000px",
  101. "computed value of clamped border radius (bottom left, overflow-y)");
  102. p.style.overflowY = "hidden";
  103. p.style.overflowX = "scroll";
  104. is(cs.borderTopLeftRadius, "1000px",
  105. "computed value of clamped border radius (top left, overflow-x)");
  106. is(cs.borderTopRightRadius, "1000px",
  107. "computed value of clamped border radius (top right, overflow-x)");
  108. // Fennec doesn't have scrollbars for overflow:scroll content
  109. if (p.clientHeight == p.offsetHeight - 10) {
  110. is(cs.borderBottomRightRadius, "1000px",
  111. "computed value of border radius (bottom right, overflow-x)");
  112. is(cs.borderBottomLeftRadius, "1000px",
  113. "computed value of border radius (bottom left, overflow-x)");
  114. } else {
  115. is(cs.borderBottomRightRadius, "1000px",
  116. "computed value of clamped border radius (bottom right, overflow-x)");
  117. is(cs.borderBottomLeftRadius, "1000px",
  118. "computed value of clamped border radius (bottom left, overflow-x)");
  119. }
  120. p.parentNode.removeChild(p);
  121. })();
  122. (function test_bug_647885_1() {
  123. // Test that various background-position styles round-trip correctly
  124. var backgroundPositions = [
  125. [ "0 0", "0px 0px", "unitless 0" ],
  126. [ "0px 0px", "0px 0px", "0 with units" ],
  127. [ "0% 0%", "0% 0%", "0%" ],
  128. [ "calc(0px) 0", "0px 0px", "0 calc with units x" ],
  129. [ "0 calc(0px)", "0px 0px", "0 calc with units y" ],
  130. [ "calc(3px - 3px) 0", "0px 0px", "computed 0 calc with units x" ],
  131. [ "0 calc(3px - 3px)", "0px 0px", "computed 0 calc with units y" ],
  132. [ "calc(0%) 0", "0% 0px", "0% calc x"],
  133. [ "0 calc(0%)", "0px 0%", "0% calc y"],
  134. [ "calc(3px + 2% - 2%) 0", "calc(3px + 0%) 0px",
  135. "computed 0% calc x"],
  136. [ "0 calc(3px + 2% - 2%)", "0px calc(3px + 0%)",
  137. "computed 0% calc y"],
  138. [ "calc(3px - 5px) calc(6px - 7px)", "-2px -1px",
  139. "negative pixel width"],
  140. [ "", "0% 0%", "initial value" ],
  141. ];
  142. var p = document.createElement("p");
  143. var cs = getComputedStyle(p, "");
  144. frame_container.appendChild(p);
  145. for (var i = 0; i < backgroundPositions.length; ++i) {
  146. var test = backgroundPositions[i];
  147. p.style.backgroundPosition = test[0];
  148. is(cs.backgroundPosition, test[1], "computed value of " + test[2] + " background-position");
  149. }
  150. p.parentNode.removeChild(p);
  151. })();
  152. (function test_bug_647885_2() {
  153. // Test that various background-size styles round-trip correctly
  154. var backgroundSizes = [
  155. [ "0 0", "0px 0px", "unitless 0" ],
  156. [ "0px 0px", "0px 0px", "0 with units" ],
  157. [ "0% 0%", "0% 0%", "0%" ],
  158. [ "calc(0px) 0", "0px 0px", "0 calc with units horizontal" ],
  159. [ "0 calc(0px)", "0px 0px", "0 calc with units vertical" ],
  160. [ "calc(3px - 3px) 0", "0px 0px", "computed 0 calc with units horizontal" ],
  161. [ "0 calc(3px - 3px)", "0px 0px", "computed 0 calc with units vertical" ],
  162. [ "calc(0%) 0", "0% 0px", "0% calc horizontal"],
  163. [ "0 calc(0%)", "0px 0%", "0% calc vertical"],
  164. [ "calc(3px + 2% - 2%) 0", "calc(3px + 0%) 0px",
  165. "computed 0% calc horizontal"],
  166. [ "0 calc(3px + 2% - 2%)", "0px calc(3px + 0%)",
  167. "computed 0% calc vertical"],
  168. [ "calc(3px - 5px) calc(6px - 9px)",
  169. "calc(-2px) calc(-3px)", "negative pixel width" ],
  170. [ "", "auto auto", "initial value" ],
  171. ];
  172. var p = document.createElement("p");
  173. var cs = getComputedStyle(p, "");
  174. frame_container.appendChild(p);
  175. for (var i = 0; i < backgroundSizes.length; ++i) {
  176. var test = backgroundSizes[i];
  177. p.style.backgroundSize = test[0];
  178. is(cs.backgroundSize, test[1], "computed value of " + test[2] + " background-size");
  179. }
  180. p.parentNode.removeChild(p);
  181. })();
  182. (function test_bug_716628() {
  183. // Test that various gradient styles round-trip correctly
  184. var backgroundImages = [
  185. [ "-moz-radial-gradient(10% bottom, #ffffff, black)",
  186. "radial-gradient(at 10% 100%, rgb(255, 255, 255), rgb(0, 0, 0))",
  187. "radial gradient 1" ],
  188. [ "-moz-radial-gradient(#ffffff, black)",
  189. "radial-gradient(rgb(255, 255, 255), rgb(0, 0, 0))",
  190. "radial gradient 2" ],
  191. [ "-moz-radial-gradient(cover, #ffffff, black)",
  192. "radial-gradient(rgb(255, 255, 255), rgb(0, 0, 0))",
  193. "radial gradient 3" ],
  194. [ "-moz-radial-gradient(top left -45deg, #ffffff, black)",
  195. "-moz-radial-gradient(0% 0% -45deg, rgb(255, 255, 255), rgb(0, 0, 0))",
  196. "radial gradient with angle in degrees" ],
  197. [ "-moz-linear-gradient(red, blue)",
  198. "linear-gradient(rgb(255, 0, 0), rgb(0, 0, 255))",
  199. "linear gradient 1" ],
  200. [ "-moz-linear-gradient(to bottom, red, blue)",
  201. "linear-gradient(rgb(255, 0, 0), rgb(0, 0, 255))",
  202. "linear gradient 2" ],
  203. [ "-moz-linear-gradient(to right, red, blue)",
  204. "linear-gradient(to right, rgb(255, 0, 0), rgb(0, 0, 255))",
  205. "linear gradient 3" ],
  206. [ "-moz-linear-gradient(10px 10px -45deg, red, blue)",
  207. "-moz-linear-gradient(10px 10px -45deg, rgb(255, 0, 0), rgb(0, 0, 255))",
  208. "linear gradient with angle in degrees" ],
  209. [ "-moz-linear-gradient(10px 10px -0.125turn, red, blue)",
  210. "-moz-linear-gradient(10px 10px -0.125turn, rgb(255, 0, 0), rgb(0, 0, 255))",
  211. "linear gradient with angle in turns" ],
  212. ];
  213. var p = document.createElement("p");
  214. var cs = getComputedStyle(p, "");
  215. frame_container.appendChild(p);
  216. for (var i = 0; i < backgroundImages.length; ++i) {
  217. var test = backgroundImages[i];
  218. p.style.backgroundImage = test[0];
  219. is(cs.backgroundImage, test[1], "computed value of " + test[2] + " background-image");
  220. }
  221. p.parentNode.removeChild(p);
  222. })();
  223. (function test_bug_1235015() {
  224. if (!("maskImage" in document.documentElement.style)) {
  225. return;
  226. }
  227. // "masks" object contains non-initial mask longhand values.
  228. var emptyMasks = {
  229. // More then one <mask-reference>, or any mask-image value other then
  230. // <mask-source>,
  231. "mask-image": [
  232. "url(#mask1), url(#mask2)",
  233. "linear-gradient(red, yellow)",
  234. "-moz-element(#test)"
  235. ],
  236. // any mask-clip value other than "border-box".
  237. "mask-clip": [
  238. "content-box", "padding-box", "margin-box", "fill-box", "stroke-box",
  239. "view-box", "no-clip"
  240. ],
  241. // any mask-origin value other than "border-box".
  242. "mask-origin": [
  243. "content-box", "padding-box", "margin-box", "fill-box", "stroke-box",
  244. "view-box"
  245. ],
  246. // any mask-composite value other than "add".
  247. "mask-composite": [
  248. "subtract", "intersect", "exclude"
  249. ],
  250. // any mask-mode value other than "match-source".
  251. "mask-mode": [
  252. "alpha", "luminance"
  253. ],
  254. // any mask-position value other then "0%" "top" "left"
  255. // "center center".
  256. "mask-position": [
  257. "0%", "center", "right", "bottom", "50%", "100%"
  258. ],
  259. // any mask-repeat value other then "repeat" "repeat repeat".
  260. "mask-repeat": [
  261. "repeat-x", "repeat-y", "no-repeat", "space", "round"
  262. ],
  263. // any mask-size value other then "auto" "auto auto".
  264. "mask-size": [
  265. "10px", "100%", "cover", "contain", "auto 5px"
  266. ],
  267. };
  268. // "masks" object contains initial mask longhand values.
  269. var nonEmptyMasks = {
  270. "mask-image": [
  271. "url(#mask1)", "none"
  272. ],
  273. "mask-clip": [
  274. "border-box"
  275. ],
  276. "mask-origin": [
  277. "border-box"
  278. ],
  279. "mask-composite": [
  280. "add"
  281. ],
  282. "mask-mode": [
  283. "match-source"
  284. ],
  285. "mask-position": [
  286. "0% 0%", "left top"
  287. ],
  288. "mask-repeat": [
  289. "repeat", "repeat repeat"
  290. ],
  291. "mask-size": [
  292. "auto", "auto auto"
  293. ],
  294. };
  295. var p = document.createElement("p");
  296. var cs = getComputedStyle(p, "");
  297. frame_container.appendChild(p);
  298. for (var prop in emptyMasks) {
  299. var subProp = emptyMasks[prop];
  300. for (var i = 0; i < subProp.length; i++) {
  301. p.style.mask = subProp[i];
  302. is(cs.mask, "", "computed value of " + subProp[i] + " mask");
  303. }
  304. }
  305. for (var prop in nonEmptyMasks) {
  306. var subProp = nonEmptyMasks[prop];
  307. for (var i = 0; i < subProp.length; i++) {
  308. p.style.mask = subProp[i];
  309. isnot(cs.mask, "", "computed value of " + subProp[i] + " mask");
  310. }
  311. }
  312. p.parentNode.removeChild(p);
  313. })();
  314. (function test_bug_1293164() {
  315. var p = document.createElement("p");
  316. var cs = getComputedStyle(p, "");
  317. frame_container.appendChild(p);
  318. var docPath = document.URL.substring(0, document.URL.lastIndexOf("/") + 1);
  319. var localURL = "url(\"#foo\")";
  320. var nonLocalURL = "url(\"foo.svg#foo\")";
  321. var resolvedNonLocalURL = "url(\"" + docPath + "foo.svg#foo\")";
  322. var testStyles = {
  323. "mask" : "",
  324. "markerStart" : "",
  325. "markerMid" : "",
  326. "markerEnd" : "",
  327. "clipPath" : "",
  328. "filter" : "",
  329. "fill" : " transparent",
  330. "stroke" : " transparent",
  331. };
  332. for (var prop in testStyles) {
  333. p.style[prop] = localURL;
  334. is(cs[prop], localURL + testStyles[prop], "computed value of " + prop);
  335. p.style[prop] = nonLocalURL;
  336. is(cs[prop], resolvedNonLocalURL + testStyles[prop], "computed value of " + prop);
  337. }
  338. p.parentNode.removeChild(p);
  339. })();
  340. (function test_bug_1347164() {
  341. // Test that computed color values are serialized as "rgb()"
  342. // IFF they're fully-opaque (and otherwise as "rgba()").
  343. var color = [
  344. ["rgba(0, 0, 0, 1)", "rgb(0, 0, 0)"],
  345. ["rgba(0, 0, 0, 0.5)", "rgba(0, 0, 0, 0.5)"],
  346. ["hsla(0, 0%, 0%, 1)", "rgb(0, 0, 0)"],
  347. ["hsla(0, 0%, 0%, 0.5)", "rgba(0, 0, 0, 0.5)"],
  348. // css-color-4
  349. ["rgba(0 0 0 / 1)", "rgb(0, 0, 0)"],
  350. ["rgba(0 0 0 / 0.5)", "rgba(0, 0, 0, 0.5)"],
  351. ["rgb(0 0 0 / 1)", "rgb(0, 0, 0)"],
  352. ["rgb(0 0 0 / 0.5)", "rgba(0, 0, 0, 0.5)"],
  353. ["hsla(0 0% 0% / 1)", "rgb(0, 0, 0)"],
  354. ["hsla(0deg 0% 0% / 0.5)", "rgba(0, 0, 0, 0.5)"],
  355. ["hsl(0 0% 0% / 1)", "rgb(0, 0, 0)"],
  356. ["hsl(0 0% 0% / 0.5)", "rgba(0, 0, 0, 0.5)"],
  357. ];
  358. var p = document.createElement("p");
  359. var cs = getComputedStyle(p, "");
  360. frame_container.appendChild(p);
  361. for (var i = 0; i < color.length; ++i) {
  362. var test = color[i];
  363. p.style.color = test[0];
  364. is(cs.color, test[1], "computed value of " + test[0]);
  365. }
  366. p.remove();
  367. })();
  368. </script>
  369. </pre>
  370. </body>
  371. </html>