michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: function createURI(s) { michael@0: let service = Components.classes["@mozilla.org/network/io-service;1"] michael@0: .getService(Components.interfaces.nsIIOService); michael@0: return service.newURI(s, null, null); michael@0: } michael@0: michael@0: function run_test() { michael@0: // Set up a profile. michael@0: do_get_profile(); michael@0: michael@0: var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager); michael@0: const kURI1 = "http://example.com"; michael@0: var app1 = secMan.getAppCodebasePrincipal(createURI(kURI1), 1, false); michael@0: var app10 = secMan.getAppCodebasePrincipal(createURI(kURI1), 10, false); michael@0: var app1browser = secMan.getAppCodebasePrincipal(createURI(kURI1), 1, true); michael@0: michael@0: var am = Cc["@mozilla.org/network/http-auth-manager;1"]. michael@0: getService(Ci.nsIHttpAuthManager); michael@0: am.setAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", "example.com", "user", "pass", false, app1); michael@0: am.setAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", "example.com", "user3", "pass3", false, app1browser); michael@0: am.setAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", "example.com", "user2", "pass2", false, app10); michael@0: michael@0: let subject = { michael@0: appId: 1, michael@0: browserOnly: true, michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams]) michael@0: }; michael@0: Services.obs.notifyObservers(subject, "webapps-clear-data", null); michael@0: michael@0: var domain = {value: ""}, user = {value: ""}, pass = {value: ""}; michael@0: try { michael@0: am.getAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", domain, user, pass, false, app1browser); michael@0: do_check_false(true); // no identity should be present michael@0: } catch (x) { michael@0: do_check_eq(domain.value, ""); michael@0: do_check_eq(user.value, ""); michael@0: do_check_eq(pass.value, ""); michael@0: } michael@0: michael@0: am.getAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", domain, user, pass, false, app1); michael@0: do_check_eq(domain.value, "example.com"); michael@0: do_check_eq(user.value, "user"); michael@0: do_check_eq(pass.value, "pass"); michael@0: michael@0: michael@0: am.getAuthIdentity("http", "a.example.com", -1, "basic", "realm", "", domain, user, pass, false, app10); michael@0: do_check_eq(domain.value, "example.com"); michael@0: do_check_eq(user.value, "user2"); michael@0: do_check_eq(pass.value, "pass2"); michael@0: }