Bug 1165340 - Part 3: Update xpcshell tests. r=allstars.chh
authorKrzysztof Mioduszewski <kmioduszewski@gmail.com>
Wed, 03 Jun 2015 05:06:00 -0400
changeset 248098 14105196466189474e833fc5b7e2a5b32744e3ea
parent 248097 2b8d4fb773c541bb76570cacc1a123130cf85413
child 248099 91c6f410b278e2813abe116de6ff8493fbb5fef6
push id60888
push userkwierso@gmail.com
push dateThu, 11 Jun 2015 01:38:38 +0000
treeherdermozilla-inbound@39e638ed06bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersallstars.chh
bugs1165340
milestone41.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 1165340 - Part 3: Update xpcshell tests. r=allstars.chh
dom/nfc/tests/unit/test_HCIEventTransactionSystemMessageConfigurator.js
--- a/dom/nfc/tests/unit/test_HCIEventTransactionSystemMessageConfigurator.js
+++ b/dom/nfc/tests/unit/test_HCIEventTransactionSystemMessageConfigurator.js
@@ -18,56 +18,71 @@ const MANIFEST = {
     // rule0, full AID, SIM1 Secure Element
     "SIM1/000102030405060708090A0B0C0D0E",
     // rule1, every AID from embedded Secure Element
     "eSE/*",
     // rule2, every AID which starts with 0xA0, from every Secure Element
     "*/a0*"
   ]
 };
+const APPID = 1111;
 const PAGE_URL = "app://system.gaiamobile.org/index.html";
 const TYPE = "nfc-hci-event-transaction";
 
 // dummy messages for testing with additional test property - |expectedResult|
 const TEST_MESSAGES = [
   { origin: "SIM1", expectedResult: false },
   { aid: new Uint8Array([0xA0]), expectedResult: true },
   { aid: new Uint8Array([0xDF]), origin: "eSE", expectedResult: true },
   { aid: new Uint8Array([0xA0, 0x01, 0x02, 0x03]), origin: "SIM2", expectedResult: true },
   { aid: new Uint8Array([0x02]), origin: "SIM3", expectedResult: false },
   { aid: new Uint8Array([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                          0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E]),
     origin: "SIM1", expectedResult: true }
 ];
 
 let HCIEvtTransactionConfigurator = null;
+let aceAccessAllowed = true;
 
-function setMockAppService(manifest) {
-  XPCOMUtils.defineLazyServiceGetter = (obj) => {
-    obj.appsService = {
-      getManifestFor: (manifestURL) => {
-        equal(manifestURL, MANIFEST_URL, "should pass proper manifestUrl");
-        return Promise.resolve(manifest);
-      }
-    };
+function setMockServices(manifest) {
+  XPCOMUtils.defineLazyServiceGetter = (obj, service) => {
+    if (service === "appsService") {
+      obj.appsService = {
+        getManifestFor: (manifestURL) => {
+          equal(manifestURL, MANIFEST_URL, "should pass proper manifestUrl");
+          return Promise.resolve(manifest);
+        },
+        getAppLocalIdByManifestURL: (manifestURL) => {
+          equal(manifestURL, MANIFEST_URL, "should pass proper manifestUrl");
+          return APPID;
+        },
+      };
+    }
+    else if (service === "aceService") {
+      obj.aceService = {
+        isAccessAllowed: () => {
+          return Promise.resolve(aceAccessAllowed);
+        }
+      };
+    }
   };
 }
 
 function getSystemMessageConfigurator() {
   return Cc[
     "@mozilla.org/dom/system-messages/configurator/nfc-hci-event-transaction;1"
   ].createInstance(Ci.nsISystemMessagesConfigurator);
 }
 
 function handleRejectedPromise() {
   ok(false, "Promise should not be rejected");
 }
 
 function run_test() {
-  setMockAppService(MANIFEST);
+  setMockServices(MANIFEST);
   HCIEvtTransactionConfigurator = getSystemMessageConfigurator();
 
   ok(!!HCIEvtTransactionConfigurator, "Configurator should be instantiated");
   ok((typeof HCIEvtTransactionConfigurator.shouldDispatch) === "function",
      "shouldDispatch should be a function");
 
   run_next_test();
 }
@@ -91,8 +106,26 @@ add_test(function test_shouldDispatch_ge
   Promise.all(promises).then((results) => {
     results.forEach((result, idx) => {
       ok(result === TEST_MESSAGES[idx].expectedResult, "tested message: " + JSON.stringify(TEST_MESSAGES[idx]));
     });
   })
   .catch(handleRejectedPromise)
   .then(run_next_test);
 });
+
+add_test(function test_shouldDispatch_aceIsAccessAllowed() {
+  var testAccessAllowed = () => {
+    return HCIEvtTransactionConfigurator
+    .shouldDispatch(MANIFEST_URL, PAGE_URL, TYPE, TEST_MESSAGES[1])
+    .then((result) => {
+      ok(result === aceAccessAllowed, "Should be equal to ACE access decision");
+    });
+  };
+
+  aceAccessAllowed = false;
+  testAccessAllowed().then(() => {
+    aceAccessAllowed = true;
+    return testAccessAllowed();
+  })
+  .catch(handleRejectedPromise)
+  .then(run_next_test);
+});