Bug 980354 - 1/2: add mmdb_head.js and run mmdb test cases in chrome context. r=hsinyi
authorVicamo Yang <vyang@mozilla.com>
Thu, 13 Mar 2014 13:44:49 +0900
changeset 191577 3103bfd98c391f6efbc275f6dbcb0fd9caf78c36
parent 191576 c778c2a3fc0202050033c856c72b6b9cd89846a6
child 191578 93c1de5151273362b55af4de26175d3abb1290f4
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs980354
milestone30.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 980354 - 1/2: add mmdb_head.js and run mmdb test cases in chrome context. r=hsinyi
dom/mobilemessage/tests/marionette/head.js
dom/mobilemessage/tests/marionette/mmdb_head.js
dom/mobilemessage/tests/marionette/test_mmdb_foreachmatchedmmsdeliveryinfo.js
dom/mobilemessage/tests/marionette/test_mmdb_full_storage.js
dom/mobilemessage/tests/marionette/test_mmdb_new.js
--- a/dom/mobilemessage/tests/marionette/head.js
+++ b/dom/mobilemessage/tests/marionette/head.js
@@ -340,107 +340,30 @@ function sendTextSmsToEmulator(aFrom, aT
  * @return A deferred promise.
  */
 function sendRawSmsToEmulator(aPdu) {
   let command = "sms pdu " + aPdu;
   return runEmulatorCmdSafe(command);
 }
 
 /**
- * Name space for MobileMessageDB.jsm.  Only initialized after first call to
- * newMobileMessageDB.
- */
-let MMDB;
-
-// Create a new MobileMessageDB instance.
-function newMobileMessageDB() {
-  if (!MMDB) {
-    MMDB = Cu.import("resource://gre/modules/MobileMessageDB.jsm", {});
-    is(typeof MMDB.MobileMessageDB, "function", "MMDB.MobileMessageDB");
-  }
-
-  let mmdb = new MMDB.MobileMessageDB();
-  ok(mmdb, "MobileMessageDB instance");
-  return mmdb;
-}
-
-/**
- * Initialize a MobileMessageDB.  Resolve if initialized with success, reject
- * otherwise.
- *
- * Fulfill params: a MobileMessageDB instance.
- * Reject params: a MobileMessageDB instance.
- *
- * @param aMmdb
- *        A MobileMessageDB instance.
- * @param aDbName
- *        A string name for that database.
- * @param aDbVersion
- *        The version that MobileMessageDB should upgrade to. 0 for the lastest
- *        version.
- *
- * @return A deferred promise.
- */
-function initMobileMessageDB(aMmdb, aDbName, aDbVersion) {
-  let deferred = Promise.defer();
-
-  aMmdb.init(aDbName, aDbVersion, function(aError) {
-    if (aError) {
-      deferred.reject(aMmdb);
-    } else {
-      deferred.resolve(aMmdb);
-    }
-  });
-
-  return deferred.promise;
-}
-
-/**
- * Close a MobileMessageDB.
- *
- * @return The passed MobileMessageDB instance.
- */
-function closeMobileMessageDB(aMmdb) {
-  aMmdb.close();
-  return aMmdb;
-}
-
-/**
  * Create a new array of id attribute of input messages.
  *
  * @param aMessages an array of {Sms,Mms}Message instances.
  *
  * @return an array of numeric values.
  */
 function messagesToIds(aMessages) {
   let ids = [];
   for (let message of aMessages) {
     ids.push(message.id);
   }
   return ids;
 }
 
-// A reference to a nsIUUIDGenerator service.
-let uuidGenerator;
-
-/**
- * Generate a new UUID.
- *
- * @return A UUID string.
- */
-function newUUID() {
-  if (!uuidGenerator) {
-    uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
-                    .getService(Ci.nsIUUIDGenerator);
-    ok(uuidGenerator, "uuidGenerator");
-  }
-
-  return uuidGenerator.generateUUID().toString();
-}
-
 /**
  * Flush permission settings and call |finish()|.
  */
 function cleanUp() {
   waitFor(function() {
     SpecialPowers.flushPermissions(function() {
       // Use ok here so that we have at least one test run.
       ok(true, "permissions flushed");
new file mode 100644
--- /dev/null
+++ b/dom/mobilemessage/tests/marionette/mmdb_head.js
@@ -0,0 +1,117 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_CONTEXT = "chrome";
+
+let Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
+
+/**
+ * Name space for MobileMessageDB.jsm.  Only initialized after first call to
+ * newMobileMessageDB.
+ */
+let MMDB;
+
+/**
+ * Create a new MobileMessageDB instance.
+ *
+ * @return A MobileMessageDB instance.
+ */
+function newMobileMessageDB() {
+  if (!MMDB) {
+    MMDB = Cu.import("resource://gre/modules/MobileMessageDB.jsm", {});
+    is(typeof MMDB.MobileMessageDB, "function", "MMDB.MobileMessageDB");
+  }
+
+  let mmdb = new MMDB.MobileMessageDB();
+  ok(mmdb, "MobileMessageDB instance");
+  return mmdb;
+}
+
+/**
+ * Initialize a MobileMessageDB.  Resolve if initialized with success, reject
+ * otherwise.
+ *
+ * Fulfill params: a MobileMessageDB instance.
+ * Reject params: a MobileMessageDB instance.
+ *
+ * @param aMmdb
+ *        A MobileMessageDB instance.
+ * @param aDbName
+ *        A string name for that database.
+ * @param aDbVersion
+ *        The version that MobileMessageDB should upgrade to. 0 for the lastest
+ *        version.
+ *
+ * @return A deferred promise.
+ */
+function initMobileMessageDB(aMmdb, aDbName, aDbVersion) {
+  let deferred = Promise.defer();
+
+  aMmdb.init(aDbName, aDbVersion, function(aError) {
+    if (aError) {
+      deferred.reject(aMmdb);
+    } else {
+      deferred.resolve(aMmdb);
+    }
+  });
+
+  return deferred.promise;
+}
+
+/**
+ * Close a MobileMessageDB.
+ *
+ * @param aMmdb
+ *        A MobileMessageDB instance.
+ *
+ * @return The passed MobileMessageDB instance.
+ */
+function closeMobileMessageDB(aMmdb) {
+  aMmdb.close();
+  return aMmdb;
+}
+
+// A reference to a nsIUUIDGenerator service.
+let _uuidGenerator;
+
+/**
+ * Generate a new UUID.
+ *
+ * @return A UUID string.
+ */
+function newUUID() {
+  if (!_uuidGenerator) {
+    _uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
+                     .getService(Ci.nsIUUIDGenerator);
+    ok(_uuidGenerator, "uuidGenerator");
+  }
+
+  return _uuidGenerator.generateUUID().toString();
+}
+
+/**
+ * Flush permission settings and call |finish()|.
+ */
+function cleanUp() {
+  // Use ok here so that we have at least one test run.
+  ok(true, "permissions flushed");
+
+  finish();
+}
+
+/**
+ * Basic test routine helper for mobile message tests.
+ *
+ * This helper does nothing but clean-ups.
+ *
+ * @param aTestCaseMain
+ *        A function that takes no parameter.
+ */
+function startTestBase(aTestCaseMain) {
+  Promise.resolve()
+    .then(aTestCaseMain)
+    .then(null, function() {
+      ok(false, 'promise rejects during test.');
+    })
+    .then(cleanUp);
+}
--- a/dom/mobilemessage/tests/marionette/test_mmdb_foreachmatchedmmsdeliveryinfo.js
+++ b/dom/mobilemessage/tests/marionette/test_mmdb_foreachmatchedmmsdeliveryinfo.js
@@ -1,17 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
+MARIONETTE_HEAD_JS = 'mmdb_head.js';
 
-// TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
-// empty object in return.
-let mmdb;
+const DBNAME = "test_mmdb_foreachmatchedmmsdeliveryinfo:" + newUUID();
 
 const PHONE_0 = "+15555215500";
 const PHONE_1 = "+15555215501";
 const PHONE_2 = "+15555215502";
 const PHONE_2_NET = "5555215502";
 const PHONE_3 = "+15555215503";
 const PHONE_3_NET = "5555215503";
 const EMAIL_1 = "foo@bar.com";
@@ -46,34 +44,26 @@ function doTest(aMmdb, aNeedle, aVerifyF
     ++count;
   });
   is(count, aCount, "matched count");
 }
 
 function testNotFound(aMmdb) {
   log("Testing unavailable");
 
-  // TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
-  // empty object in return.
-  aMmdb = mmdb;
-
   doTest(aMmdb, PHONE_0, function(aElement) {
     ok(false, "Should never have a match");
   }, 0);
 
   return aMmdb;
 }
 
 function testDirectMatch(aMmdb) {
   log("Testing direct matching");
 
-  // TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
-  // empty object in return.
-  aMmdb = mmdb;
-
   for (let needle of [PHONE_1, EMAIL_1]) {
     let count = deliveryInfo.reduce(function(aCount, aElement) {
       return aElement.receiver == needle ? aCount + 1 : aCount;
     }, 0);
     doTest(aMmdb, needle, function(aElement) {
       is(aElement.receiver, needle, "element.receiver");
     }, count);
   }
@@ -82,33 +72,30 @@ function testDirectMatch(aMmdb) {
 }
 
 function testPhoneMatch(aMmdb) {
   log("Testing phone matching");
 
   let verifyFunc = function(aValid, aElement) {
     ok(aValid.indexOf(aElement.receiver) >= 0, "element.receiver");
   };
-  // TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
-  // empty object in return.
-  aMmdb = mmdb;
 
   let matchingGroups = [
     [PHONE_2, PHONE_2_NET],
     [PHONE_3, PHONE_3_NET],
   ];
   for (let group of matchingGroups) {
     for (let item of group) {
       doTest(aMmdb, item, verifyFunc.bind(null, group), group.length);
     }
   }
 
   return aMmdb;
 }
 
 startTestBase(function testCaseMain() {
-  mmdb = newMobileMessageDB();
-  return initMobileMessageDB(mmdb, "test_mmdb_foreachmatchedmmsdeliveryinfo", 0)
+  let mmdb = newMobileMessageDB();
+  return initMobileMessageDB(mmdb, DBNAME, 0)
     .then(testNotFound)
     .then(testDirectMatch)
     .then(testPhoneMatch)
-    .then(closeMobileMessageDB.bind(null, mmdb));
+    .then(closeMobileMessageDB);
 });
--- a/dom/mobilemessage/tests/marionette/test_mmdb_full_storage.js
+++ b/dom/mobilemessage/tests/marionette/test_mmdb_full_storage.js
@@ -1,89 +1,89 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
+MARIONETTE_HEAD_JS = 'mmdb_head.js';
 
-let gMmdb;
+const DBNAME = "test_mmdb_full_storage:" + newUUID();
 
 let gIsDiskFull = true;
 
 let gMessageToSave = {
   type: "sms",
   sender: "+0987654321",
   receiver: "+1234567890",
   body: "quick fox jump over the lazy dog",
   deliveryStatusRequested: false,
   timestamp: Date.now(),
   iccId: "1029384756"
 };
 
-function testSaveSendingMessage() {
+function testSaveSendingMessage(aMmdb) {
   log("testSaveSendingMessage()");
 
   let deferred = Promise.defer();
 
-  gMmdb.saveSendingMessage(gMessageToSave,
+  aMmdb.saveSendingMessage(gMessageToSave,
                           { notify : function(aRv, aDomMessage) {
     if (aRv === Cr.NS_ERROR_FILE_NO_DEVICE_SPACE) {
       ok(true, "Forbidden due to storage full.");
-      deferred.resolve(Promise.resolve());
+      deferred.resolve(aMmdb);
     } else {
       ok(false, "Unexpected result: " + aRv);
       deferred.reject(aRv);
     }
   }});
 
   return deferred.promise;
 }
 
-function testSaveReceivingMessage() {
+function testSaveReceivingMessage(aMmdb) {
   log("testSaveReceivingMessage()");
 
   let deferred = Promise.defer();
 
-  gMmdb.saveReceivedMessage(gMessageToSave,
+  aMmdb.saveReceivedMessage(gMessageToSave,
                             { notify : function(aRv, aDomMessage) {
     if (aRv === Cr.NS_ERROR_FILE_NO_DEVICE_SPACE) {
       ok(true, "Forbidden due to storage full.");
-      deferred.resolve(Promise.resolve());
+      deferred.resolve(aMmdb);
     } else {
       ok(false, "Unexpected result: " + aRv);
       deferred.reject(aRv);
     }
   }});
 
   return deferred.promise;
 }
 
-function testGetMessage() {
+function testGetMessage(aMmdb) {
   log("testGetMessage()");
 
   let deferred = Promise.defer();
 
-  gMmdb.getMessage(1,
+  aMmdb.getMessage(1,
                    { notifyGetMessageFailed : function(aRv) {
     if (aRv === Ci.nsIMobileMessageCallback.NOT_FOUND_ERROR) {
       ok(true, "Getting message successfully!");
-      deferred.resolve(Promise.resolve());
+      deferred.resolve(aMmdb);
     } else {
       ok(false, "Unexpected result: " + aRv);
       deferred.reject(aRv);
     }
   }});
 
   return deferred.promise;
 }
 
 startTestBase(function testCaseMain() {
 
-  gMmdb = newMobileMessageDB();
-  gMmdb.isDiskFull = function() {
+  let mmdb = newMobileMessageDB();
+  mmdb.isDiskFull = function() {
     return gIsDiskFull;
   };
-  return initMobileMessageDB(gMmdb, "test_gMmdb_full_storage", 0)
+  return initMobileMessageDB(mmdb, DBNAME, 0)
          .then(testSaveSendingMessage)
          .then(testSaveReceivingMessage)
          .then(testGetMessage)
-         .then(closeMobileMessageDB.bind(null, gMmdb));
+         .then(closeMobileMessageDB);
 });
--- a/dom/mobilemessage/tests/marionette/test_mmdb_new.js
+++ b/dom/mobilemessage/tests/marionette/test_mmdb_new.js
@@ -1,36 +1,37 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 60000;
-MARIONETTE_HEAD_JS = 'head.js';
+MARIONETTE_HEAD_JS = 'mmdb_head.js';
+
+const DBNAME = "test_mmdb_new:" + newUUID();
+let dbVersion = 0;
+
+function check(aMmdb) {
+  is(aMmdb.dbName, DBNAME, "dbName");
+  if (!dbVersion) {
+    ok(aMmdb.dbVersion, "dbVersion");
+    dbVersion = aMmdb.dbVersion;
+  } else {
+    is(aMmdb.dbVersion, dbVersion, "dbVersion");
+  }
+
+  return aMmdb;
+}
 
 startTestBase(function testCaseMain() {
   log("Test init MobileMessageDB");
 
-  // TODO: bug 943233 - passing jsm exported objects to |Promise.resolve| gets
-  // empty object in return.
   let mmdb = newMobileMessageDB();
-  let dbName = "test_mmdb_new";
-  let dbVersion = 0;
-  let check = function() {
-    is(mmdb.dbName, dbName, "dbName");
-    if (!dbVersion) {
-      ok(mmdb.dbVersion, "dbVersion");
-      dbVersion = mmdb.dbVersion;
-    } else {
-      is(mmdb.dbVersion, dbVersion, "dbVersion");
-    }
-  };
-
-  return initMobileMessageDB(mmdb, dbName, dbVersion)
+  return initMobileMessageDB(mmdb, DBNAME, dbVersion)
+    .then(check)
+    .then(closeMobileMessageDB)
     .then(check)
-    .then(closeMobileMessageDB.bind(null, mmdb))
-    .then(check)
-    .then(function() {
+    .then(function(aMmdb) {
       log("Test re-init and close.");
-      return initMobileMessageDB(mmdb, dbName, dbVersion);
+      return initMobileMessageDB(aMmdb, DBNAME, dbVersion);
     })
     .then(check)
-    .then(closeMobileMessageDB.bind(null, mmdb))
+    .then(closeMobileMessageDB)
     .then(check);
 });