OLD | NEW |
1 /** | 1 /** |
2 * Copyright 2016 The Chromium Authors. All rights reserved. | 2 * Copyright 2016 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /** @private */ | 7 /** @private */ |
8 var kDatabaseName = 'WebRTC-Database'; | 8 var kDatabaseName = 'WebRTC-Database'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 * successfully to the test, the global variables |gCertificate| and | 70 * successfully to the test, the global variables |gCertificate| and |
71 * |gCertificateClone| have been set. | 71 * |gCertificateClone| have been set. |
72 * @param {!Object} keygenAlgorithm An |AlgorithmIdentifier| to be used as | 72 * @param {!Object} keygenAlgorithm An |AlgorithmIdentifier| to be used as |
73 * parameter to |RTCPeerConnection.generateCertificate|. The resulting | 73 * parameter to |RTCPeerConnection.generateCertificate|. The resulting |
74 * certificate will be used by the peer connection. | 74 * certificate will be used by the peer connection. |
75 */ | 75 */ |
76 function generateAndCloneCertificate(keygenAlgorithm) { | 76 function generateAndCloneCertificate(keygenAlgorithm) { |
77 RTCPeerConnection.generateCertificate(keygenAlgorithm).then( | 77 RTCPeerConnection.generateCertificate(keygenAlgorithm).then( |
78 function(certificate) { | 78 function(certificate) { |
79 gCertificate = certificate; | 79 gCertificate = certificate; |
| 80 if (gCertificate.getFingerprints().length == 0) |
| 81 throw failTest('getFingerprints() is empty.'); |
| 82 for (let i = 0; i < gCertificate.getFingerprints().length; ++i) { |
| 83 if (gCertificate.getFingerprints()[i].algorithm != 'sha-256') |
| 84 throw failTest('Unexpected fingerprint algorithm.'); |
| 85 if (gCertificate.getFingerprints()[i].value.length == 0) |
| 86 throw failTest('Unexpected fingerprint value.'); |
| 87 } |
80 cloneCertificate_(gCertificate).then( | 88 cloneCertificate_(gCertificate).then( |
81 function(clone) { | 89 function(clone) { |
| 90 let cloneIsEqual = (clone.getFingerprints().length == |
| 91 gCertificate.getFingerprints().length); |
| 92 if (cloneIsEqual) { |
| 93 for (let i = 0; i < clone.getFingerprints().length; ++i) { |
| 94 if (clone.getFingerprints()[i].algorithm != |
| 95 gCertificate.getFingerprints()[i].algorithm || |
| 96 clone.getFingerprints()[i].value != |
| 97 gCertificate.getFingerprints()[i].value) { |
| 98 cloneIsEqual = false; |
| 99 break; |
| 100 } |
| 101 } |
| 102 } |
| 103 if (!cloneIsEqual) { |
| 104 throw failTest('The cloned certificate\'s fingerprints does ' + |
| 105 'not match the original certificate.'); |
| 106 } |
| 107 |
82 gCertificateClone = clone; | 108 gCertificateClone = clone; |
83 // TODO(hbos): Verify that |gCertificate| is value-equal to | |
84 // |gCertificateClone|. crbug.com/609108 | |
85 returnToTest('ok-generated-and-cloned'); | 109 returnToTest('ok-generated-and-cloned'); |
86 }, | 110 }, |
87 function() { | 111 function() { |
88 failTest('Error cloning certificate.'); | 112 failTest('Error cloning certificate.'); |
89 }); | 113 }); |
90 }, | 114 }, |
91 function() { | 115 function() { |
92 failTest('Certificate generation failed. keygenAlgorithm: ' + | 116 failTest('Certificate generation failed. keygenAlgorithm: ' + |
93 JSON.stringify(keygenAlgorithm)); | 117 JSON.stringify(keygenAlgorithm)); |
94 }); | 118 }); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 function cloneCertificate_(certificate) { | 170 function cloneCertificate_(certificate) { |
147 return saveCertificate_(certificate) | 171 return saveCertificate_(certificate) |
148 .then(loadCertificate_) | 172 .then(loadCertificate_) |
149 .then(function(clone) { | 173 .then(function(clone) { |
150 // Save + load successful. | 174 // Save + load successful. |
151 if (clone === null) | 175 if (clone === null) |
152 failTest('loadCertificate returned a null certificate.'); | 176 failTest('loadCertificate returned a null certificate.'); |
153 return clone; | 177 return clone; |
154 }); | 178 }); |
155 } | 179 } |
OLD | NEW |