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