OLD | NEW |
---|---|
1 // FIXME: Delete this (tests should import their own keys). | 1 // FIXME: Delete this (tests should import their own keys). |
2 function importTestKeys() | 2 function importTestKeys() |
3 { | 3 { |
4 var data = asciiToUint8Array("16 bytes of key!"); | 4 var data = asciiToUint8Array("16 bytes of key!"); |
5 var extractable = true; | 5 var extractable = true; |
6 var keyUsages = ['wrapKey', 'unwrapKey', 'encrypt', 'decrypt', 'sign', 'veri fy']; | 6 var keyUsages = ['wrapKey', 'unwrapKey', 'encrypt', 'decrypt', 'sign', 'veri fy']; |
7 | 7 |
8 var hmacPromise = crypto.subtle.importKey('raw', data, {name: 'hmac', hash: {name: 'sha-1'}}, extractable, keyUsages); | 8 var hmacPromise = crypto.subtle.importKey('raw', data, {name: 'hmac', hash: {name: 'sha-1'}}, extractable, keyUsages); |
9 var aesCbcPromise = crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable, keyUsages); | 9 var aesCbcPromise = crypto.subtle.importKey('raw', data, {name: 'AES-CBC'}, extractable, keyUsages); |
10 var aesCbcJustDecrypt = crypto.subtle.importKey('raw', data, {name: 'AES-CBC '}, false, ['decrypt']); | 10 var aesCbcJustDecrypt = crypto.subtle.importKey('raw', data, {name: 'AES-CBC '}, false, ['decrypt']); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 { | 91 { |
92 if (error) | 92 if (error) |
93 debug(error); | 93 debug(error); |
94 finishJSTest(); | 94 finishJSTest(); |
95 } | 95 } |
96 | 96 |
97 // ===================================================== | 97 // ===================================================== |
98 // FIXME: Delete the addTask() functions (better to test results directly) | 98 // FIXME: Delete the addTask() functions (better to test results directly) |
99 // ===================================================== | 99 // ===================================================== |
100 | 100 |
101 numOutstandingTasks = 0; | 101 var tasks = []; |
102 | 102 |
103 function addTask(promise) | 103 function runLoop() |
104 { | 104 { |
105 numOutstandingTasks++; | 105 if (tasks.length === 0) { |
106 finishJSTest(); | |
107 return; | |
108 } | |
109 var task = tasks.shift(); | |
110 task().then(runLoop); | |
111 } | |
106 | 112 |
107 function taskFinished() | 113 function addTask(task) |
108 { | 114 { |
109 numOutstandingTasks--; | 115 tasks.push(task); |
110 completeTestWhenAllTasksDone(); | 116 if (tasks.length === 1) { |
117 runLoop(); | |
111 } | 118 } |
112 | |
113 promise.then(taskFinished, taskFinished); | |
114 } | 119 } |
115 | 120 |
116 function completeTestWhenAllTasksDone() | 121 function completeTestWhenAllTasksDone() |
117 { | 122 { |
118 if (numOutstandingTasks == 0) { | 123 if (tasks.length === 0) { |
119 finishJSTest(); | 124 finishJSTest(); |
120 } | 125 } |
121 } | 126 } |
122 | 127 |
123 function shouldRejectPromiseWithNull(code) | 128 function shouldRejectPromiseWithNull(code) |
124 { | 129 { |
125 var promise = eval(code); | |
126 | |
127 function acceptCallback(result) | 130 function acceptCallback(result) |
128 { | 131 { |
129 debug("FAIL: '" + code + "' accepted with " + result + " but should have been rejected"); | 132 debug("FAIL: '" + code + "' accepted with " + result + " but should have been rejected"); |
130 } | 133 } |
131 | 134 |
132 function rejectCallback(result) | 135 function rejectCallback(result) |
133 { | 136 { |
134 if (result == null) | 137 if (result == null) |
135 debug("PASS: '" + code + "' rejected with null"); | 138 debug("PASS: '" + code + "' rejected with null"); |
136 else | 139 else |
137 debug("FAIL: '" + code + "' rejected with " + result + " but was exp ecting null"); | 140 debug("FAIL: '" + code + "' rejected with " + result + " but was exp ecting null"); |
138 } | 141 } |
139 | 142 |
140 addTask(promise.then(acceptCallback, rejectCallback)); | 143 addTask(function() { |
144 var promise = eval(code); | |
eroman
2014/03/26 09:07:58
In general this change is not a good idea, since "
| |
145 return promise.then(acceptCallback, rejectCallback); | |
146 }); | |
141 } | 147 } |
142 | 148 |
143 function shouldAcceptPromise(code) | 149 function shouldAcceptPromise(code) |
144 { | 150 { |
145 var promise = eval(code); | |
146 | |
147 function acceptCallback(result) | 151 function acceptCallback(result) |
148 { | 152 { |
149 debug("PASS: '" + code + "' accepted with " + result); | 153 debug("PASS: '" + code + "' accepted with " + result); |
150 } | 154 } |
151 | 155 |
152 function rejectCallback(result) | 156 function rejectCallback(result) |
153 { | 157 { |
154 debug("FAIL: '" + code + "' rejected with " + result); | 158 debug("FAIL: '" + code + "' rejected with " + result); |
155 } | 159 } |
156 | 160 |
157 addTask(promise.then(acceptCallback, rejectCallback)); | 161 addTask(function() { |
162 var promise = eval(code); | |
eroman
2014/03/26 09:07:58
Same comment as above.
| |
163 return promise.then(acceptCallback, rejectCallback); | |
164 }); | |
158 } | 165 } |
159 | 166 |
160 // ===================================================== | 167 // ===================================================== |
161 | 168 |
162 // Returns a Promise for the cloned key. | 169 // Returns a Promise for the cloned key. |
163 function cloneKey(key) | 170 function cloneKey(key) |
164 { | 171 { |
165 // Sending an object through a MessagePort implicitly clones it. | 172 // Sending an object through a MessagePort implicitly clones it. |
166 // Use a single MessageChannel so requests complete in FIFO order. | 173 // Use a single MessageChannel so requests complete in FIFO order. |
167 var self = cloneKey; | 174 var self = cloneKey; |
(...skipping 19 matching lines...) Expand all Loading... | |
187 if (internals) | 194 if (internals) |
188 debug("Serialized key bytes: " + bytesToHexString(internals.serializeObj ect(o))); | 195 debug("Serialized key bytes: " + bytesToHexString(internals.serializeObj ect(o))); |
189 } | 196 } |
190 | 197 |
191 function shouldEvaluateAs(actual, expectedValue) | 198 function shouldEvaluateAs(actual, expectedValue) |
192 { | 199 { |
193 if (typeof expectedValue == "string") | 200 if (typeof expectedValue == "string") |
194 return shouldBeEqualToString(actual, expectedValue); | 201 return shouldBeEqualToString(actual, expectedValue); |
195 return shouldEvaluateTo(actual, expectedValue); | 202 return shouldEvaluateTo(actual, expectedValue); |
196 } | 203 } |
OLD | NEW |