michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let pm; michael@0: michael@0: // Create a principal based on the { origin, appId, browserElement }. michael@0: function createPrincipal(aOrigin, aAppId, aBrowserElement) michael@0: { michael@0: return Services.scriptSecurityManager.getAppCodebasePrincipal(NetUtil.newURI(aOrigin), aAppId, aBrowserElement); michael@0: } michael@0: michael@0: // Return the subject required by 'webapps-clear-data' notification. michael@0: function getSubject(aAppId, aBrowserOnly) michael@0: { michael@0: return { michael@0: appId: aAppId, michael@0: browserOnly: aBrowserOnly, michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams]) michael@0: }; michael@0: } michael@0: michael@0: // Use aEntries to create principals, add permissions to them and check that they have them. michael@0: // Then, it is notifying 'webapps-clear-data' with the given aSubject and check if the permissions michael@0: // of principals[i] matches the permission in aResults[i]. michael@0: function test(aEntries, aSubject, aResults) michael@0: { michael@0: let principals = []; michael@0: michael@0: for (entry of aEntries) { michael@0: principals.push(createPrincipal(entry.origin, entry.appId, entry.browserElement)); michael@0: } michael@0: michael@0: for (principal of principals) { michael@0: do_check_eq(pm.testPermissionFromPrincipal(principal, "test/webapps-clear"), pm.UNKNOWN_ACTION); michael@0: pm.addFromPrincipal(principal, "test/webapps-clear", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); michael@0: do_check_eq(pm.testPermissionFromPrincipal(principal, "test/webapps-clear"), pm.ALLOW_ACTION); michael@0: } michael@0: michael@0: Services.obs.notifyObservers(aSubject, 'webapps-clear-data', null); michael@0: michael@0: var length = aEntries.length; michael@0: for (let i=0; i