Ensure that buildFragment clones elements properly in all browsers. Fixes #3879,...
[jquery.git] / test / unit / manipulation.js
index ba57a6f..559a076 100644 (file)
@@ -1,5 +1,8 @@
 module("manipulation");
 
+// Ensure that an extended Array prototype doesn't break jQuery
+Array.prototype.arrayProtoFn = function(arg) { throw("arrayProtoFn should not be called"); };
+
 var bareObj = function(value) { return value; };
 var functionReturningObj = function(value) { return (function() { return value; }); };
 
@@ -392,7 +395,7 @@ test("append(Function) with incoming value", function() {
 });
 
 test("append the same fragment with events (Bug #6997, 5566)", function () {
-       expect(4 + (document.fireEvent ? 1 : 0));
+       expect(2 + (document.fireEvent ? 1 : 0));
        stop(1000);
 
        var element;
@@ -423,14 +426,6 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
 
        jQuery("#listWithTabIndex li").before(element);
        jQuery("#listWithTabIndex li.test6997").eq(1).click();
-
-       element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
-
-       equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
-
-       element = jQuery("<input type='checkbox'>").attr('checked', 'checked');
-
-       equals( element.clone().is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
 });
 
 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
@@ -942,6 +937,28 @@ test("clone()", function() {
        equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
 });
 
+test("clone(form element) (Bug #3879, #6655)", function() {
+       expect(6);
+       element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
+
+       equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
+
+       element = jQuery("<input type='checkbox' value='foo'>").attr('checked', 'checked');
+       clone = element.clone();
+
+       equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
+       equals( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" );
+       equals( clone[0].defaultChecked, !jQuery.support.noCloneEvent, "Checked input defaultChecked cloned correctly" );
+
+       element = jQuery("<input type='text' value='foo'>");
+       clone = element.clone();
+       equals( clone[0].defaultValue, "foo", "Text input defaultValue cloned correctly" );
+
+       element = jQuery("<textarea>foo</textarea>");
+       clone = element.clone();
+       equals( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
+});
+
 if (!isLocal) {
 test("clone() on XML nodes", function() {
        expect(2);
@@ -1244,3 +1261,20 @@ test("jQuery.cleanData", function() {
                return div;
        }
 });
+
+test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
+       expect(1);
+
+       // DOM manipulation fails if added text matches an Object method
+       var $f = jQuery( "<div />" ).appendTo( "#main" ),
+               bad = [ "start-", "toString", "hasOwnProperty", "append", "here&there!", "-end" ];
+
+       for ( var i=0; i < bad.length; i++ ) {
+               try {
+                       $f.append( bad[i] );
+               }
+               catch(e) {}
+       }
+    equals($f.text(), bad.join(''), "Cached strings that match Object properties");
+       $f.remove();
+});