Permalink
Browse files

Tests: Make iframe tests wait after checking isReady

  • Loading branch information...
1 parent 755e7cc commit 08d73d7f9c7eec2f0abd14d00bf903625728ef17 @dmethvin dmethvin committed Apr 8, 2016
View
@@ -340,32 +340,25 @@ url("data/test.php?foo=bar");
```
-### 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?
----------
@@ -12,6 +12,11 @@
<body>
<div>
<script src="../../jquery.js"></script>
+ <script>
+ jQuery( function() {
+ window.parent.iframeCallback( jQuery, window, document );
+ } );
+ </script>
</div>
</body>
</html>
@@ -24,6 +24,7 @@
$(this).css({ top: pos.top, left: pos.left });
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
@@ -16,6 +16,7 @@
$("marker").css( $(this).offset() );
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
@@ -20,6 +20,7 @@
$("#marker").css( $(this).offset() );
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
@@ -20,6 +20,7 @@
$(this).css({ position: 'absolute', top: pos.top, left: pos.left });
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
@@ -24,6 +24,7 @@
$("#marker").css( $(this).offset() );
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
@@ -19,6 +19,7 @@
$(this).css({ position: 'absolute', top: pos.top, left: pos.left });
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
@@ -17,6 +17,7 @@
$("#marker").css( $(this).offset() );
return false;
});
+ window.parent.iframeCallback( jQuery, window, document );
});
</script>
</head>
@@ -15,6 +15,10 @@
document.createElement('audio');
document.createElement('article');
document.createElement('details');
+
+ jQuery( function() {
+ window.parent.iframeCallback( jQuery, window, document );
+ } );
</script>
</head>
<body>
@@ -17,5 +17,10 @@
<div class="test">
<a href="#" id="collision">Worlds collide</a>
</div>
+ <script>
+ jQuery( function() {
+ window.parent.iframeCallback( jQuery, window, document );
+ } );
+ </script>
</body>
</html>
View
@@ -232,37 +232,6 @@ this.ajaxTest = function( title, expect, options ) {
} );
};
-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;
@@ -469,9 +469,9 @@ QUnit.test( "setters with and without box-sizing:border-box", function( assert )
} );
} );
-testIframe(
- "dimensions/documentLarge",
+testIframeWithCallback(
"window vs. large document",
+ "dimensions/documentLarge.html",
function( jQuery, window, document, assert ) {
assert.expect( 2 );
View
@@ -35,13 +35,6 @@ QUnit.module( "offset", { setup: function() {
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)" );
@@ -75,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)" );
} );
-testIframe( "offset/absolute", "absolute", function( $, iframe, document, assert ) {
+testIframeWithCallback( "absolute", "offset/absolute.html", function( $, iframe, document, assert ) {
assert.expect( 4 );
var doc = iframe.document,
@@ -100,7 +93,7 @@ testIframe( "offset/absolute", "absolute", function( $, iframe, document, assert
} );
} );
-testIframe( "offset/absolute", "absolute", function( $, window, document, assert ) {
+testIframeWithCallback( "absolute", "offset/absolute.html", function( $, window, document, assert ) {
assert.expect( 178 );
var tests, offset;
@@ -185,7 +178,7 @@ testIframe( "offset/absolute", "absolute", function( $, window, document, assert
} );
} );
-testIframe( "offset/relative", "relative", function( $, window, document, assert ) {
+testIframeWithCallback( "relative", "offset/relative.html", function( $, window, document, assert ) {
assert.expect( 64 );
// get offset
@@ -243,7 +236,7 @@ testIframe( "offset/relative", "relative", function( $, window, document, assert
} );
} );
-testIframe( "offset/static", "static", function( $, window, document, assert ) {
+testIframeWithCallback( "static", "offset/static.html", function( $, window, document, assert ) {
assert.expect( 80 );
// get offset
@@ -305,7 +298,7 @@ testIframe( "offset/static", "static", function( $, window, document, assert ) {
} );
} );
-testIframe( "offset/fixed", "fixed", function( $, window, document, assert ) {
+testIframeWithCallback( "fixed", "offset/fixed.html", function( $, window, document, assert ) {
assert.expect( 34 );
var tests, $noTopLeft;
@@ -395,7 +388,7 @@ testIframe( "offset/fixed", "fixed", function( $, window, document, assert ) {
}
} );
-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" );
@@ -405,7 +398,7 @@ testIframe( "offset/table", "table", function( $, window, document, assert ) {
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" );
@@ -464,7 +457,7 @@ testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) {
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" );
@@ -289,9 +289,9 @@ QUnit[ jQuery.find.compile ? "test" : "skip" ]( "disconnected nodes", function(
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 );
@@ -489,9 +489,9 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
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" ];

0 comments on commit 08d73d7

Please sign in to comment.