view iframe-resizer/test/mutationObserver.html @ 6:42076db43d42 draft

Fixed auto resizing plus various other minor bugs
author saskia-hiltemann
date Mon, 16 Nov 2015 08:56:22 -0500
parents ac5f9272033b
children
line wrap: on
line source

<!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 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="../js/iframeResizer.min.js"></script>
  <script>
  
    'use strict';

     function mutationObserverTest(){ 
      asyncTest( "iFrame MutationObserver", function() {

        var callbackCounter = 0;

        $('iframe').iFrameResize({
        log:true,
          resizedCallback:function(messageData){
            
            switch  (''+(++callbackCounter)){
              case '1':
                document.getElementsByTagName('iframe')[0].contentWindow.postMessage( msgId + 'changeContent', '*' );
                break;
              case '2':
                ok( true, 'iFrame detected content change');
                ok( 'mutationObserver' === messageData.type, 'Received '+messageData.type+' message back from iFrame. Expected mutationObserver' );
                start();
            }
          }
        });
      });
    }

    var msgId = '[iFrameSizerTest]:';

    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

    if (MutationObserver)
      mutationObserverTest()
    else{
      console.warn('(MutationObserver not supported in this browser! Unable to run test)');
      test('iFrame MutationObserver',function(){
        ok(true,'MutationObserver not supported in this browser! Unable to run test.');
      });
    }

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