1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/identity/tests/unit/test_observer_topics.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * By their nature, these tests duplicate some of the functionality of 1.9 + * other tests for Identity, RelyingParty, and IdentityProvider. 1.10 + * 1.11 + * In particular, "identity-auth-complete" and 1.12 + * "identity-login-state-changed" are tested in test_authentication.js 1.13 + */ 1.14 + 1.15 +"use strict"; 1.16 + 1.17 +XPCOMUtils.defineLazyModuleGetter(this, "IDService", 1.18 + "resource://gre/modules/identity/Identity.jsm", 1.19 + "IdentityService"); 1.20 + 1.21 +function test_smoke() { 1.22 + do_check_neq(IDService, null); 1.23 + run_next_test(); 1.24 +} 1.25 + 1.26 +function test_identity_request() { 1.27 + // In response to navigator.id.request(), initiate a login with user 1.28 + // interaction by notifying observers of 'identity-request' 1.29 + 1.30 + do_test_pending(); 1.31 + 1.32 + IDService.reset(); 1.33 + 1.34 + let id = "landru@mockmyid.com"; 1.35 + setup_test_identity(id, TEST_CERT, function() { 1.36 + // deliberately adding a trailing final slash on the domain 1.37 + // to test path composition 1.38 + let mockedDoc = mock_doc(null, "http://jed.gov/", function() {}); 1.39 + 1.40 + // by calling watch() we create an rp flow. 1.41 + IDService.RP.watch(mockedDoc); 1.42 + 1.43 + // register the request UX observer 1.44 + makeObserver("identity-request", function (aSubject, aTopic, aData) { 1.45 + do_check_eq(aTopic, "identity-request"); 1.46 + do_check_eq(aData, null); 1.47 + 1.48 + // check that all the URLs are properly resolved 1.49 + let subj = aSubject.wrappedJSObject; 1.50 + do_check_eq(subj.privacyPolicy, "http://jed.gov/pp.html"); 1.51 + do_check_eq(subj.termsOfService, "http://jed.gov/tos.html"); 1.52 + 1.53 + do_test_finished(); 1.54 + run_next_test(); 1.55 + }); 1.56 + 1.57 + let requestOptions = { 1.58 + privacyPolicy: "/pp.html", 1.59 + termsOfService: "/tos.html" 1.60 + }; 1.61 + IDService.RP.request(mockedDoc.id, requestOptions); 1.62 + }); 1.63 + 1.64 +} 1.65 + 1.66 +function test_identity_auth() { 1.67 + // see test_authentication.js for "identity-auth-complete" 1.68 + // and "identity-login-state-changed" 1.69 + 1.70 + do_test_pending(); 1.71 + let _provId = "bogus"; 1.72 + 1.73 + // Simulate what would be returned by IDService._fetchWellKnownFile 1.74 + // for a given domain. 1.75 + let idpParams = { 1.76 + domain: "myfavoriteflan.com", 1.77 + idpParams: { 1.78 + authentication: "/foo/authenticate.html", 1.79 + provisioning: "/foo/provision.html" 1.80 + } 1.81 + }; 1.82 + 1.83 + // Create an RP flow 1.84 + let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {}); 1.85 + IDService.RP.watch(mockedDoc); 1.86 + 1.87 + // The identity-auth notification is sent up to the UX from the 1.88 + // _doAuthentication function. Be ready to receive it and call 1.89 + // beginAuthentication 1.90 + makeObserver("identity-auth", function (aSubject, aTopic, aData) { 1.91 + do_check_neq(aSubject, null); 1.92 + do_check_eq(aTopic, "identity-auth"); 1.93 + do_check_eq(aData, "https://myfavoriteflan.com/foo/authenticate.html"); 1.94 + 1.95 + do_check_eq(aSubject.wrappedJSObject.provId, _provId); 1.96 + do_test_finished(); 1.97 + run_next_test(); 1.98 + }); 1.99 + 1.100 + // Even though our provisioning flow id is bogus, IdentityProvider 1.101 + // won't look at it until farther along in the authentication 1.102 + // process. So this test can pass with a fake provId. 1.103 + IDService.IDP._doAuthentication(_provId, idpParams); 1.104 +} 1.105 + 1.106 +let TESTS = [ 1.107 + test_smoke, 1.108 + test_identity_request, 1.109 + test_identity_auth, 1.110 + ]; 1.111 + 1.112 + 1.113 +TESTS.forEach(add_test); 1.114 + 1.115 +function run_test() { 1.116 + run_next_test(); 1.117 +}