function testFocusTakeFocus() {
  var input = document.createElement('input');
  var webview = embedder.setUpGuest_();
  g_webview = webview;
  document.body.appendChild(input);

  var onChannelEstablished = function(webview) {
    input.focus();

    var msg = ['request-coords'];
    webview.contentWindow.postMessage(JSON.stringify(msg), '*');
  };

  var inputFocusedHandler = function(e) {
      chrome.test.sendMessage('TEST_STEP_PASSED');
  }

  var guestFocusedHandler = function(e) {
      console.log('input focused in guest');
      window.removeEventListener('message', guestFocusedHandler);
      input.addEventListener('focus', inputFocusedHandler);
      chrome.test.sendMessage('TEST_STEP_PASSED');
  };

  var coordHandler = function(response) {
    var rect = g_webview.getBoundingClientRect();
    window.clickX = rect.left + response[1];
    window.clickY = rect.top + response[2];
    window.addEventListener('message', guestFocusedHandler);
    chrome.test.sendMessage('TEST_PASSED');
  };

  embedder.waitForResponseFromGuest_(webview,
      'inject_focus_take_focus.js',
      onChannelEstablished,
      'response-coords',
      coordHandler);
}
// 4) Wait for the embedder input to receive another input event.
4) Wait for the embedder input to receive another input event.
4 ) Wait for the embedder input to receive another input event .
function testFocusTakeFocus() {
  var input = document.createElement('input');
  var webview = embedder.setUpGuest_();
  g_webview = webview;
  document.body.appendChild(input);
  var onChannelEstablished = function(webview) {
    input.focus();
    var msg = ['request-coords'];
    webview.contentWindow.postMessage(JSON.stringify(msg), '*');
  };
  var inputFocusedHandler = function(e) {
      chrome.test.sendMessage('TEST_STEP_PASSED');
  }
  var guestFocusedHandler = function(e) {
      console.log('input focused in guest');
      window.removeEventListener('message', guestFocusedHandler);
      input.addEventListener('focus', inputFocusedHandler);
      chrome.test.sendMessage('TEST_STEP_PASSED');
  };
  var coordHandler = function(response) {
    var rect = g_webview.getBoundingClientRect();
    window.clickX = rect.left + response[1];
    window.clickY = rect.top + response[2];
    window.addEventListener('message', guestFocusedHandler);
    chrome.test.sendMessage('TEST_PASSED');
  };
  embedder.waitForResponseFromGuest_(webview,
      'inject_focus_take_focus.js',
      onChannelEstablished,
      'response-coords',
      coordHandler);
}
function testFocusTakeFocus ( ) { var input = document . createElement ( 'input' ) ; var webview = embedder . setUpGuest_ ( ) ; g_webview = webview ; document . body . appendChild ( input ) ; var onChannelEstablished = function ( webview ) { input . focus ( ) ; var msg = [ 'request-coords' ] ; webview . contentWindow . postMessage ( JSON . stringify ( msg ) , '*' ) ; } ; var inputFocusedHandler = function ( e ) { chrome . test . sendMessage ( 'TEST_STEP_PASSED' ) ; } var guestFocusedHandler = function ( e ) { console . log ( 'input focused in guest' ) ; window . removeEventListener ( 'message' , guestFocusedHandler ) ; input . addEventListener ( 'focus' , inputFocusedHandler ) ; chrome . test . sendMessage ( 'TEST_STEP_PASSED' ) ; } ; var coordHandler = function ( response ) { var rect = g_webview . getBoundingClientRect ( ) ; window . clickX = rect . left + response [ 1 ] ; window . clickY = rect . top + response [ 2 ] ; window . addEventListener ( 'message' , guestFocusedHandler ) ; chrome . test . sendMessage ( 'TEST_PASSED' ) ; } ; embedder . waitForResponseFromGuest_ ( webview , 'inject_focus_take_focus.js' , onChannelEstablished , 'response-coords' , coordHandler ) ; }
4) Wait for the embedder input to receive another input event.
4 ) Wait for the embedder input to receive another input event .