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

  console.log('Step 1: call <webview>.addContentScripts.');
  webview.addContentScripts(
      [{name: 'myrule',
        matches: ['http://*/extensions/*'],
        js: {
          files: ['inject_comm_channel.js']
        },
        run_at: 'document_start'}]);

  var count = 0;
  webview.addEventListener('loadstop', function() {
    if (count == 0) {
      console.log('Step 2: call webview.terminate().');
      webview.terminate();
      ++count;
      return;
    } else if (count == 1) {
      console.log('Step 4: postMessage to build communication.');
      var msg = [request_to_comm_channel_1];
      webview.contentWindow.postMessage(JSON.stringify(msg), '*');
      ++count;
    }
  });

  webview.addEventListener('exit', function() {
    console.log('Step 3: call webview.reload().');
    webview.reload();
  });

  window.addEventListener('message', function(e) {
    var data = JSON.parse(e.data);
    if (data == response_from_comm_channel_1) {
      console.log(
          'Step 5: A communication channel has been established with webview.');
      embedder.test.succeed();
      return;
    }
    console.log('Unexpected message: \'' + data[0]  + '\'');
    embedder.test.fail();
  });

  webview.src = embedder.emptyGuestURL;
  document.body.appendChild(webview);
}
// injected after terminate and reload <webview>.
injected after terminate and reload .
injected after terminate and reload .
function testContentScriptIsInjectedAfterTerminateAndReloadWebView() {
  var webview = document.createElement('webview');
  console.log('Step 1: call <webview>.addContentScripts.');
  webview.addContentScripts(
      [{name: 'myrule',
        matches: ['http://*/extensions/*'],
        js: {
          files: ['inject_comm_channel.js']
        },
        run_at: 'document_start'}]);
  var count = 0;
  webview.addEventListener('loadstop', function() {
    if (count == 0) {
      console.log('Step 2: call webview.terminate().');
      webview.terminate();
      ++count;
      return;
    } else if (count == 1) {
      console.log('Step 4: postMessage to build communication.');
      var msg = [request_to_comm_channel_1];
      webview.contentWindow.postMessage(JSON.stringify(msg), '*');
      ++count;
    }
  });
  webview.addEventListener('exit', function() {
    console.log('Step 3: call webview.reload().');
    webview.reload();
  });
  window.addEventListener('message', function(e) {
    var data = JSON.parse(e.data);
    if (data == response_from_comm_channel_1) {
      console.log(
          'Step 5: A communication channel has been established with webview.');
      embedder.test.succeed();
      return;
    }
    console.log('Unexpected message: \'' + data[0]  + '\'');
    embedder.test.fail();
  });
  webview.src = embedder.emptyGuestURL;
  document.body.appendChild(webview);
}
function testContentScriptIsInjectedAfterTerminateAndReloadWebView ( ) { var webview = document . createElement ( 'webview' ) ; console . log ( 'Step 1: call <webview>.addContentScripts.' ) ; webview . addContentScripts ( [ { name : 'myrule' , matches : [ 'http://*/extensions/*' ] , js : { files : [ 'inject_comm_channel.js' ] } , run_at : 'document_start' } ] ) ; var count = 0 ; webview . addEventListener ( 'loadstop' , function ( ) { if ( count == 0 ) { console . log ( 'Step 2: call webview.terminate().' ) ; webview . terminate ( ) ; ++ count ; return ; } else if ( count == 1 ) { console . log ( 'Step 4: postMessage to build communication.' ) ; var msg = [ request_to_comm_channel_1 ] ; webview . contentWindow . postMessage ( JSON . stringify ( msg ) , '*' ) ; ++ count ; } } ) ; webview . addEventListener ( 'exit' , function ( ) { console . log ( 'Step 3: call webview.reload().' ) ; webview . reload ( ) ; } ) ; window . addEventListener ( 'message' , function ( e ) { var data = JSON . parse ( e . data ) ; if ( data == response_from_comm_channel_1 ) { console . log ( 'Step 5: A communication channel has been established with webview.' ) ; embedder . test . succeed ( ) ; return ; } console . log ( 'Unexpected message: \'' + data [ 0 ] + '\'' ) ; embedder . test . fail ( ) ; } ) ; webview . src = embedder . emptyGuestURL ; document . body . appendChild ( webview ) ; }
injected after terminate and reload <webview>.
injected after terminate and reload <webview > .