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

  console.log('Step 1: call <webview>.addContentScripts(myrule1)');
  webview.addContentScripts(
      [{name: 'myrule1',
        matches: ['http://*/extensions/*'],
        js: {
          files: ['inject_comm_channel.js']
        },
        run_at: 'document_start'}]);
  var connect_script_1 = true;
  var connect_script_2 = false;

  webview.addEventListener('loadstop', function() {
    if (connect_script_1) {
      var msg1 = [request_to_comm_channel_1];
      webview.contentWindow.postMessage(JSON.stringify(msg1), '*');
      connect_script_1 = false;
    }
    if (connect_script_2) {
      var msg2 = [request_to_comm_channel_2];
      webview.contentWindow.postMessage(JSON.stringify(msg2), '*');
      connect_script_2 = false;
    }
  });

  var should_get_response_from_script_1 = true;
  window.addEventListener('message', function(e) {
    var data = JSON.parse(e.data);
    if (data == response_from_comm_channel_1) {
      if (should_get_response_from_script_1) {
        console.log(
            'Step 2: A communication channel has been established with webview.'
            );
        webview.addContentScripts(
            [{name: 'myrule1',
              matches: ['http://*/extensions/*'],
              js: {
                files: ['inject_comm_channel_2.js']
              },
              run_at: 'document_start'}]);
        connect_script_2 = true;
        should_get_response_from_script_1 = false;
        webview.src = embedder.emptyGuestURL;
      } else {
        embedder.test.fail();
      }
      return;
    } else if (data == response_from_comm_channel_2) {
      console.log(
          'Step 3: Another communication channel has been established ' +
          'with webview.');
      setTimeout(function() {
        embedder.test.succeed();
      }, 0);
      return;
    }
    console.log('Unexpected message: \'' + data[0]  + '\'');
    embedder.test.fail();
  });

  webview.src = embedder.emptyGuestURL;
  document.body.appendChild(webview);
}
// get any message from the first script anymore.
get any message from the first script anymore.
get any message from the first script anymore .
function testAddContentScriptWithSameNameShouldOverwriteTheExistingOne() {
  var webview = document.createElement('webview');
  console.log('Step 1: call <webview>.addContentScripts(myrule1)');
  webview.addContentScripts(
      [{name: 'myrule1',
        matches: ['http://*/extensions/*'],
        js: {
          files: ['inject_comm_channel.js']
        },
        run_at: 'document_start'}]);
  var connect_script_1 = true;
  var connect_script_2 = false;
  webview.addEventListener('loadstop', function() {
    if (connect_script_1) {
      var msg1 = [request_to_comm_channel_1];
      webview.contentWindow.postMessage(JSON.stringify(msg1), '*');
      connect_script_1 = false;
    }
    if (connect_script_2) {
      var msg2 = [request_to_comm_channel_2];
      webview.contentWindow.postMessage(JSON.stringify(msg2), '*');
      connect_script_2 = false;
    }
  });
  var should_get_response_from_script_1 = true;
  window.addEventListener('message', function(e) {
    var data = JSON.parse(e.data);
    if (data == response_from_comm_channel_1) {
      if (should_get_response_from_script_1) {
        console.log(
            'Step 2: A communication channel has been established with webview.'
            );
        webview.addContentScripts(
            [{name: 'myrule1',
              matches: ['http://*/extensions/*'],
              js: {
                files: ['inject_comm_channel_2.js']
              },
              run_at: 'document_start'}]);
        connect_script_2 = true;
        should_get_response_from_script_1 = false;
        webview.src = embedder.emptyGuestURL;
      } else {
        embedder.test.fail();
      }
      return;
    } else if (data == response_from_comm_channel_2) {
      console.log(
          'Step 3: Another communication channel has been established ' +
          'with webview.');
      setTimeout(function() {
        embedder.test.succeed();
      }, 0);
      return;
    }
    console.log('Unexpected message: \'' + data[0]  + '\'');
    embedder.test.fail();
  });
  webview.src = embedder.emptyGuestURL;
  document.body.appendChild(webview);
}
function testAddContentScriptWithSameNameShouldOverwriteTheExistingOne ( ) { var webview = document . createElement ( 'webview' ) ; console . log ( 'Step 1: call <webview>.addContentScripts(myrule1)' ) ; webview . addContentScripts ( [ { name : 'myrule1' , matches : [ 'http://*/extensions/*' ] , js : { files : [ 'inject_comm_channel.js' ] } , run_at : 'document_start' } ] ) ; var connect_script_1 = true ; var connect_script_2 = false ; webview . addEventListener ( 'loadstop' , function ( ) { if ( connect_script_1 ) { var msg1 = [ request_to_comm_channel_1 ] ; webview . contentWindow . postMessage ( JSON . stringify ( msg1 ) , '*' ) ; connect_script_1 = false ; } if ( connect_script_2 ) { var msg2 = [ request_to_comm_channel_2 ] ; webview . contentWindow . postMessage ( JSON . stringify ( msg2 ) , '*' ) ; connect_script_2 = false ; } } ) ; var should_get_response_from_script_1 = true ; window . addEventListener ( 'message' , function ( e ) { var data = JSON . parse ( e . data ) ; if ( data == response_from_comm_channel_1 ) { if ( should_get_response_from_script_1 ) { console . log ( 'Step 2: A communication channel has been established with webview.' ) ; webview . addContentScripts ( [ { name : 'myrule1' , matches : [ 'http://*/extensions/*' ] , js : { files : [ 'inject_comm_channel_2.js' ] } , run_at : 'document_start' } ] ) ; connect_script_2 = true ; should_get_response_from_script_1 = false ; webview . src = embedder . emptyGuestURL ; } else { embedder . test . fail ( ) ; } return ; } else if ( data == response_from_comm_channel_2 ) { console . log ( 'Step 3: Another communication channel has been established ' + 'with webview.' ) ; setTimeout ( function ( ) { embedder . test . succeed ( ) ; } , 0 ) ; return ; } console . log ( 'Unexpected message: \'' + data [ 0 ] + '\'' ) ; embedder . test . fail ( ) ; } ) ; webview . src = embedder . emptyGuestURL ; document . body . appendChild ( webview ) ; }
get any message from the first script anymore.
get any message from the first script anymore .