Skip to content

Commit

Permalink
Pass iframe support tests at doc ready. Fixes support fail in FF7
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Oct 31, 2011
1 parent 0752687 commit 006fde2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion test/data/support/bodyBackground.html
Expand Up @@ -32,7 +32,9 @@
<script src="../../../src/dimensions.js"></script> <script src="../../../src/dimensions.js"></script>
</div> </div>
<script> <script>
window.parent.supportCallback( jQuery( "body" ).css( "backgroundColor" ), jQuery.support ); jQuery(function() {
window.parent.supportCallback( jQuery( "body" ).css( "backgroundColor" ), jQuery.support );
});
</script> </script>
</body> </body>
</html> </html>
8 changes: 5 additions & 3 deletions test/unit/support.js
Expand Up @@ -33,12 +33,14 @@ supportIFrameTest( "proper boxModel in compatMode CSS1Compat (IE6 and IE7)", "bo


supportIFrameTest( "body background is not lost if set prior to loading jQuery (#9238)", "bodyBackground", function( color, support ) { supportIFrameTest( "body background is not lost if set prior to loading jQuery (#9238)", "bodyBackground", function( color, support ) {
expect( 2 ); expect( 2 );
var okValue = { var i,
passed = true,
okValue = {
"#000000": true, "#000000": true,
"rgb(0, 0, 0)": true "rgb(0, 0, 0)": true
}; };
ok( okValue[ color ], "color was not reset (" + color + ")" ); ok( okValue[ color ], "color was not reset (" + color + ")" );
var i, passed = true;
for ( i in jQuery.support ) { for ( i in jQuery.support ) {
if ( jQuery.support[ i ] !== support[ i ] ) { if ( jQuery.support[ i ] !== support[ i ] ) {
passed = false; passed = false;
Expand Down

1 comment on commit 006fde2

@mikesherov
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I actually sorta figured out why FF7 complains and Chrome doesn't, and Opera does sometimes before this change.

It seems as if Firefox lets 2 windows run javascript independent of each other (as expected?). By the time the window.supportCallback actually runs in FF7, there is no gaurantee the support tests ran in the IFRAME yet. If you change the setTimeout in supportIFrameTest to something like 100 instead of 0, FF complains a lot less often. It's a race.

It seems as if it's the same situation in Opera, however Opera seems like the document.ready on the iframe fires early enough to never complain. It's still a race, but the IFRAME always wins. If you want the IFRAME to lose, just put an alert('hi!'); after window.parent.supportCallback( jQuery( "body" ).css( "backgroundColor" ), jQuery.support ); and you'll see that the IFRAME now loses because the alert stops execution on that IFRAME.

For Chrome, different story. It seems as if Chrome finishes executing all the code in the IFRAME (including doc ready ?) before executing the callback on the parent window. To demonstrate, go ahead and and put that same alert in. If you notice, if you close the alert after 4 seconds, it's four more seconds before the test finishing running. It's as if the alert stops JS execution on both windows!

Weird.

Please sign in to comment.