Skip to content

Commit

Permalink
Add test for asyncronously added iframe and iframe-resizer script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickolay Ribal committed May 14, 2015
1 parent 198eda4 commit 17bcc69
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions test/_init_once_async.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit LoadHide</title>
<link rel="stylesheet" href="resources/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">

<div class="iframe-wrapper" style="width:600px;">
<iframe src="resources/frame.content.html" width="100%" scrolling="no"></iframe>
</div>

</div>
<script src="resources/qunit.js"></script>
<script src="resources/jquery.js"></script>
<script src="../src/iframeResizer.js"></script>
<script>

'use strict';
var $iframeFirst = $('iframe');
var recievedIframeIds = [];
function getIframeFirstAttrs(){
var attrs = {};
var blacklistedAttrs = { id: true };
function cloneAllowedAttr(){
var attrName = this.name;
if (!(attrName in blacklistedAttrs)) {
attrs[attrName] = this.value;
}
}
$.each( $iframeFirst[0].attributes, cloneAllowedAttr );
return attrs;
}

function addSecondIframeAndScript(){
var $injectedIframe = $('<iframe/>').attr(getIframeFirstAttrs());
var firstScriptSource = $('script[src*=iframeResizer]').attr('src');
$iframeFirst.after($injectedIframe);
$.getScript(firstScriptSource, function(){
iFrameResize({
log:true,
bodyBackground:'wheat',
heightCalculationMethod:'max',
initCallback:function(iframe){
ok( true, 'Receive init message back from iFrame1.' );
ok( 'iFrameResizer1' === iframe.id, 'iFrame id = iFrameResizer1.' );
start();
}
});
});
}

asyncTest( "postMessage Response", function() {
iFrameResize({
log:true,
bodyBackground:'wheat',
heightCalculationMethod:'max',
initCallback:function(iframe){
ok( true, 'Receive init message back from iFrame0.' );
ok( 'iFrameResizer0' === iframe.id, 'iFrame id = iFrameResizer0.' );
addSecondIframeAndScript();
}
});
});

</script>
</body>
</html>

0 comments on commit 17bcc69

Please sign in to comment.