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