Index: chrome/test/data/extensions/api_test/certificate_provider/basic.js |
diff --git a/chrome/test/data/extensions/api_test/certificate_provider/basic.js b/chrome/test/data/extensions/api_test/certificate_provider/basic.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1bb3d0e01ba5735c662c129c1d4e3e706d3cd26a |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/certificate_provider/basic.js |
@@ -0,0 +1,79 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+'use strict'; |
+ |
+var assertEq = chrome.test.assertEq; |
+var assertTrue = chrome.test.assertTrue; |
+var succeed = chrome.test.succeed; |
+var callbackPass = chrome.test.callbackPass; |
+ |
+var data = { |
+ // X.509 certificate in DER encoding issued by 'root.pem' which is set to be |
+ // trusted by the test setup. |
+ // Generated by create_test_certs.sh . |
+ l1_leaf_cert: 'l1_leaf.der', |
+ |
+ l1_leaf_key: 'l1_leaf.pk8', |
+}; |
+ |
+// Reads the binary file at |path| and passes it as a Uin8Array to |callback|. |
+function readFile(path, callback) { |
+ var oReq = new XMLHttpRequest(); |
+ oReq.responseType = "arraybuffer"; |
+ oReq.open("GET", path, true /* asynchronous */); |
+ oReq.onload = function() { |
+ var arrayBuffer = oReq.response; |
+ if (arrayBuffer) { |
+ callback(new Uint8Array(arrayBuffer)); |
+ } else { |
+ callback(null); |
+ } |
+ }; |
+ oReq.send(null); |
+} |
+ |
+// For each key in dictionary, replaces the path dictionary[key] by the content |
+// of the resource located at that path stored in a Uint8Array. |
+function readData(dictionary, callback) { |
+ var keys = Object.keys(dictionary); |
+ function recurse(index) { |
+ if (index >= keys.length) { |
+ callback(); |
+ return; |
+ } |
+ var key = keys[index]; |
+ var path = dictionary[key]; |
+ readFile(path, function(array) { |
+ assertTrue(!!array); |
+ dictionary[key] = array; |
+ recurse(index + 1); |
+ }); |
+ } |
+ |
+ recurse(0); |
+} |
+ |
+function setUp(callback) { |
+ readData(data, callback); |
+} |
+ |
+function test1() { |
+ assertTrue(!!chrome.certificateProvider); |
+ assertTrue(!!chrome.certificateProvider.publishClientCertificates); |
+ |
+ var certInfo = { |
+ certificate: data.l1_leaf_cert.buffer, |
+ supportedHashes: ['SHA256'] |
+ }; |
+ |
+ chrome.certificateProvider.publishClientCertificates([certInfo], |
+ callbackPass()); |
+} |
+ |
+function runTests() { |
+ chrome.test.runTests([test1]); |
+} |
+ |
+setUp(runTests); |