diff options
author | jrburke <jrburke@gmail.com> | 2011-02-12 03:42:35 +0100 |
---|---|---|
committer | Anton M <obhvsbypqghgc@gmail.com> | 2011-02-12 13:53:05 +0100 |
commit | d99268a4b728e47d02b9b893e08796c8060a68e9 (patch) | |
tree | d8ba4759a1a31ec3b78ba3b929512807fa4e5ba7 | |
parent | 2862f589db08b92c7b1f78fa961aff7354027c0b (diff) | |
download | jquery-d99268a4b728e47d02b9b893e08796c8060a68e9.tar.gz jquery-d99268a4b728e47d02b9b893e08796c8060a68e9.zip |
Add readyWait tests. Fixes #8145.
Adds tests for the fix to #6781.
-rw-r--r-- | test/data/readywaitasset.js | 1 | ||||
-rw-r--r-- | test/data/readywaitloader.js | 25 | ||||
-rw-r--r-- | test/readywait.html | 85 |
3 files changed, 111 insertions, 0 deletions
diff --git a/test/data/readywaitasset.js b/test/data/readywaitasset.js new file mode 100644 index 000000000..2308965ce --- /dev/null +++ b/test/data/readywaitasset.js @@ -0,0 +1 @@ +var delayedMessage = "It worked!"; diff --git a/test/data/readywaitloader.js b/test/data/readywaitloader.js new file mode 100644 index 000000000..483e07c4d --- /dev/null +++ b/test/data/readywaitloader.js @@ -0,0 +1,25 @@ +// Simple script loader that uses jQuery.readyWait + +//Hold on jQuery! +jQuery.readyWait++; + +var readyRegExp = /^(complete|loaded)$/; + +function assetLoaded( evt ){ + var node = evt.currentTarget || evt.srcElement; + if ( evt.type === "load" || readyRegExp.test(node.readyState) ) { + jQuery.ready(true); + } +} + +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 new file mode 100644 index 000000000..8e0d3d534 --- /dev/null +++ b/test/readywait.html @@ -0,0 +1,85 @@ +<!DOCTYPE html> +<html> +<!-- + Test for jQuery.readyWait. Needs to be a + standalone test since it deals with DOM + ready. +--> +<head> + <title> + jQuery.readyWait Test + </title> + <style> + div { margin-top: 10px; } + #output { background-color: green } + #expectedOutput { background-color: green } + </style> + <script src="../src/core.js"></script> + <script src="../src/support.js"></script> + <script src="../src/data.js"></script> + <script src="../src/queue.js"></script> + <script src="../src/attributes.js"></script> + <script src="../src/event.js"></script> + <script src="../src/sizzle/sizzle.js"></script> + <script src="../src/sizzle-jquery.js"></script> + <script src="../src/traversing.js"></script> + <script src="../src/manipulation.js"></script> + <script src="../src/css.js"></script> + <script src="../src/ajax.js"></script> + <script src="../src/ajax/jsonp.js"></script> + <script src="../src/ajax/script.js"></script> + <script src="../src/ajax/xhr.js"></script> + <script src="../src/effects.js"></script> + <script src="../src/offset.js"></script> + <script src="../src/dimensions.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.readyWait Test + </h1> + <p> + This is a test page for jQuery.readyWait, that was + added due to this ticket + <a href="http://bugs.jquery.com/ticket/6781">#6781</a>. + </p> + <p> + Test for jQuery.readyWait, 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.readyWait, 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> |