webapprt/test/chrome/browser_webperm.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 Cu.import("resource://webapprt/modules/WebappRT.jsm");
michael@0 2 let { AppsUtils } = Cu.import("resource://gre/modules/AppsUtils.jsm", {});
michael@0 3 let { DOMApplicationRegistry } =
michael@0 4 Cu.import("resource://gre/modules/Webapps.jsm", {});
michael@0 5 let { PermissionsTable, PermissionsReverseTable } =
michael@0 6 Cu.import("resource://gre/modules/PermissionsTable.jsm", {});
michael@0 7
michael@0 8 function test() {
michael@0 9 waitForExplicitFinish();
michael@0 10
michael@0 11 loadWebapp("webperm.webapp", undefined, function onLoad() {
michael@0 12 let app = WebappRT.config.app;
michael@0 13
michael@0 14 // Check that the app is non privileged.
michael@0 15 is(AppsUtils.getAppManifestStatus(app.manifest), Ci.nsIPrincipal.APP_STATUS_INSTALLED, "The app is not privileged");
michael@0 16
michael@0 17 // Check that the app principal has the correct appId.
michael@0 18 let principal = document.getElementById("content").contentDocument.defaultView.document.nodePrincipal;
michael@0 19 is(DOMApplicationRegistry.getAppLocalIdByManifestURL(app.manifestURL), principal.appId, "Principal app ID correct");
michael@0 20
michael@0 21 let perms = [ "indexedDB-unlimited", "geolocation",
michael@0 22 "camera", "alarms", "tcp-socket", "network-events",
michael@0 23 "webapps-manage", "desktop-notification" ];
michael@0 24
michael@0 25 for (let permName of perms) {
michael@0 26 // Get the values for all the permission.
michael@0 27 let permValue = Services.perms.testExactPermissionFromPrincipal(principal, permName);
michael@0 28
michael@0 29 // Check if the app has the permission as specified in the PermissionsTable.jsm file.
michael@0 30 let realPerm = PermissionsReverseTable[permName];
michael@0 31 is(permValue, PermissionsTable[realPerm]["app"], "Permission " + permName + " correctly set.");
michael@0 32 }
michael@0 33
michael@0 34 finish();
michael@0 35 });
michael@0 36 }

mercurial