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