From 08d73d7f9c7eec2f0abd14d00bf903625728ef17 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Fri, 8 Apr 2016 12:00:17 -0400 Subject: [PATCH] Tests: Make iframe tests wait after checking isReady Ref gh-3040 --- README.md | 33 ++++++++++--------------- test/data/dimensions/documentLarge.html | 5 ++++ test/data/offset/absolute.html | 1 + test/data/offset/body.html | 1 + test/data/offset/fixed.html | 1 + test/data/offset/relative.html | 1 + test/data/offset/scroll.html | 1 + test/data/offset/static.html | 1 + test/data/offset/table.html | 1 + test/data/selector/html5_selector.html | 4 +++ test/data/selector/sizzle_cache.html | 5 ++++ test/data/testinit.js | 31 ----------------------- test/unit/dimensions.js | 4 +-- test/unit/offset.js | 23 ++++++----------- test/unit/selector.js | 8 +++--- 15 files changed, 48 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 404a26885..5c1a90c04 100644 --- a/README.md +++ b/README.md @@ -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? ---------- diff --git a/test/data/dimensions/documentLarge.html b/test/data/dimensions/documentLarge.html index a6598fcc8..c977fac96 100644 --- a/test/data/dimensions/documentLarge.html +++ b/test/data/dimensions/documentLarge.html @@ -12,6 +12,11 @@
+
diff --git a/test/data/offset/absolute.html b/test/data/offset/absolute.html index 58f0cbd2a..84a9e33de 100644 --- a/test/data/offset/absolute.html +++ b/test/data/offset/absolute.html @@ -24,6 +24,7 @@ $(this).css({ top: pos.top, left: pos.left }); return false; }); + window.parent.iframeCallback( jQuery, window, document ); }); diff --git a/test/data/offset/body.html b/test/data/offset/body.html index c0de297b7..cada87a15 100644 --- a/test/data/offset/body.html +++ b/test/data/offset/body.html @@ -16,6 +16,7 @@ $("marker").css( $(this).offset() ); return false; }); + window.parent.iframeCallback( jQuery, window, document ); }); diff --git a/test/data/offset/fixed.html b/test/data/offset/fixed.html index c695ba4dd..e54389596 100644 --- a/test/data/offset/fixed.html +++ b/test/data/offset/fixed.html @@ -20,6 +20,7 @@ $("#marker").css( $(this).offset() ); return false; }); + window.parent.iframeCallback( jQuery, window, document ); }); diff --git a/test/data/offset/relative.html b/test/data/offset/relative.html index f88c82ab9..b413e05ee 100644 --- a/test/data/offset/relative.html +++ b/test/data/offset/relative.html @@ -20,6 +20,7 @@ $(this).css({ position: 'absolute', top: pos.top, left: pos.left }); return false; }); + window.parent.iframeCallback( jQuery, window, document ); }); diff --git a/test/data/offset/scroll.html b/test/data/offset/scroll.html index c8c08020f..49304eee7 100644 --- a/test/data/offset/scroll.html +++ b/test/data/offset/scroll.html @@ -24,6 +24,7 @@ $("#marker").css( $(this).offset() ); return false; }); + window.parent.iframeCallback( jQuery, window, document ); }); diff --git a/test/data/offset/static.html b/test/data/offset/static.html index f8cafa882..125ad740f 100644 --- a/test/data/offset/static.html +++ b/test/data/offset/static.html @@ -19,6 +19,7 @@ $(this).css({ position: 'absolute', top: pos.top, left: pos.left }); return false; }); + window.parent.iframeCallback( jQuery, window, document ); }); diff --git a/test/data/offset/table.html b/test/data/offset/table.html index ff2b8579e..1e37957ce 100644 --- a/test/data/offset/table.html +++ b/test/data/offset/table.html @@ -17,6 +17,7 @@ $("#marker").css( $(this).offset() ); return false; }); + window.parent.iframeCallback( jQuery, window, document ); }); diff --git a/test/data/selector/html5_selector.html b/test/data/selector/html5_selector.html index 30f25c9d5..bf0e5ba5e 100644 --- a/test/data/selector/html5_selector.html +++ b/test/data/selector/html5_selector.html @@ -15,6 +15,10 @@ document.createElement('audio'); document.createElement('article'); document.createElement('details'); + + jQuery( function() { + window.parent.iframeCallback( jQuery, window, document ); + } ); diff --git a/test/data/selector/sizzle_cache.html b/test/data/selector/sizzle_cache.html index 1055c75ae..4320fdcfd 100644 --- a/test/data/selector/sizzle_cache.html +++ b/test/data/selector/sizzle_cache.html @@ -17,5 +17,10 @@
Worlds collide
+ diff --git a/test/data/testinit.js b/test/data/testinit.js index dfae73d7c..70c9bbd5a 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -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( "