-
-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for asyncronously added iframe and iframe-resizer script.
- Loading branch information
Nickolay Ribal
committed
May 14, 2015
1 parent
198eda4
commit 17bcc69
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |