Skip to content

Commit

Permalink
Remove test of the invalid object for IE9's sake; Rewrite the appropr…
Browse files Browse the repository at this point in the history
…iate support test for html5 clone caching. Fixes #10682
  • Loading branch information
timmywil committed Nov 8, 2011
2 parents f8eba6e + 92c8404 commit 41b31d7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/manipulation.js
Expand Up @@ -483,7 +483,7 @@ jQuery.buildFragment = function( args, nodes, scripts ) {
if ( args.length === 1 && typeof first === "string" && first.length < 512 && doc === document && if ( args.length === 1 && typeof first === "string" && first.length < 512 && doc === document &&
first.charAt(0) === "<" && !rnocache.test( first ) && first.charAt(0) === "<" && !rnocache.test( first ) &&
(jQuery.support.checkClone || !rchecked.test( first )) && (jQuery.support.checkClone || !rchecked.test( first )) &&
(!jQuery.support.unknownElems && rnoshimcache.test( first )) ) { (jQuery.support.html5Clone || !rnoshimcache.test( first )) ) {


cacheable = true; cacheable = true;


Expand Down
9 changes: 5 additions & 4 deletions src/support.js
Expand Up @@ -24,7 +24,7 @@ jQuery.support = (function() {


// Preliminary tests // Preliminary tests
div.setAttribute("className", "t"); div.setAttribute("className", "t");
div.innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/><nav></nav>"; div.innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";




all = div.getElementsByTagName( "*" ); all = div.getElementsByTagName( "*" );
Expand Down Expand Up @@ -69,9 +69,6 @@ jQuery.support = (function() {
// (IE uses styleFloat instead of cssFloat) // (IE uses styleFloat instead of cssFloat)
cssFloat: !!a.style.cssFloat, cssFloat: !!a.style.cssFloat,


// Make sure unknown elements (like HTML5 elems) are handled appropriately
unknownElems: !!div.getElementsByTagName( "nav" ).length,

// Make sure that if no value is specified for a checkbox // Make sure that if no value is specified for a checkbox
// that it defaults to "on". // that it defaults to "on".
// (WebKit defaults to "" instead) // (WebKit defaults to "" instead)
Expand All @@ -87,6 +84,10 @@ jQuery.support = (function() {
// Tests for enctype support on a form(#6743) // Tests for enctype support on a form(#6743)
enctype: !!document.createElement("form").enctype, enctype: !!document.createElement("form").enctype,


// Makes sure cloning an html5 element does not cause problems
// Where outerHTML is undefined, this still works
html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav></:nav>",

// Will be defined later // Will be defined later
submitBubbles: true, submitBubbles: true,
changeBubbles: true, changeBubbles: true,
Expand Down
54 changes: 51 additions & 3 deletions test/unit/manipulation.js
Expand Up @@ -513,7 +513,7 @@ test("HTML5 Elements inherit styles from style rules (Bug #10501)", function ()
notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles"); notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles");
}); });


test("clone() (#6485)", function () { test("html5 clone() cannot use the fragment cache in IE (#6485)", function () {
expect(1); expect(1);


jQuery("<article><section><aside>HTML5 elements</aside></section></article>").appendTo("#qunit-fixture"); jQuery("<article><section><aside>HTML5 elements</aside></section></article>").appendTo("#qunit-fixture");
Expand Down Expand Up @@ -1034,7 +1034,7 @@ test("clone() (#8070)", function () {
}); });


test("clone()", function() { test("clone()", function() {
expect(40); expect(39);
equal( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" ); equal( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" );
var clone = jQuery("#yahoo").clone(); var clone = jQuery("#yahoo").clone();
equal( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" ); equal( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" );
Expand Down Expand Up @@ -1116,7 +1116,7 @@ test("clone()", function() {


clone = div.clone(true); clone = div.clone(true);
equal( clone.length, 1, "One element cloned" ); equal( clone.length, 1, "One element cloned" );
equal( clone.html(), div.html(), "Element contents cloned" ); // equal( clone.html(), div.html(), "Element contents cloned" );
equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); equal( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );


// and here's a valid one. // and here's a valid one.
Expand Down Expand Up @@ -1642,3 +1642,51 @@ test("Cloned, detached HTML5 elems (#10667,10670)", function() {
$section.unbind( "click" ); $section.unbind( "click" );
$clone.unbind( "click" ); $clone.unbind( "click" );
}); });

test("jQuery.fragments cache expectations", function() {

expect( 10 );

jQuery.fragments = {};

function fragmentCacheSize() {
var n = 0, c;

for ( c in jQuery.fragments ) {
n++;
}
return n;
}

jQuery("<li></li>");
jQuery("<li>?</li>");
jQuery("<li>whip</li>");
jQuery("<li>it</li>");
jQuery("<li>good</li>");
jQuery("<div></div>");
jQuery("<div><div><span></span></div></div>");
jQuery("<tr><td></td></tr>");
jQuery("<tr><td></tr>");
jQuery("<li>aaa</li>");
jQuery("<ul><li>?</li></ul>");
jQuery("<div><p>arf</p>nnn</div>");
jQuery("<div><p>dog</p>?</div>");
jQuery("<span><span>");

equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 1" );

jQuery.each( [
"<tr><td></td></tr>",
"<ul><li>?</li></ul>",
"<div><p>dog</p>?</div>",
"<span><span>"
], function( i, frag ) {

jQuery( frag );

equal( jQuery.fragments[ frag ].nodeType, 11, "Second call with " + frag + " creates a cached DocumentFragment, has nodeType 11" );
ok( jQuery.fragments[ frag ].childNodes.length, "Second call with " + frag + " creates a cached DocumentFragment, has childNodes with length" );
});

equal( fragmentCacheSize(), 12, "12 entries exist in jQuery.fragments, 2" );
});

0 comments on commit 41b31d7

Please sign in to comment.