function testAutosizeAfterNavigation() {
  var webview = document.createElement('webview');

  var step = 1;
  var autosizeWidth = -1;
  var autosizeHeight = -1;
  var sizeChangeHandler = function(e) {
    switch (step) {
      case 1:
        // This would be triggered after we set autosize attribute.
        embedder.test.assertEq(50, e.oldWidth);
        embedder.test.assertEq(100, e.oldHeight);
        embedder.test.assertTrue(e.newWidth >= 60 && e.newWidth <= 70);
        embedder.test.assertTrue(e.newHeight >= 110 && e.newHeight <= 120);

        // Remove autosize attribute and expect webview to retain the same size.
        autosizeWidth = e.newWidth;
        autosizeHeight = e.newHeight;
        webview.removeAttribute('autosize');
        break;
      case 2:
        // Expect the autosized size.
        embedder.test.assertEq(autosizeWidth, e.newWidth);
        embedder.test.assertEq(autosizeHeight, e.newHeight);

        embedder.test.succeed();
        break;
      default:
        window.console.log('Unexpected sizechanged event, step = ' + step);
        embedder.test.fail();
        break;
    }

    ++step;
  };

  webview.addEventListener('sizechanged', sizeChangeHandler);

  webview.addEventListener('loadstop', function(e) {
    webview.setAttribute('autosize', true);
    webview.setAttribute('minwidth', 60);
    webview.setAttribute('maxwidth', 70);
    webview.setAttribute('minheight', 110);
    webview.setAttribute('maxheight', 120);
  });

  webview.style.width = '50px';
  webview.style.height = '100px';
  webview.setAttribute('src', 'data:text/html,webview test sizechanged event');
  document.body.appendChild(webview);
}
// one) sizechanged event with size1 as old size and size2 as new size.
one) sizechanged event with size1 as old size and size2 as new size.
one ) sizechanged event with size1 as old size and size2 as new size .
function testAutosizeAfterNavigation() {
  var webview = document.createElement('webview');
  var step = 1;
  var autosizeWidth = -1;
  var autosizeHeight = -1;
  var sizeChangeHandler = function(e) {
    switch (step) {
      case 1:
        embedder.test.assertEq(50, e.oldWidth);
        embedder.test.assertEq(100, e.oldHeight);
        embedder.test.assertTrue(e.newWidth >= 60 && e.newWidth <= 70);
        embedder.test.assertTrue(e.newHeight >= 110 && e.newHeight <= 120);
        autosizeWidth = e.newWidth;
        autosizeHeight = e.newHeight;
        webview.removeAttribute('autosize');
        break;
      case 2:
        embedder.test.assertEq(autosizeWidth, e.newWidth);
        embedder.test.assertEq(autosizeHeight, e.newHeight);
        embedder.test.succeed();
        break;
      default:
        window.console.log('Unexpected sizechanged event, step = ' + step);
        embedder.test.fail();
        break;
    }
    ++step;
  };
  webview.addEventListener('sizechanged', sizeChangeHandler);
  webview.addEventListener('loadstop', function(e) {
    webview.setAttribute('autosize', true);
    webview.setAttribute('minwidth', 60);
    webview.setAttribute('maxwidth', 70);
    webview.setAttribute('minheight', 110);
    webview.setAttribute('maxheight', 120);
  });
  webview.style.width = '50px';
  webview.style.height = '100px';
  webview.setAttribute('src', 'data:text/html,webview test sizechanged event');
  document.body.appendChild(webview);
}
function testAutosizeAfterNavigation ( ) { var webview = document . createElement ( 'webview' ) ; var step = 1 ; var autosizeWidth = - 1 ; var autosizeHeight = - 1 ; var sizeChangeHandler = function ( e ) { switch ( step ) { case 1 : embedder . test . assertEq ( 50 , e . oldWidth ) ; embedder . test . assertEq ( 100 , e . oldHeight ) ; embedder . test . assertTrue ( e . newWidth >= 60 && e . newWidth <= 70 ) ; embedder . test . assertTrue ( e . newHeight >= 110 && e . newHeight <= 120 ) ; autosizeWidth = e . newWidth ; autosizeHeight = e . newHeight ; webview . removeAttribute ( 'autosize' ) ; break ; case 2 : embedder . test . assertEq ( autosizeWidth , e . newWidth ) ; embedder . test . assertEq ( autosizeHeight , e . newHeight ) ; embedder . test . succeed ( ) ; break ; default : window . console . log ( 'Unexpected sizechanged event, step = ' + step ) ; embedder . test . fail ( ) ; break ; } ++ step ; } ; webview . addEventListener ( 'sizechanged' , sizeChangeHandler ) ; webview . addEventListener ( 'loadstop' , function ( e ) { webview . setAttribute ( 'autosize' , true ) ; webview . setAttribute ( 'minwidth' , 60 ) ; webview . setAttribute ( 'maxwidth' , 70 ) ; webview . setAttribute ( 'minheight' , 110 ) ; webview . setAttribute ( 'maxheight' , 120 ) ; } ) ; webview . style . width = '50px' ; webview . style . height = '100px' ; webview . setAttribute ( 'src' , 'data:text/html,webview test sizechanged event' ) ; document . body . appendChild ( webview ) ; }
one) sizechanged event with size1 as old size and size2 as new size.
one ) sizechanged event with size1 as old size and size2 as new size .
// This would be triggered after we set autosize attribute. // Remove autosize attribute and expect webview to retain the same size. // Expect the autosized size.