michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: XPCOMUtils.defineLazyModuleGetter(this, "IDService", michael@0: "resource://gre/modules/identity/Identity.jsm", michael@0: "IdentityService"); michael@0: michael@0: function test_id_store() { michael@0: // XXX - this is ugly, peaking in like this into IDService michael@0: // probably should instantiate our own. michael@0: var store = get_idstore(); michael@0: michael@0: // try adding an identity michael@0: store.addIdentity(TEST_USER, TEST_PRIVKEY, TEST_CERT); michael@0: do_check_neq(store.getIdentities()[TEST_USER], null); michael@0: do_check_eq(store.getIdentities()[TEST_USER].cert, TEST_CERT); michael@0: michael@0: // does fetch identity work? michael@0: do_check_neq(store.fetchIdentity(TEST_USER), null); michael@0: do_check_eq(store.fetchIdentity(TEST_USER).cert, TEST_CERT); michael@0: michael@0: // clear the cert should keep the identity but not the cert michael@0: store.clearCert(TEST_USER); michael@0: do_check_neq(store.getIdentities()[TEST_USER], null); michael@0: do_check_null(store.getIdentities()[TEST_USER].cert); michael@0: michael@0: // remove it should remove everything michael@0: store.removeIdentity(TEST_USER); michael@0: do_check_eq(store.getIdentities()[TEST_USER], undefined); michael@0: michael@0: // act like we're logged in to TEST_URL michael@0: store.setLoginState(TEST_URL, true, TEST_USER); michael@0: do_check_neq(store.getLoginState(TEST_URL), null); michael@0: do_check_true(store.getLoginState(TEST_URL).isLoggedIn); michael@0: do_check_eq(store.getLoginState(TEST_URL).email, TEST_USER); michael@0: michael@0: // log out michael@0: store.setLoginState(TEST_URL, false, TEST_USER); michael@0: do_check_neq(store.getLoginState(TEST_URL), null); michael@0: do_check_false(store.getLoginState(TEST_URL).isLoggedIn); michael@0: michael@0: // email is still set michael@0: do_check_eq(store.getLoginState(TEST_URL).email, TEST_USER); michael@0: michael@0: // not logged into other site michael@0: do_check_null(store.getLoginState(TEST_URL2)); michael@0: michael@0: // clear login state michael@0: store.clearLoginState(TEST_URL); michael@0: do_check_null(store.getLoginState(TEST_URL)); michael@0: do_check_null(store.getLoginState(TEST_URL2)); michael@0: michael@0: run_next_test(); michael@0: } michael@0: michael@0: let TESTS = [test_id_store,]; michael@0: michael@0: TESTS.forEach(add_test); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: }