testrunner: Removing every global variable leaked within (and outside) tests. Some...
[jquery.git] / test / unit / core.js
1 module("core");
2
3 test("Basic requirements", function() {
4         expect(7);
5         ok( Array.prototype.push, "Array.push()" );
6         ok( Function.prototype.apply, "Function.apply()" );
7         ok( document.getElementById, "getElementById" );
8         ok( document.getElementsByTagName, "getElementsByTagName" );
9         ok( RegExp, "RegExp" );
10         ok( jQuery, "jQuery" );
11         ok( $, "$" );
12 });
13
14 test("jQuery()", function() {
15         expect(8);
16
17         var main = jQuery("#main");
18         isSet( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
19
20 /*
21         // disabled since this test was doing nothing. i tried to fix it but i'm not sure
22         // what the expected behavior should even be. FF returns "\n" for the text node
23         // make sure this is handled
24         var crlfContainer = jQuery('<p>\r\n</p>');
25         var x = crlfContainer.contents().get(0).nodeValue;
26         equals( x, what???, "Check for \\r and \\n in jQuery()" );
27 */
28
29         /* // Disabled until we add this functionality in
30         var pass = true;
31         try {
32                 jQuery("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
33         } catch(e){
34                 pass = false;
35         }
36         ok( pass, "jQuery('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
37
38         var code = jQuery("<code/>");
39         equals( code.length, 1, "Correct number of elements generated for code" );
40         var img = jQuery("<img/>");
41         equals( img.length, 1, "Correct number of elements generated for img" );
42         var div = jQuery("<div/><hr/><code/><b/>");
43         equals( div.length, 4, "Correct number of elements generated for div hr code b" );
44
45         // can actually yield more than one, when iframes are included, the window is an array as well
46         equals( jQuery(window).length, 1, "Correct number of elements generated for window" );
47
48         equals( jQuery(document).length, 1, "Correct number of elements generated for document" );
49
50         equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
51
52         equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" );
53 });
54
55 test("selector state", function() {
56         expect(28);
57
58         var test;
59         
60         test = jQuery();
61         equals( test.selector, "", "Empty jQuery Selector" );
62         equals( test.context, document, "Empty jQuery Context" );
63         
64         test = jQuery(document);
65         equals( test.selector, "", "Document Selector" );
66         equals( test.context, document, "Document Context" );
67         
68         test = jQuery(document.body);
69         equals( test.selector, "", "Body Selector" );
70         equals( test.context, document.body, "Body Context" );
71         
72         test = jQuery("#main");
73         equals( test.selector, "#main", "#main Selector" );
74         equals( test.context, document, "#main Context" );
75         
76         test = jQuery("#main", document);
77         equals( test.selector, "#main", "#main Selector" );
78         equals( test.context, document, "#main Context" );
79         
80         test = jQuery("#main", document.body);
81         equals( test.selector, "#main", "#main Selector" );
82         equals( test.context, document.body, "#main Context" );
83
84         // Test cloning
85         test = jQuery(test);
86         equals( test.selector, "#main", "#main Selector" );
87         equals( test.context, document.body, "#main Context" );
88         
89         test = jQuery(document.body).find("#main");
90         equals( test.selector, "#main", "#main find Selector" );
91         equals( test.context, document.body, "#main find Context" );
92
93         test = jQuery("#main").filter("div");
94         equals( test.selector, "#main.filter(div)", "#main filter Selector" );
95         equals( test.context, document, "#main filter Context" );
96         
97         test = jQuery("#main").not("div");
98         equals( test.selector, "#main.not(div)", "#main not Selector" );
99         equals( test.context, document, "#main not Context" );
100         
101         test = jQuery("#main").filter("div").not("div");
102         equals( test.selector, "#main.filter(div).not(div)", "#main filter, not Selector" );
103         equals( test.context, document, "#main filter, not Context" );
104         
105         test = jQuery("#main").filter("div").not("div").end();
106         equals( test.selector, "#main.filter(div)", "#main filter, not, end Selector" );
107         equals( test.context, document, "#main filter, not, end Context" );
108         
109         test = jQuery("#main").parent("body");
110         equals( test.selector, "#main.parent(body)", "#main parent Selector" );
111         equals( test.context, document, "#main parent Context" );
112         
113         test = jQuery("#main").eq(0);
114         equals( test.selector, "#main.slice(0,1)", "#main eq Selector" );
115         equals( test.context, document, "#main eq Context" );
116 });
117
118 test("browser", function() {
119         expect(13);
120         var browsers = {
121                 //Internet Explorer
122                 "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0",
123                 "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0",
124                 /** Failing #1876
125                  * "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0",
126                  */
127                 //Browsers with Gecko engine
128                 //Mozilla
129                 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12",
130                 //Firefox
131                 "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3",
132                 //Netscape
133                 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5",
134                 //Flock
135                 "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11",
136                 //Opera browser
137                 "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20",
138                 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20",
139                 "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20",
140                 //WebKit engine
141                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9",
142                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8",
143                 "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8",
144                 //Other user agent string
145                 "Other browser's user agent 1.0":null
146         };
147         for (var i in browsers) {
148                 var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check
149                 var version = v ? v[1] : null;
150                 equals( version, browsers[i], "Checking UA string" );
151         }
152 });
153
154 test("noConflict", function() {
155         expect(6);
156
157         var $$ = jQuery;
158
159         equals( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
160         equals( jQuery, $$, "Make sure jQuery wasn't touched." );
161         equals( $, original$, "Make sure $ was reverted." );
162
163         jQuery = $ = $$;
164
165         equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
166         equals( jQuery, originaljQuery, "Make sure jQuery was reverted." );
167         equals( $, original$, "Make sure $ was reverted." );
168
169         jQuery = $$;
170 });
171
172 test("isFunction", function() {
173         expect(19);
174
175         // Make sure that false values return false
176         ok( !jQuery.isFunction(), "No Value" );
177         ok( !jQuery.isFunction( null ), "null Value" );
178         ok( !jQuery.isFunction( undefined ), "undefined Value" );
179         ok( !jQuery.isFunction( "" ), "Empty String Value" );
180         ok( !jQuery.isFunction( 0 ), "0 Value" );
181
182         // Check built-ins
183         // Safari uses "(Internal Function)"
184         ok( jQuery.isFunction(String), "String Function("+String+")" );
185         ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
186         ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
187         ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
188
189         // When stringified, this could be misinterpreted
190         var mystr = "function";
191         ok( !jQuery.isFunction(mystr), "Function String" );
192
193         // When stringified, this could be misinterpreted
194         var myarr = [ "function" ];
195         ok( !jQuery.isFunction(myarr), "Function Array" );
196
197         // When stringified, this could be misinterpreted
198         var myfunction = { "function": "test" };
199         ok( !jQuery.isFunction(myfunction), "Function Object" );
200
201         // Make sure normal functions still work
202         var fn = function(){};
203         ok( jQuery.isFunction(fn), "Normal Function" );
204
205         var obj = document.createElement("object");
206
207         // Firefox says this is a function
208         ok( !jQuery.isFunction(obj), "Object Element" );
209
210         // IE says this is an object
211         // Since 1.3, this isn't supported (#2968)
212         //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
213
214         var nodes = document.body.childNodes;
215
216         // Safari says this is a function
217         ok( !jQuery.isFunction(nodes), "childNodes Property" );
218
219         var first = document.body.firstChild;
220
221         // Normal elements are reported ok everywhere
222         ok( !jQuery.isFunction(first), "A normal DOM Element" );
223
224         var input = document.createElement("input");
225         input.type = "text";
226         document.body.appendChild( input );
227
228         // IE says this is an object
229         // Since 1.3, this isn't supported (#2968)
230         //ok( jQuery.isFunction(input.focus), "A default function property" );
231
232         document.body.removeChild( input );
233
234         var a = document.createElement("a");
235         a.href = "some-function";
236         document.body.appendChild( a );
237
238         // This serializes with the word 'function' in it
239         ok( !jQuery.isFunction(a), "Anchor Element" );
240
241         document.body.removeChild( a );
242
243         // Recursive function calls have lengths and array-like properties
244         function callme(callback){
245                 function fn(response){
246                         callback(response);
247                 }
248
249                 ok( jQuery.isFunction(fn), "Recursive Function Call" );
250
251                 fn({ some: "data" });
252         };
253
254         callme(function(){
255                 callme(function(){});
256         });
257 });
258
259 test("jQuery('html')", function() {
260         expect(8);
261
262         reset();
263         jQuery.foo = false;
264         var s = jQuery("<script>jQuery.foo='test';</script>")[0];
265         ok( s, "Creating a script" );
266         ok( !jQuery.foo, "Make sure the script wasn't executed prematurely" );
267         jQuery("body").append("<script>jQuery.foo='test';</script>");
268         ok( jQuery.foo, "Executing a scripts contents in the right context" );
269
270         reset();
271         ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" );
272
273         ok( !jQuery("<script/>")[0].parentNode, "Create a script" );
274
275         ok( jQuery("<input/>").attr("type", "hidden"), "Create an input and set the type." );
276
277         var j = jQuery("<span>hi</span> there <!-- mon ami -->");
278         ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
279
280         ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" );
281 });
282
283 test("jQuery('html', context)", function() {
284         expect(1);
285
286         var $div = jQuery("<div/>");
287         var $span = jQuery("<span/>", $div);
288         equals($span.length, 1, "Verify a span created with a div context works, #1763");
289 });
290
291 if ( !isLocal ) {
292 test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
293         expect(2);
294         stop();
295         jQuery.get('data/dashboard.xml', function(xml) {
296                 // tests for #1419 where IE was a problem
297                 var tab = jQuery("tab", xml).eq(0);
298                 equals( tab.text(), "blabla", "Verify initial text correct" );
299                 tab.text("newtext");
300                 equals( tab.text(), "newtext", "Verify new text correct" );
301                 start();
302         });
303 });
304 }
305
306 test("length", function() {
307         expect(1);
308         equals( jQuery("p").length, 6, "Get Number of Elements Found" );
309 });
310
311 test("size()", function() {
312         expect(1);
313         equals( jQuery("p").size(), 6, "Get Number of Elements Found" );
314 });
315
316 test("get()", function() {
317         expect(1);
318         isSet( jQuery("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
319 });
320
321 test("get(Number)", function() {
322         expect(1);
323         equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
324 });
325
326 test("add(String|Element|Array|undefined)", function() {
327         expect(12);
328         isSet( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
329         isSet( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
330         ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" );
331
332         // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
333         // use jQuery([]).add(form.elements) instead.
334         //equals( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
335
336         var x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
337         equals( x[0].id, "x1", "Check on-the-fly element1" );
338         equals( x[1].id, "x2", "Check on-the-fly element2" );
339
340         var x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
341         equals( x[0].id, "x1", "Check on-the-fly element1" );
342         equals( x[1].id, "x2", "Check on-the-fly element2" );
343
344         var notDefined;
345         equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
346
347         // Added after #2811
348         equals( jQuery([]).add([window,document,document.body,document]).length, 3, "Pass an array" );
349         equals( jQuery(document).add(document).length, 1, "Check duplicated elements" );
350         equals( jQuery(window).add(window).length, 1, "Check duplicated elements using the window" );
351         ok( jQuery([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
352 });
353
354 test("each(Function)", function() {
355         expect(1);
356         var div = jQuery("div");
357         div.each(function(){this.foo = 'zoo';});
358         var pass = true;
359         for ( var i = 0; i < div.size(); i++ ) {
360                 if ( div.get(i).foo != "zoo" ) pass = false;
361         }
362         ok( pass, "Execute a function, Relative" );
363 });
364
365 test("index(Object)", function() {
366         expect(10);
367
368         var elements = jQuery([window, document]),
369                 inputElements = jQuery('#radio1,#radio2,#check1,#check2');
370
371         equals( elements.index(window), 0, "Check for index of elements" );
372         equals( elements.index(document), 1, "Check for index of elements" );
373         equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" );
374         equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" );
375         equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" );
376         equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" );
377         equals( inputElements.index(window), -1, "Check for not found index" );
378         equals( inputElements.index(document), -1, "Check for not found index" );
379
380         // enabled since [5500]
381         equals( elements.index( elements ), 0, "Pass in a jQuery object" );
382         equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
383 });
384
385 test("attr(String)", function() {
386         expect(26);
387         equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
388         equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
389         equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
390         equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' );
391         equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' );
392         equals( jQuery('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' );
393         equals( jQuery('#google').attr('title'), "Google!", 'Check for title attribute' );
394         equals( jQuery('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' );
395         equals( jQuery('#en').attr('lang'), "en", 'Check for lang attribute' );
396         equals( jQuery('#simon').attr('class'), "blog link", 'Check for class attribute' );
397         equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' );
398         equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' );
399         ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
400         equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' );
401         equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' );
402         equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );
403         equals( jQuery('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' );
404         equals( jQuery('#foo').attr('nodeName'), 'DIV', 'Check for nodeName attribute' );
405         equals( jQuery('#foo').attr('tagName'), 'DIV', 'Check for tagName attribute' );
406
407         jQuery('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
408         equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' );
409
410
411         // Related to [5574] and [5683]
412         var body = document.body, $body = jQuery(body);
413
414         ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' );
415         ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' );
416         
417         body.setAttribute('foo', 'baz');
418         equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' );
419         
420         body.foo = 'bar';
421         equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' );
422         
423         $body.attr('foo','cool');
424         equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' );
425         
426         body.foo = undefined;
427         ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' );
428         
429         body.removeAttribute('foo'); // Cleanup
430 });
431
432 if ( !isLocal ) {
433         test("attr(String) in XML Files", function() {
434                 expect(2);
435                 stop();
436                 jQuery.get("data/dashboard.xml", function(xml) {
437                         equals( jQuery("locations", xml).attr("class"), "foo", "Check class attribute in XML document" );
438                         equals( jQuery("location", xml).attr("for"), "bar", "Check for attribute in XML document" );
439                         start();
440                 });
441         });
442 }
443
444 test("attr(String, Function)", function() {
445         expect(2);
446         equals( jQuery('#text1').attr('value', function() { return this.id })[0].value, "text1", "Set value from id" );
447         equals( jQuery('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index");
448 });
449
450 test("attr(Hash)", function() {
451         expect(1);
452         var pass = true;
453         jQuery("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
454                 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
455         });
456         ok( pass, "Set Multiple Attributes" );
457 });
458
459 test("attr(String, Object)", function() {
460         expect(19);
461         var div = jQuery("div").attr("foo", "bar"),
462                 fail = false;
463         for ( var i = 0; i < div.size(); i++ ) {
464                 if ( div.get(i).getAttribute('foo') != "bar" ){
465                         fail = i;
466                         break;
467                 }
468         }
469         equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" );
470
471         ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
472
473         jQuery("#name").attr('name', 'something');
474         equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' );
475         jQuery("#check2").attr('checked', true);
476         equals( document.getElementById('check2').checked, true, 'Set checked attribute' );
477         jQuery("#check2").attr('checked', false);
478         equals( document.getElementById('check2').checked, false, 'Set checked attribute' );
479         jQuery("#text1").attr('readonly', true);
480         equals( document.getElementById('text1').readOnly, true, 'Set readonly attribute' );
481         jQuery("#text1").attr('readonly', false);
482         equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' );
483         jQuery("#name").attr('maxlength', '5');
484         equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' );
485         jQuery("#name").attr('maxLength', '10');
486         equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
487
488         // for #1070
489         jQuery("#name").attr('someAttr', '0');
490         equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
491         jQuery("#name").attr('someAttr', 0);
492         equals( jQuery("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
493         jQuery("#name").attr('someAttr', 1);
494         equals( jQuery("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
495
496         // using contents will get comments regular, text, and comment nodes
497         var j = jQuery("#nonnodes").contents();
498
499         j.attr("name", "attrvalue");
500         equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
501         j.removeAttr("name");
502
503         reset();
504
505         var type = jQuery("#check2").attr('type');
506         var thrown = false;
507         try {
508                 jQuery("#check2").attr('type','hidden');
509         } catch(e) {
510                 thrown = true;
511         }
512         ok( thrown, "Exception thrown when trying to change type property" );
513         equals( type, jQuery("#check2").attr('type'), "Verify that you can't change the type of an input element" );
514
515         var check = document.createElement("input");
516         var thrown = true;
517         try {
518                 jQuery(check).attr('type','checkbox');
519         } catch(e) {
520                 thrown = false;
521         }
522         ok( thrown, "Exception thrown when trying to change type property" );
523         equals( "checkbox", jQuery(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
524         
525         var check = jQuery("<input />");
526         var thrown = true;
527         try {
528                 check.attr('type','checkbox');
529         } catch(e) {
530                 thrown = false;
531         }
532         ok( thrown, "Exception thrown when trying to change type property" );
533         equals( "checkbox", check.attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
534 });
535
536 if ( !isLocal ) {
537         test("attr(String, Object) - Loaded via XML document", function() {
538                 expect(2);
539                 stop();
540                 jQuery.get('data/dashboard.xml', function(xml) {
541                         var titles = [];
542                         jQuery('tab', xml).each(function() {
543                                 titles.push(jQuery(this).attr('title'));
544                         });
545                         equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
546                         equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
547                         start();
548                 });
549         });
550 }
551
552 test("attr('tabindex')", function() {
553         expect(5);
554
555         // tabindex 0
556         equals(jQuery('#listWithTabIndex').attr('tabindex'), 0, 'tabindex of 0');
557
558         // positive tabindex
559         equals(jQuery('#linkWithTabIndex').attr('tabindex'), 2, 'tabindex of 2');
560
561         // negative tabindex
562         equals(jQuery('#linkWithNegativeTabIndex').attr('tabindex'), -1, 'negative tabindex');
563
564         // regular element without a tabindex
565         equals(jQuery('#divWithNoTabIndex').attr('tabindex'), undefined, 'no tabindex, not tabbable by default');
566
567     // link without a tabindex
568         equals(jQuery('#linkWithNoTabIndex').attr('tabindex'), 0, 'no tabindex, tabbable by default');
569 });
570
571 test("attr('tabindex', value)", function() {
572         expect(9);
573
574         var element = jQuery('#divWithNoTabIndex');
575         equals(element.attr('tabindex'), undefined, 'start with no tabindex');
576
577         // set a positive string
578         element.attr('tabindex', '1');
579         equals(element.attr('tabindex'), 1, 'set tabindex to 1 (string)');
580
581         // set a zero string
582         element.attr('tabindex', '0');
583         equals(element.attr('tabindex'), 0, 'set tabindex to 0 (string)');
584
585         // set a negative string
586         element.attr('tabindex', '-1');
587         equals(element.attr('tabindex'), -1, 'set tabindex to -1 (string)');
588         
589         // set a positive number
590         element.attr('tabindex', 1);
591         equals(element.attr('tabindex'), 1, 'set tabindex to 1 (number)');
592
593         // set a zero number
594         element.attr('tabindex', 0);
595         equals(element.attr('tabindex'), 0, 'set tabindex to 0 (number)');
596
597         // set a negative number
598         element.attr('tabindex', -1);
599         equals(element.attr('tabindex'), -1, 'set tabindex to -1 (number)');
600         
601         element = jQuery('#linkWithTabIndex');
602         equals(element.attr('tabindex'), 2, 'start with tabindex 2');
603
604         element.attr('tabindex', -1);
605         equals(element.attr('tabindex'), -1, 'set negative tabindex');
606 });
607
608 test("css(String|Hash)", function() {
609         expect(19);
610
611         equals( jQuery('#main').css("display"), 'none', 'Check for css property "display"');
612
613         ok( jQuery('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
614         jQuery('#foo').css({display: 'none'});
615         ok( !jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
616         jQuery('#foo').css({display: 'block'});
617         ok( jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
618
619         jQuery('#floatTest').css({styleFloat: 'right'});
620         equals( jQuery('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right');
621         jQuery('#floatTest').css({cssFloat: 'left'});
622         equals( jQuery('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left');
623         jQuery('#floatTest').css({'float': 'right'});
624         equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
625         jQuery('#floatTest').css({'font-size': '30px'});
626         equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
627
628         jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
629                 jQuery('#foo').css({opacity: n});
630                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
631                 jQuery('#foo').css({opacity: parseFloat(n)});
632                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
633         });
634         jQuery('#foo').css({opacity: ''});
635         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
636 });
637
638 test("css(String, Object)", function() {
639         expect(21);
640         ok( jQuery('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
641         jQuery('#foo').css('display', 'none');
642         ok( !jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
643         jQuery('#foo').css('display', 'block');
644         ok( jQuery('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
645
646         jQuery('#floatTest').css('styleFloat', 'left');
647         equals( jQuery('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left');
648         jQuery('#floatTest').css('cssFloat', 'right');
649         equals( jQuery('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right');
650         jQuery('#floatTest').css('float', 'left');
651         equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
652         jQuery('#floatTest').css('font-size', '20px');
653         equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
654
655         jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
656                 jQuery('#foo').css('opacity', n);
657                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
658                 jQuery('#foo').css('opacity', parseFloat(n));
659                 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
660         });
661         jQuery('#foo').css('opacity', '');
662         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
663         // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
664         if (jQuery.browser.msie) {
665                 jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
666         }
667         equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
668
669         // using contents will get comments regular, text, and comment nodes
670         var j = jQuery("#nonnodes").contents();
671         j.css("padding-left", "1px");
672         equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
673
674         // opera sometimes doesn't update 'display' correctly, see #2037
675         jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
676         equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
677 });
678
679 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
680         expect(4);
681
682         var $checkedtest = jQuery("#checkedtest");
683         // IE6 was clearing "checked" in jQuery.css(elem, "height");
684         jQuery.css($checkedtest[0], "height");
685         ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
686         ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
687         ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
688         ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
689 });
690
691 test("width()", function() {
692         expect(8);
693
694         var $div = jQuery("#nothiddendiv");
695         $div.width(30);
696         equals($div.width(), 30, "Test set to 30 correctly");
697         $div.width(-1); // handle negative numbers by ignoring #1599
698         equals($div.width(), 30, "Test negative width ignored");
699         $div.css("padding", "20px");
700         equals($div.width(), 30, "Test padding specified with pixels");
701         $div.css("border", "2px solid #fff");
702         equals($div.width(), 30, "Test border specified with pixels");
703         $div.css("padding", "2em");
704         equals($div.width(), 30, "Test padding specified with ems");
705         $div.css("border", "1em solid #fff");
706         //DISABLED - Opera 9.6 fails this test, returns 8
707         //equals($div.width(), 30, "Test border specified with ems");
708         $div.css("padding", "2%");
709         equals($div.width(), 30, "Test padding specified with percent");
710         $div.hide();
711         equals($div.width(), 30, "Test hidden div");
712
713         $div.css({ display: "", border: "", padding: "" });
714
715         jQuery("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" });
716         equals(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
717         jQuery("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" });
718 });
719
720 test("height()", function() {
721         expect(7);
722
723         var $div = jQuery("#nothiddendiv");
724         $div.height(30);
725         equals($div.height(), 30, "Test set to 30 correctly");
726         $div.height(-1); // handle negative numbers by ignoring #1599
727         equals($div.height(), 30, "Test negative height ignored");
728         $div.css("padding", "20px");
729         equals($div.height(), 30, "Test padding specified with pixels");
730         $div.css("border", "2px solid #fff");
731         equals($div.height(), 30, "Test border specified with pixels");
732         $div.css("padding", "2em");
733         equals($div.height(), 30, "Test padding specified with ems");
734         $div.css("border", "1em solid #fff");
735         //DISABLED - Opera 9.6 fails this test, returns 8
736         //equals($div.height(), 30, "Test border specified with ems");
737         $div.css("padding", "2%");
738         equals($div.height(), 30, "Test padding specified with percent");
739         $div.hide();
740         equals($div.height(), 30, "Test hidden div");
741
742         $div.css({ display: "", border: "", padding: "", height: "1px" });
743 });
744
745 test("text()", function() {
746         expect(1);
747         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
748         equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' );
749 });
750
751 test("wrap(String|Element)", function() {
752         expect(8);
753         var defaultText = 'Try them out:'
754         var result = jQuery('#first').wrap('<div class="red"><span></span></div>').text();
755         equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
756         ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
757
758         reset();
759         var defaultText = 'Try them out:'
760         var result = jQuery('#first').wrap(document.getElementById('empty')).parent();
761         ok( result.is('ol'), 'Check for element wrapping' );
762         equals( result.text(), defaultText, 'Check for element wrapping' );
763
764         reset();
765         jQuery('#check1').click(function() {
766                 var checkbox = this;
767                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
768                 jQuery(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
769                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
770         }).click();
771
772         // using contents will get comments regular, text, and comment nodes
773         var j = jQuery("#nonnodes").contents();
774         j.wrap("<i></i>");
775         equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
776         equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
777 });
778
779 test("wrapAll(String|Element)", function() {
780         expect(8);
781         var prev = jQuery("#firstp")[0].previousSibling;
782         var p = jQuery("#firstp,#first")[0].parentNode;
783         var result = jQuery('#firstp,#first').wrapAll('<div class="red"><div id="tmp"></div></div>');
784         equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
785         ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
786         ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
787         equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
788         equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
789
790         reset();
791         var prev = jQuery("#firstp")[0].previousSibling;
792         var p = jQuery("#first")[0].parentNode;
793         var result = jQuery('#firstp,#first').wrapAll(document.getElementById('empty'));
794         equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
795         equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
796         equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
797 });
798
799 test("wrapInner(String|Element)", function() {
800         expect(6);
801         var num = jQuery("#first").children().length;
802         var result = jQuery('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
803         equals( jQuery("#first").children().length, 1, "Only one child" );
804         ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
805         equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
806
807         reset();
808         var num = jQuery("#first").children().length;
809         var result = jQuery('#first').wrapInner(document.getElementById('empty'));
810         equals( jQuery("#first").children().length, 1, "Only one child" );
811         ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
812         equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
813 });
814
815 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
816         expect(21);
817         var defaultText = 'Try them out:'
818         var result = jQuery('#first').append('<b>buga</b>');
819         equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
820         equals( jQuery('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
821
822         reset();
823         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
824         jQuery('#sap').append(document.getElementById('first'));
825         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
826
827         reset();
828         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
829         jQuery('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
830         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
831
832         reset();
833         expected = document.querySelectorAll ?
834                 "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:" :
835                 "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
836         jQuery('#sap').append(jQuery("#first, #yahoo"));
837         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
838
839         reset();
840         jQuery("#sap").append( 5 );
841         ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
842
843         reset();
844         jQuery("#sap").append( " text with spaces " );
845         ok( jQuery("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
846
847         reset();
848         ok( jQuery("#sap").append([]), "Check for appending an empty array." );
849         ok( jQuery("#sap").append(""), "Check for appending an empty string." );
850         ok( jQuery("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
851
852         reset();
853         jQuery("#sap").append(document.getElementById('form'));
854         equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
855
856         reset();
857         var pass = true;
858         try {
859                 jQuery( jQuery("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
860         } catch(e) {
861                 pass = false;
862         }
863
864         ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
865
866         reset();
867         jQuery('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
868         t( 'Append legend', '#legend', ['legend'] );
869
870         reset();
871         jQuery('#select1').append('<OPTION>Test</OPTION>');
872         equals( jQuery('#select1 option:last').text(), "Test", "Appending &lt;OPTION&gt; (all caps)" );
873
874         jQuery('#table').append('<colgroup></colgroup>');
875         ok( jQuery('#table colgroup').length, "Append colgroup" );
876
877         jQuery('#table colgroup').append('<col/>');
878         ok( jQuery('#table colgroup col').length, "Append col" );
879
880         reset();
881         jQuery('#table').append('<caption></caption>');
882         ok( jQuery('#table caption').length, "Append caption" );
883
884         reset();
885         jQuery('form:last')
886                 .append('<select id="appendSelect1"></select>')
887                 .append('<select id="appendSelect2"><option>Test</option></select>');
888
889         t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
890
891         // using contents will get comments regular, text, and comment nodes
892         var j = jQuery("#nonnodes").contents();
893         var d = jQuery("<div/>").appendTo("#nonnodes").append(j);
894         equals( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
895         ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
896         d.contents().appendTo("#nonnodes");
897         d.remove();
898         ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
899 });
900
901 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
902         expect(6);
903         var defaultText = 'Try them out:'
904         jQuery('<b>buga</b>').appendTo('#first');
905         equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' );
906         equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
907
908         reset();
909         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
910         jQuery(document.getElementById('first')).appendTo('#sap');
911         equals( expected, jQuery('#sap').text(), "Check for appending of element" );
912
913         reset();
914         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
915         jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
916         equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
917
918         reset();
919         expected = document.querySelectorAll ?
920                 "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:" :
921                 "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
922         jQuery("#first, #yahoo").appendTo('#sap');
923         equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
924
925         reset();
926         jQuery('#select1').appendTo('#foo');
927         t( 'Append select', '#foo select', ['select1'] );
928 });
929
930 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
931         expect(5);
932         var defaultText = 'Try them out:'
933         var result = jQuery('#first').prepend('<b>buga</b>');
934         equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
935         equals( jQuery('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
936
937         reset();
938         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
939         jQuery('#sap').prepend(document.getElementById('first'));
940         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
941
942         reset();
943         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
944         jQuery('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
945         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
946
947         reset();
948         expected = document.querySelectorAll ?
949                 "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog" :
950                 "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
951         jQuery('#sap').prepend(jQuery("#first, #yahoo"));
952         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
953 });
954
955 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
956         expect(6);
957         var defaultText = 'Try them out:'
958         jQuery('<b>buga</b>').prependTo('#first');
959         equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' );
960         equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
961
962         reset();
963         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
964         jQuery(document.getElementById('first')).prependTo('#sap');
965         equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
966
967         reset();
968         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
969         jQuery([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
970         equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
971
972         reset();
973         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
974         jQuery("#yahoo, #first").prependTo('#sap');
975         equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
976
977         reset();
978         jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
979         jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
980
981         t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
982 });
983
984 test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
985         expect(4);
986         var expected = 'This is a normal link: bugaYahoo';
987         jQuery('#yahoo').before('<b>buga</b>');
988         equals( expected, jQuery('#en').text(), 'Insert String before' );
989
990         reset();
991         expected = "This is a normal link: Try them out:Yahoo";
992         jQuery('#yahoo').before(document.getElementById('first'));
993         equals( expected, jQuery('#en').text(), "Insert element before" );
994
995         reset();
996         expected = "This is a normal link: Try them out:diveintomarkYahoo";
997         jQuery('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
998         equals( expected, jQuery('#en').text(), "Insert array of elements before" );
999
1000         reset();
1001         expected = document.querySelectorAll ?
1002                 "This is a normal link: diveintomarkTry them out:Yahoo" :
1003                 "This is a normal link: Try them out:diveintomarkYahoo";
1004         jQuery('#yahoo').before(jQuery("#first, #mark"));
1005         equals( expected, jQuery('#en').text(), "Insert jQuery before" );
1006 });
1007
1008 test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
1009         expect(4);
1010         var expected = 'This is a normal link: bugaYahoo';
1011         jQuery('<b>buga</b>').insertBefore('#yahoo');
1012         equals( expected, jQuery('#en').text(), 'Insert String before' );
1013
1014         reset();
1015         expected = "This is a normal link: Try them out:Yahoo";
1016         jQuery(document.getElementById('first')).insertBefore('#yahoo');
1017         equals( expected, jQuery('#en').text(), "Insert element before" );
1018
1019         reset();
1020         expected = "This is a normal link: Try them out:diveintomarkYahoo";
1021         jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
1022         equals( expected, jQuery('#en').text(), "Insert array of elements before" );
1023
1024         reset();
1025         expected = document.querySelectorAll ?
1026                 "This is a normal link: diveintomarkTry them out:Yahoo" :
1027                 "This is a normal link: Try them out:diveintomarkYahoo";
1028         jQuery("#first, #mark").insertBefore('#yahoo');
1029         equals( expected, jQuery('#en').text(), "Insert jQuery before" );
1030 });
1031
1032 test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
1033         expect(4);
1034         var expected = 'This is a normal link: Yahoobuga';
1035         jQuery('#yahoo').after('<b>buga</b>');
1036         equals( expected, jQuery('#en').text(), 'Insert String after' );
1037
1038         reset();
1039         expected = "This is a normal link: YahooTry them out:";
1040         jQuery('#yahoo').after(document.getElementById('first'));
1041         equals( expected, jQuery('#en').text(), "Insert element after" );
1042
1043         reset();
1044         expected = "This is a normal link: YahooTry them out:diveintomark";
1045         jQuery('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
1046         equals( expected, jQuery('#en').text(), "Insert array of elements after" );
1047
1048         reset();
1049         expected = document.querySelectorAll ?
1050                 "This is a normal link: YahoodiveintomarkTry them out:" :
1051                 "This is a normal link: YahooTry them out:diveintomark";
1052         jQuery('#yahoo').after(jQuery("#first, #mark"));
1053         equals( expected, jQuery('#en').text(), "Insert jQuery after" );
1054 });
1055
1056 test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
1057         expect(4);
1058         var expected = 'This is a normal link: Yahoobuga';
1059         jQuery('<b>buga</b>').insertAfter('#yahoo');
1060         equals( expected, jQuery('#en').text(), 'Insert String after' );
1061
1062         reset();
1063         expected = "This is a normal link: YahooTry them out:";
1064         jQuery(document.getElementById('first')).insertAfter('#yahoo');
1065         equals( expected, jQuery('#en').text(), "Insert element after" );
1066
1067         reset();
1068         expected = "This is a normal link: YahooTry them out:diveintomark";
1069         jQuery([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
1070         equals( expected, jQuery('#en').text(), "Insert array of elements after" );
1071
1072         reset();
1073         expected = "This is a normal link: YahooTry them out:diveintomark";
1074         jQuery("#mark, #first").insertAfter('#yahoo');
1075         equals( expected, jQuery('#en').text(), "Insert jQuery after" );
1076 });
1077
1078 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
1079         expect(10);
1080         jQuery('#yahoo').replaceWith('<b id="replace">buga</b>');
1081         ok( jQuery("#replace")[0], 'Replace element with string' );
1082         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
1083
1084         reset();
1085         jQuery('#yahoo').replaceWith(document.getElementById('first'));
1086         ok( jQuery("#first")[0], 'Replace element with element' );
1087         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
1088
1089         reset();
1090         jQuery('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
1091         ok( jQuery("#first")[0], 'Replace element with array of elements' );
1092         ok( jQuery("#mark")[0], 'Replace element with array of elements' );
1093         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
1094
1095         reset();
1096         jQuery('#yahoo').replaceWith(jQuery("#first, #mark"));
1097         ok( jQuery("#first")[0], 'Replace element with set of elements' );
1098         ok( jQuery("#mark")[0], 'Replace element with set of elements' );
1099         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
1100 });
1101
1102 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
1103         expect(10);
1104         jQuery('<b id="replace">buga</b>').replaceAll("#yahoo");
1105         ok( jQuery("#replace")[0], 'Replace element with string' );
1106         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' );
1107
1108         reset();
1109         jQuery(document.getElementById('first')).replaceAll("#yahoo");
1110         ok( jQuery("#first")[0], 'Replace element with element' );
1111         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' );
1112
1113         reset();
1114         jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
1115         ok( jQuery("#first")[0], 'Replace element with array of elements' );
1116         ok( jQuery("#mark")[0], 'Replace element with array of elements' );
1117         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
1118
1119         reset();
1120         jQuery("#first, #mark").replaceAll("#yahoo");
1121         ok( jQuery("#first")[0], 'Replace element with set of elements' );
1122         ok( jQuery("#mark")[0], 'Replace element with set of elements' );
1123         ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
1124 });
1125
1126 test("end()", function() {
1127         expect(3);
1128         equals( 'Yahoo', jQuery('#yahoo').parent().end().text(), 'Check for end' );
1129         ok( jQuery('#yahoo').end(), 'Check for end with nothing to end' );
1130
1131         var x = jQuery('#yahoo');
1132         x.parent();
1133         equals( 'Yahoo', jQuery('#yahoo').text(), 'Check for non-destructive behaviour' );
1134 });
1135
1136 test("find(String)", function() {
1137         expect(2);
1138         equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );
1139
1140         // using contents will get comments regular, text, and comment nodes
1141         var j = jQuery("#nonnodes").contents();
1142         equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
1143 });
1144
1145 test("clone()", function() {
1146         expect(20);
1147         equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
1148         var clone = jQuery('#yahoo').clone();
1149         equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
1150         equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' );
1151
1152         var cloneTags = [
1153                 "<table/>", "<tr/>", "<td/>", "<div/>",
1154                 "<button/>", "<ul/>", "<ol/>", "<li/>",
1155                 "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
1156                 "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
1157         ];
1158         for (var i = 0; i < cloneTags.length; i++) {
1159                 var j = jQuery(cloneTags[i]);
1160                 equals( j[0].tagName, j.clone()[0].tagName, 'Clone a &lt;' + cloneTags[i].substring(1));
1161         }
1162
1163         // using contents will get comments regular, text, and comment nodes
1164         var cl = jQuery("#nonnodes").contents().clone();
1165         ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
1166 });
1167
1168 if (!isLocal) {
1169 test("clone() on XML nodes", function() {
1170         expect(2);
1171         stop();
1172         jQuery.get("data/dashboard.xml", function (xml) {
1173                 var root = jQuery(xml.documentElement).clone();
1174                 var origTab = jQuery("tab", xml).eq(0);
1175                 var cloneTab = jQuery("tab", root).eq(0);
1176                 origTab.text("origval");
1177                 cloneTab.text("cloneval");
1178                 equals(origTab.text(), "origval", "Check original XML node was correctly set");
1179                 equals(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
1180                 start();
1181         });
1182 });
1183 }
1184
1185 test("is(String)", function() {
1186         expect(26);
1187         ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' );
1188         ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' );
1189         ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
1190         ok( !jQuery('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
1191         ok( jQuery('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
1192         ok( !jQuery('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
1193         ok( jQuery('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
1194         ok( !jQuery('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
1195         ok( jQuery('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
1196         ok( !jQuery('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
1197         ok( jQuery('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
1198         ok( !jQuery('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
1199         ok( jQuery('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
1200         ok( !jQuery('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
1201         ok( jQuery('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
1202         ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
1203         ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
1204         ok( !jQuery('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
1205         ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' );
1206         ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' );
1207         ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' );
1208         ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
1209
1210         // test is() with comma-seperated expressions
1211         ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1212         ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1213         ok( jQuery('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1214         ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
1215 });
1216
1217 test("jQuery.merge()", function() {
1218         expect(6);
1219                 
1220         var parse = jQuery.merge;
1221         
1222         same( parse([],[]), [], "Empty arrays" );
1223         
1224         same( parse([1],[2]), [1,2], "Basic" );
1225         same( parse([1,2],[3,4]), [1,2,3,4], "Basic" );
1226         
1227         same( parse([1,2],[]), [1,2], "Second empty" );
1228         same( parse([],[1,2]), [1,2], "First empty" );  
1229         
1230         // Fixed at [5998], #3641
1231         same( parse([-2,-1], [0,1,2]), [-2,-1,0,1,2], "Second array including a zero (falsy)");
1232 });
1233
1234 test("jQuery.extend(Object, Object)", function() {
1235         expect(20);
1236
1237         var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1238                 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
1239                 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
1240                 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
1241                 deep1 = { foo: { bar: true } },
1242                 deep1copy = { foo: { bar: true } },
1243                 deep2 = { foo: { baz: true }, foo2: document },
1244                 deep2copy = { foo: { baz: true }, foo2: document },
1245                 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
1246
1247         jQuery.extend(settings, options);
1248         isObj( settings, merged, "Check if extended: settings must be extended" );
1249         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
1250
1251         jQuery.extend(settings, null, options);
1252         isObj( settings, merged, "Check if extended: settings must be extended" );
1253         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
1254
1255         jQuery.extend(true, deep1, deep2);
1256         isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
1257         isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
1258         equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
1259
1260         var nullUndef;
1261         nullUndef = jQuery.extend({}, options, { xnumber2: null });
1262         ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
1263
1264         nullUndef = jQuery.extend({}, options, { xnumber2: undefined });
1265         ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
1266
1267         nullUndef = jQuery.extend({}, options, { xnumber0: null });
1268         ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
1269
1270         var target = {};
1271         var recursive = { foo:target, bar:5 };
1272         jQuery.extend(true, target, recursive);
1273         isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
1274
1275         var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
1276         equals( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
1277
1278         var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
1279         ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
1280
1281         var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
1282         ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
1283
1284         var obj = { foo:null };
1285         jQuery.extend(true, obj, { foo:"notnull" } );
1286         equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
1287
1288         function func() {}
1289         jQuery.extend(func, { key: "value" } );
1290         equals( func.key, "value", "Verify a function can be extended" );
1291
1292         var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1293                 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
1294                 options1 = { xnumber2: 1, xstring2: "x" },
1295                 options1Copy = { xnumber2: 1, xstring2: "x" },
1296                 options2 = { xstring2: "xx", xxx: "newstringx" },
1297                 options2Copy = { xstring2: "xx", xxx: "newstringx" },
1298                 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
1299
1300         var settings = jQuery.extend({}, defaults, options1, options2);
1301         isObj( settings, merged2, "Check if extended: settings must be extended" );
1302         isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
1303         isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
1304         isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
1305 });
1306
1307 test("val()", function() {
1308         expect(8);
1309
1310         equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
1311         // ticket #1714 this caused a JS error in IE
1312         equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
1313         ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
1314         
1315         equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
1316
1317         isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
1318
1319         equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
1320         
1321         equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
1322         
1323         equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
1324         
1325 });
1326
1327 test("val(String/Number)", function() {
1328         expect(6);
1329         document.getElementById('text1').value = "bla";
1330         equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
1331         
1332         jQuery("#text1").val('test');
1333         equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
1334         
1335         jQuery("#text1").val(67);
1336         equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
1337
1338         jQuery("#select1").val("3");
1339         equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
1340
1341         jQuery("#select1").val(2);
1342         equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
1343
1344         // using contents will get comments regular, text, and comment nodes
1345         var j = jQuery("#nonnodes").contents();
1346         j.val("asdf");
1347         equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
1348         j.removeAttr("value");
1349 });
1350
1351 test("html(String)", function() {
1352         expect(13);
1353         
1354         jQuery.scriptorder = 0;
1355         
1356         var div = jQuery("#main > div");
1357         div.html("<b>test</b>");
1358         var pass = true;
1359         for ( var i = 0; i < div.size(); i++ ) {
1360                 if ( div.get(i).childNodes.length != 1 ) pass = false;
1361         }
1362         ok( pass, "Set HTML" );
1363
1364         reset();
1365         // using contents will get comments regular, text, and comment nodes
1366         var j = jQuery("#nonnodes").contents();
1367         j.html("<b>bold</b>");
1368
1369         // this is needed, or the expando added by jQuery unique will yield a different html
1370         j.find('b').removeData();
1371         equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1372
1373         jQuery("#main").html("<select/>");
1374         jQuery("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
1375         equals( jQuery("#main select").val(), "O2", "Selected option correct" );
1376
1377         var $div = jQuery('<div />');
1378         equals( $div.html( 5 ).html(), '5', 'Setting a number as html' );
1379         equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' );
1380
1381         stop();
1382
1383         jQuery("#main").html('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
1384
1385         jQuery("#main").html('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
1386
1387         // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
1388         jQuery("#main").html("<script>equals(jQuery.scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>");
1389
1390         setTimeout( start, 100 );
1391 });
1392
1393 test("filter()", function() {
1394         expect(6);
1395         isSet( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
1396         isSet( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
1397         isSet( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
1398         isSet( jQuery("p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
1399
1400         // using contents will get comments regular, text, and comment nodes
1401         var j = jQuery("#nonnodes").contents();
1402         equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
1403         equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
1404 });
1405
1406 test("closest()", function() {
1407         expect(4);
1408         isSet( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
1409         isSet( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
1410         isSet( jQuery("body").closest("div").get(), [], "closest(div)" );
1411         isSet( jQuery("#main").closest("span,#html").get(), q("html"), "closest(span,#html)" );
1412 });
1413
1414 test("not()", function() {
1415         expect(11);
1416         equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
1417         equals( jQuery("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
1418         isSet( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
1419         isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
1420         isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
1421         equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
1422         isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')");
1423
1424         var selects = jQuery("#form select");
1425         isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
1426
1427         isSet( jQuery('#ap *').not('code'), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
1428         isSet( jQuery('#ap *').not('code, #mark'), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
1429         isSet( jQuery('#ap *').not('#mark, code'), q("google", "groups", "anchor1"), "not('ID, tag selector')"); 
1430 });
1431
1432 test("andSelf()", function() {
1433         expect(4);
1434         isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
1435         isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
1436         isSet( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" );
1437         isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
1438 });
1439
1440 test("siblings([String])", function() {
1441         expect(5);
1442         isSet( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
1443         isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
1444         isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
1445         isSet( jQuery("#foo").siblings("form, b").get(), q("form", "lengthtest", "name-tests", "testForm", "floatTest"), "Check for multiple filters" );
1446         var set = document.querySelectorAll ? q("en", "sap", "sndp") : q("sndp", "sap", "en");
1447         isSet( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
1448 });
1449
1450 test("children([String])", function() {
1451         expect(3);
1452         isSet( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
1453         isSet( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
1454         isSet( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
1455 });
1456
1457 test("parent([String])", function() {
1458         expect(5);
1459         equals( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
1460         equals( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
1461         equals( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
1462         equals( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
1463         isSet( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
1464 });
1465
1466 test("parents([String])", function() {
1467         expect(5);
1468         equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
1469         equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
1470         equals( jQuery("#groups").parents("div")[0].id, "main", "Filtered parents check2" );
1471         isSet( jQuery("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
1472         isSet( jQuery("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
1473 });
1474
1475 test("next([String])", function() {
1476         expect(4);
1477         equals( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
1478         equals( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
1479         equals( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
1480         equals( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
1481 });
1482
1483 test("prev([String])", function() {
1484         expect(4);
1485         equals( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
1486         equals( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
1487         equals( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
1488         equals( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
1489 });
1490
1491 test("show()", function() {
1492         expect(15);
1493         var pass = true, div = jQuery("div");
1494         div.show().each(function(){
1495                 if ( this.style.display == "none" ) pass = false;
1496         });
1497         ok( pass, "Show" );
1498
1499         jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
1500         var test = {
1501                 "div"      : "block",
1502                 "p"        : "block",
1503                 "a"        : "inline",
1504                 "code"     : "inline",
1505                 "pre"      : "block",
1506                 "span"     : "inline",
1507                 "table"    : jQuery.browser.msie ? "block" : "table",
1508                 "thead"    : jQuery.browser.msie ? "block" : "table-header-group",
1509                 "tbody"    : jQuery.browser.msie ? "block" : "table-row-group",
1510                 "tr"       : jQuery.browser.msie ? "block" : "table-row",
1511                 "th"       : jQuery.browser.msie ? "block" : "table-cell",
1512                 "td"       : jQuery.browser.msie ? "block" : "table-cell",
1513                 "ul"       : "block",
1514                 "li"       : jQuery.browser.msie ? "block" : "list-item"
1515         };
1516
1517         jQuery.each(test, function(selector, expected) {
1518                 var elem = jQuery(selector, "#show-tests").show();
1519                 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
1520         });
1521 });
1522
1523 test("addClass(String)", function() {
1524         expect(2);
1525         var div = jQuery("div");
1526         div.addClass("test");
1527         var pass = true;
1528         for ( var i = 0; i < div.size(); i++ ) {
1529          if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
1530         }
1531         ok( pass, "Add Class" );
1532
1533         // using contents will get regular, text, and comment nodes
1534         var j = jQuery("#nonnodes").contents();
1535         j.addClass("asdf");
1536         ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
1537 });
1538
1539 test("removeClass(String) - simple", function() {
1540         expect(4);
1541         
1542         var $divs = jQuery('div');
1543         
1544         $divs.addClass("test").removeClass("test");
1545                 
1546         ok( !$divs.is('.test'), "Remove Class" );
1547
1548         reset();
1549         
1550         $divs.addClass("test").addClass("foo").addClass("bar");
1551         $divs.removeClass("test").removeClass("bar").removeClass("foo");
1552         
1553         ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" );
1554
1555         reset();
1556         
1557         $divs.eq(0).addClass("test").removeClass("");
1558         ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" );
1559
1560         // using contents will get regular, text, and comment nodes
1561         var j = jQuery("#nonnodes").contents();
1562         j.removeClass("asdf");
1563         ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
1564 });
1565
1566 test("toggleClass(String)", function() {
1567         expect(6);
1568         var e = jQuery("#firstp");
1569         ok( !e.is(".test"), "Assert class not present" );
1570         e.toggleClass("test");
1571         ok( e.is(".test"), "Assert class present" );
1572         e.toggleClass("test");
1573         ok( !e.is(".test"), "Assert class not present" );
1574
1575         e.toggleClass("test", false);
1576         ok( !e.is(".test"), "Assert class not present" );
1577         e.toggleClass("test", true);
1578         ok( e.is(".test"), "Assert class present" );
1579         e.toggleClass("test", false);
1580         ok( !e.is(".test"), "Assert class not present" );
1581 });
1582
1583 test("removeAttr(String", function() {
1584         expect(1);
1585         equals( jQuery('#mark').removeAttr("class")[0].className, "", "remove class" );
1586 });
1587
1588 test("text(String)", function() {
1589         expect(4);
1590         equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
1591
1592         // using contents will get comments regular, text, and comment nodes
1593         var j = jQuery("#nonnodes").contents();
1594         j.text("hi!");
1595         equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
1596         equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
1597         equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
1598 });
1599
1600 test("jQuery.each(Object,Function)", function() {
1601         expect(12);
1602         jQuery.each( [0,1,2], function(i, n){
1603                 equals( i, n, "Check array iteration" );
1604         });
1605
1606         jQuery.each( [5,6,7], function(i, n){
1607                 equals( i, n - 5, "Check array iteration" );
1608         });
1609
1610         jQuery.each( { name: "name", lang: "lang" }, function(i, n){
1611                 equals( i, n, "Check object iteration" );
1612         });
1613
1614         var total = 0;
1615         jQuery.each([1,2,3], function(i,v){ total += v; });
1616         equals( total, 6, "Looping over an array" );
1617         total = 0;
1618         jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
1619         equals( total, 3, "Looping over an array, with break" );
1620         total = 0;
1621         jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
1622         equals( total, 6, "Looping over an object" );
1623         total = 0;
1624         jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
1625         equals( total, 3, "Looping over an object, with break" );
1626 });
1627
1628 test("jQuery.prop", function() {
1629         expect(2);
1630         var handle = function() { return this.id };
1631         equals( jQuery.prop(jQuery("#ap")[0], handle), "ap", "Check with Function argument" );
1632         equals( jQuery.prop(jQuery("#ap")[0], "value"), "value", "Check with value argument" );
1633 });
1634
1635 test("jQuery.className", function() {
1636         expect(6);
1637         var x = jQuery("<p>Hi</p>")[0];
1638         var c = jQuery.className;
1639         c.add(x, "hi");
1640         equals( x.className, "hi", "Check single added class" );
1641         c.add(x, "foo bar");
1642         equals( x.className, "hi foo bar", "Check more added classes" );
1643         c.remove(x);
1644         equals( x.className, "", "Remove all classes" );
1645         c.add(x, "hi foo bar");
1646         c.remove(x, "foo");
1647         equals( x.className, "hi bar", "Check removal of one class" );
1648         ok( c.has(x, "hi"), "Check has1" );
1649         ok( c.has(x, "bar"), "Check has2" );
1650 });
1651
1652 test("remove()", function() {
1653         expect(6);
1654         jQuery("#ap").children().remove();
1655         ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1656         equals( jQuery("#ap").children().length, 0, "Check remove" );
1657
1658         reset();
1659         jQuery("#ap").children().remove("a");
1660         ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
1661         equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
1662
1663         // using contents will get comments regular, text, and comment nodes
1664         equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
1665         jQuery("#nonnodes").contents().remove();
1666         equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1667 });
1668
1669 test("empty()", function() {
1670         expect(3);
1671         equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
1672         equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
1673
1674         // using contents will get comments regular, text, and comment nodes
1675         var j = jQuery("#nonnodes").contents();
1676         j.empty();
1677         equals( j.html(), "", "Check node,textnode,comment empty works" );
1678 });
1679
1680 test("slice()", function() {
1681         expect(6);
1682         
1683         var $links = jQuery("#ap a");
1684         
1685         isSet( $links.slice(1,2), q("groups"), "slice(1,2)" );
1686         isSet( $links.slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
1687         isSet( $links.slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
1688         isSet( $links.slice(-1), q("mark"), "slice(-1)" );
1689
1690         isSet( $links.eq(1), q("groups"), "eq(1)" );
1691         
1692         isSet( $links.eq('2'), q("anchor1"), "eq('2')" );
1693 });
1694
1695 test("map()", function() {
1696         expect(2);//expect(6);
1697
1698         isSet(
1699                 jQuery("#ap").map(function(){
1700                         return jQuery(this).find("a").get();
1701                 }),
1702                 q("google", "groups", "anchor1", "mark"),
1703                 "Array Map"
1704         );
1705
1706         isSet(
1707                 jQuery("#ap > a").map(function(){
1708                         return this.parentNode;
1709                 }),
1710                 q("ap","ap","ap"),
1711                 "Single Map"
1712         );
1713
1714         return;//these haven't been accepted yet
1715
1716         //for #2616
1717         var keys = jQuery.map( {a:1,b:2}, function( v, k ){
1718                 return k;
1719         }, [ ] );
1720
1721         equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
1722
1723         var values = jQuery.map( {a:1,b:2}, function( v, k ){
1724                 return v;
1725         }, [ ] );
1726
1727         equals( values.join(""), "12", "Map the values from a hash to an array" );
1728
1729         var scripts = document.getElementsByTagName("script");
1730         var mapped = jQuery.map( scripts, function( v, k ){
1731                 return v;
1732         }, {length:0} );
1733
1734         equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
1735
1736         var flat = jQuery.map( Array(4), function( v, k ){
1737                 return k % 2 ? k : [k,k,k];//try mixing array and regular returns
1738         });
1739
1740         equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
1741 });
1742
1743 test("contents()", function() {
1744         expect(12);
1745         equals( jQuery("#ap").contents().length, 9, "Check element contents" );
1746         ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" );
1747         var ibody = jQuery("#loadediframe").contents()[0].body;
1748         ok( ibody, "Check existance of IFrame body" );
1749
1750         equals( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
1751
1752         jQuery(ibody).append("<div>init text</div>");
1753         equals( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
1754
1755         equals( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
1756
1757         jQuery("div:last", ibody).text("div text");
1758         equals( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
1759
1760         jQuery("div:last", ibody).remove();
1761         equals( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
1762
1763         equals( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
1764
1765         jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
1766         jQuery("table", ibody).remove();
1767         equals( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
1768
1769         // using contents will get comments regular, text, and comment nodes
1770         var c = jQuery("#nonnodes").contents().contents();
1771         equals( c.length, 1, "Check node,textnode,comment contents is just one" );
1772         equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
1773 });
1774
1775 test("jQuery.makeArray", function(){
1776         expect(15);
1777
1778         equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName, "HEAD", "Pass makeArray a jQuery object" );
1779
1780         equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
1781
1782         equals( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
1783
1784         equals( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
1785
1786         equals( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
1787
1788         equals( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
1789
1790         equals( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
1791
1792         equals( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
1793
1794         equals( jQuery.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" );
1795
1796         equals( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
1797
1798         ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
1799
1800         // function, is tricky as it has length
1801         equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
1802         
1803         //window, also has length
1804         equals( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
1805
1806         equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
1807
1808         ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
1809 });