Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/test/data/extensions/api_test/certificate_provider/basic.js

Issue 1232553003: Add new certificateProvider extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 var assertEq = chrome.test.assertEq;
8 var assertTrue = chrome.test.assertTrue;
9 var succeed = chrome.test.succeed;
10 var callbackPass = chrome.test.callbackPass;
11
12 var data = {
13 // X.509 certificate in DER encoding issued by 'root.pem' which is set to be
14 // trusted by the test setup.
15 // Generated by create_test_certs.sh .
16 l1_leaf_cert: 'l1_leaf.der',
17
18 l1_leaf_key: 'l1_leaf.pk8',
19 };
20
21 // Reads the binary file at |path| and passes it as a Uin8Array to |callback|.
22 function readFile(path, callback) {
23 var oReq = new XMLHttpRequest();
24 oReq.responseType = "arraybuffer";
25 oReq.open("GET", path, true /* asynchronous */);
26 oReq.onload = function() {
27 var arrayBuffer = oReq.response;
28 if (arrayBuffer) {
29 callback(new Uint8Array(arrayBuffer));
30 } else {
31 callback(null);
32 }
33 };
34 oReq.send(null);
35 }
36
37 // For each key in dictionary, replaces the path dictionary[key] by the content
38 // of the resource located at that path stored in a Uint8Array.
39 function readData(dictionary, callback) {
40 var keys = Object.keys(dictionary);
41 function recurse(index) {
42 if (index >= keys.length) {
43 callback();
44 return;
45 }
46 var key = keys[index];
47 var path = dictionary[key];
48 readFile(path, function(array) {
49 assertTrue(!!array);
50 dictionary[key] = array;
51 recurse(index + 1);
52 });
53 }
54
55 recurse(0);
56 }
57
58 function setUp(callback) {
59 readData(data, callback);
60 }
61
62 function test1() {
63 assertTrue(!!chrome.certificateProvider);
64 assertTrue(!!chrome.certificateProvider.publishClientCertificates);
65
66 var certInfo = {
67 certificate: data.l1_leaf_cert.buffer,
68 supportedHashes: ['SHA256']
69 };
70
71 chrome.certificateProvider.publishClientCertificates([certInfo],
72 callbackPass());
73 }
74
75 function runTests() {
76 chrome.test.runTests([test1]);
77 }
78
79 setUp(runTests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698