Bug 892837 - Tests for desktop webrt permissions. r=myk
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Fri, 16 Aug 2013 15:17:52 -0400
changeset 143008 1cac9051df04
parent 143007 4a6b9390ff5a
child 143009 859d42fcc526
push id25119
push userphilringnalda@gmail.com
push date2013-08-19 00:45 +0000
treeherdermozilla-central@c8c9bd74cc40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmyk
bugs892837
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 892837 - Tests for desktop webrt permissions. r=myk
webapprt/test/chrome/Makefile.in
webapprt/test/chrome/browser_noperm.js
webapprt/test/chrome/browser_webperm.js
webapprt/test/chrome/noperm.html
webapprt/test/chrome/noperm.webapp
webapprt/test/chrome/noperm.webapp^headers^
webapprt/test/chrome/webperm.html
webapprt/test/chrome/webperm.webapp
webapprt/test/chrome/webperm.webapp^headers^
--- a/webapprt/test/chrome/Makefile.in
+++ b/webapprt/test/chrome/Makefile.in
@@ -15,11 +15,19 @@ MOCHITEST_WEBAPPRT_CHROME_FILES = \
   browser_sample.js \
     sample.webapp \
     sample.webapp^headers^ \
     sample.html \
   browser_window-title.js \
     window-title.webapp \
     window-title.webapp^headers^ \
     window-title.html \
+  browser_webperm.js \
+    webperm.webapp \
+    webperm.webapp^headers^ \
+    webperm.html \
+  browser_noperm.js \
+    noperm.webapp \
+    noperm.webapp^headers^ \
+    noperm.html \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/webapprt/test/chrome/browser_noperm.js
@@ -0,0 +1,31 @@
+Cu.import("resource://webapprt/modules/WebappRT.jsm");
+let { AllPossiblePermissions } =
+  Cu.import("resource://gre/modules/PermissionsInstaller.jsm", {});
+let { AppsUtils } = Cu.import("resource://gre/modules/AppsUtils.jsm", {});
+let { DOMApplicationRegistry } =
+  Cu.import("resource://gre/modules/Webapps.jsm", {});
+
+function test() {
+  waitForExplicitFinish();
+
+  loadWebapp("noperm.webapp", undefined, function onLoad() {
+    let app = WebappRT.config.app;
+
+    // Check that the app is non privileged.
+    is(AppsUtils.getAppManifestStatus(app.manifest), Ci.nsIPrincipal.APP_STATUS_INSTALLED, "The app is not privileged");
+
+    // Check that the app principal has the correct appId.
+    let principal = document.getElementById("content").contentDocument.defaultView.document.nodePrincipal;
+    is(DOMApplicationRegistry.getAppLocalIdByManifestURL(app.manifestURL), principal.appId, "Principal app ID correct");
+
+    // Check if all the permissions of the app are unknown.
+    for (let permName of AllPossiblePermissions) {
+      // Get the value for the permission.
+      let permValue = Services.perms.testExactPermissionFromPrincipal(principal, permName);
+
+      is(permValue, Ci.nsIPermissionManager.UNKNOWN_ACTION, "Permission " + permName + " unknown.");
+    }
+
+    finish();
+  });
+}
new file mode 100644
--- /dev/null
+++ b/webapprt/test/chrome/browser_webperm.js
@@ -0,0 +1,36 @@
+Cu.import("resource://webapprt/modules/WebappRT.jsm");
+let { AppsUtils } = Cu.import("resource://gre/modules/AppsUtils.jsm", {});
+let { DOMApplicationRegistry } =
+  Cu.import("resource://gre/modules/Webapps.jsm", {});
+let { PermissionsTable, PermissionsReverseTable } =
+  Cu.import("resource://gre/modules/PermissionsTable.jsm", {});
+
+function test() {
+  waitForExplicitFinish();
+
+  loadWebapp("webperm.webapp", undefined, function onLoad() {
+    let app = WebappRT.config.app;
+
+    // Check that the app is non privileged.
+    is(AppsUtils.getAppManifestStatus(app.manifest), Ci.nsIPrincipal.APP_STATUS_INSTALLED, "The app is not privileged");
+
+    // Check that the app principal has the correct appId.
+    let principal = document.getElementById("content").contentDocument.defaultView.document.nodePrincipal;
+    is(DOMApplicationRegistry.getAppLocalIdByManifestURL(app.manifestURL), principal.appId, "Principal app ID correct");
+
+    let perms = [ "indexedDB-unlimited", "offline-app", "pin-app", "geolocation",
+                  "camera", "alarms", "tcp-socket", "network-events",
+                  "webapps-manage", "desktop-notification" ];
+
+    for (let permName of perms) {
+      // Get the values for all the permission.
+      let permValue = Services.perms.testExactPermissionFromPrincipal(principal, permName);
+
+      // Check if the app has the permission as specified in the PermissionsTable.jsm file.
+      let realPerm = PermissionsReverseTable[permName];
+      is(permValue, PermissionsTable[realPerm]["app"], "Permission " + permName + " correctly set.");
+    }
+
+    finish();
+  });
+}
new file mode 100644
--- /dev/null
+++ b/webapprt/test/chrome/noperm.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <meta charset="utf-8">
+  </head>
+  <body>
+    <p>This is the test webapp.</p>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/webapprt/test/chrome/noperm.webapp
@@ -0,0 +1,5 @@
+{
+  "name": "No Permissions Test Webapp",
+  "description": "A webapp for testing permission installation.",
+  "launch_path": "/webapprtChrome/webapprt/test/chrome/noperm.html"
+}
new file mode 100644
--- /dev/null
+++ b/webapprt/test/chrome/noperm.webapp^headers^
@@ -0,0 +1,1 @@
+Content-Type: application/x-web-app-manifest+json
new file mode 100644
--- /dev/null
+++ b/webapprt/test/chrome/webperm.html
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <meta charset="utf-8">
+  </head>
+  <body>
+    <p>This is the test webapp.</p>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/webapprt/test/chrome/webperm.webapp
@@ -0,0 +1,15 @@
+{
+  "name": "Hosted Permissions Test Webapp",
+  "description": "A webapp for testing permission installation.",
+  "launch_path": "/webapprtChrome/webapprt/test/chrome/webperm.html",
+  "permissions": {
+    "storage": { "description": "I need to store 1 million dollars in your bank account" },
+    "geolocation": { "description": "Desc" },
+    "camera": { "description": "Desc" },
+    "alarms": { "description": "Desc" },
+    "tcp-socket": { "description": "Desc" },
+    "network-events": { "description": "Desc" },
+    "webapps-manage": { "description": "Desc" },
+    "desktop-notification": { "description": "Desc" }
+  }
+}
new file mode 100644
--- /dev/null
+++ b/webapprt/test/chrome/webperm.webapp^headers^
@@ -0,0 +1,1 @@
+Content-Type: application/x-web-app-manifest+json