Skip to content

Commit

Permalink
Updated "Basic iframe behaviors" tests to also run in-browser.
Browse files Browse the repository at this point in the history
Same fixtures and assertions as before, but a real browser doesn't
handle iframe.src= synchronously, so needed to use QUnit's stop/start.
  • Loading branch information
gleneivey committed Apr 19, 2010
1 parent 2a378b8 commit da5cab0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion specs/scope/boot.js
Expand Up @@ -6,7 +6,7 @@ load('dist/env.rhino.js');

load('specs/qunit.js');
load('specs/env.qunit.js');
load('specs/helpers.js');
// "load('specs/helpers.js');" is in the "index.html" file

load('local_settings.js');
// "load('specs/scope/spec.js');" is in the "index.html" file
Expand Down
2 changes: 2 additions & 0 deletions specs/scope/index.html
Expand Up @@ -20,6 +20,8 @@
// both Envjs and browsers:
Envjs.scriptTypes['text/javascript'] = true;
</script>
<script src="../helpers.js"
type="text/javascript" ></script>
<script src="../fixtures/scope/define-some-variables.js"
type="text/javascript" ></script>
<script src="spec.js"
Expand Down
58 changes: 42 additions & 16 deletions specs/scope/spec.js
Expand Up @@ -25,25 +25,42 @@ test("Basic window object/global scope identity", function(){
'"var" variables defined in external files are window members' );
});

test("Basic iframe behaviors", function(){
asyncTest("Basic iframe behaviors", function(){
var adjustExpect = runningUnderEnvjs() ? 0 : -3;
/* should be this
expect( 8+8+8 + 0 );
expect( 8+8+8 + 0 + adjustExpect );
* but asserts commented out in ok_accessToIFrame1x() mean we do this for now:
*/ expect( 7+7+7 + 0 );
*/ expect( 7+7+7 + 0 + adjustExpect );


// check for things loaded directly by index.html
// iframe1a.html loaded via src= attribute when index.html was parsed
var iframe = document.getElementById('loaded-iframe');
ok_accessToIFrame1x(iframe, contentOfIFrameA,
'iframe loads with page load');

iframe = document.getElementById('empty-iframe');
iframe.src = "../fixtures/scope/iframe1a.html";
ok_accessToIFrame1x(iframe, contentOfIFrameA,
'empty iframe loads on .src=');

// for dynamically-loaded iframes, we need to use QUnit's
// async testing features
// test dynamic loading of an empty iframe
var emptyIFrame = document.getElementById('empty-iframe');
emptyIFrame.onload = function(){
ok_accessToIFrame1x(emptyIFrame, contentOfIFrameA,
'empty iframe loads on .src=');
};
emptyIFrame.src = "../fixtures/scope/iframe1a.html";

// test dynamic reloading of an already-populated iframe
iframe.onload = function(){
ok_accessToIFrame1x(iframe, contentOfIFrameB,
'iframe reloads on .src=');
}
iframe.src = "../fixtures/scope/iframe1b.html";
ok_accessToIFrame1x(iframe, contentOfIFrameB,
'iframe reloads on .src=');

setTimeout(function(){
start();
}, 300); // short should be fine as long as tests are always
// run via "file:" or from a web server on same host
});

// iframe1a and iframe1b are identical in structure (so we can use the
Expand All @@ -64,7 +81,7 @@ contentOfIFrameB = {
};


// add 8 to your expect() call's argument for each call to this function
// add 7-or-8 to your expect() call's argument for each call to this function
function ok_accessToIFrame1x(iframe, contentOf, message) {
ok( iframe.src.match(contentOf.urlRE),
message + ": Initial iframe src matches test page source" );
Expand All @@ -80,12 +97,21 @@ function ok_accessToIFrame1x(iframe, contentOf, message) {
message + ": iframe's conent is correct" );


equals( iframe.contentWindow.top, window, message +
": '.top' from iframe does point to top window");
equals( idoc.parentWindow, iframe.contentWindow, message +
": iframe doc's .parentWindow points to iframe's .contentWindow");
if (window.top.allTestsAreBeingRunWithinAnExtraIFrame)
equals( iframe.contentWindow.top, window.parent, message +
": '.top' from iframe does point to top window" );
else
equals( iframe.contentWindow.top, window, message +
": '.top' from iframe does point to top window" );


// document.parentWindow is IE-specific extension implemented by env.js
if (runningUnderEnvjs()){
equals( idoc.parentWindow, iframe.contentWindow, message +
": iframe doc's .parentWindow points to iframe's .contentWindow");
/* re-enable this once the preceding passes
equals( idoc.parentWindow.parent, window, message +
": Can follow chain from iframe's doc to containing window");
equals( idoc.parentWindow.parent, window, message +
": Can follow chain from iframe's doc to containing window");
*/
}
};

0 comments on commit da5cab0

Please sign in to comment.