Commit 6a6604b7 authored by Richard Gibson's avatar Richard Gibson

No ticket: Hide the testing-support jQuery from tests

(cherry picked from commit 0c185209)

Conflicts:

	test/data/testrunner.js
parent ceb5b4c9
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
"ajaxTest": false, "ajaxTest": false,
"testIframe": false, "testIframe": false,
"testIframeWithCallback": false, "testIframeWithCallback": false,
"iframeCallback": true,
"createDashboardXML": false, "createDashboardXML": false,
"createXMLFragment": false, "createXMLFragment": false,
"moduleTeardown": false, "moduleTeardown": false,
...@@ -54,6 +55,7 @@ ...@@ -54,6 +55,7 @@
"Globals": true, "Globals": true,
"hasPHP": true, "hasPHP": true,
"isLocal": true, "isLocal": true,
"supportjQuery": true,
"originaljQuery": true, "originaljQuery": true,
"$": true, "$": true,
"original$": true, "original$": true,
......
/*jshint multistr:true, quotmark:false */ /*jshint multistr:true, quotmark:false */
var fireNative, var fireNative, originaljQuery, original$,
originaljQuery = this.jQuery || "jQuery", supportjQuery = this.jQuery,
original$ = this.$ || "$",
// see RFC 2606 // see RFC 2606
externalHost = "example.com"; externalHost = "example.com";
this.hasPHP = true; this.hasPHP = true;
this.isLocal = window.location.protocol === "file:"; this.isLocal = window.location.protocol === "file:";
// For testing .noConflict() // Setup global variables before loading jQuery for testing .noConflict()
this.jQuery = originaljQuery; supportjQuery.noConflict( true );
this.$ = original$; originaljQuery = this.jQuery = undefined;
original$ = this.$ = "replaced";
/** /**
* Returns an array of elements with the given IDs * Returns an array of elements with the given IDs
...@@ -253,3 +253,4 @@ this.testIframeWithCallback = function( title, fileName, func ) { ...@@ -253,3 +253,4 @@ this.testIframeWithCallback = function( title, fileName, func ) {
).appendTo( "body" ); ).appendTo( "body" );
}); });
}; };
this.iframeCallback = undefined;
/** if ( typeof jQuery !== "undefined" ) {
* Allow the test suite to run with other libs or jQuery's. /**
*/ * Allow the test suite to run with other libs or jQuery's.
jQuery.noConflict(); */
jQuery.noConflict();
// Expose Sizzle for Sizzle's selector tests
// We remove Sizzle's globalization in jQuery
this.Sizzle = this.Sizzle || jQuery.find;
}
// For checking globals pollution despite auto-created globals in various environments // For checking globals pollution despite auto-created globals in various environments
jQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) { supportjQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) {
window[ name ] = window[ name ]; window[ name ] = window[ name ];
}); });
// Expose Sizzle for Sizzle's selector tests
// We remove Sizzle's globalization in jQuery
var Sizzle = Sizzle || jQuery.find,
// Allow subprojects to test against their own fixtures // Allow subprojects to test against their own fixtures
qunitModule = QUnit.module, var qunitModule = QUnit.module,
qunitTest = QUnit.test; qunitTest = QUnit.test;
/** /**
...@@ -53,7 +55,7 @@ this.testSubproject = function( label, url, risTests, complete ) { ...@@ -53,7 +55,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
// Find test function and wrap to require subproject fixture // Find test function and wrap to require subproject fixture
for ( ; i >= 0; i-- ) { for ( ; i >= 0; i-- ) {
if ( originaljQuery.isFunction( args[i] ) ) { if ( supportjQuery.isFunction( args[i] ) ) {
args[i] = requireFixture( args[i] ); args[i] = requireFixture( args[i] );
break; break;
} }
...@@ -64,7 +66,7 @@ this.testSubproject = function( label, url, risTests, complete ) { ...@@ -64,7 +66,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
// Load tests and fixture from subproject // Load tests and fixture from subproject
// Test order matters, so we must be synchronous and throw an error on load failure // Test order matters, so we must be synchronous and throw an error on load failure
originaljQuery.ajax( url, { supportjQuery.ajax( url, {
async: false, async: false,
dataType: "html", dataType: "html",
error: function( jqXHR, status ) { error: function( jqXHR, status ) {
...@@ -72,7 +74,7 @@ this.testSubproject = function( label, url, risTests, complete ) { ...@@ -72,7 +74,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
}, },
success: function( data, status, jqXHR ) { success: function( data, status, jqXHR ) {
var sources = [], var sources = [],
page = originaljQuery.parseHTML( page = supportjQuery.parseHTML(
// replace html/head with dummy elements so they are represented in the DOM // replace html/head with dummy elements so they are represented in the DOM
( data || "" ).replace( /<\/?((!DOCTYPE|html|head)\b.*?)>/gi, "[$1]" ), ( data || "" ).replace( /<\/?((!DOCTYPE|html|head)\b.*?)>/gi, "[$1]" ),
document, document,
...@@ -82,11 +84,11 @@ this.testSubproject = function( label, url, risTests, complete ) { ...@@ -82,11 +84,11 @@ this.testSubproject = function( label, url, risTests, complete ) {
if ( !page || !page.length ) { if ( !page || !page.length ) {
this.error( jqXHR, "no data" ); this.error( jqXHR, "no data" );
} }
page = originaljQuery( page ); page = supportjQuery( page );
// Include subproject tests // Include subproject tests
page.filter("script[src]").add( page.find("script[src]") ).map(function() { page.filter("script[src]").add( page.find("script[src]") ).map(function() {
var src = originaljQuery( this ).attr("src"); var src = supportjQuery( this ).attr("src");
if ( risTests.test( src ) ) { if ( risTests.test( src ) ) {
sources.push( src ); sources.push( src );
} }
...@@ -123,7 +125,7 @@ this.testSubproject = function( label, url, risTests, complete ) { ...@@ -123,7 +125,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
} }
// Replace the current fixture, including content outside of #qunit-fixture // Replace the current fixture, including content outside of #qunit-fixture
var oldFixture = originaljQuery("#qunit-fixture"); var oldFixture = supportjQuery("#qunit-fixture");
while ( oldFixture.length && !oldFixture.prevAll("[id='qunit']").length ) { while ( oldFixture.length && !oldFixture.prevAll("[id='qunit']").length ) {
oldFixture = oldFixture.parent(); oldFixture = oldFixture.parent();
} }
...@@ -133,7 +135,7 @@ this.testSubproject = function( label, url, risTests, complete ) { ...@@ -133,7 +135,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
// WARNING: UNDOCUMENTED INTERFACE // WARNING: UNDOCUMENTED INTERFACE
QUnit.config.fixture = fixtureHTML; QUnit.config.fixture = fixtureHTML;
QUnit.reset(); QUnit.reset();
if ( originaljQuery("#qunit-fixture").html() !== fixtureHTML ) { if ( supportjQuery("#qunit-fixture").html() !== fixtureHTML ) {
ok( false, "Copied subproject fixture" ); ok( false, "Copied subproject fixture" );
return; return;
} }
...@@ -153,15 +155,15 @@ this.Globals = (function() { ...@@ -153,15 +155,15 @@ this.Globals = (function() {
return { return {
register: function( name ) { register: function( name ) {
globals[ name ] = true; globals[ name ] = true;
jQuery.globalEval( "var " + name + " = undefined;" ); supportjQuery.globalEval( "var " + name + " = undefined;" );
}, },
cleanup: function() { cleanup: function() {
var name, var name,
current = globals; current = globals;
globals = {}; globals = {};
for ( name in current ) { for ( name in current ) {
jQuery.globalEval( "try { " + supportjQuery.globalEval( "try { " +
"delete " + ( jQuery.support.deleteExpando ? "window['" + name + "']" : name ) + "delete " + ( supportjQuery.support.deleteExpando ? "window['" + name + "']" : name ) +
"; } catch( x ) {}" ); "; } catch( x ) {}" );
} }
} }
...@@ -335,7 +337,7 @@ this.Globals = (function() { ...@@ -335,7 +337,7 @@ this.Globals = (function() {
QUnit.done(function() { QUnit.done(function() {
// Remove our own fixtures outside #qunit-fixture // Remove our own fixtures outside #qunit-fixture
jQuery("#qunit ~ *").remove(); supportjQuery("#qunit ~ *").remove();
}); });
// jQuery-specific QUnit.reset // jQuery-specific QUnit.reset
...@@ -343,6 +345,8 @@ this.Globals = (function() { ...@@ -343,6 +345,8 @@ this.Globals = (function() {
// Ensure jQuery events and data on the fixture are properly removed // Ensure jQuery events and data on the fixture are properly removed
jQuery("#qunit-fixture").empty(); jQuery("#qunit-fixture").empty();
// ...even if the jQuery under test has a broken .empty()
supportjQuery("#qunit-fixture").empty();
// Reset internal jQuery state // Reset internal jQuery state
jQuery.event.global = {}; jQuery.event.global = {};
......
...@@ -100,7 +100,7 @@ test( "attr(String)", function() { ...@@ -100,7 +100,7 @@ test( "attr(String)", function() {
jQuery("<a id='tAnchor6' href='#5' />").appendTo("#qunit-fixture"); jQuery("<a id='tAnchor6' href='#5' />").appendTo("#qunit-fixture");
equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" ); equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" );
$("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture"); jQuery("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture");
equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" ); equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" );
// list attribute is readonly by default in browsers that support it // list attribute is readonly by default in browsers that support it
......
...@@ -353,8 +353,9 @@ asyncTest("isPlainObject", function() { ...@@ -353,8 +353,9 @@ asyncTest("isPlainObject", function() {
ok( pass, "Does not throw exceptions on host objects" ); ok( pass, "Does not throw exceptions on host objects" );
// Objects from other windows should be matched // Objects from other windows should be matched
window.iframeCallback = function( otherObject, detail ) { Globals.register("iframeDone");
window.iframeCallback = undefined; window.iframeDone = function( otherObject, detail ) {
window.iframeDone = undefined;
iframe.parentNode.removeChild( iframe ); iframe.parentNode.removeChild( iframe );
ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) ); ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
start(); start();
...@@ -364,7 +365,7 @@ asyncTest("isPlainObject", function() { ...@@ -364,7 +365,7 @@ asyncTest("isPlainObject", function() {
iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") ); iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
doc = iframe.contentDocument || iframe.contentWindow.document; doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open(); doc.open();
doc.write("<body onload='window.parent.iframeCallback(Object);'>"); doc.write("<body onload='window.parent.iframeDone(Object);'>");
doc.close(); doc.close();
} catch(e) { } catch(e) {
window.iframeDone( Object, "iframes not supported" ); window.iframeDone( Object, "iframes not supported" );
......
...@@ -2453,6 +2453,7 @@ test("focus-blur order (#12868)", function() { ...@@ -2453,6 +2453,7 @@ test("focus-blur order (#12868)", function() {
// Run handlers without native method on an input // Run handlers without native method on an input
order = 1; order = 1;
$radio.triggerHandler( "focus" ); $radio.triggerHandler( "focus" );
$text.off();
start(); start();
}, 50 ); }, 50 );
}, 50 ); }, 50 );
......
...@@ -1681,11 +1681,11 @@ test("empty()", function() { ...@@ -1681,11 +1681,11 @@ test("empty()", function() {
equal( j.html(), "", "Check node,textnode,comment empty works" ); equal( j.html(), "", "Check node,textnode,comment empty works" );
// Ensure oldIE empties selects (#12336) // Ensure oldIE empties selects (#12336)
notEqual( $("#select1").find("option").length, 0, "Have some initial options" ); notEqual( jQuery("#select1").find("option").length, 0, "Have some initial options" );
$("#select1").empty(); jQuery("#select1").empty();
equal( $("#select1").find("option").length, 0, "No more option elements found" ); equal( jQuery("#select1").find("option").length, 0, "No more option elements found" );
equal( $("#select1")[0].options.length, 0, "options.length cleared as well" ); equal( jQuery("#select1")[0].options.length, 0, "options.length cleared as well" );
}); });
test( "jQuery.cleanData", function() { test( "jQuery.cleanData", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment