OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
5 <style> | 5 <style> |
6 .test { position: absolute; width: 50px; left: 25px; } | 6 .test { position: absolute; width: 50px; left: 25px; } |
7 </style> | 7 </style> |
8 </head> | 8 </head> |
9 <body> | 9 <body> |
10 <p> | 10 <p> |
11 Test handling of numbers outside of the supported range. | 11 Test handling of numbers outside of the supported range. |
12 </p> | 12 </p> |
13 <p> | 13 <p> |
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> | 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>. | 15 As per the <a href="http://www.w3.org/TR/css3-values/#numeric-types"
>CSS3 specification</a>. |
16 </p> | 16 </p> |
17 <script> | 17 <script> |
18 function testSize(width, opt_expectedWidth) | 18 function testSize(width, opt_expectedWidth) |
19 { | 19 { |
20 var expectedWidth = typeof opt_expectedWidth == 'number' ? opt_e
xpectedWidth : width; | 20 var expectedWidth = typeof opt_expectedWidth == 'number' ? opt_e
xpectedWidth : width; |
21 | 21 |
22 el.style.width = width + 'px'; | 22 el.style.width = width + 'px'; |
23 | 23 |
24 var style = window.getComputedStyle(el, null); | 24 var style = window.getComputedStyle(el, null); |
25 var rect = el.getBoundingClientRect(); | 25 var rect = el.getBoundingClientRect(); |
| 26 if (el.offsetWidth == expectedWidth && rect.width == expectedWid
th) |
| 27 testPassed('element.width = ' + width + 'px, returns offsetW
idth, rect.width expected.'); |
| 28 else |
| 29 testFailed('element.width = ' + width + 'px, returns offsetW
idth ' + el.offsetWidth + ', rect.width ' + rect.width + ', expected ' + expecte
dWidth + '.'); |
| 30 } |
| 31 |
| 32 function testComputedWidth(width, opt_expectedWidth) |
| 33 { |
| 34 var expectedWidth = typeof opt_expectedWidth == 'number' ? opt_e
xpectedWidth : width; |
| 35 |
| 36 el.style.width = width + 'px'; |
| 37 |
| 38 var style = window.getComputedStyle(el, null); |
26 var computedWidth = Number(style.width.replace('px', '')); | 39 var computedWidth = Number(style.width.replace('px', '')); |
27 if (el.offsetWidth == expectedWidth && rect.width == expectedWid
th && computedWidth == expectedWidth) | 40 if (computedWidth == expectedWidth) |
28 testPassed('element.width = ' + width + 'px, returns offsetW
idth, rect.width and computed width as expected.'); | 41 testPassed('element.width = ' + width + 'px, returns compute
d width as expected.'); |
29 else | 42 else |
30 testFailed('element.width = ' + width + 'px, returns offsetW
idth ' + el.offsetWidth + ', rect.width ' + rect.width + ' and computed width '
+ computedWidth + ', expected ' + expectedWidth + '.'); | 43 testFailed('element.width = ' + width + 'px, returns compute
d width ' + computedWidth + ', expected ' + expectedWidth + '.'); |
31 } | 44 } |
32 | 45 |
33 | 46 |
34 function testLeft(left, opt_expectedLeft) | 47 function testLeft(left, opt_expectedLeft) |
35 { | 48 { |
36 var expectedLeft = typeof opt_expectedLeft == 'number' ? opt_exp
ectedLeft : left; | 49 var expectedLeft = typeof opt_expectedLeft == 'number' ? opt_exp
ectedLeft : left; |
37 | 50 |
38 el.style.left = left + 'px'; | 51 el.style.left = left + 'px'; |
39 | 52 |
40 var style = window.getComputedStyle(el, null); | 53 var style = window.getComputedStyle(el, null); |
41 var rect = el.getBoundingClientRect(); | 54 var rect = el.getBoundingClientRect(); |
| 55 if (el.offsetLeft == expectedLeft && rect.left == expectedLeft) |
| 56 testPassed('element.left = ' + left + 'px, returns offsetLef
t, rect.left as expected.'); |
| 57 else |
| 58 testFailed('element.left = ' + left + 'px, returns offsetLef
t ' + el.offsetLeft + ', rect.left ' + rect.left + ', expected ' + expectedLeft
+ '.'); |
| 59 } |
| 60 |
| 61 function testComputedLeft(left, opt_expectedLeft) |
| 62 { |
| 63 var expectedLeft = typeof opt_expectedLeft == 'number' ? opt_exp
ectedLeft : left; |
| 64 |
| 65 el.style.left = left + 'px'; |
| 66 |
| 67 var style = window.getComputedStyle(el, null); |
42 var computedLeft = Number(style.left.replace('px', '')); | 68 var computedLeft = Number(style.left.replace('px', '')); |
43 if (el.offsetLeft == expectedLeft && rect.left == expectedLeft &
& computedLeft == expectedLeft) | 69 if (computedLeft == expectedLeft) |
44 testPassed('element.left = ' + left + 'px, returns offsetLef
t, rect.left and computed left as expected.'); | 70 testPassed('element.left = ' + left + 'px, returns computed
left as expected.'); |
45 else | 71 else |
46 testFailed('element.left = ' + left + 'px, returns offsetLef
t ' + el.offsetLeft + ', rect.left ' + rect.left + ' and computed left ' + compu
tedLeft + ', expected ' + expectedLeft + '.'); | 72 testFailed('element.left = ' + left + 'px, returns computedL
eft, expected ' + expectedLeft + '.'); |
47 } | 73 } |
48 | 74 |
49 var el = document.createElement('div'); | 75 var el = document.createElement('div'); |
50 el.className = 'test'; | 76 el.className = 'test'; |
51 document.body.appendChild(el); | 77 document.body.appendChild(el); |
52 | 78 |
53 var MAX_VALUE = 33554428; | 79 var MAX_VALUE = 33554428; |
54 var MIN_VALUE = -33554430; | 80 var MIN_VALUE = -33554430; |
55 | 81 |
56 // Test setting style.width, negative values are considered invalid. | 82 // Test setting style.width, negative values are considered invalid. |
57 testSize(0); | 83 testSize(0); |
58 testSize(1); | 84 testSize(1); |
(...skipping 15 matching lines...) Expand all Loading... |
74 testSize(-100, 0); | 100 testSize(-100, 0); |
75 testSize(-10000, 0); | 101 testSize(-10000, 0); |
76 testSize(-100000, 0); | 102 testSize(-100000, 0); |
77 testSize(-1000000, 0); | 103 testSize(-1000000, 0); |
78 testSize(-10000000, 0); | 104 testSize(-10000000, 0); |
79 testSize(-100000000, 0); | 105 testSize(-100000000, 0); |
80 testSize(-1000000000, 0); | 106 testSize(-1000000000, 0); |
81 testSize(-10000000000, 0); | 107 testSize(-10000000000, 0); |
82 testSize(-100000000000, 0); | 108 testSize(-100000000000, 0); |
83 | 109 |
| 110 MAX_VALUE = 33554400; |
| 111 MIN_VALUE = -33554400; |
| 112 |
| 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); |
| 126 |
| 127 testSize(0, 0); |
| 128 testSize(-1, 0); |
| 129 testSize(-10, 0); |
| 130 testSize(-100, 0); |
| 131 testSize(-10000, 0); |
| 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); |
| 139 |
| 140 MAX_VALUE = 33554428; |
| 141 MIN_VALUE = -33554430; |
| 142 |
84 // Test setting style.left, negative values are considered valid. | 143 // Test setting style.left, negative values are considered valid. |
85 testLeft(0); | 144 testLeft(0); |
86 testLeft(1); | 145 testLeft(1); |
87 testLeft(10); | 146 testLeft(10); |
88 testLeft(100); | 147 testLeft(100); |
89 testLeft(10000); | 148 testLeft(10000); |
90 testLeft(100000); | 149 testLeft(100000); |
91 testLeft(1000000); | 150 testLeft(1000000); |
92 testLeft(10000000); | 151 testLeft(10000000); |
93 testLeft(100000000, MAX_VALUE); | 152 testLeft(100000000, MAX_VALUE); |
94 testLeft(1000000000, MAX_VALUE); | 153 testLeft(1000000000, MAX_VALUE); |
95 testLeft(10000000000, MAX_VALUE); | 154 testLeft(10000000000, MAX_VALUE); |
96 testLeft(100000000000, MAX_VALUE); | 155 testLeft(100000000000, MAX_VALUE); |
97 testLeft(1000000000000, MAX_VALUE); | 156 testLeft(1000000000000, MAX_VALUE); |
98 | 157 |
99 testLeft(-1); | 158 testLeft(-1); |
100 testLeft(-10); | 159 testLeft(-10); |
101 testLeft(-100); | 160 testLeft(-100); |
102 testLeft(-10000); | 161 testLeft(-10000); |
103 testLeft(-100000); | 162 testLeft(-100000); |
104 testLeft(-1000000); | 163 testLeft(-1000000); |
105 testLeft(-10000000); | 164 testLeft(-10000000); |
106 testLeft(-100000000, MIN_VALUE); | 165 testLeft(-100000000, MIN_VALUE); |
107 testLeft(-1000000000, MIN_VALUE); | 166 testLeft(-1000000000, MIN_VALUE); |
108 testLeft(-10000000000, MIN_VALUE); | 167 testLeft(-10000000000, MIN_VALUE); |
109 testLeft(-100000000000, MIN_VALUE); | 168 testLeft(-100000000000, MIN_VALUE); |
110 testLeft(-1000000000000, MIN_VALUE); | 169 testLeft(-1000000000000, MIN_VALUE); |
111 | 170 |
| 171 MAX_VALUE = 33554400; |
| 172 MIN_VALUE = -33554400; |
| 173 |
| 174 testComputedLeft(0); |
| 175 testComputedLeft(1); |
| 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); |
| 187 |
| 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); |
| 200 |
112 document.body.removeChild(el); | 201 document.body.removeChild(el); |
113 </script> | 202 </script> |
114 </body> | 203 </body> |
115 </html> | 204 </html> |
OLD | NEW |