From e5ffcb0838c894e26f4ff32dfec162cf624d8d7d Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Sun, 10 Apr 2016 15:42:44 -0400 Subject: [PATCH] Tests: Refactor testIframe() to make it DRYer and more consistent Ref gh-3040 Closes gh-3049 --- README.md | 30 +++++++++++++-------- test/data/ajax/onunload.html | 3 ++- test/data/ajax/unreleasedXHR.html | 3 ++- test/data/core/aliased.html | 7 ++--- test/data/core/cc_on.html | 3 ++- test/data/core/dynamic_ready.html | 5 ++-- test/data/core/onready.html | 3 ++- test/data/css/cssWidthBeforeDocReady.html | 3 ++- test/data/data/dataAttrs.html | 3 ++- test/data/dimensions/documentLarge.html | 5 ++-- test/data/event/focusElem.html | 3 ++- test/data/event/focusinCrossFrame.html | 3 ++- test/data/event/interactiveReady.html | 7 ++--- test/data/event/promiseReady.html | 3 ++- test/data/event/syncReady.html | 3 ++- test/data/event/triggerunload.html | 3 ++- test/data/iframeTest.js | 8 ++++++ test/data/manipulation/iframe-denied.html | 3 ++- test/data/manipulation/scripts-context.html | 7 ++--- test/data/offset/absolute.html | 3 ++- test/data/offset/body.html | 3 ++- test/data/offset/fixed.html | 3 ++- test/data/offset/relative.html | 3 ++- test/data/offset/scroll.html | 3 ++- test/data/offset/static.html | 3 ++- test/data/offset/table.html | 3 ++- test/data/selector/html5_selector.html | 6 ++--- test/data/selector/sizzle_cache.html | 5 ++-- test/data/support/bodyBackground.html | 3 ++- test/data/support/csp.js | 2 +- test/data/support/csp.php | 1 + test/data/testinit.js | 7 +++-- test/unit/ajax.js | 6 ++--- test/unit/core.js | 18 ++++++------- test/unit/css.js | 4 +-- test/unit/data.js | 4 +-- test/unit/dimensions.js | 4 +-- test/unit/event.js | 24 ++++++++--------- test/unit/manipulation.js | 10 +++---- test/unit/offset.js | 16 +++++------ test/unit/selector.js | 8 +++--- test/unit/support.js | 8 +++--- 42 files changed, 142 insertions(+), 110 deletions(-) create mode 100644 test/data/iframeTest.js diff --git a/README.md b/README.md index 5c1a90c04..9e5b130c4 100644 --- a/README.md +++ b/README.md @@ -340,24 +340,32 @@ url("data/test.php?foo=bar"); ``` -### Load tests in an iframe (window.iframeCallback) ### +### Run tests in an iframe ### + +Some tests may require a document other than the standard test fixture, and +these can be run in a separate iframe. The actual test code and assertions +remain in jQuery's main test files; only the minimal test fixture markup +and setup code should be placed in the iframe file. ```js -testIframeWithCallback( testName, fileName, - function callback( arg1, arg2, ... assert ) { +testIframe( testName, fileName, + function testCallback( + assert, jQuery, window, document, + [ additional args ] ) { ... } ); ``` -Loads a given page constructing a url with fileName: `"./data/" + fileName + ".html"` -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. +This loads a page, constructing a url with fileName `"./data/" + fileName`. +The iframed page determines when the callback occurs in the test by +including the "/test/data/iframeTest.js" script and calling +`startIframeTest( [ additional args ] )` when appropriate. Often this +will be after either document ready or `window.onload` fires. +The `testCallback` receives the QUnit `assert` object created by `testIframe` +for this test, followed by the global `jQuery`, `window`, and `document` from +the iframe. If the iframe code passes any arguments to `startIframeTest`, +they follow the `document` argument. Questions? diff --git a/test/data/ajax/onunload.html b/test/data/ajax/onunload.html index eb1bca263..ec6e4b702 100644 --- a/test/data/ajax/onunload.html +++ b/test/data/ajax/onunload.html @@ -4,6 +4,7 @@ onunload ajax requests (#14379) + @@ -17,7 +18,7 @@ ajaxStatus = status; } }); - parent.iframeCallback( ajaxStatus ); + startIframeTest( ajaxStatus ); }); jQuery(function() { diff --git a/test/data/ajax/unreleasedXHR.html b/test/data/ajax/unreleasedXHR.html index 8a41c4967..3eedaabf8 100644 --- a/test/data/ajax/unreleasedXHR.html +++ b/test/data/ajax/unreleasedXHR.html @@ -4,13 +4,14 @@ Attempt to block tests because of dangling XHR requests (IE) + +
diff --git a/test/data/core/cc_on.html b/test/data/core/cc_on.html index 131e2e853..5db18916c 100644 --- a/test/data/core/cc_on.html +++ b/test/data/core/cc_on.html @@ -13,10 +13,11 @@ }; + diff --git a/test/data/core/dynamic_ready.html b/test/data/core/dynamic_ready.html index 3b29c1104..1db068b95 100644 --- a/test/data/core/dynamic_ready.html +++ b/test/data/core/dynamic_ready.html @@ -4,6 +4,7 @@ + @@ -20,14 +21,14 @@ $(function () { clearTimeout( timeoutId ); if ( !timeoutFired ) { - window.parent.iframeCallback( true ); + startIframeTest( true ); } }); }); timeoutId = setTimeout(function () { timeoutFired = true; - window.parent.iframeCallback( false ); + startIframeTest( false ); }, 10000); }); diff --git a/test/data/core/onready.html b/test/data/core/onready.html index 1e8f127e7..88ba94a07 100644 --- a/test/data/core/onready.html +++ b/test/data/core/onready.html @@ -8,6 +8,7 @@ window.onready = function() { error = "Called window.onready"; }; +
@@ -16,7 +17,7 @@ diff --git a/test/data/css/cssWidthBeforeDocReady.html b/test/data/css/cssWidthBeforeDocReady.html index a8fa4af0f..4ebc2c9d3 100644 --- a/test/data/css/cssWidthBeforeDocReady.html +++ b/test/data/css/cssWidthBeforeDocReady.html @@ -14,8 +14,9 @@
+ diff --git a/test/data/data/dataAttrs.html b/test/data/data/dataAttrs.html index 5e6e442a6..785150eb8 100644 --- a/test/data/data/dataAttrs.html +++ b/test/data/data/dataAttrs.html @@ -4,9 +4,10 @@ IE11 onpageshow strangeness (#14894) + diff --git a/test/data/dimensions/documentLarge.html b/test/data/dimensions/documentLarge.html index c977fac96..9d6a7291d 100644 --- a/test/data/dimensions/documentLarge.html +++ b/test/data/dimensions/documentLarge.html @@ -8,14 +8,13 @@ height: 1000px; } +
diff --git a/test/data/event/focusElem.html b/test/data/event/focusElem.html index a9a976518..1940e8b61 100644 --- a/test/data/event/focusElem.html +++ b/test/data/event/focusElem.html @@ -5,12 +5,13 @@ .focus() (activeElement access #13393) + diff --git a/test/data/event/focusinCrossFrame.html b/test/data/event/focusinCrossFrame.html index 487f8de8f..6dd187e90 100644 --- a/test/data/event/focusinCrossFrame.html +++ b/test/data/event/focusinCrossFrame.html @@ -5,13 +5,14 @@ focusin event cross-frame (#14180) + diff --git a/test/data/event/interactiveReady.html b/test/data/event/interactiveReady.html index 77b37104d..3fb25f907 100644 --- a/test/data/event/interactiveReady.html +++ b/test/data/event/interactiveReady.html @@ -4,13 +4,14 @@ Test case for gh-2100 +