]> source.dussan.org Git - jquery.git/commitdiff
Tests: move readywait to an iframe test
authorSteve Mao <maochenyan@gmail.com>
Sun, 25 Sep 2016 04:12:20 +0000 (14:12 +1000)
committerTimmy Willison <4timmywil@gmail.com>
Mon, 20 Mar 2017 15:37:15 +0000 (11:37 -0400)
Close gh-3576
Fixes gh-3573

src/deprecated.js
test/data/readywait.html [new file with mode: 0644]
test/data/readywaitasset.js [deleted file]
test/data/readywaitloader.js [deleted file]
test/readywait.html [deleted file]
test/unit/ready.js

index 195ce7ad92c155337d92ca4e8481a12d98c3363b..9589ec872618926fe2fd8f711b3c8b50a8f414f7 100644 (file)
@@ -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 (file)
index 0000000..d7de0b0
--- /dev/null
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html>
+<!--
+       Test for jQuery.holdReady. Needs to be a
+       standalone test since it deals with DOM
+       ready.
+-->
+<head>
+       <title>
+               jQuery.holdReady Test
+       </title>
+       <style>
+               div { margin-top: 10px; }
+               #output { background-color: green }
+               #expectedOutput { background-color: green }
+       </style>
+       <script src="../jquery.js"></script>
+       <script src="./iframeTest.js"></script>
+
+       <!-- Load the script loader that uses
+               jQuery.readyWait -->
+
+       <script type="text/javascript">
+       (function() {
+               var released = false;
+               // Hold on jQuery!
+               jQuery.holdReady( true );
+
+               setTimeout( function() {
+                       released = true;
+                       jQuery.holdReady( false );
+               }, 300 );
+
+               jQuery(function() {
+                       jQuery( "#output" ).text( "Ready called, holdReady released: " + released );
+                       startIframeTest( released );
+               });
+       })();
+       </script>
+</head>
+<body>
+       <h1>
+               jQuery.holdReady Test
+       </h1>
+       <p>
+               This is a test page for jQuery.readyWait and jQuery.holdReady,
+               see
+               <a href="https://bugs.jquery.com/ticket/6781">#6781</a>
+               and
+               <a href="https://bugs.jquery.com/ticket/8803">#8803</a>.
+       </p>
+       <p>
+       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.
+       </p>
+       <p>
+       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.
+       </p>
+       <p>
+       <strong>Expected Result</strong>: The text
+       <span id="expectedOutput">It Worked!</span>
+       appears below after about <strong>2 seconds.</strong>
+       </p>
+       <p>
+       If there is an error in the console,
+       or the text does not show up, then the test failed.
+       </p>
+       <div id="output"></div>
+</body>
+</html>
diff --git a/test/data/readywaitasset.js b/test/data/readywaitasset.js
deleted file mode 100644 (file)
index 2308965..0000000
+++ /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 (file)
index 8f4a345..0000000
+++ /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 (file)
index e34a0d7..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-<!DOCTYPE html>
-<html>
-<!--
-       Test for jQuery.holdReady. Needs to be a
-       standalone test since it deals with DOM
-       ready.
--->
-<head>
-       <title>
-               jQuery.holdReady Test
-       </title>
-       <style>
-               div { margin-top: 10px; }
-               #output { background-color: green }
-               #expectedOutput { background-color: green }
-       </style>
-       <script src="jquery.js"></script>
-
-       <!-- Load the script loader that uses
-               jQuery.readyWait -->
-       <script src="data/readywaitloader.js"></script>
-
-       <script type="text/javascript">
-       jQuery(function() {
-               // The delayedMessage is defined by
-               // the readywaitasset.js file, so the
-               // next line will only work if this DOM
-               // ready callback is called after readyWait
-               // has been decremented by readywaitloader.js
-               // If an error occurs.
-               jQuery("#output").append(delayedMessage);
-       });
-       </script>
-</head>
-<body>
-       <h1>
-               jQuery.holdReady Test
-       </h1>
-       <p>
-               This is a test page for jQuery.readyWait and jQuery.holdReady,
-               see
-               <a href="https://bugs.jquery.com/ticket/6781">#6781</a>
-               and
-               <a href="https://bugs.jquery.com/ticket/8803">#8803</a>.
-       </p>
-       <p>
-       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.
-       </p>
-       <p>
-       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.
-       </p>
-       <p>
-       <strong>Expected Result</strong>: The text
-       <span id="expectedOutput">It Worked!</span>
-       appears below after about <strong>2 seconds.</strong>
-       </p>
-       <p>
-       If there is an error in the console,
-       or the text does not show up, then the test failed.
-       </p>
-       <div id="output"></div>
-</body>
-</html>
index 775b6048a962b91ca470135bc6f0e87e8487d9e6..d3396b1c49731a556d760b3a05f81356cce22079 100644 (file)
@@ -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" );
+               }
+       );
+
 } )();