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.

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

mercurial