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