aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSteve Mao <maochenyan@gmail.com>2016-09-25 14:12:20 +1000
committerTimmy Willison <4timmywil@gmail.com>2017-03-20 11:37:15 -0400
commitfcc9a9ec9685e25864ca793698e4ac5e60226272 (patch)
tree99ea209438834538b9da56894356dd1e2a4bc314 /test
parentd33bb9c33ac84a1d1aa1aa8805b667efca2e51d6 (diff)
downloadjquery-fcc9a9ec9685e25864ca793698e4ac5e60226272.tar.gz
jquery-fcc9a9ec9685e25864ca793698e4ac5e60226272.zip
Tests: move readywait to an iframe test
Close gh-3576 Fixes gh-3573
Diffstat (limited to 'test')
-rw-r--r--test/data/readywait.html (renamed from test/readywait.html)28
-rw-r--r--test/data/readywaitasset.js1
-rw-r--r--test/data/readywaitloader.js25
-rw-r--r--test/unit/ready.js13
4 files changed, 30 insertions, 37 deletions
diff --git a/test/readywait.html b/test/data/readywait.html
index e34a0d795..d7de0b082 100644
--- a/test/readywait.html
+++ b/test/data/readywait.html
@@ -14,22 +14,28 @@
#output { background-color: green }
#expectedOutput { background-color: green }
</style>
- <script src="jquery.js"></script>
+ <script src="../jquery.js"></script>
+ <script src="./iframeTest.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);
- });
+ (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>
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/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" );
+ }
+ );
+
} )();