Tests: Refactor testIframe() to make it DRYer and more consistent

Ref gh-3040
Closes gh-3049
This commit is contained in:
Dave Methvin
2016-04-10 15:42:44 -04:00
parent 08d73d7f9c
commit e5ffcb0838
42 changed files with 142 additions and 110 deletions

View File

@@ -28,7 +28,7 @@ QUnit.module( "ajax", {
//----------- jQuery.ajax()
testIframeWithCallback(
testIframe(
"XMLHttpRequest - Attempt to block tests because of dangling XHR requests (IE)",
"ajax/unreleasedXHR.html",
function( assert ) {
@@ -1826,10 +1826,10 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
};
} );
testIframeWithCallback(
testIframe(
"#14379 - jQuery.ajax() on unload",
"ajax/onunload.html",
function( status, assert ) {
function( assert, jQuery, window, document, status ) {
assert.expect( 1 );
assert.strictEqual( status, "success", "Request completed" );
}

View File

@@ -1648,14 +1648,14 @@ QUnit.test( "jQuery.camelCase()", function( assert ) {
} );
} );
testIframeWithCallback(
testIframe(
"Conditional compilation compatibility (#13274)",
"core/cc_on.html",
function( cc_on, errors, $, assert ) {
function( assert, jQuery, window, document, cc_on, errors ) {
assert.expect( 3 );
assert.ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
assert.deepEqual( errors, [], "No errors" );
assert.ok( $(), "jQuery executes" );
assert.ok( jQuery(), "jQuery executes" );
}
);
@@ -1663,29 +1663,29 @@ testIframeWithCallback(
// This makes this test fail but it doesn't seem to cause any real-life problems so blacklisting
// this test there is preferred to complicating the hard-to-test core/ready code further.
if ( !/iphone os 7_/i.test( navigator.userAgent ) ) {
testIframeWithCallback(
testIframe(
"document ready when jQuery loaded asynchronously (#13655)",
"core/dynamic_ready.html",
function( ready, assert ) {
function( assert, jQuery, window, document, ready ) {
assert.expect( 1 );
assert.equal( true, ready, "document ready correctly fired when jQuery is loaded after DOMContentLoaded" );
}
);
}
testIframeWithCallback(
testIframe(
"Tolerating alias-masked DOM properties (#14074)",
"core/aliased.html",
function( errors, assert ) {
function( assert, jQuery, window, document, errors ) {
assert.expect( 1 );
assert.deepEqual( errors, [], "jQuery loaded" );
}
);
testIframeWithCallback(
testIframe(
"Don't call window.onready (#14802)",
"core/onready.html",
function( error, assert ) {
function( assert, jQuery, window, document, error ) {
assert.expect( 1 );
assert.equal( error, false, "no call to user-defined onready" );
}

View File

@@ -1139,10 +1139,10 @@ QUnit.test( "css('width') and css('height') should respect box-sizing, see #1100
assert.equal( el_dis.css( "height" ), el_dis.css( "height", el_dis.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing for disconnected element, see #11004" );
} );
testIframeWithCallback(
testIframe(
"css('width') should work correctly before document ready (#14084)",
"css/cssWidthBeforeDocReady.html",
function( cssWidthBeforeDocReady, assert ) {
function( assert, jQuery, window, document, cssWidthBeforeDocReady ) {
assert.expect( 1 );
assert.strictEqual( cssWidthBeforeDocReady, "100px", "elem.css('width') works correctly before document ready" );
}

View File

@@ -857,10 +857,10 @@ QUnit.test( "Check proper data removal of non-element descendants nodes (#8335)"
assert.ok( !text.data( "test" ), "Be sure data is not stored in non-element" );
} );
testIframeWithCallback(
testIframe(
"enumerate data attrs on body (#14894)",
"data/dataAttrs.html",
function( result, assert ) {
function( assert, jQuery, window, document, result ) {
assert.expect( 1 );
assert.equal( result, "ok", "enumeration of data- attrs on body" );
}

View File

@@ -469,10 +469,10 @@ QUnit.test( "setters with and without box-sizing:border-box", function( assert )
} );
} );
testIframeWithCallback(
testIframe(
"window vs. large document",
"dimensions/documentLarge.html",
function( jQuery, window, document, assert ) {
function( assert, jQuery, window, document ) {
assert.expect( 2 );
assert.ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height" );

View File

@@ -2476,10 +2476,10 @@ QUnit.test( "focusin using non-element targets", function( assert ) {
} );
testIframeWithCallback(
testIframe(
"focusin from an iframe",
"event/focusinCrossFrame.html",
function( frameDoc, assert ) {
function( assert, framejQuery, frameWin, frameDoc ) {
assert.expect( 1 );
var input = jQuery( frameDoc ).find( "#frame-input" );
@@ -2507,10 +2507,10 @@ testIframeWithCallback(
}
);
testIframeWithCallback(
testIframe(
"jQuery.ready promise",
"event/promiseReady.html",
function( isOk, assert ) {
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "$.when( $.ready ) works" );
}
@@ -2518,29 +2518,29 @@ testIframeWithCallback(
// need PHP here to make the incepted IFRAME hang
if ( hasPHP ) {
testIframeWithCallback(
testIframe(
"jQuery.ready uses interactive",
"event/interactiveReady.html",
function( isOk, assert ) {
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "jQuery fires ready when the DOM can truly be interacted with" );
}
);
}
testIframeWithCallback(
testIframe(
"Focusing iframe element",
"event/focusElem.html",
function( isOk, assert ) {
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "Focused an element in an iframe" );
}
);
testIframeWithCallback(
testIframe(
"triggerHandler(onbeforeunload)",
"event/triggerunload.html",
function( isOk, assert ) {
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "Triggered onbeforeunload without an error" );
}
@@ -2548,10 +2548,10 @@ testIframeWithCallback(
// need PHP here to make the incepted IFRAME hang
if ( hasPHP ) {
testIframeWithCallback(
testIframe(
"jQuery.ready synchronous load with long loading subresources",
"event/syncReady.html",
function( isOk, assert ) {
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "jQuery loaded synchronously fires ready when the DOM can truly be interacted with" );
}

View File

@@ -2237,21 +2237,21 @@ QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9
].join( "\n" ) ).appendTo( "#qunit-fixture" );
} );
testIframeWithCallback(
testIframe(
"domManip tolerates window-valued document[0] in IE9/10 (trac-12266)",
"manipulation/iframe-denied.html",
function( test, assert ) {
function( assert, jQuery, window, document, test ) {
assert.expect( 1 );
assert.ok( test.status, test.description );
}
);
testIframeWithCallback(
testIframe(
"domManip executes scripts in iframes in the iframes' context",
"manipulation/scripts-context.html",
function( frameWindow, bodyElement, html, assert ) {
function( assert, framejQuery, frameWindow, frameDocument ) {
assert.expect( 2 );
jQuery( bodyElement ).append( html );
jQuery( frameDocument.body ).append( "<script>window.scriptTest = true;<\x2fscript>" );
assert.ok( !window.scriptTest, "script executed in iframe context" );
assert.ok( frameWindow.scriptTest, "script executed in iframe context" );
}

View File

@@ -68,7 +68,7 @@ QUnit.test( "hidden (display: none) element", function( assert ) {
assert.equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
} );
testIframeWithCallback( "absolute", "offset/absolute.html", function( $, iframe, document, assert ) {
testIframe( "absolute", "offset/absolute.html", function( assert, $, iframe ) {
assert.expect( 4 );
var doc = iframe.document,
@@ -93,7 +93,7 @@ testIframeWithCallback( "absolute", "offset/absolute.html", function( $, iframe,
} );
} );
testIframeWithCallback( "absolute", "offset/absolute.html", function( $, window, document, assert ) {
testIframe( "absolute", "offset/absolute.html", function( assert, $ ) {
assert.expect( 178 );
var tests, offset;
@@ -178,7 +178,7 @@ testIframeWithCallback( "absolute", "offset/absolute.html", function( $, window,
} );
} );
testIframeWithCallback( "relative", "offset/relative.html", function( $, window, document, assert ) {
testIframe( "relative", "offset/relative.html", function( assert, $ ) {
assert.expect( 64 );
// get offset
@@ -236,7 +236,7 @@ testIframeWithCallback( "relative", "offset/relative.html", function( $, window,
} );
} );
testIframeWithCallback( "static", "offset/static.html", function( $, window, document, assert ) {
testIframe( "static", "offset/static.html", function( assert, $ ) {
assert.expect( 80 );
// get offset
@@ -298,7 +298,7 @@ testIframeWithCallback( "static", "offset/static.html", function( $, window, doc
} );
} );
testIframeWithCallback( "fixed", "offset/fixed.html", function( $, window, document, assert ) {
testIframe( "fixed", "offset/fixed.html", function( assert, $, window ) {
assert.expect( 34 );
var tests, $noTopLeft;
@@ -388,7 +388,7 @@ testIframeWithCallback( "fixed", "offset/fixed.html", function( $, window, docum
}
} );
testIframeWithCallback( "table", "offset/table.html", function( $, window, document, assert ) {
testIframe( "table", "offset/table.html", function( assert, $ ) {
assert.expect( 4 );
assert.equal( $( "#table-1" ).offset().top, 6, "jQuery('#table-1').offset().top" );
@@ -398,7 +398,7 @@ testIframeWithCallback( "table", "offset/table.html", function( $, window, docum
assert.equal( $( "#th-1" ).offset().left, 10, "jQuery('#th-1').offset().left" );
} );
testIframeWithCallback( "scroll", "offset/scroll.html", function( $, win, doc, assert ) {
testIframe( "scroll", "offset/scroll.html", function( assert, $, win ) {
assert.expect( 26 );
assert.equal( $( "#scroll-1" ).offset().top, 7, "jQuery('#scroll-1').offset().top" );
@@ -457,7 +457,7 @@ testIframeWithCallback( "scroll", "offset/scroll.html", function( $, win, doc, a
assert.strictEqual( $().scrollLeft(), undefined, "jQuery().scrollLeft() testing getter on empty jquery object" );
} );
testIframeWithCallback( "body", "offset/body.html", function( $, window, document, assert ) {
testIframe( "body", "offset/body.html", function( assert, $ ) {
assert.expect( 4 );
assert.equal( $( "body" ).offset().top, 1, "jQuery('#body').offset().top" );

View File

@@ -289,10 +289,10 @@ QUnit[ jQuery.find.compile ? "test" : "skip" ]( "disconnected nodes", function(
assert.equal( $opt.is( ":selected" ), true, "selected option" );
} );
testIframeWithCallback(
testIframe(
"attributes - jQuery.attr",
"selector/html5_selector.html",
function( jQuery, window, document, assert ) {
function( assert, jQuery, window, document ) {
assert.expect( 38 );
/**
@@ -489,10 +489,10 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
assert.strictEqual( jQuery.unique, jQuery.uniqueSort, "jQuery.unique() is an alias for jQuery.uniqueSort()" );
} );
testIframeWithCallback(
testIframe(
"Sizzle cache collides with multiple Sizzles on a page",
"selector/sizzle_cache.html",
function( jQuery, window, document, assert ) {
function( assert, jQuery, window, document ) {
var $cached = window[ "$cached" ];
assert.expect( 4 );

View File

@@ -18,10 +18,10 @@ function getComputedSupport( support ) {
}
if ( jQuery.css ) {
testIframeWithCallback(
testIframe(
"body background is not lost if set prior to loading jQuery (#9239)",
"support/bodyBackground.html",
function( color, support, assert ) {
function( assert, jQuery, window, document, color, support ) {
assert.expect( 2 );
var okValue = {
"#000000": true,
@@ -37,10 +37,10 @@ if ( jQuery.css ) {
// This test checks CSP only for browsers with "Content-Security-Policy" header support
// i.e. no old WebKit or old Firefox
testIframeWithCallback(
testIframe(
"Check CSP (https://developer.mozilla.org/en-US/docs/Security/CSP) restrictions",
"support/csp.php",
function( support, assert ) {
function( assert, jQuery, window, document, support ) {
var done = assert.async();
assert.expect( 2 );