toolkit/identity/tests/unit/test_identity.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_overall() {
    11   do_check_neq(IDService, null);
    12   run_next_test();
    13 }
    15 function test_mock_doc() {
    16   do_test_pending();
    17   let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {
    18     do_check_eq(action, 'coffee');
    19     do_test_finished();
    20     run_next_test();
    21   });
    23   mockedDoc.doCoffee();
    24 }
    26 function test_add_identity() {
    27   IDService.reset();
    29   IDService.addIdentity(TEST_USER);
    31   let identities = IDService.RP.getIdentitiesForSite(TEST_URL);
    32   do_check_eq(identities.result.length, 1);
    33   do_check_eq(identities.result[0], TEST_USER);
    35   run_next_test();
    36 }
    38 function test_select_identity() {
    39   do_test_pending();
    41   IDService.reset();
    43   let id = "ishtar@mockmyid.com";
    44   setup_test_identity(id, TEST_CERT, function() {
    45     let gotAssertion = false;
    46     let mockedDoc = mock_doc(null, TEST_URL, call_sequentially(
    47       function(action, params) {
    48         // ready emitted from first watch() call
    49         do_check_eq(action, 'ready');
    50         do_check_null(params);
    51       },
    52       // first the login call
    53       function(action, params) {
    54         do_check_eq(action, 'login');
    55         do_check_neq(params, null);
    57         // XXX - check that the assertion is for the right email
    59         gotAssertion = true;
    60       },
    61       // then the ready call
    62       function(action, params) {
    63         do_check_eq(action, 'ready');
    64         do_check_null(params);
    66         // we should have gotten the assertion already
    67         do_check_true(gotAssertion);
    69         do_test_finished();
    70         run_next_test();
    71       }));
    73     // register the callbacks
    74     IDService.RP.watch(mockedDoc);
    76     // register the request UX observer
    77     makeObserver("identity-request", function (aSubject, aTopic, aData) {
    78       // do the select identity
    79       // we expect this to succeed right away because of test_identity
    80       // so we don't mock network requests or otherwise
    81       IDService.selectIdentity(aSubject.wrappedJSObject.rpId, id);
    82     });
    84     // do the request
    85     IDService.RP.request(mockedDoc.id, {});
    86   });
    87 }
    89 function test_parse_good_email() {
    90   var parsed = IDService.parseEmail('prime-minister@jed.gov');
    91   do_check_eq(parsed.username, 'prime-minister');
    92   do_check_eq(parsed.domain, 'jed.gov');
    93   run_next_test();
    94 }
    96 function test_parse_bogus_emails() {
    97   do_check_eq(null, IDService.parseEmail('@evil.org'));
    98   do_check_eq(null, IDService.parseEmail('foo@bar@baz.com'));
    99   do_check_eq(null, IDService.parseEmail('you@wellsfargo.com/accounts/transfer?to=dolske&amt=all'));
   100   run_next_test();
   101 }
   103 let TESTS = [test_overall, test_mock_doc];
   105 TESTS.push(test_add_identity);
   106 TESTS.push(test_select_identity);
   107 TESTS.push(test_parse_good_email);
   108 TESTS.push(test_parse_bogus_emails);
   110 TESTS.forEach(add_test);
   112 function run_test() {
   113   run_next_test();
   114 }

mercurial