toolkit/identity/tests/unit/test_store.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 "use strict";
michael@0 5
michael@0 6 XPCOMUtils.defineLazyModuleGetter(this, "IDService",
michael@0 7 "resource://gre/modules/identity/Identity.jsm",
michael@0 8 "IdentityService");
michael@0 9
michael@0 10 function test_id_store() {
michael@0 11 // XXX - this is ugly, peaking in like this into IDService
michael@0 12 // probably should instantiate our own.
michael@0 13 var store = get_idstore();
michael@0 14
michael@0 15 // try adding an identity
michael@0 16 store.addIdentity(TEST_USER, TEST_PRIVKEY, TEST_CERT);
michael@0 17 do_check_neq(store.getIdentities()[TEST_USER], null);
michael@0 18 do_check_eq(store.getIdentities()[TEST_USER].cert, TEST_CERT);
michael@0 19
michael@0 20 // does fetch identity work?
michael@0 21 do_check_neq(store.fetchIdentity(TEST_USER), null);
michael@0 22 do_check_eq(store.fetchIdentity(TEST_USER).cert, TEST_CERT);
michael@0 23
michael@0 24 // clear the cert should keep the identity but not the cert
michael@0 25 store.clearCert(TEST_USER);
michael@0 26 do_check_neq(store.getIdentities()[TEST_USER], null);
michael@0 27 do_check_null(store.getIdentities()[TEST_USER].cert);
michael@0 28
michael@0 29 // remove it should remove everything
michael@0 30 store.removeIdentity(TEST_USER);
michael@0 31 do_check_eq(store.getIdentities()[TEST_USER], undefined);
michael@0 32
michael@0 33 // act like we're logged in to TEST_URL
michael@0 34 store.setLoginState(TEST_URL, true, TEST_USER);
michael@0 35 do_check_neq(store.getLoginState(TEST_URL), null);
michael@0 36 do_check_true(store.getLoginState(TEST_URL).isLoggedIn);
michael@0 37 do_check_eq(store.getLoginState(TEST_URL).email, TEST_USER);
michael@0 38
michael@0 39 // log out
michael@0 40 store.setLoginState(TEST_URL, false, TEST_USER);
michael@0 41 do_check_neq(store.getLoginState(TEST_URL), null);
michael@0 42 do_check_false(store.getLoginState(TEST_URL).isLoggedIn);
michael@0 43
michael@0 44 // email is still set
michael@0 45 do_check_eq(store.getLoginState(TEST_URL).email, TEST_USER);
michael@0 46
michael@0 47 // not logged into other site
michael@0 48 do_check_null(store.getLoginState(TEST_URL2));
michael@0 49
michael@0 50 // clear login state
michael@0 51 store.clearLoginState(TEST_URL);
michael@0 52 do_check_null(store.getLoginState(TEST_URL));
michael@0 53 do_check_null(store.getLoginState(TEST_URL2));
michael@0 54
michael@0 55 run_next_test();
michael@0 56 }
michael@0 57
michael@0 58 let TESTS = [test_id_store,];
michael@0 59
michael@0 60 TESTS.forEach(add_test);
michael@0 61
michael@0 62 function run_test() {
michael@0 63 run_next_test();
michael@0 64 }

mercurial