Fix tests

This commit is contained in:
lilia 2015-05-14 15:44:43 -07:00
parent 5a7ab54ee6
commit 029c9754f0
7 changed files with 34 additions and 21 deletions

View file

@ -16,6 +16,7 @@
;(function() {
'use strict';
storage.fetch();
storage.onready(function() {
var messageReceiver;

View file

@ -180,7 +180,7 @@
});
};
if (chrome.runtime) {
if (chrome.runtime.onInstalled) {
chrome.runtime.onInstalled.addListener(function(options) {
if (options.reason === 'install') {
extension.install();

View file

@ -29,7 +29,6 @@
var ready = false;
var items = new ItemCollection();
items.on('reset', function() { ready = true; });
items.fetch({reset: true});
window.storage = {
/*****************************
*** Base Storage Routines ***
@ -62,6 +61,12 @@
} else {
items.on('reset', callback);
}
},
fetch: function() {
return new Promise(function(resolve) {
items.fetch({reset: true}).always(resolve);
});
}
};
window.textsecure = window.textsecure || {};

View file

@ -4,10 +4,10 @@ function AxolotlStore() {
AxolotlStore.prototype = {
getMyIdentityKey: function() {
return this.get('identityKey');
return Promise.resolve(this.get('identityKey'));
},
getMyRegistrationId: function() {
return this.get('registrationId');
return Promise.resolve(this.get('registrationId'));
},
put: function(key, value) {
if (key === undefined || value === undefined || key === null || value === null)

View file

@ -29,16 +29,18 @@ describe("AxolotlStore", function() {
pubKey: textsecure.crypto.getRandomBytes(33),
privKey: textsecure.crypto.getRandomBytes(32),
};
it('retrieves my registration id', function() {
it('retrieves my registration id', function(done) {
store.put('registrationId', 1337);
var reg = store.getMyRegistrationId();
assert.strictEqual(reg, 1337);
store.getMyRegistrationId().then(function(reg) {
assert.strictEqual(reg, 1337);
}).then(done, done);
});
it('retrieves my identity key', function() {
it('retrieves my identity key', function(done) {
store.put('identityKey', identityKey);
var key = store.getMyIdentityKey();
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
store.getMyIdentityKey().then(function(key) {
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
}).then(done,done);
});
it('stores identity keys', function(done) {
store.putIdentityKey(identifier, testKey.pubKey).then(function() {

View file

@ -117,6 +117,7 @@
<script type="text/javascript" src="../js/components.js"></script>
<script type="text/javascript" src="../js/database.js"></script>
<script type="text/javascript" src="../js/storage.js"></script>
<script type="text/javascript" src="../js/axolotl_store.js"></script>
<script type="text/javascript" src="../js/libtextsecure.js"></script>

View file

@ -17,7 +17,11 @@
'use strict';
describe("AxolotlStore", function() {
before(function() { localStorage.clear(); });
before(function(done) {
storage.put('registrationId', 1337);
storage.put('identityKey', identityKey);
storage.fetch().then(done, done);
});
var store = textsecure.storage.axolotl;
var identifier = '+5558675309';
var identityKey = {
@ -28,16 +32,16 @@ describe("AxolotlStore", function() {
pubKey: textsecure.crypto.getRandomBytes(33),
privKey: textsecure.crypto.getRandomBytes(32),
};
it('retrieves my registration id', function() {
textsecure.storage.put('registrationId', 1337);
var reg = store.getMyRegistrationId();
assert.strictEqual(reg, 1337);
it('retrieves my registration id', function(done) {
store.getMyRegistrationId().then(function(reg) {
assert.strictEqual(reg, 1337);
}).then(done, done);
});
it('retrieves my identity key', function() {
textsecure.storage.put('identityKey', identityKey);
var key = store.getMyIdentityKey();
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
it('retrieves my identity key', function(done) {
store.getMyIdentityKey().then(function(key) {
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
}).then(done,done);
});
it('stores identity keys', function(done) {
store.putIdentityKey(identifier, testKey.pubKey).then(function() {