Fix tests
This commit is contained in:
parent
5a7ab54ee6
commit
029c9754f0
7 changed files with 34 additions and 21 deletions
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
;(function() {
|
;(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
storage.fetch();
|
||||||
storage.onready(function() {
|
storage.onready(function() {
|
||||||
var messageReceiver;
|
var messageReceiver;
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (chrome.runtime) {
|
if (chrome.runtime.onInstalled) {
|
||||||
chrome.runtime.onInstalled.addListener(function(options) {
|
chrome.runtime.onInstalled.addListener(function(options) {
|
||||||
if (options.reason === 'install') {
|
if (options.reason === 'install') {
|
||||||
extension.install();
|
extension.install();
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
var ready = false;
|
var ready = false;
|
||||||
var items = new ItemCollection();
|
var items = new ItemCollection();
|
||||||
items.on('reset', function() { ready = true; });
|
items.on('reset', function() { ready = true; });
|
||||||
items.fetch({reset: true});
|
|
||||||
window.storage = {
|
window.storage = {
|
||||||
/*****************************
|
/*****************************
|
||||||
*** Base Storage Routines ***
|
*** Base Storage Routines ***
|
||||||
|
@ -62,6 +61,12 @@
|
||||||
} else {
|
} else {
|
||||||
items.on('reset', callback);
|
items.on('reset', callback);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
fetch: function() {
|
||||||
|
return new Promise(function(resolve) {
|
||||||
|
items.fetch({reset: true}).always(resolve);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
|
@ -4,10 +4,10 @@ function AxolotlStore() {
|
||||||
|
|
||||||
AxolotlStore.prototype = {
|
AxolotlStore.prototype = {
|
||||||
getMyIdentityKey: function() {
|
getMyIdentityKey: function() {
|
||||||
return this.get('identityKey');
|
return Promise.resolve(this.get('identityKey'));
|
||||||
},
|
},
|
||||||
getMyRegistrationId: function() {
|
getMyRegistrationId: function() {
|
||||||
return this.get('registrationId');
|
return Promise.resolve(this.get('registrationId'));
|
||||||
},
|
},
|
||||||
put: function(key, value) {
|
put: function(key, value) {
|
||||||
if (key === undefined || value === undefined || key === null || value === null)
|
if (key === undefined || value === undefined || key === null || value === null)
|
||||||
|
|
|
@ -29,16 +29,18 @@ describe("AxolotlStore", function() {
|
||||||
pubKey: textsecure.crypto.getRandomBytes(33),
|
pubKey: textsecure.crypto.getRandomBytes(33),
|
||||||
privKey: textsecure.crypto.getRandomBytes(32),
|
privKey: textsecure.crypto.getRandomBytes(32),
|
||||||
};
|
};
|
||||||
it('retrieves my registration id', function() {
|
it('retrieves my registration id', function(done) {
|
||||||
store.put('registrationId', 1337);
|
store.put('registrationId', 1337);
|
||||||
var reg = store.getMyRegistrationId();
|
store.getMyRegistrationId().then(function(reg) {
|
||||||
assert.strictEqual(reg, 1337);
|
assert.strictEqual(reg, 1337);
|
||||||
|
}).then(done, done);
|
||||||
});
|
});
|
||||||
it('retrieves my identity key', function() {
|
it('retrieves my identity key', function(done) {
|
||||||
store.put('identityKey', identityKey);
|
store.put('identityKey', identityKey);
|
||||||
var key = store.getMyIdentityKey();
|
store.getMyIdentityKey().then(function(key) {
|
||||||
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
|
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
|
||||||
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
|
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
|
||||||
|
}).then(done,done);
|
||||||
});
|
});
|
||||||
it('stores identity keys', function(done) {
|
it('stores identity keys', function(done) {
|
||||||
store.putIdentityKey(identifier, testKey.pubKey).then(function() {
|
store.putIdentityKey(identifier, testKey.pubKey).then(function() {
|
||||||
|
|
|
@ -117,6 +117,7 @@
|
||||||
|
|
||||||
<script type="text/javascript" src="../js/components.js"></script>
|
<script type="text/javascript" src="../js/components.js"></script>
|
||||||
<script type="text/javascript" src="../js/database.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/axolotl_store.js"></script>
|
||||||
<script type="text/javascript" src="../js/libtextsecure.js"></script>
|
<script type="text/javascript" src="../js/libtextsecure.js"></script>
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe("AxolotlStore", function() {
|
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 store = textsecure.storage.axolotl;
|
||||||
var identifier = '+5558675309';
|
var identifier = '+5558675309';
|
||||||
var identityKey = {
|
var identityKey = {
|
||||||
|
@ -28,16 +32,16 @@ describe("AxolotlStore", function() {
|
||||||
pubKey: textsecure.crypto.getRandomBytes(33),
|
pubKey: textsecure.crypto.getRandomBytes(33),
|
||||||
privKey: textsecure.crypto.getRandomBytes(32),
|
privKey: textsecure.crypto.getRandomBytes(32),
|
||||||
};
|
};
|
||||||
it('retrieves my registration id', function() {
|
it('retrieves my registration id', function(done) {
|
||||||
textsecure.storage.put('registrationId', 1337);
|
store.getMyRegistrationId().then(function(reg) {
|
||||||
var reg = store.getMyRegistrationId();
|
assert.strictEqual(reg, 1337);
|
||||||
assert.strictEqual(reg, 1337);
|
}).then(done, done);
|
||||||
});
|
});
|
||||||
it('retrieves my identity key', function() {
|
it('retrieves my identity key', function(done) {
|
||||||
textsecure.storage.put('identityKey', identityKey);
|
store.getMyIdentityKey().then(function(key) {
|
||||||
var key = store.getMyIdentityKey();
|
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
|
||||||
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
|
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
|
||||||
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
|
}).then(done,done);
|
||||||
});
|
});
|
||||||
it('stores identity keys', function(done) {
|
it('stores identity keys', function(done) {
|
||||||
store.putIdentityKey(identifier, testKey.pubKey).then(function() {
|
store.putIdentityKey(identifier, testKey.pubKey).then(function() {
|
||||||
|
|
Loading…
Reference in a new issue