```
-### Load tests in an iframe ###
-
-Loads a given page constructing a url with fileName: `"./data/" + fileName + ".html"`
-and fires the given callback on jQuery ready (using the jQuery loading from that page)
-and passes the iFrame's jQuery to the callback.
-
-```js
-testIframe( fileName, testName, callback );
-```
-
-Callback arguments:
+### Load tests in an iframe (window.iframeCallback) ###
```js
-callback( jQueryFromIFrame, iFrameWindow, iFrameDocument );
+testIframeWithCallback( testName, fileName,
+ function callback( arg1, arg2, ... assert ) {
+ ...
+ } );
```
-### Load tests in an iframe (window.iframeCallback) ###
-
Loads a given page constructing a url with fileName: `"./data/" + fileName + ".html"`
-The given callback is fired when window.iframeCallback is called by the page.
-The arguments passed to the callback are the same as the
-arguments passed to window.iframeCallback, whatever that may be.
+The iframe page is responsible for determining when `window.parent.iframeCallback`
+should be called, for example at document ready or window.onload time.
+Arguments passed to the callback are the same as the arguments passed
+to `window.parent.iframeCallback` by the iframe, plus the QUnit `assert`
+object from the `QUnit.test()` that this wrapper sets up for you.
+The iframe should send any objects needed by the unit test via arguments, for example
+its `jQuery`, `window`, and `document` objects from the iframe.
+
-```js
-testIframeWithCallback( testName, fileName, callback );
-```
Questions?
----------
<body>
<div>
<script src="../../jquery.js"></script>
+ <script>
+ jQuery( function() {
+ window.parent.iframeCallback( jQuery, window, document );
+ } );
+ </script>
</div>
</body>
</html>
$(this).css({ top: pos.top, left: pos.left });
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
$("marker").css( $(this).offset() );
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
$("#marker").css( $(this).offset() );
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
$(this).css({ position: 'absolute', top: pos.top, left: pos.left });
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
$("#marker").css( $(this).offset() );
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
$(this).css({ position: 'absolute', top: pos.top, left: pos.left });
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
$("#marker").css( $(this).offset() );
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
document.createElement('audio');
document.createElement('article');
document.createElement('details');
+
+ jQuery( function() {
+ window.parent.iframeCallback( jQuery, window, document );
+ } );
</script>
</head>
<body>
<div class="test">
<a href="#" id="collision">Worlds collide</a>
</div>
+ <script>
+ jQuery( function() {
+ window.parent.iframeCallback( jQuery, window, document );
+ } );
+ </script>
</body>
</html>
} );
};
-this.testIframe = function( fileName, name, fn ) {
- QUnit.test( name, function( assert ) {
- var done = assert.async();
-
- // load fixture in iframe
- var iframe = loadFixture(),
- win = iframe.contentWindow,
- interval = setInterval( function() {
- if ( win && win.jQuery && win.jQuery.isReady ) {
- clearInterval( interval );
-
- // call actual tests passing the correct jQuery instance to use
- fn.call( this, win.jQuery, win, win.document, assert );
- done();
- document.body.removeChild( iframe );
- iframe = null;
- }
- }, 15 );
- } );
-
- function loadFixture() {
- var src = url( "./data/" + fileName + ".html" ),
- iframe = jQuery( "<iframe />" ).appendTo( "body" )[ 0 ];
- iframe.style.cssText = "width: 500px; height: 500px; position: absolute; " +
- "top: -600px; left: -600px; visibility: hidden;";
-
- iframe.contentWindow.location = src;
- return iframe;
- }
-};
-
this.testIframeWithCallback = function( title, fileName, func ) {
QUnit.test( title, 1, function( assert ) {
var iframe;
} );
} );
-testIframe(
- "dimensions/documentLarge",
+testIframeWithCallback(
"window vs. large document",
+ "dimensions/documentLarge.html",
function( jQuery, window, document, assert ) {
assert.expect( 2 );
forceScroll.detach();
}, teardown: moduleTeardown } );
-/*
- Closure-compiler will roll static methods off of the jQuery object and so they will
- not be passed with the jQuery object across the windows. To differentiate this, the
- testIframe callbacks use the "$" symbol to refer to the jQuery object passed from
- the iframe window and the "jQuery" symbol is used to access any static methods.
-*/
-
QUnit.test( "empty set", function( assert ) {
assert.expect( 2 );
assert.strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" );
assert.equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
} );
-testIframe( "offset/absolute", "absolute", function( $, iframe, document, assert ) {
+testIframeWithCallback( "absolute", "offset/absolute.html", function( $, iframe, document, assert ) {
assert.expect( 4 );
var doc = iframe.document,
} );
} );
-testIframe( "offset/absolute", "absolute", function( $, window, document, assert ) {
+testIframeWithCallback( "absolute", "offset/absolute.html", function( $, window, document, assert ) {
assert.expect( 178 );
var tests, offset;
} );
} );
-testIframe( "offset/relative", "relative", function( $, window, document, assert ) {
+testIframeWithCallback( "relative", "offset/relative.html", function( $, window, document, assert ) {
assert.expect( 64 );
// get offset
} );
} );
-testIframe( "offset/static", "static", function( $, window, document, assert ) {
+testIframeWithCallback( "static", "offset/static.html", function( $, window, document, assert ) {
assert.expect( 80 );
// get offset
} );
} );
-testIframe( "offset/fixed", "fixed", function( $, window, document, assert ) {
+testIframeWithCallback( "fixed", "offset/fixed.html", function( $, window, document, assert ) {
assert.expect( 34 );
var tests, $noTopLeft;
}
} );
-testIframe( "offset/table", "table", function( $, window, document, assert ) {
+testIframeWithCallback( "table", "offset/table.html", function( $, window, document, assert ) {
assert.expect( 4 );
assert.equal( $( "#table-1" ).offset().top, 6, "jQuery('#table-1').offset().top" );
assert.equal( $( "#th-1" ).offset().left, 10, "jQuery('#th-1').offset().left" );
} );
-testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) {
+testIframeWithCallback( "scroll", "offset/scroll.html", function( $, win, doc, assert ) {
assert.expect( 26 );
assert.equal( $( "#scroll-1" ).offset().top, 7, "jQuery('#scroll-1').offset().top" );
assert.strictEqual( $().scrollLeft(), undefined, "jQuery().scrollLeft() testing getter on empty jquery object" );
} );
-testIframe( "offset/body", "body", function( $, window, document, assert ) {
+testIframeWithCallback( "body", "offset/body.html", function( $, window, document, assert ) {
assert.expect( 4 );
assert.equal( $( "body" ).offset().top, 1, "jQuery('#body').offset().top" );
assert.equal( $opt.is( ":selected" ), true, "selected option" );
} );
-testIframe(
- "selector/html5_selector",
+testIframeWithCallback(
"attributes - jQuery.attr",
+ "selector/html5_selector.html",
function( jQuery, window, document, assert ) {
assert.expect( 38 );
assert.strictEqual( jQuery.unique, jQuery.uniqueSort, "jQuery.unique() is an alias for jQuery.uniqueSort()" );
} );
-testIframe(
- "selector/sizzle_cache",
+testIframeWithCallback(
"Sizzle cache collides with multiple Sizzles on a page",
+ "selector/sizzle_cache.html",
function( jQuery, window, document, assert ) {
var $cached = window[ "$cached" ];