Fix #10996, simplify offset code by forsaking ancient browsers.
[jquery.git] / test / unit / support.js
bloba9243be51d1c74aed1d1ed6260bb3120d1509471
1 module("support", { teardown: moduleTeardown });
3 function supportIFrameTest( title, url, noDisplay, func ) {
5         if ( noDisplay !== true ) {
6                 func = noDisplay;
7                 noDisplay = false;
8         }
10         test( title, function() {
11                 var iframe;
13                 stop();
14                 window.supportCallback = function() {
15                         var self = this,
16                                 args = arguments;
17                         setTimeout( function() {
18                                 window.supportCallback = undefined;
19                                 iframe.remove();
20                                 func.apply( self, args );
21                                 start();
22                         }, 0 );
23                 };
24                 iframe = jQuery( "<div/>" ).css( "display", noDisplay ? "none" : "block" ).append(
25                                 jQuery( "<iframe/>" ).attr( "src", "data/support/" + url + ".html" )
26                         ).appendTo( "body" );
27         });
30 supportIFrameTest( "proper boxModel in compatMode CSS1Compat (IE6 and IE7)", "boxModelIE", function( compatMode, boxModel ) {
31         ok( compatMode !== "CSS1Compat" || boxModel, "boxModel properly detected" );
32 });
34 supportIFrameTest( "body background is not lost if set prior to loading jQuery (#9238)", "bodyBackground", function( color, support ) {
35         expect( 2 );
36         var i,
37                 passed = true,
38                 okValue = {
39                         "#000000": true,
40                         "rgb(0, 0, 0)": true
41                 };
42         ok( okValue[ color ], "color was not reset (" + color + ")" );
44         for ( i in jQuery.support ) {
45                 if ( jQuery.support[ i ] !== support[ i ] ) {
46                         passed = false;
47                         strictEqual( jQuery.support[ i ], support[ i ], "Support property " + i + " is different" );
48                 }
49         }
50         for ( i in support ) {
51                 if ( !( i in jQuery.support ) ) {
52                         passed = false;
53                         strictEqual( jQuery.support[ i ], support[ i ], "Unexpected property: " + i );
54                 }
55         }
56         ok( passed, "Same support properties" );
57 });
59 supportIFrameTest( "A background on the testElement does not cause IE8 to crash (#9823)", "testElementCrash", function() {
60         expect(1);
61         ok( true, "IE8 does not crash" );
62 });
64 var userAgent = window.navigator.userAgent;
66 // These tests do not have to stay
67 // They are here to help with upcoming support changes for 1.8
68 if ( /chrome\/16\.0/i.test(userAgent) ) {
69         test("Verify that the support tests resolve as expected per browser", function() {
70                 var i,
71                 expected = {
72                         "leadingWhitespace":true,
73                         "tbody":true,
74                         "htmlSerialize":true,
75                         "style":true,
76                         "hrefNormalized":true,
77                         "opacity":true,
78                         "cssFloat":true,
79                         "checkOn":true,
80                         "optSelected":true,
81                         "getSetAttribute":true,
82                         "enctype":true,
83                         "html5Clone":true,
84                         "submitBubbles":true,
85                         "changeBubbles":true,
86                         "focusinBubbles":false,
87                         "deleteExpando":true,
88                         "noCloneEvent":true,
89                         "inlineBlockNeedsLayout":false,
90                         "shrinkWrapBlocks":false,
91                         "reliableMarginRight":true,
92                         "noCloneChecked":true,
93                         "optDisabled":true,
94                         "radioValue":true,
95                         "checkClone":true,
96                         "appendChecked":true,
97                         "boxModel":true,
98                         "reliableHiddenOffsets":true,
99                         "ajax":true,
100                         "cors":true,
101                         "doesNotIncludeMarginInBodyOffset":true
102                 };
103                 for ( i in expected ) {
104                         equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
105                 }
106         });
107 } else if ( /msie 8\.0/i.test(userAgent) ) {
108         test("Verify that the support tests resolve as expected per browser", function() {
109                 var i,
110                 expected = {
111                         "leadingWhitespace":false,
112                         "tbody":true,
113                         "htmlSerialize":false,
114                         "style":false,
115                         "hrefNormalized":true,
116                         "opacity":false,
117                         "cssFloat":false,
118                         "checkOn":true,
119                         "optSelected":false,
120                         "getSetAttribute":true,
121                         "enctype":true,
122                         "html5Clone":false,
123                         "submitBubbles":false,
124                         "changeBubbles":false,
125                         "focusinBubbles":true,
126                         "deleteExpando":false,
127                         "noCloneEvent":false,
128                         "inlineBlockNeedsLayout":false,
129                         "shrinkWrapBlocks":false,
130                         "reliableMarginRight":true,
131                         "noCloneChecked":false,
132                         "optDisabled":true,
133                         "radioValue":false,
134                         "checkClone":true,
135                         "appendChecked":true,
136                         "boxModel":true,
137                         "reliableHiddenOffsets":false,
138                         "ajax":true,
139                         "cors":false,
140                         "doesNotIncludeMarginInBodyOffset":true
141                 };
142                 for ( i in expected ) {
143                         equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
144                 }
145         });
146 } else if ( /msie 7\.0/i.test(userAgent) ) {
147         test("Verify that the support tests resolve as expected per browser", function() {
148                 var i,
149                 expected = {
150                         "ajax": true,
151                         "appendChecked": false,
152                         "boxModel": true,
153                         "changeBubbles": false,
154                         "checkClone": false,
155                         "checkOn": true,
156                         "cors": false,
157                         "cssFloat": false,
158                         "deleteExpando": false,
159                         "doesNotIncludeMarginInBodyOffset": true,
160                         "enctype": true,
161                         "focusinBubbles": true,
162                         "getSetAttribute": false,
163                         "hrefNormalized": false,
164                         "html5Clone": false,
165                         "htmlSerialize": false,
166                         "inlineBlockNeedsLayout": true,
167                         "leadingWhitespace": false,
168                         "noCloneChecked": false,
169                         "noCloneEvent": false,
170                         "opacity": false,
171                         "optDisabled": true,
172                         "optSelected": false,
173                         "radioValue": false,
174                         "reliableHiddenOffsets": false,
175                         "reliableMarginRight": true,
176                         "shrinkWrapBlocks": false,
177                         "submitBubbles": false,
178                         "tbody": false,
179                         "style": false
180                 };
181                 for ( i in expected ) {
182                         equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
183                 }
184         });
185 } else if ( /msie 6\.0/i.test(userAgent) ) {
186         test("Verify that the support tests resolve as expected per browser", function() {
187                 var i,
188                 expected = {
189                         "leadingWhitespace":false,
190                         "tbody":false,
191                         "htmlSerialize":false,
192                         "style":false,
193                         "hrefNormalized":false,
194                         "opacity":false,
195                         "cssFloat":false,
196                         "checkOn":true,
197                         "optSelected":false,
198                         "getSetAttribute":false,
199                         "enctype":true,
200                         "html5Clone":false,
201                         "submitBubbles":false,
202                         "changeBubbles":false,
203                         "focusinBubbles":true,
204                         "deleteExpando":false,
205                         "noCloneEvent":false,
206                         "inlineBlockNeedsLayout":true,
207                         "shrinkWrapBlocks":true,
208                         "reliableMarginRight":true,
209                         "noCloneChecked":false,
210                         "optDisabled":true,
211                         "radioValue":false,
212                         "checkClone":false,
213                         "appendChecked":false,
214                         "boxModel":true,
215                         "reliableHiddenOffsets":false,
216                         "ajax":true,
217                         "cors":false,
218                         "doesNotIncludeMarginInBodyOffset":true
219                 };
220                 for ( i in expected ) {
221                         equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
222                 }
223         });
224 } else if ( /5\.1\.1 safari/i.test(userAgent) ) {
225         test("Verify that the support tests resolve as expected per browser", function() {
226                 var i,
227                 expected = {
228                         "leadingWhitespace":true,
229                         "tbody":true,
230                         "htmlSerialize":true,
231                         "style":true,
232                         "hrefNormalized":true,
233                         "opacity":true,
234                         "cssFloat":true,
235                         "checkOn":false,
236                         "optSelected":true,
237                         "getSetAttribute":true,
238                         "enctype":true,
239                         "html5Clone":true,
240                         "submitBubbles":true,
241                         "changeBubbles":true,
242                         "focusinBubbles":false,
243                         "deleteExpando":true,
244                         "noCloneEvent":true,
245                         "inlineBlockNeedsLayout":false,
246                         "shrinkWrapBlocks":false,
247                         "reliableMarginRight":true,
248                         "noCloneChecked":true,
249                         "optDisabled":true,
250                         "radioValue":true,
251                         "checkClone":true,
252                         "appendChecked":true,
253                         "boxModel":true,
254                         "reliableHiddenOffsets":true,
255                         "ajax":true,
256                         "cors":true,
257                         "doesNotIncludeMarginInBodyOffset":true
258                 };
259                 for ( i in expected ) {
260                         equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
261                 }
262         });
263 } else if ( /firefox\/3\.6/i.test(userAgent) ) {
264         test("Verify that the support tests resolve as expected per browser", function() {
265                 var i,
266                 expected = {
267                         "leadingWhitespace":true,
268                         "tbody":true,
269                         "htmlSerialize":true,
270                         "style":true,
271                         "hrefNormalized":true,
272                         "opacity":true,
273                         "cssFloat":true,
274                         "checkOn":true,
275                         "optSelected":true,
276                         "getSetAttribute":true,
277                         "enctype":false,
278                         "html5Clone":true,
279                         "submitBubbles":true,
280                         "changeBubbles":true,
281                         "focusinBubbles":false,
282                         "deleteExpando":true,
283                         "noCloneEvent":true,
284                         "inlineBlockNeedsLayout":false,
285                         "shrinkWrapBlocks":false,
286                         "reliableMarginRight":true,
287                         "noCloneChecked":true,
288                         "optDisabled":true,
289                         "radioValue":true,
290                         "checkClone":true,
291                         "appendChecked":true,
292                         "boxModel":true,
293                         "reliableHiddenOffsets":true,
294                         "ajax":true,
295                         "cors":true,
296                         "doesNotIncludeMarginInBodyOffset":true
297                 };
298                 for ( i in expected ) {
299                         equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
300                 }
301         });