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