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