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

Side by Side Diff: LayoutTests/crypto/importKey.html

Issue 19885002: WebCrypto: Add interfaces for importKey(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase and rename Interface --> Private Created 7 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/TestExpectations ('k') | LayoutTests/crypto/importKey-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../fast/js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9
10 <script>
11 description("Tests cypto.subtle.importKey.");
12
13 jsTestIsAsync = true;
14
15 function asciiToArrayBuffer(str)
16 {
17 var chars = [];
18 for (var i = 0; i < str.length; ++i)
19 chars.push(str.charCodeAt(i));
20 return new Uint8Array(chars);
21 }
22
23 // Each sub-test run in this file is asynchronous. Chaining them together
24 // manually leads to very unreadable code, due to having closures within
25 // closures within closures. Instead of doing that, each subtest calls
26 // "startNextTest()" once it has completed.
27
28 currentTestIndex = 0;
29
30 function startNextTest()
31 {
32 var currentTest = allTests[currentTestIndex++];
33
34 if (!currentTest) {
35 finishJSTest();
36 return;
37 }
38
39 currentTest();
40 }
41
42 function rejectHandler(value)
43 {
44 debug(" rejected with value of " + value);
45 startNextTest();
46 }
47
48 function failHandler(value)
49 {
50 testFailed(value);
51 startNextTest();
52 }
53
54 allTests = [
55 function()
56 {
57 keyFormat = "raw";
58 data = asciiToArrayBuffer("private");
59 algorithm = {name: "Sha-256"};
60 extractable = true;
61 // Note there are duplicates
62 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign'];
63
64 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
65 function(value) {
66 key = value;
67 shouldBe("key.type", "'private'")
68 shouldBe("key.extractable", "true")
69 shouldBe("key.algorithm.name", "'SHA-256'")
70 shouldBe("key.usages.join(',')", "'encrypt,sign'")
71
72 startNextTest();
73 }, failHandler);
74 },
75
76 // Same test as above, but with an keyUsages.
77 function()
78 {
79 keyFormat = "raw";
80 data = asciiToArrayBuffer("private");
81 algorithm = {name: "Sha-256"};
82 extractable = true;
83 keyUsages = [];
84
85 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
86 function(value) {
87 key = value;
88 shouldBe("key.type", "'private'")
89 shouldBe("key.extractable", "true")
90 shouldBe("key.algorithm.name", "'SHA-256'")
91 shouldBe("key.usages.join(',')", "''")
92
93 startNextTest();
94 }, failHandler);
95 },
96
97 // Same test as above, but with extractable = false.
98 function()
99 {
100 keyFormat = "raw";
101 data = asciiToArrayBuffer("private");
102 algorithm = {name: "Sha-256"};
103 extractable = false;
104 keyUsages = [];
105
106 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
107 function(value) {
108 key = value;
109 shouldBe("key.type", "'private'")
110 shouldBe("key.extractable", "false")
111 shouldBe("key.algorithm.name", "'SHA-256'")
112 shouldBe("key.usages.join(',')", "''")
113
114 startNextTest();
115 }, failHandler);
116 },
117
118 // Same test as above, but with key.type of public.
119 function()
120 {
121 keyFormat = "raw";
122 data = asciiToArrayBuffer("public");
123 algorithm = {name: "Sha-256"};
124 extractable = false;
125 keyUsages = [];
126
127 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
128 function(value) {
129 key = value;
130 shouldBe("key.type", "'public'")
131 shouldBe("key.extractable", "false")
132 shouldBe("key.algorithm.name", "'SHA-256'")
133 shouldBe("key.usages.join(',')", "''")
134
135 startNextTest();
136 }, failHandler);
137 },
138
139 // Same test as above, but with keyFormat = spki
140 function()
141 {
142 keyFormat = "spki";
143 data = asciiToArrayBuffer("public");
144 algorithm = {name: "Sha-256"};
145 extractable = false;
146 keyUsages = [];
147
148 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
149 function(value) {
150 key = value;
151 shouldBe("key.type", "'public'")
152 shouldBe("key.extractable", "false")
153 shouldBe("key.algorithm.name", "'SHA-256'")
154 shouldBe("key.usages.join(',')", "''")
155
156 startNextTest();
157 }, failHandler);
158 },
159
160 function()
161 {
162 keyFormat = "spki";
163 data = asciiToArrayBuffer("reject");
164 algorithm = {name: "Sha-256"};
165 extractable = false;
166 keyUsages = [];
167
168 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
169 failHandler,
170 function(value) {
171 debug("rejected with " + value);
172 startNextTest();
173 });
174 },
175
176 function()
177 {
178 keyFormat = "spki";
179 data = asciiToArrayBuffer("throw");
180 algorithm = {name: "Sha-256"};
181 extractable = false;
182 keyUsages = [];
183
184 shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extract able, keyUsages)");
185 startNextTest();
186 },
187
188 function()
189 {
190 keyFormat = "raw";
191 data = asciiToArrayBuffer("private");
192 algorithm = {name: 'sha-256'};
193 extractable = true;
194
195 // Note contains duplicates and invalid entries.
196 keyUsages = [];
197
198 // Invalid format.
199 shouldThrow("crypto.subtle.importKey('invalid format', data, algorithm, extractable, keyUsages)");
200
201 // Invalid key usage.
202 shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extract able, ['SIGN'])");
203
204 // Undefined key usage.
205 // FIXME: http://crbug.com/262383
206 //shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extra ctable, undefined)");
207
208 startNextTest();
209 },
210
211 ];
212
213 // Begin!
214 startNextTest();
215 </script>
216
217 <script src="../fast/js/resources/js-test-post.js"></script>
218 </body>
219 </html>
OLDNEW
« no previous file with comments | « LayoutTests/TestExpectations ('k') | LayoutTests/crypto/importKey-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698