toolkit/identity/tests/unit/test_store.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial