diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/identity/tests/unit/test_observer_topics.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/identity/tests/unit/test_observer_topics.js')
-rw-r--r-- | toolkit/identity/tests/unit/test_observer_topics.js | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/toolkit/identity/tests/unit/test_observer_topics.js b/toolkit/identity/tests/unit/test_observer_topics.js new file mode 100644 index 000000000..8e5a89c91 --- /dev/null +++ b/toolkit/identity/tests/unit/test_observer_topics.js @@ -0,0 +1,114 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * By their nature, these tests duplicate some of the functionality of + * other tests for Identity, RelyingParty, and IdentityProvider. + * + * In particular, "identity-auth-complete" and + * "identity-login-state-changed" are tested in test_authentication.js + */ + +"use strict"; + +XPCOMUtils.defineLazyModuleGetter(this, "IDService", + "resource://gre/modules/identity/Identity.jsm", + "IdentityService"); + +function test_smoke() { + do_check_neq(IDService, null); + run_next_test(); +} + +function test_identity_request() { + // In response to navigator.id.request(), initiate a login with user + // interaction by notifying observers of 'identity-request' + + do_test_pending(); + + IDService.reset(); + + let id = "landru@mockmyid.com"; + setup_test_identity(id, TEST_CERT, function() { + // deliberately adding a trailing final slash on the domain + // to test path composition + let mockedDoc = mock_doc(null, "http://jed.gov/", function() {}); + + // by calling watch() we create an rp flow. + IDService.RP.watch(mockedDoc); + + // register the request UX observer + makeObserver("identity-request", function (aSubject, aTopic, aData) { + do_check_eq(aTopic, "identity-request"); + do_check_eq(aData, null); + + // check that all the URLs are properly resolved + let subj = aSubject.wrappedJSObject; + do_check_eq(subj.privacyPolicy, "http://jed.gov/pp.html"); + do_check_eq(subj.termsOfService, "http://jed.gov/tos.html"); + + do_test_finished(); + run_next_test(); + }); + + let requestOptions = { + privacyPolicy: "/pp.html", + termsOfService: "/tos.html" + }; + IDService.RP.request(mockedDoc.id, requestOptions); + }); + +} + +function test_identity_auth() { + // see test_authentication.js for "identity-auth-complete" + // and "identity-login-state-changed" + + do_test_pending(); + let _provId = "bogus"; + + // Simulate what would be returned by IDService._fetchWellKnownFile + // for a given domain. + let idpParams = { + domain: "myfavoriteflan.com", + idpParams: { + authentication: "/foo/authenticate.html", + provisioning: "/foo/provision.html" + } + }; + + // Create an RP flow + let mockedDoc = mock_doc(null, TEST_URL, function(action, params) {}); + IDService.RP.watch(mockedDoc); + + // The identity-auth notification is sent up to the UX from the + // _doAuthentication function. Be ready to receive it and call + // beginAuthentication + makeObserver("identity-auth", function (aSubject, aTopic, aData) { + do_check_neq(aSubject, null); + do_check_eq(aTopic, "identity-auth"); + do_check_eq(aData, "https://myfavoriteflan.com/foo/authenticate.html"); + + do_check_eq(aSubject.wrappedJSObject.provId, _provId); + do_test_finished(); + run_next_test(); + }); + + // Even though our provisioning flow id is bogus, IdentityProvider + // won't look at it until farther along in the authentication + // process. So this test can pass with a fake provId. + IDService.IDP._doAuthentication(_provId, idpParams); +} + +var TESTS = [ + test_smoke, + test_identity_request, + test_identity_auth, + ]; + + +TESTS.forEach(add_test); + +function run_test() { + run_next_test(); +} |