From: Steve Mao Date: Sun, 25 Sep 2016 04:12:20 +0000 (+1000) Subject: Tests: move readywait to an iframe test X-Git-Tag: 3.2.1~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fcc9a9ec9685e25864ca793698e4ac5e60226272;p=jquery.git Tests: move readywait to an iframe test Close gh-3576 Fixes gh-3573 --- diff --git a/src/deprecated.js b/src/deprecated.js index 195ce7ad9..9589ec872 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -23,16 +23,16 @@ jQuery.fn.extend( { return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn ); - }, - holdReady: function( hold ) { - if ( hold ) { - jQuery.readyWait++; - } else { - jQuery.ready( true ); - } } } ); +jQuery.holdReady = function( hold ) { + if ( hold ) { + jQuery.readyWait++; + } else { + jQuery.ready( true ); + } +}; jQuery.isArray = Array.isArray; jQuery.parseJSON = JSON.parse; jQuery.nodeName = nodeName; diff --git a/test/data/readywait.html b/test/data/readywait.html new file mode 100644 index 000000000..d7de0b082 --- /dev/null +++ b/test/data/readywait.html @@ -0,0 +1,76 @@ + + + + + + jQuery.holdReady Test + + + + + + + + + + +

+ jQuery.holdReady Test +

+

+ This is a test page for jQuery.readyWait and jQuery.holdReady, + see + #6781 + and + #8803. +

+

+ Test for jQuery.holdReady, which can be used + by plugins and other scripts to indicate something + important to the page is still loading and needs + to block the DOM ready callbacks that are registered + with jQuery. +

+

+ Script loaders are the most likely kind of script + to use jQuery.holdReady, but it could be used by + other things like a script that loads a CSS file + and wants to pause the DOM ready callbacks. +

+

+ Expected Result: The text + It Worked! + appears below after about 2 seconds. +

+

+ If there is an error in the console, + or the text does not show up, then the test failed. +

+
+ + diff --git a/test/data/readywaitasset.js b/test/data/readywaitasset.js deleted file mode 100644 index 2308965ce..000000000 --- a/test/data/readywaitasset.js +++ /dev/null @@ -1 +0,0 @@ -var delayedMessage = "It worked!"; diff --git a/test/data/readywaitloader.js b/test/data/readywaitloader.js deleted file mode 100644 index 8f4a3452e..000000000 --- a/test/data/readywaitloader.js +++ /dev/null @@ -1,25 +0,0 @@ -// Simple script loader that uses jQuery.readyWait via jQuery.holdReady() - -//Hold on jQuery! -jQuery.holdReady( true ); - -var readyRegExp = /^(complete|loaded)$/; - -function assetLoaded( evt ) { - var node = evt.currentTarget || evt.srcElement; - if ( evt.type === "load" || readyRegExp.test( node.readyState ) ) { - jQuery.holdReady( false ); - } -} - -setTimeout( function() { - var script = document.createElement( "script" ); - script.type = "text/javascript"; - if ( script.addEventListener ) { - script.addEventListener( "load", assetLoaded, false ); - } else { - script.attachEvent( "onreadystatechange", assetLoaded ); - } - script.src = "data/readywaitasset.js"; - document.getElementsByTagName( "head" )[ 0 ].appendChild( script ); -}, 2000 ); diff --git a/test/readywait.html b/test/readywait.html deleted file mode 100644 index e34a0d795..000000000 --- a/test/readywait.html +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - jQuery.holdReady Test - - - - - - - - - - -

- jQuery.holdReady Test -

-

- This is a test page for jQuery.readyWait and jQuery.holdReady, - see - #6781 - and - #8803. -

-

- Test for jQuery.holdReady, which can be used - by plugins and other scripts to indicate something - important to the page is still loading and needs - to block the DOM ready callbacks that are registered - with jQuery. -

-

- Script loaders are the most likely kind of script - to use jQuery.holdReady, but it could be used by - other things like a script that loads a CSS file - and wants to pause the DOM ready callbacks. -

-

- Expected Result: The text - It Worked! - appears below after about 2 seconds. -

-

- If there is an error in the console, - or the text does not show up, then the test failed. -

-
- - diff --git a/test/unit/ready.js b/test/unit/ready.js index 775b6048a..d3396b1c4 100644 --- a/test/unit/ready.js +++ b/test/unit/ready.js @@ -4,6 +4,7 @@ QUnit.module( "ready" ); var notYetReady, noEarlyExecution, whenified = jQuery.when( jQuery.ready ), promisified = Promise.resolve( jQuery.ready ), + start = new Date(), order = [], args = {}; @@ -147,4 +148,16 @@ QUnit.module( "ready" ); done(); } ); } ); + + testIframe( + "holdReady test needs to be a standalone test since it deals with DOM ready", + "readywait.html", + function( assert, jQuery, window, document, releaseCalled ) { + assert.expect( 2 ); + var now = new Date(); + assert.ok( now - start >= 300, "Needs to have waited at least half a second" ); + assert.ok( releaseCalled, "The release function was called, which resulted in ready" ); + } + ); + } )();