3 <script src=
"../../../resources/js-test.js"></script>
5 .visible { position: absolute; }
6 .hidden { position: relative; display: none; }
10 <div id=
"test">Tests that getComputedStyle returns length properties with a unit.
</div>
11 <div id=
"console"></div>
13 var propertiesToCheck
= {
14 "background-position": "10px 10px",
15 "background-size": "400px 300px",
16 "-webkit-border-horizontal-spacing": "10px",
17 "-webkit-border-vertical-spacing": "10px",
19 "border-top-width": "2px",
20 "border-right-width": "2px",
21 "border-bottom-width": "2px",
22 "border-left-width": "2px",
23 "border-top-left-radius": "5px",
24 "border-top-right-radius": "5px",
25 "border-bottom-left-radius": "5px",
26 "border-bottom-right-radius": "5px",
28 "outline-width": "2px",
30 "-webkit-column-rule-width": "10px",
31 "-webkit-column-width": "80px",
32 "-webkit-column-gap": "20px",
34 "-webkit-mask-position": "10px 10px",
35 "-webkit-mask-size": "10px 10px",
36 "-webkit-perspective": "400px",
37 "-webkit-perspective-origin": "20px 20px",
38 "-webkit-text-stroke-width": "2px",
39 "-webkit-transform-origin": "10px 10px",
51 "max-height": "600px",
52 "min-height": "200px",
53 "letter-spacing": "2px",
54 "word-spacing": "10px",
57 "margin-right": "10px",
58 "margin-bottom": "10px",
59 "margin-left": "10px",
61 "padding-top": "10px",
62 "padding-right": "10px",
63 "padding-bottom": "10px",
64 "padding-left": "10px",
69 var testElement
= document
.getElementById('test');
70 for (var propertyName
in propertiesToCheck
)
71 testElement
.style
[propertyName
] = propertiesToCheck
[propertyName
];
73 function testPropertyUnit(className
, propertyName
)
75 if (testElement
.className
!= className
)
76 testElement
.className
= className
;
77 var computedStyled
= document
.defaultView
.getComputedStyle(testElement
);
78 var results
= /\d+([a-z%]+)/.exec(computedStyled
[propertyName
]);
79 return results
? results
[1] : '';
82 for (var propertyName
in propertiesToCheck
)
83 shouldBe("testPropertyUnit('visible', '" + propertyName
+ "')", "'px'");
84 for (var propertyName
in propertiesToCheck
)
85 shouldBe("testPropertyUnit('hidden', '" + propertyName
+ "')", "'px'");
87 for (var propertyName
in propertiesToCheck
)
88 testElement
.style
[propertyName
] = '';