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