X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fmanipulation.js;h=de841445f66811129c5b83c751b77b81e8c53db0;hb=e2941d5a98e91c5f61b200b2763e5fa0eb339365;hp=52f76ed6983b9e4cdf05189bee124611e93e7afc;hpb=faefbb1ad0b81e8001b582d06d5bd9c9236e62ce;p=jquery.git diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 52f76ed..de84144 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1,4 +1,7 @@ -module("manipulation"); +module("manipulation", { teardown: moduleTeardown }); + +// 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; }); }; @@ -112,12 +115,19 @@ var testWrap = function(val) { // Wrap an element with a jQuery set and event result = jQuery("
").click(function(){ ok(true, "Event triggered."); + + // Remove handlers on detached elements + result.unbind(); + jQuery(this).unbind(); }); j = jQuery("").wrap(result); equals( j[0].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); j.parent().trigger("click"); + + // clean up attached elements + QUnit.reset(); } test("wrap(String|Element)", function() { @@ -405,8 +415,12 @@ test("append the same fragment with events (Bug #6997, 5566)", function () { ok(true, "Event exists on original after being unbound on clone"); jQuery(this).unbind('click'); }); - element.clone(true).unbind('click')[0].fireEvent('onclick'); + var clone = element.clone(true).unbind('click'); + clone[0].fireEvent('onclick'); element[0].fireEvent('onclick'); + + // manually clean up detached elements + clone.remove(); } element = jQuery("").click(function () { @@ -891,20 +905,36 @@ test("clone()", function() { ok( true, "Bound event still exists." ); }); - div = div.clone(true).clone(true); + clone = div.clone(true); + + // manually clean up detached elements + div.remove(); + + div = clone.clone(true); + + // manually clean up detached elements + clone.remove(); + equals( div.length, 1, "One element cloned" ); equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); div.trigger("click"); + // manually clean up detached elements + div.remove(); + div = jQuery("
").append([ document.createElement("table"), document.createElement("table") ]); div.find("table").click(function(){ ok( true, "Bound event still exists." ); }); - div = div.clone(true); - equals( div.length, 1, "One element cloned" ); - equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); - div.find("table:last").trigger("click"); + clone = div.clone(true); + equals( clone.length, 1, "One element cloned" ); + equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); + clone.find("table:last").trigger("click"); + + // manually clean up detached elements + div.remove(); + clone.remove(); // this is technically an invalid object, but because of the special // classid instantiation it is the only kind that IE has trouble with, @@ -924,16 +954,16 @@ test("clone()", function() { equals( clone.html(), div.html(), "Element contents cloned" ); equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); - div = jQuery("
").data({ - a: true, b: true, - c: { nesty: ["Block", "Head"] } - }); - var div2 = div.clone(true); - equals( div2.data("a"), true, "Data cloned." ); - equals( div2.data("b"), true, "Data cloned." ); - var c = div2.data("c"); - c.nesty[0] = "Fish"; - equals( div.data("c").nesty[0], "Block", "Ensure cloned element data is deep copied (Bug #7717)" ); + div = jQuery("
").data({ a: true }); + clone = div.clone(true); + equals( clone.data("a"), true, "Data cloned." ); + clone.data("a", false); + equals( clone.data("a"), false, "Ensure cloned element data object was correctly modified" ); + equals( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" ); + + // manually clean up detached elements + div.remove(); + clone.remove(); var form = document.createElement("form"); form.action = "/test/"; @@ -1142,15 +1172,21 @@ var testRemove = function(method) { jQuery("#nonnodes").contents()[method](); equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" ); + // manually clean up detached elements + if (method === "detach") { + first.remove(); + } + QUnit.reset(); var count = 0; var first = jQuery("#ap").children(":first"); - var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click(); + var cleanUp = first.click(function() { count++ })[method]().appendTo("#main").click(); equals( method == "remove" ? 0 : 1, count ); - cleanUp.detach(); + // manually clean up detached elements + cleanUp.remove(); }; test("remove()", function() { @@ -1248,3 +1284,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( "
" ).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(); +});