You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/js/test.js

63 lines
2.2 KiB
JavaScript

11 years ago
// Setup dumb test wrapper
var testsdiv = $('#tests');
11 years ago
var testsOutstanding = [];
11 years ago
function TEST(func, name) {
var funcName = name === undefined ? func + "" : name;
11 years ago
var testIndex = testsOutstanding.length;
function callback(result) {
if (result)
11 years ago
testsdiv.append('<p style="color: green;">' + funcName + ' passed</p>');
else
testsdiv.append('<p style="color: red;">' + funcName + ' returned false</p>');
11 years ago
delete testsOutstanding[testIndex];
}
try {
testsOutstanding[testIndex] = funcName;
func(callback);
11 years ago
} catch (e) {
testsdiv.append('<p style="color: red;">' + funcName + ' threw ' + e + '</p>');
}
}
11 years ago
registerOnLoadFunction(function() {
localStorage.clear();
// Random tests to check my JS knowledge
TEST(function(callback) { callback(!objectContainsKeys({})); });
TEST(function(callback) { callback(objectContainsKeys({ a: undefined })); });
TEST(function(callback) { callback(objectContainsKeys({ a: null })); });
// Basic sanity-checks on the crypto library
TEST(function(callback) {
var PushMessageProto = dcodeIO.ProtoBuf.loadProtoFile("protos/IncomingPushMessageSignal.proto").build("textsecure.PushMessageContent");
var IncomingMessageProto = dcodeIO.ProtoBuf.loadProtoFile("protos/IncomingPushMessageSignal.proto").build("textsecure.IncomingPushMessageSignal");
var text_message = new PushMessageProto();
text_message.body = "Hi Mom";
var server_message = {type: 0, // unencrypted
source: "+19999999999", timestamp: 42, message: text_message.encode() };
11 years ago
11 years ago
crypto.handleIncomingPushMessageProto(server_message, function(message) {
callback(message.body == text_message.body &&
message.attachments.length == text_message.attachments.length &&
text_message.attachments.length == 0);
});
}, 'Unencrypted PushMessageProto "decrypt"');
11 years ago
11 years ago
TEST(function(callback) {
crypto.generateKeys(function() {
callback(true);
});
}, "Test simple create key");
11 years ago
11 years ago
// TODO: Run through the test vectors for the axolotl ratchet
11 years ago
11 years ago
window.setTimeout(function() {
for (var i = 0; i < testsOutstanding.length; i++)
if (testsOutstanding[i] !== undefined)
testsdiv.append('<p style="color: red;">' + testsOutstanding[i] + ' timed out</p>');
11 years ago
11 years ago
localStorage.clear();
}, 1000);
});