diff -r 000000000000 -r 6474c204b198 extensions/cookie/test/unit/test_permmanager_cleardata.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/cookie/test/unit/test_permmanager_cleardata.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,72 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +let pm; + +// Create a principal based on the { origin, appId, browserElement }. +function createPrincipal(aOrigin, aAppId, aBrowserElement) +{ + return Services.scriptSecurityManager.getAppCodebasePrincipal(NetUtil.newURI(aOrigin), aAppId, aBrowserElement); +} + +// Return the subject required by 'webapps-clear-data' notification. +function getSubject(aAppId, aBrowserOnly) +{ + return { + appId: aAppId, + browserOnly: aBrowserOnly, + QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams]) + }; +} + +// Use aEntries to create principals, add permissions to them and check that they have them. +// Then, it is notifying 'webapps-clear-data' with the given aSubject and check if the permissions +// of principals[i] matches the permission in aResults[i]. +function test(aEntries, aSubject, aResults) +{ + let principals = []; + + for (entry of aEntries) { + principals.push(createPrincipal(entry.origin, entry.appId, entry.browserElement)); + } + + for (principal of principals) { + do_check_eq(pm.testPermissionFromPrincipal(principal, "test/webapps-clear"), pm.UNKNOWN_ACTION); + pm.addFromPrincipal(principal, "test/webapps-clear", pm.ALLOW_ACTION, pm.EXPIRE_NEVER, 0); + do_check_eq(pm.testPermissionFromPrincipal(principal, "test/webapps-clear"), pm.ALLOW_ACTION); + } + + Services.obs.notifyObservers(aSubject, 'webapps-clear-data', null); + + var length = aEntries.length; + for (let i=0; i