diff options
author | Dave Methvin <dave.methvin@gmail.com> | 2016-04-10 15:42:44 -0400 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2016-04-11 13:32:51 -0400 |
commit | e5ffcb0838c894e26f4ff32dfec162cf624d8d7d (patch) | |
tree | 1a57c3a0cbf026dcd98d1f821dc9ed6f848f46d3 /test/data | |
parent | 08d73d7f9c7eec2f0abd14d00bf903625728ef17 (diff) | |
download | jquery-e5ffcb0838c894e26f4ff32dfec162cf624d8d7d.tar.gz jquery-e5ffcb0838c894e26f4ff32dfec162cf624d8d7d.zip |
Tests: Refactor testIframe() to make it DRYer and more consistent
Ref gh-3040
Closes gh-3049
Diffstat (limited to 'test/data')
31 files changed, 72 insertions, 48 deletions
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 @@ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> <title>onunload ajax requests (#14379)</title> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> </head> <body> <form id="navigate" action="../iframe.html"></form> @@ -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 @@ <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Attempt to block tests because of dangling XHR requests (IE)</title> <script src="../../jquery.js"></script> +<script src="../iframeTest.js"></script> <script type="text/javascript"> window.onunload = function() {}; jQuery(function() { setTimeout(function() { var parent = window.parent; document.write(""); - parent.iframeCallback(); + startIframeTest(); }, 200 ); var number = 50; while( number-- ) { diff --git a/test/data/core/aliased.html b/test/data/core/aliased.html index ed06606af..87b5871f4 100644 --- a/test/data/core/aliased.html +++ b/test/data/core/aliased.html @@ -10,15 +10,16 @@ }; </script> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> </head> <body> <form> <input type="text" id="nodeName"/> </form> <script> - jQuery(function() { - window.parent.iframeCallback( errors ); - }); + jQuery( function() { + startIframeTest( errors ); + } ); </script> </body> </html> 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 @@ }; </script> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> </head> <body> <script> - window.parent.iframeCallback( cc_on, errors, jQuery ); + startIframeTest( cc_on, errors ); </script> </body> </html> 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 @@ <meta charset="utf-8"> <script src="../../jquery.js"></script> <script>var $j = jQuery.noConflict();</script> + <script src="../iframeTest.js"></script> </head> <body> <iframe id="dont_return" src="dont_return.php"></iframe> @@ -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); }); </script> 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"; }; </script> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> </head> <body> <form> @@ -16,7 +17,7 @@ <script> jQuery(function() { setTimeout( function() { - window.parent.iframeCallback( error ); + startIframeTest( error ); }); }); </script> 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 @@ <body> <div id="test"></div> <script src="../../jquery.js"></script> +<script src="../iframeTest.js"></script> <script> - window.parent.iframeCallback( jQuery( "#test" ).css( 'width' ) ); + startIframeTest( jQuery( "#test" ).css( 'width' ) ); </script> </body> </html> 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 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>IE11 onpageshow strangeness (#14894)</title> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script> $(function(){ - window.parent.iframeCallback( $( "body" ).data().result ); + startIframeTest( $( "body" ).data().result ); }); </script> </head> 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; } </style> + <script src="../iframeTest.js"></script> </head> <body> <div> <script src="../../jquery.js"></script> <script> - jQuery( function() { - window.parent.iframeCallback( jQuery, window, document ); - } ); + jQuery( startIframeTest ); </script> </div> </body> 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 @@ <title>.focus() (activeElement access #13393)</title> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> </head> <body> <a href="#" id="frame-link"></a> <script> jQuery( "#frame-link" ).trigger( "focus" ); - window.parent.iframeCallback( true ); + startIframeTest( true ); </script> </body> </html> 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 @@ <title>focusin event cross-frame (#14180)</title> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> </head> <body> <input type="text" id="frame-input" /> <script> // Call parent when this frame is fully loaded, it will mess with #frame-input jQuery( window ).one( "load", function() { - window.parent.iframeCallback( document ); + startIframeTest(); }); </script> </body> 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 @@ <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Test case for gh-2100</title> <script src="../../jquery.js"></script> +<script src="../iframeTest.js"></script> </head> <body> <script type="text/javascript"> -jQuery( document ).ready(function () { - window.parent.iframeCallback( jQuery("#container").length === 1 ); -}); +jQuery( function () { + startIframeTest( jQuery("#container").length === 1 ); +} ); </script> <!-- external resources that come before elements trick diff --git a/test/data/event/promiseReady.html b/test/data/event/promiseReady.html index 17b6e7f2c..c6e086245 100644 --- a/test/data/event/promiseReady.html +++ b/test/data/event/promiseReady.html @@ -4,10 +4,11 @@ <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Test case for jQuery ticket #11470</title> <script src="../../jquery.js"></script> +<script src="../iframeTest.js"></script> <script type="text/javascript"> jQuery.when( jQuery.ready ).done(function() { jQuery("body").append("<div>modifying DOM</div>"); - window.parent.iframeCallback( $("div").text() === "modifying DOM" ); + startIframeTest( $("div").text() === "modifying DOM" ); }); </script> </head> diff --git a/test/data/event/syncReady.html b/test/data/event/syncReady.html index dfa9ac337..61a50e423 100644 --- a/test/data/event/syncReady.html +++ b/test/data/event/syncReady.html @@ -4,12 +4,13 @@ <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Test case for jQuery ticket #10067</title> <script src="../../jquery.js"></script> +<script src="../iframeTest.js"></script> </head> <body> <script type="text/javascript"> jQuery( document ).ready(function () { - window.parent.iframeCallback( jQuery('#container').length === 1 ); + startIframeTest( jQuery('#container').length === 1 ); }); </script> diff --git a/test/data/event/triggerunload.html b/test/data/event/triggerunload.html index a7879c772..02be59d48 100644 --- a/test/data/event/triggerunload.html +++ b/test/data/event/triggerunload.html @@ -1,6 +1,7 @@ <!doctype html> <html> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script> var called = false, error = false; @@ -12,7 +13,7 @@ return "maybe"; }).on( "load", function( event ) { $( window ).triggerHandler( "beforeunload" ); - window.parent.iframeCallback( called && !error ); + startIframeTest( called && !error ); }); </script> </html> diff --git a/test/data/iframeTest.js b/test/data/iframeTest.js new file mode 100644 index 000000000..877e884f0 --- /dev/null +++ b/test/data/iframeTest.js @@ -0,0 +1,8 @@ + +window.startIframeTest = function() { + var args = Array.prototype.slice.call( arguments ); + + // Note: jQuery may be undefined if page did not load it + args.unshift( window.jQuery, window, document ); + window.parent.iframeCallback.apply( null, args ); +}; diff --git a/test/data/manipulation/iframe-denied.html b/test/data/manipulation/iframe-denied.html index 14df26a69..e74872ad0 100644 --- a/test/data/manipulation/iframe-denied.html +++ b/test/data/manipulation/iframe-denied.html @@ -7,6 +7,7 @@ <body> <div id="qunit-fixture"></div> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script> var script = document.getElementsByTagName( "script" )[ 0 ], div = document.createElement( "div" ), @@ -25,7 +26,7 @@ error = e; } - window.parent.iframeCallback({ + startIframeTest({ status: success, description: "buildFragment sets the context without throwing an exception" + ( error ? ": " + error : "" ) diff --git a/test/data/manipulation/scripts-context.html b/test/data/manipulation/scripts-context.html index 6958453c5..1b75e3a0a 100644 --- a/test/data/manipulation/scripts-context.html +++ b/test/data/manipulation/scripts-context.html @@ -7,12 +7,9 @@ <body> <div id="qunit-fixture"></div> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script> - window.parent.iframeCallback( - window, - document.body, - "<script>window.scriptTest = true;<\x2fscript>" - ); + startIframeTest(); </script> </body> </html> diff --git a/test/data/offset/absolute.html b/test/data/offset/absolute.html index 84a9e33de..9d8700465 100644 --- a/test/data/offset/absolute.html +++ b/test/data/offset/absolute.html @@ -16,6 +16,7 @@ #positionTest { position: absolute; } </style> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script type="text/javascript" charset="utf-8"> jQuery(function($) { $(".absolute").click(function() { @@ -24,7 +25,7 @@ $(this).css({ top: pos.top, left: pos.left }); return false; }); - window.parent.iframeCallback( jQuery, window, document ); + startIframeTest(); }); </script> </head> diff --git a/test/data/offset/body.html b/test/data/offset/body.html index cada87a15..75757d7e6 100644 --- a/test/data/offset/body.html +++ b/test/data/offset/body.html @@ -10,13 +10,14 @@ #firstElement { width: 50px; height: 50px; background: green; } </style> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script type="text/javascript" charset="utf-8"> jQuery(function($) { $("body").click(function() { $("marker").css( $(this).offset() ); return false; }); - window.parent.iframeCallback( jQuery, window, document ); + startIframeTest(); }); </script> </head> diff --git a/test/data/offset/fixed.html b/test/data/offset/fixed.html index e54389596..48a2c4797 100644 --- a/test/data/offset/fixed.html +++ b/test/data/offset/fixed.html @@ -13,6 +13,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script type="text/javascript" charset="utf-8"> jQuery(function($) { window.scrollTo(1000,1000); @@ -20,7 +21,7 @@ $("#marker").css( $(this).offset() ); return false; }); - window.parent.iframeCallback( jQuery, window, document ); + startIframeTest(); }); </script> </head> diff --git a/test/data/offset/relative.html b/test/data/offset/relative.html index b413e05ee..288fd4ea3 100644 --- a/test/data/offset/relative.html +++ b/test/data/offset/relative.html @@ -12,6 +12,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script type="text/javascript" charset="utf-8"> jQuery(function($) { $(".relative").click(function() { @@ -20,7 +21,7 @@ $(this).css({ position: 'absolute', top: pos.top, left: pos.left }); return false; }); - window.parent.iframeCallback( jQuery, window, document ); + startIframeTest(); }); </script> </head> diff --git a/test/data/offset/scroll.html b/test/data/offset/scroll.html index 49304eee7..28cade1c3 100644 --- a/test/data/offset/scroll.html +++ b/test/data/offset/scroll.html @@ -15,6 +15,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script type="text/javascript" charset="utf-8"> jQuery(function($) { window.scrollTo(1000,1000); @@ -24,7 +25,7 @@ $("#marker").css( $(this).offset() ); return false; }); - window.parent.iframeCallback( jQuery, window, document ); + startIframeTest(); }); </script> </head> diff --git a/test/data/offset/static.html b/test/data/offset/static.html index 125ad740f..1f4c3dc3d 100644 --- a/test/data/offset/static.html +++ b/test/data/offset/static.html @@ -11,6 +11,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script type="text/javascript" charset="utf-8"> jQuery(function($) { $(".static").click(function() { @@ -19,7 +20,7 @@ $(this).css({ position: 'absolute', top: pos.top, left: pos.left }); return false; }); - window.parent.iframeCallback( jQuery, window, document ); + startIframeTest(); }); </script> </head> diff --git a/test/data/offset/table.html b/test/data/offset/table.html index 1e37957ce..eeac19b77 100644 --- a/test/data/offset/table.html +++ b/test/data/offset/table.html @@ -11,13 +11,14 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script type="text/javascript" charset="utf-8"> jQuery(function($) { $("table, th, td").click(function() { $("#marker").css( $(this).offset() ); return false; }); - window.parent.iframeCallback( jQuery, window, document ); + startIframeTest(); }); </script> </head> diff --git a/test/data/selector/html5_selector.html b/test/data/selector/html5_selector.html index bf0e5ba5e..35c583cd0 100644 --- a/test/data/selector/html5_selector.html +++ b/test/data/selector/html5_selector.html @@ -5,7 +5,7 @@ <title>jQuery selector - attributes</title> <script src="../../jquery.js"></script> - + <script src="../iframeTest.js"></script> <script id="script1" defer async></script> @@ -16,9 +16,7 @@ document.createElement('article'); document.createElement('details'); - jQuery( function() { - window.parent.iframeCallback( jQuery, window, document ); - } ); + jQuery( startIframeTest ); </script> </head> <body> diff --git a/test/data/selector/sizzle_cache.html b/test/data/selector/sizzle_cache.html index 4320fdcfd..513390cab 100644 --- a/test/data/selector/sizzle_cache.html +++ b/test/data/selector/sizzle_cache.html @@ -5,6 +5,7 @@ <title>jQuery selector - sizzle cache</title> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script> document.write( "<script>var $cached = jQuery.noConflict(true);<\x2Fscript>" + @@ -18,9 +19,7 @@ <a href="#" id="collision">Worlds collide</a> </div> <script> - jQuery( function() { - window.parent.iframeCallback( jQuery, window, document ); - } ); + jQuery( startIframeTest ); </script> </body> </html> diff --git a/test/data/support/bodyBackground.html b/test/data/support/bodyBackground.html index cac099805..d95f39d57 100644 --- a/test/data/support/bodyBackground.html +++ b/test/data/support/bodyBackground.html @@ -18,10 +18,11 @@ <body> <div> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script src="getComputedSupport.js"></script> </div> <script> - window.parent.iframeCallback( jQuery( "body" ).css( "backgroundColor" ), + startIframeTest( jQuery( "body" ).css( "backgroundColor" ), getComputedSupport( jQuery.support ) ); </script> </body> diff --git a/test/data/support/csp.js b/test/data/support/csp.js index 5ebdcea08..4d55bdaa1 100644 --- a/test/data/support/csp.js +++ b/test/data/support/csp.js @@ -1,3 +1,3 @@ jQuery( function() { - parent.iframeCallback( getComputedSupport( jQuery.support ) ); + startIframeTest( getComputedSupport( jQuery.support ) ); } ); diff --git a/test/data/support/csp.php b/test/data/support/csp.php index 0783e1774..446000239 100644 --- a/test/data/support/csp.php +++ b/test/data/support/csp.php @@ -9,6 +9,7 @@ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CSP Test Page</title> <script src="../../jquery.js"></script> + <script src="../iframeTest.js"></script> <script src="csp.js"></script> <script src="getComputedSupport.js"></script> </head> diff --git a/test/data/testinit.js b/test/data/testinit.js index 70c9bbd5a..40ac02114 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -232,15 +232,15 @@ this.ajaxTest = function( title, expect, options ) { } ); }; -this.testIframeWithCallback = function( title, fileName, func ) { - QUnit.test( title, 1, function( assert ) { +this.testIframe = function( title, fileName, func ) { + QUnit.test( title, function( assert ) { var iframe; var done = assert.async(); window.iframeCallback = function() { var args = Array.prototype.slice.call( arguments ); - args.push( assert ); + args.unshift( assert ); setTimeout( function() { this.iframeCallback = undefined; @@ -248,7 +248,6 @@ this.testIframeWithCallback = function( title, fileName, func ) { func.apply( this, args ); func = function() {}; iframe.remove(); - done(); } ); }; |