function generateAndCloneCertificate(keygenAlgorithm) {
  RTCPeerConnection.generateCertificate(keygenAlgorithm).then(
      function(certificate) {
        gCertificate = certificate;
        if (gCertificate.getFingerprints().length == 0)
          throw failTest('getFingerprints() is empty.');
        for (let i = 0; i < gCertificate.getFingerprints().length; ++i) {
          if (gCertificate.getFingerprints()[i].algorithm != 'sha-256')
            throw failTest('Unexpected fingerprint algorithm.');
          if (gCertificate.getFingerprints()[i].value.length == 0)
            throw failTest('Unexpected fingerprint value.');
        }
        cloneCertificate_(gCertificate).then(
            function(clone) {
              let cloneIsEqual = (clone.getFingerprints().length ==
                                  gCertificate.getFingerprints().length);
              if (cloneIsEqual) {
                for (let i = 0; i < clone.getFingerprints().length; ++i) {
                  if (clone.getFingerprints()[i].algorithm !=
                      gCertificate.getFingerprints()[i].algorithm ||
                      clone.getFingerprints()[i].value !=
                      gCertificate.getFingerprints()[i].value) {
                    cloneIsEqual = false;
                    break;
                  }
                }
              }
              if (!cloneIsEqual) {
                throw failTest('The cloned certificate\'s fingerprints does ' +
                               'not match the original certificate.');
              }

              gCertificateClone = clone;
              returnToTest('ok-generated-and-cloned');
            },
            function() {
              failTest('Error cloning certificate.');
            });
      },
      function() {
        failTest('Certificate generation failed. keygenAlgorithm: ' +
            JSON.stringify(keygenAlgorithm));
      });
}
/**
 * Generates a certificate and clones it by saving and loading it to the
 * database (requires database to be open, see |openDatabase|). After returning
 * successfully to the test, the global variables |gCertificate| and
 * |gCertificateClone| have been set.
 * @param {!Object} keygenAlgorithm An |AlgorithmIdentifier| to be used as
 * parameter to |RTCPeerConnection.generateCertificate|. The resulting
 * certificate will be used by the peer connection.
 */
Generates a certificate and clones it by saving and loading it to the
database (requires database to be open, see |openDatabase|). After returning
successfully to the test, the global variables |gCertificate| and
|gCertificateClone| have been set.
@param {!Object} keygenAlgorithm An |AlgorithmIdentifier| to be used as
parameter to |RTCPeerConnection.generateCertificate|. The resulting
certificate will be used by the peer connection.
Generates a certificate and clones it by saving and loading it to the database ( requires database to be open see |openDatabase| ) . After returning successfully to the test the global variables |gCertificate| and |gCertificateClone| have been set . @param { !Object } keygenAlgorithm An |AlgorithmIdentifier| to be used as parameter to |RTCPeerConnection . generateCertificate| . The resulting certificate will be used by the peer connection .
function generateAndCloneCertificate(keygenAlgorithm) {
  RTCPeerConnection.generateCertificate(keygenAlgorithm).then(
      function(certificate) {
        gCertificate = certificate;
        if (gCertificate.getFingerprints().length == 0)
          throw failTest('getFingerprints() is empty.');
        for (let i = 0; i < gCertificate.getFingerprints().length; ++i) {
          if (gCertificate.getFingerprints()[i].algorithm != 'sha-256')
            throw failTest('Unexpected fingerprint algorithm.');
          if (gCertificate.getFingerprints()[i].value.length == 0)
            throw failTest('Unexpected fingerprint value.');
        }
        cloneCertificate_(gCertificate).then(
            function(clone) {
              let cloneIsEqual = (clone.getFingerprints().length ==
                                  gCertificate.getFingerprints().length);
              if (cloneIsEqual) {
                for (let i = 0; i < clone.getFingerprints().length; ++i) {
                  if (clone.getFingerprints()[i].algorithm !=
                      gCertificate.getFingerprints()[i].algorithm ||
                      clone.getFingerprints()[i].value !=
                      gCertificate.getFingerprints()[i].value) {
                    cloneIsEqual = false;
                    break;
                  }
                }
              }
              if (!cloneIsEqual) {
                throw failTest('The cloned certificate\'s fingerprints does ' +
                               'not match the original certificate.');
              }
              gCertificateClone = clone;
              returnToTest('ok-generated-and-cloned');
            },
            function() {
              failTest('Error cloning certificate.');
            });
      },
      function() {
        failTest('Certificate generation failed. keygenAlgorithm: ' +
            JSON.stringify(keygenAlgorithm));
      });
}
function generateAndCloneCertificate ( keygenAlgorithm ) { RTCPeerConnection . generateCertificate ( keygenAlgorithm ) . then ( function ( certificate ) { gCertificate = certificate ; if ( gCertificate . getFingerprints ( ) . length == 0 ) throw failTest ( 'getFingerprints() is empty.' ) ; for ( let i = 0 ; i < gCertificate . getFingerprints ( ) . length ; ++ i ) { if ( gCertificate . getFingerprints ( ) [ i ] . algorithm != 'sha-256' ) throw failTest ( 'Unexpected fingerprint algorithm.' ) ; if ( gCertificate . getFingerprints ( ) [ i ] . value . length == 0 ) throw failTest ( 'Unexpected fingerprint value.' ) ; } cloneCertificate_ ( gCertificate ) . then ( function ( clone ) { let cloneIsEqual = ( clone . getFingerprints ( ) . length == gCertificate . getFingerprints ( ) . length ) ; if ( cloneIsEqual ) { for ( let i = 0 ; i < clone . getFingerprints ( ) . length ; ++ i ) { if ( clone . getFingerprints ( ) [ i ] . algorithm != gCertificate . getFingerprints ( ) [ i ] . algorithm || clone . getFingerprints ( ) [ i ] . value != gCertificate . getFingerprints ( ) [ i ] . value ) { cloneIsEqual = false ; break ; } } } if ( ! cloneIsEqual ) { throw failTest ( 'The cloned certificate\'s fingerprints does ' + 'not match the original certificate.' ) ; } gCertificateClone = clone ; returnToTest ( 'ok-generated-and-cloned' ) ; } , function ( ) { failTest ( 'Error cloning certificate.' ) ; } ) ; } , function ( ) { failTest ( 'Certificate generation failed. keygenAlgorithm: ' + JSON . stringify ( keygenAlgorithm ) ) ; } ) ; }
Generates a certificate and clones it by saving and loading it to the
 database (requires database to be open, see |openDatabase|).
Generates a certificate and clones it by saving and loading it to the database ( requires database to be open see |openDatabase| ) .