4 <script src=
"../../resources/js-test.js"></script>
6 .test { position: absolute; width:
50px; left:
25px; }
11 Test handling of numbers outside of the supported range.
14 <q cite=
"http://www.w3.org/TR/css3-values/#numeric-types">Properties may restrict numeric values to some range. If the value is outside the allowed range, the declaration is invalid and must be ignored.
</q>
15 As per the
<a href=
"http://www.w3.org/TR/css3-values/#numeric-types">CSS3 specification
</a>.
18 function testSize(width
, opt_expectedWidth
)
20 var expectedWidth
= typeof opt_expectedWidth
== 'number' ? opt_expectedWidth
: width
;
22 el
.style
.width
= width
+ 'px';
24 var style
= window
.getComputedStyle(el
, null);
25 var rect
= el
.getBoundingClientRect();
26 if (el
.offsetWidth
== expectedWidth
&& rect
.width
== expectedWidth
)
27 testPassed('element.width = ' + width
+ 'px, returns offsetWidth, rect.width expected.');
29 testFailed('element.width = ' + width
+ 'px, returns offsetWidth ' + el
.offsetWidth
+ ', rect.width ' + rect
.width
+ ', expected ' + expectedWidth
+ '.');
32 function testComputedWidth(width
, opt_expectedWidth
)
34 var expectedWidth
= typeof opt_expectedWidth
== 'number' ? opt_expectedWidth
: width
;
36 el
.style
.width
= width
+ 'px';
38 var style
= window
.getComputedStyle(el
, null);
39 var computedWidth
= Number(style
.width
.replace('px', ''));
40 if (computedWidth
== expectedWidth
)
41 testPassed('element.width = ' + width
+ 'px, returns computed width as expected.');
43 testFailed('element.width = ' + width
+ 'px, returns computed width ' + computedWidth
+ ', expected ' + expectedWidth
+ '.');
47 function testLeft(left
, opt_expectedLeft
)
49 var expectedLeft
= typeof opt_expectedLeft
== 'number' ? opt_expectedLeft
: left
;
51 el
.style
.left
= left
+ 'px';
53 var style
= window
.getComputedStyle(el
, null);
54 var rect
= el
.getBoundingClientRect();
55 if (el
.offsetLeft
== expectedLeft
&& rect
.left
== expectedLeft
)
56 testPassed('element.left = ' + left
+ 'px, returns offsetLeft, rect.left as expected.');
58 testFailed('element.left = ' + left
+ 'px, returns offsetLeft ' + el
.offsetLeft
+ ', rect.left ' + rect
.left
+ ', expected ' + expectedLeft
+ '.');
61 function testComputedLeft(left
, opt_expectedLeft
)
63 var expectedLeft
= typeof opt_expectedLeft
== 'number' ? opt_expectedLeft
: left
;
65 el
.style
.left
= left
+ 'px';
67 var style
= window
.getComputedStyle(el
, null);
68 var computedLeft
= Number(style
.left
.replace('px', ''));
69 if (computedLeft
== expectedLeft
)
70 testPassed('element.left = ' + left
+ 'px, returns computed left as expected.');
72 testFailed('element.left = ' + left
+ 'px, returns computedLeft, expected ' + expectedLeft
+ '.');
75 var el
= document
.createElement('div');
76 el
.className
= 'test';
77 document
.body
.appendChild(el
);
79 var MAX_VALUE
= 33554428;
80 var MIN_VALUE
= -33554430;
82 // Test setting style.width, negative values are considered invalid.
91 testSize(100000000, MAX_VALUE
);
92 testSize(1000000000, MAX_VALUE
);
93 testSize(10000000000, MAX_VALUE
);
94 testSize(100000000000, MAX_VALUE
);
95 testSize(1000000000000, MAX_VALUE
);
102 testSize(-100000, 0);
103 testSize(-1000000, 0);
104 testSize(-10000000, 0);
105 testSize(-100000000, 0);
106 testSize(-1000000000, 0);
107 testSize(-10000000000, 0);
108 testSize(-100000000000, 0);
110 MAX_VALUE
= 33554400;
111 MIN_VALUE
= -33554400;
113 testComputedWidth(0);
114 testComputedWidth(1);
115 testComputedWidth(10);
116 testComputedWidth(100);
117 testComputedWidth(10000);
118 testComputedWidth(100000);
119 testComputedWidth(1000000);
120 testComputedWidth(10000000);
121 testComputedWidth(100000000, MAX_VALUE
);
122 testComputedWidth(1000000000, MAX_VALUE
);
123 testComputedWidth(10000000000, MAX_VALUE
);
124 testComputedWidth(100000000000, MAX_VALUE
);
125 testComputedWidth(1000000000000, MAX_VALUE
);
132 testSize(-100000, 0);
133 testSize(-1000000, 0);
134 testSize(-10000000, 0);
135 testSize(-100000000, 0);
136 testSize(-1000000000, 0);
137 testSize(-10000000000, 0);
138 testSize(-100000000000, 0);
140 MAX_VALUE
= 33554428;
141 MIN_VALUE
= -33554430;
143 // Test setting style.left, negative values are considered valid.
152 testLeft(100000000, MAX_VALUE
);
153 testLeft(1000000000, MAX_VALUE
);
154 testLeft(10000000000, MAX_VALUE
);
155 testLeft(100000000000, MAX_VALUE
);
156 testLeft(1000000000000, MAX_VALUE
);
165 testLeft(-100000000, MIN_VALUE
);
166 testLeft(-1000000000, MIN_VALUE
);
167 testLeft(-10000000000, MIN_VALUE
);
168 testLeft(-100000000000, MIN_VALUE
);
169 testLeft(-1000000000000, MIN_VALUE
);
171 MAX_VALUE
= 33554400;
172 MIN_VALUE
= -33554400;
176 testComputedLeft(10);
177 testComputedLeft(100);
178 testComputedLeft(10000);
179 testComputedLeft(100000);
180 testComputedLeft(1000000);
181 testComputedLeft(10000000);
182 testComputedLeft(100000000, MAX_VALUE
);
183 testComputedLeft(1000000000, MAX_VALUE
);
184 testComputedLeft(10000000000, MAX_VALUE
);
185 testComputedLeft(100000000000, MAX_VALUE
);
186 testComputedLeft(1000000000000, MAX_VALUE
);
188 testComputedLeft(-1);
189 testComputedLeft(-10);
190 testComputedLeft(-100);
191 testComputedLeft(-10000);
192 testComputedLeft(-100000);
193 testComputedLeft(-1000000);
194 testComputedLeft(-10000000);
195 testComputedLeft(-100000000, MIN_VALUE
);
196 testComputedLeft(-1000000000, MIN_VALUE
);
197 testComputedLeft(-10000000000, MIN_VALUE
);
198 testComputedLeft(-100000000000, MIN_VALUE
);
199 testComputedLeft(-1000000000000, MIN_VALUE
);
201 document
.body
.removeChild(el
);