Skip to content

Commit e5ffcb0

Browse files
committed
Tests: Refactor testIframe() to make it DRYer and more consistent
Ref jquerygh-3040 Closes jquerygh-3049
1 parent 08d73d7 commit e5ffcb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+142
-110
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,24 +340,32 @@ url("data/test.php?foo=bar");
340340
```
341341

342342

343-
### Load tests in an iframe (window.iframeCallback) ###
343+
### Run tests in an iframe ###
344+
345+
Some tests may require a document other than the standard test fixture, and
346+
these can be run in a separate iframe. The actual test code and assertions
347+
remain in jQuery's main test files; only the minimal test fixture markup
348+
and setup code should be placed in the iframe file.
344349

345350
```js
346-
testIframeWithCallback( testName, fileName,
347-
function callback( arg1, arg2, ... assert ) {
351+
testIframe( testName, fileName,
352+
function testCallback(
353+
assert, jQuery, window, document,
354+
[ additional args ] ) {
348355
...
349356
} );
350357
```
351358

352-
Loads a given page constructing a url with fileName: `"./data/" + fileName + ".html"`
353-
The iframe page is responsible for determining when `window.parent.iframeCallback`
354-
should be called, for example at document ready or window.onload time.
355-
Arguments passed to the callback are the same as the arguments passed
356-
to `window.parent.iframeCallback` by the iframe, plus the QUnit `assert`
357-
object from the `QUnit.test()` that this wrapper sets up for you.
358-
The iframe should send any objects needed by the unit test via arguments, for example
359-
its `jQuery`, `window`, and `document` objects from the iframe.
359+
This loads a page, constructing a url with fileName `"./data/" + fileName`.
360+
The iframed page determines when the callback occurs in the test by
361+
including the "/test/data/iframeTest.js" script and calling
362+
`startIframeTest( [ additional args ] )` when appropriate. Often this
363+
will be after either document ready or `window.onload` fires.
360364

365+
The `testCallback` receives the QUnit `assert` object created by `testIframe`
366+
for this test, followed by the global `jQuery`, `window`, and `document` from
367+
the iframe. If the iframe code passes any arguments to `startIframeTest`,
368+
they follow the `document` argument.
361369

362370

363371
Questions?

test/data/ajax/onunload.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
55
<title>onunload ajax requests (#14379)</title>
66
<script src="../../jquery.js"></script>
7+
<script src="../iframeTest.js"></script>
78
</head>
89
<body>
910
<form id="navigate" action="../iframe.html"></form>
@@ -17,7 +18,7 @@
1718
ajaxStatus = status;
1819
}
1920
});
20-
parent.iframeCallback( ajaxStatus );
21+
startIframeTest( ajaxStatus );
2122
});
2223

2324
jQuery(function() {

test/data/ajax/unreleasedXHR.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
<meta http-equiv="content-type" content="text/html; charset=utf-8">
55
<title>Attempt to block tests because of dangling XHR requests (IE)</title>
66
<script src="../../jquery.js"></script>
7+
<script src="../iframeTest.js"></script>
78
<script type="text/javascript">
89
window.onunload = function() {};
910
jQuery(function() {
1011
setTimeout(function() {
1112
var parent = window.parent;
1213
document.write("");
13-
parent.iframeCallback();
14+
startIframeTest();
1415
}, 200 );
1516
var number = 50;
1617
while( number-- ) {

test/data/core/aliased.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
};
1111
</script>
1212
<script src="../../jquery.js"></script>
13+
<script src="../iframeTest.js"></script>
1314
</head>
1415
<body>
1516
<form>
1617
<input type="text" id="nodeName"/>
1718
</form>
1819
<script>
19-
jQuery(function() {
20-
window.parent.iframeCallback( errors );
21-
});
20+
jQuery( function() {
21+
startIframeTest( errors );
22+
} );
2223
</script>
2324
</body>
2425
</html>

test/data/core/cc_on.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
};
1414
</script>
1515
<script src="../../jquery.js"></script>
16+
<script src="../iframeTest.js"></script>
1617
</head>
1718
<body>
1819
<script>
19-
window.parent.iframeCallback( cc_on, errors, jQuery );
20+
startIframeTest( cc_on, errors );
2021
</script>
2122
</body>
2223
</html>

test/data/core/dynamic_ready.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="utf-8">
55
<script src="../../jquery.js"></script>
66
<script>var $j = jQuery.noConflict();</script>
7+
<script src="../iframeTest.js"></script>
78
</head>
89
<body>
910
<iframe id="dont_return" src="dont_return.php"></iframe>
@@ -20,14 +21,14 @@
2021
$(function () {
2122
clearTimeout( timeoutId );
2223
if ( !timeoutFired ) {
23-
window.parent.iframeCallback( true );
24+
startIframeTest( true );
2425
}
2526
});
2627
});
2728

2829
timeoutId = setTimeout(function () {
2930
timeoutFired = true;
30-
window.parent.iframeCallback( false );
31+
startIframeTest( false );
3132
}, 10000);
3233
});
3334
</script>

test/data/core/onready.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
window.onready = function() { error = "Called window.onready"; };
99
</script>
1010
<script src="../../jquery.js"></script>
11+
<script src="../iframeTest.js"></script>
1112
</head>
1213
<body>
1314
<form>
@@ -16,7 +17,7 @@
1617
<script>
1718
jQuery(function() {
1819
setTimeout( function() {
19-
window.parent.iframeCallback( error );
20+
startIframeTest( error );
2021
});
2122
});
2223
</script>

test/data/css/cssWidthBeforeDocReady.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
<body>
1515
<div id="test"></div>
1616
<script src="../../jquery.js"></script>
17+
<script src="../iframeTest.js"></script>
1718
<script>
18-
window.parent.iframeCallback( jQuery( "#test" ).css( 'width' ) );
19+
startIframeTest( jQuery( "#test" ).css( 'width' ) );
1920
</script>
2021
</body>
2122
</html>

test/data/data/dataAttrs.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<title>IE11 onpageshow strangeness (#14894)</title>
66
<script src="../../jquery.js"></script>
7+
<script src="../iframeTest.js"></script>
78
<script>
89
$(function(){
9-
window.parent.iframeCallback( $( "body" ).data().result );
10+
startIframeTest( $( "body" ).data().result );
1011
});
1112
</script>
1213
</head>

test/data/dimensions/documentLarge.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
height: 1000px;
99
}
1010
</style>
11+
<script src="../iframeTest.js"></script>
1112
</head>
1213
<body>
1314
<div>
1415
<script src="../../jquery.js"></script>
1516
<script>
16-
jQuery( function() {
17-
window.parent.iframeCallback( jQuery, window, document );
18-
} );
17+
jQuery( startIframeTest );
1918
</script>
2019
</div>
2120
</body>

0 commit comments

Comments
 (0)