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