summaryrefslogtreecommitdiffstats
path: root/dom/apps/tests
diff options
context:
space:
mode:
Diffstat (limited to 'dom/apps/tests')
-rwxr-xr-xdom/apps/tests/create_test_receipts.py163
-rw-r--r--dom/apps/tests/head.js118
-rw-r--r--dom/apps/tests/unit/test_manifestHelper.js23
-rw-r--r--dom/apps/tests/unit/test_manifestSanitizer.js63
-rw-r--r--dom/apps/tests/unit/test_moziapplication.js64
-rw-r--r--dom/apps/tests/unit/xpcshell.ini5
6 files changed, 436 insertions, 0 deletions
diff --git a/dom/apps/tests/create_test_receipts.py b/dom/apps/tests/create_test_receipts.py
new file mode 100755
index 000000000..e8774edec
--- /dev/null
+++ b/dom/apps/tests/create_test_receipts.py
@@ -0,0 +1,163 @@
+#!/usr/bin/env python
+
+import jwt
+
+receipt1 = {
+ "typ": "purchase-receipt",
+ "product": {
+ "url": "https://www.mozilla.org",
+ "storedata": "5169314356"
+ },
+ "user": {
+ "type": "directed-identifier",
+ "value": "4fb35151-2b9b-4ba2-8283-c49d381640bd"
+ },
+ "iss": "http://mochi.test:8888",
+ "nbf": 131360185,
+ "iat": 131360188,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+receipt2 = {
+ "typ": "purchase-receipt",
+ "product": {
+ "url": "https://www.mozilla.org",
+ "storedata": "5169314357"
+ },
+ "user": {
+ "type": "directed-identifier",
+ "value": "4fb35151-2b9b-4ba2-8283-c49d381640bd"
+ },
+ "iss": "http://mochi.test:8888",
+ "nbf": 131360185,
+ "iat": 131360188,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+receipt_without_typ = {
+ "product": {
+ "url": "https://www.mozilla.org",
+ "storedata": "5169314358"
+ },
+ "user": {
+ "type": "directed-identifier",
+ "value": "4fb35151-2b9b-4ba2-8283-c49d381640bd"
+ },
+ "iss": "http://mochi.test:8888",
+ "nbf": 131360185,
+ "iat": 131360188,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+receipt_without_product = {
+ "typ": "purchase-receipt",
+ "user": {
+ "type": "directed-identifier",
+ "value": "4fb35151-2b9b-4ba2-8283-c49d381640bd"
+ },
+ "iss": "http://mochi.test:8888",
+ "nbf": 131360185,
+ "iat": 131360188,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+receipt_without_user = {
+ "typ": "purchase-receipt",
+ "product": {
+ "url": "https://www.mozilla.org",
+ "storedata": "5169314358"
+ },
+ "iss": "http://mochi.test:8888",
+ "nbf": 131360185,
+ "iat": 131360188,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+receipt_without_iss = {
+ "typ": "purchase-receipt",
+ "product": {
+ "url": "https://www.mozilla.org",
+ "storedata": "5169314358"
+ },
+ "user": {
+ "type": "directed-identifier",
+ "value": "4fb35151-2b9b-4ba2-8283-c49d381640bd"
+ },
+ "nbf": 131360185,
+ "iat": 131360188,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+receipt_without_nbf = {
+ "typ": "purchase-receipt",
+ "product": {
+ "url": "https://www.mozilla.org",
+ "storedata": "5169314358"
+ },
+ "user": {
+ "type": "directed-identifier",
+ "value": "4fb35151-2b9b-4ba2-8283-c49d381640bd"
+ },
+ "iss": "http://mochi.test:8888",
+ "iat": 131360188,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+receipt_without_iat = {
+ "typ": "purchase-receipt",
+ "product": {
+ "url": "https://www.mozilla.org",
+ "storedata": "5169314358"
+ },
+ "user": {
+ "type": "directed-identifier",
+ "value": "4fb35151-2b9b-4ba2-8283-c49d381640bd"
+ },
+ "iss": "http://mochi.test:8888",
+ "nbf": 131360185,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+receipt_with_wrong_typ = {
+ "typ": "fake",
+ "product": {
+ "url": "https://www.mozilla.org",
+ "storedata": "5169314358"
+ },
+ "user": {
+ "type": "directed-identifier",
+ "value": "4fb35151-2b9b-4ba2-8283-c49d381640bd"
+ },
+ "iss": "http://mochi.test:8888",
+ "nbf": 131360185,
+ "iat": 131360188,
+ "detail": "http://mochi.test:8888/receipt/5169314356",
+ "verify": "http://mochi.test:8888/verify/5169314356",
+ "reissue": "http://mochi.test:8888/reissue/5169314356"
+}
+
+print("let valid_receipt1 = \"" + jwt.encode(receipt1, "") + "\";\n")
+print("let valid_receipt2 = \"" + jwt.encode(receipt2, "") + "\";\n")
+print("let receipt_without_typ = \"" + jwt.encode(receipt_without_typ, "") + "\";\n")
+print("let receipt_without_product = \"" + jwt.encode(receipt_without_product, "") + "\";\n")
+print("let receipt_without_user = \"" + jwt.encode(receipt_without_user, "") + "\";\n")
+print("let receipt_without_iss = \"" + jwt.encode(receipt_without_iss, "") + "\";\n")
+print("let receipt_without_nbf = \"" + jwt.encode(receipt_without_nbf, "") + "\";\n")
+print("let receipt_without_iat = \"" + jwt.encode(receipt_without_iat, "") + "\";\n")
+print("let receipt_with_wrong_typ = \"" + jwt.encode(receipt_with_wrong_typ, "") + "\";\n")
diff --git a/dom/apps/tests/head.js b/dom/apps/tests/head.js
new file mode 100644
index 000000000..662d119a0
--- /dev/null
+++ b/dom/apps/tests/head.js
@@ -0,0 +1,118 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+function runAll(steps) {
+ SimpleTest.waitForExplicitFinish();
+
+ // Clone the array so we don't modify the original.
+ steps = steps.concat();
+ function next() {
+ if (steps.length) {
+ steps.shift()(next);
+ }
+ else {
+ SimpleTest.finish();
+ }
+ }
+ next();
+}
+
+function confirmNextPopup() {
+ var Ci = SpecialPowers.Ci;
+
+ var popupNotifications = SpecialPowers.wrap(window).top.
+ QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIWebNavigation).
+ QueryInterface(Ci.nsIDocShell).
+ chromeEventHandler.ownerDocument.defaultView.
+ PopupNotifications;
+
+ var popupPanel = popupNotifications.panel;
+
+ function onPopupShown() {
+ popupPanel.removeEventListener("popupshown", onPopupShown, false);
+ SpecialPowers.wrap(this).childNodes[0].button.doCommand();
+ popupNotifications._dismiss();
+ }
+ popupPanel.addEventListener("popupshown", onPopupShown, false);
+}
+
+function promiseNoPopup() {
+ var Ci = SpecialPowers.Ci;
+
+ var popupNotifications = SpecialPowers.wrap(window).top.
+ QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIWebNavigation).
+ QueryInterface(Ci.nsIDocShell).
+ chromeEventHandler.ownerDocument.defaultView.
+ PopupNotifications;
+
+ return new Promise((resolve) => {
+ var tries = 0;
+ var interval = setInterval(function() {
+ if (tries >= 30) {
+ ok(true, "The webapps-install notification didn't appear");
+ moveOn();
+ }
+
+ if (popupNotifications.getNotification("webapps-install")) {
+ ok(false, "Found the webapps-install notification");
+ moveOn();
+ }
+ tries++;
+ }, 100);
+
+ var moveOn = () => {
+ clearInterval(interval);
+ resolve();
+ };
+ });
+}
+
+// We need to mock the Alerts service, otherwise the alert that is shown
+// at the end of an installation makes the test leak the app's icon.
+
+const CID = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID();
+const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
+const ALERTS_SERVICE_CID = Components.ID(Cc[ALERTS_SERVICE_CONTRACT_ID].number);
+
+var AlertsService = {
+ classID: Components.ID(CID),
+
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory,
+ Ci.nsIAlertsService]),
+
+ createInstance: function(aOuter, aIID) {
+ if (aOuter) {
+ throw Cr.NS_ERROR_NO_AGGREGATION;
+ }
+
+ return this.QueryInterface(aIID);
+ },
+
+ init: function() {
+ Components.manager.nsIComponentRegistrar.registerFactory(this.classID,
+ "", ALERTS_SERVICE_CONTRACT_ID, this);
+ },
+
+ restore: function() {
+ Components.manager.nsIComponentRegistrar.registerFactory(ALERTS_SERVICE_CID,
+ "", ALERTS_SERVICE_CONTRACT_ID, null);
+ },
+
+ showAlert: function() {
+ },
+
+ showAlertNotification: function() {
+ },
+};
+
+AlertsService.init();
+
+SimpleTest.registerCleanupFunction(() => {
+ AlertsService.restore();
+});
diff --git a/dom/apps/tests/unit/test_manifestHelper.js b/dom/apps/tests/unit/test_manifestHelper.js
new file mode 100644
index 000000000..092287a7f
--- /dev/null
+++ b/dom/apps/tests/unit/test_manifestHelper.js
@@ -0,0 +1,23 @@
+// Test that W3C start_url takes precedence over mozApps launch_path
+function run_test() {
+ Components.utils.import("resource:///modules/AppsUtils.jsm");
+
+ let manifest1 = {
+ launch_path: "other.html"
+ };
+
+ let manifest2 = {
+ start_url: "start.html",
+ launch_path: "other.html"
+ };
+
+ var helper = new ManifestHelper(manifest1, "http://foo.com",
+ "http://foo.com/manifest.json");
+ var path = helper.fullLaunchPath();
+ do_check_true(path == "http://foo.com/other.html");
+
+ helper = new ManifestHelper(manifest2, "http://foo.com",
+ "http://foo.com/manifest.json");
+ path = helper.fullLaunchPath();
+ do_check_true(path == "http://foo.com/start.html");
+}
diff --git a/dom/apps/tests/unit/test_manifestSanitizer.js b/dom/apps/tests/unit/test_manifestSanitizer.js
new file mode 100644
index 000000000..4b0c999a7
--- /dev/null
+++ b/dom/apps/tests/unit/test_manifestSanitizer.js
@@ -0,0 +1,63 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function testEntryPoint(aRoot) {
+ do_check_true(aRoot.name == "hello world");
+ do_check_true(aRoot.description == "A bold name");
+ do_check_true(aRoot.developer.name == "Blink Inc.");
+
+ let permissions = aRoot.permissions;
+ do_check_true(permissions.contacts.description == "Required for autocompletion in the share screen");
+ do_check_true(permissions.alarms.description == "Required to schedule notifications");
+}
+
+function run_test() {
+ Components.utils.import("resource:///modules/AppsUtils.jsm");
+
+ do_check_true(!!AppsUtils);
+
+ // Test manifest, with one entry point.
+ let manifest = {
+ name: "hello <b>world</b>",
+ description: "A bold name",
+ developer: {
+ name: "<blink>Blink</blink> Inc.",
+ url: "http://blink.org"
+ },
+ permissions : {
+ "contacts": {
+ "description": "Required for autocompletion in the <a href='http://shareme.com'>share</a> screen",
+ "access": "readcreate"
+ },
+ "alarms": {
+ "description": "Required to schedule notifications"
+ }
+ },
+
+ entry_points: {
+ "subapp": {
+ name: "hello <b>world</b>",
+ description: "A bold name",
+ developer: {
+ name: "<blink>Blink</blink> Inc.",
+ url: "http://blink.org"
+ },
+ permissions : {
+ "contacts": {
+ "description": "Required for autocompletion in the <a href='http://shareme.com'>share</a> screen",
+ "access": "readcreate"
+ },
+ "alarms": {
+ "description": "Required to schedule notifications"
+ }
+ }
+ }
+ }
+ }
+
+ AppsUtils.sanitizeManifest(manifest);
+
+ // Check the main section and the subapp entry point.
+ testEntryPoint(manifest);
+ testEntryPoint(manifest.entry_points.subapp);
+}
diff --git a/dom/apps/tests/unit/test_moziapplication.js b/dom/apps/tests/unit/test_moziapplication.js
new file mode 100644
index 000000000..dbcf2372a
--- /dev/null
+++ b/dom/apps/tests/unit/test_moziapplication.js
@@ -0,0 +1,64 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource:///modules/AppsUtils.jsm");
+
+add_test(() => {
+ let app = {
+ name: "TestApp",
+ csp: "aCsp",
+ installOrigin: "http://installorigin.com",
+ origin: "http://www.example.com",
+ installTime: Date.now(),
+ manifestURL: "http://www.example.com/manifest.webapp",
+ appStatus: Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED,
+ removable: false,
+ id: 123,
+ localId: 123,
+ basePath: "/",
+ progress: 1.0,
+ installState: "installed",
+ downloadAvailable: false,
+ downloading: false,
+ lastUpdateCheck: Date.now(),
+ updateTime: Date.now(),
+ etag: "aEtag",
+ packageEtag: "aPackageEtag",
+ manifestHash: "aManifestHash",
+ packageHash: "aPackageHash",
+ staged: false,
+ installerAppId: 345,
+ installerIsBrowser: false,
+ storeId: "aStoreId",
+ storeVersion: 1,
+ role: "aRole",
+ kind: "aKind",
+ enabled: true,
+ sideloaded: false
+ };
+
+ let mozapp = new mozIApplication(app);
+
+ Object.keys(app).forEach((key) => {
+ if (key == "principal") {
+ return;
+ }
+ Assert.equal(app[key], mozapp[key],
+ "app[" + key + "] should be equal to mozapp[" + key + "]");
+ });
+
+ Assert.ok(mozapp.principal, "app principal should exist");
+ let expectedPrincipalOrigin = app.origin + "^appId=" + app.localId;
+ Assert.equal(mozapp.principal.origin, expectedPrincipalOrigin,
+ "app principal origin ok");
+ Assert.equal(mozapp.principal.appId, app.localId, "app principal appId ok");
+ Assert.equal(mozapp.principal.isInIsolatedMozBrowserElement, false,
+ "app principal isInIsolatedMozBrowserElement ok");
+ run_next_test();
+});
+
+function run_test() {
+ run_next_test();
+}
diff --git a/dom/apps/tests/unit/xpcshell.ini b/dom/apps/tests/unit/xpcshell.ini
new file mode 100644
index 000000000..9745b198f
--- /dev/null
+++ b/dom/apps/tests/unit/xpcshell.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+
+[test_manifestSanitizer.js]
+[test_manifestHelper.js]
+[test_moziapplication.js]