Backed out changeset eae783e43ea1 (bug 920551)
authorEd Morley <emorley@mozilla.com>
Fri, 25 Oct 2013 10:52:42 +0100
changeset 166007 79f0cc89614adc026d08d7ce8596366c087a3384
parent 166006 cff07079b35f00bf22b3d6f43559fea47002b5a7
child 166008 4601293b94c9c2086aaba96458a9a62b1ec81f6d
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs920551
milestone27.0a1
backs outeae783e43ea1730602208b2e4ee5c6e729150409
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
Backed out changeset eae783e43ea1 (bug 920551)
b2g/installer/package-manifest.in
dom/mobilemessage/interfaces/moz.build
dom/mobilemessage/src/SmsServicesFactory.cpp
dom/mobilemessage/src/moz.build
dom/mobilemessage/tests/Makefile.in
dom/mobilemessage/tests/test_smsdatabaseservice.xul
dom/mobilemessage/tests/xpcshell.ini
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -394,24 +394,16 @@
 @BINPATH@/components/jsconsole-clhandler.manifest
 @BINPATH@/components/jsconsole-clhandler.js
 @BINPATH@/components/nsHelperAppDlg.manifest
 @BINPATH@/components/nsHelperAppDlg.js
 @BINPATH@/components/nsDownloadManagerUI.manifest
 @BINPATH@/components/nsDownloadManagerUI.js
 @BINPATH@/components/nsSidebar.manifest
 @BINPATH@/components/nsSidebar.js
-
-#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
-@BINPATH@/components/MmsService.js
-@BINPATH@/components/MmsService.manifest
-@BINPATH@/components/MobileMessageDatabaseService.js
-@BINPATH@/components/MobileMessageDatabaseService.manifest
-#endif // MOZ_WIDGET_GONK && MOZ_B2G_RIL
-
 #ifndef MOZ_WIDGET_GONK
 @BINPATH@/components/extensions.manifest
 @BINPATH@/components/addonManager.js
 @BINPATH@/components/amContentHandler.js
 @BINPATH@/components/amWebInstallListener.js
 @BINPATH@/components/nsBlocklistService.js
 #endif
 
@@ -472,17 +464,21 @@
 @BINPATH@/components/webvtt.xpt
 @BINPATH@/components/WebVTT.manifest
 @BINPATH@/components/WebVTTParserWrapper.js
 #ifdef MOZ_B2G_RIL
 @BINPATH@/components/NetworkManager.manifest
 @BINPATH@/components/NetworkManager.js
 @BINPATH@/components/RadioInterfaceLayer.manifest
 @BINPATH@/components/RadioInterfaceLayer.js
+@BINPATH@/components/MmsService.manifest
+@BINPATH@/components/MmsService.js
 @BINPATH@/components/RILContentHelper.js
+@BINPATH@/components/MobileMessageDatabaseService.manifest
+@BINPATH@/components/MobileMessageDatabaseService.js
 @BINPATH@/components/WifiWorker.js
 @BINPATH@/components/WifiWorker.manifest
 @BINPATH@/components/DOMWifiManager.js
 @BINPATH@/components/DOMWifiManager.manifest
 @BINPATH@/components/NetworkStatsManager.js
 @BINPATH@/components/NetworkStatsManager.manifest
 @BINPATH@/components/NetworkInterfaceListService.manifest
 @BINPATH@/components/NetworkInterfaceListService.js
--- a/dom/mobilemessage/interfaces/moz.build
+++ b/dom/mobilemessage/interfaces/moz.build
@@ -17,15 +17,15 @@ XPIDL_SOURCES += [
     'nsIMobileMessageCallback.idl',
     'nsIMobileMessageCursorCallback.idl',
     'nsIMobileMessageDatabaseService.idl',
     'nsIMobileMessageService.idl',
     'nsISmsService.idl',
     'nsIWapPushApplication.idl',
 ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']:
+if CONFIG['MOZ_B2G_RIL']:
     XPIDL_SOURCES += [
         'nsIRilMobileMessageDatabaseService.idl',
     ]
 
 XPIDL_MODULE = 'dom_mobilemessage'
 
--- a/dom/mobilemessage/src/SmsServicesFactory.cpp
+++ b/dom/mobilemessage/src/SmsServicesFactory.cpp
@@ -5,17 +5,17 @@
 
 #include "SmsServicesFactory.h"
 #include "nsXULAppAPI.h"
 #include "ipc/SmsIPCService.h"
 #ifdef MOZ_WIDGET_ANDROID
 #include "android/MobileMessageDatabaseService.h"
 #include "android/SmsService.h"
 #include "android/MmsService.h"
-#elif defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
+#elif defined(MOZ_B2G_RIL)
 #include "gonk/SmsService.h"
 #else
 #include "fallback/MmsService.h"
 #include "fallback/MobileMessageDatabaseService.h"
 #include "fallback/SmsService.h"
 #endif
 #include "nsServiceManagerUtils.h"
 
@@ -42,17 +42,17 @@ SmsServicesFactory::CreateSmsService()
 
 /* static */ already_AddRefed<nsIMobileMessageDatabaseService>
 SmsServicesFactory::CreateMobileMessageDatabaseService()
 {
   nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService;
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     mobileMessageDBService = new SmsIPCService();
   } else {
-#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
+#ifdef MOZ_B2G_RIL
     mobileMessageDBService = do_GetService(RIL_MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
 #else
     mobileMessageDBService = new MobileMessageDatabaseService();
 #endif
   }
 
   return mobileMessageDBService.forget();
 }
@@ -60,17 +60,17 @@ SmsServicesFactory::CreateMobileMessageD
 /* static */ already_AddRefed<nsIMmsService>
 SmsServicesFactory::CreateMmsService()
 {
   nsCOMPtr<nsIMmsService> mmsService;
 
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     mmsService = new SmsIPCService();
   } else {
-#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
+#ifdef MOZ_B2G_RIL
     mmsService = do_CreateInstance(RIL_MMSSERVICE_CONTRACTID);
 #else
     mmsService = new MmsService();
 #endif
   }
 
   return mmsService.forget();
 }
--- a/dom/mobilemessage/src/moz.build
+++ b/dom/mobilemessage/src/moz.build
@@ -14,17 +14,17 @@ EXPORTS.mozilla.dom.mobilemessage += [
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     CPP_SOURCES += [
         'android/MmsService.cpp',
         'android/MobileMessageDatabaseService.cpp',
         'android/SmsService.cpp',
     ]
-elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']:
+elif CONFIG['MOZ_B2G_RIL']:
     EXTRA_JS_MODULES = [
         'gonk/mms_consts.js',
         'gonk/MmsPduHelper.jsm',
         'gonk/wap_consts.js',
         'gonk/WspPduHelper.jsm',
     ]
     EXTRA_COMPONENTS += [
         'gonk/MmsService.js',
--- a/dom/mobilemessage/tests/Makefile.in
+++ b/dom/mobilemessage/tests/Makefile.in
@@ -1,3 +1,9 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+ifdef MOZ_B2G_RIL
+MOCHITEST_CHROME_FILES = \
+  test_smsdatabaseservice.xul \
+  $(NULL)
+endif
new file mode 100644
--- /dev/null
+++ b/dom/mobilemessage/tests/test_smsdatabaseservice.xul
@@ -0,0 +1,876 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="Test MobileMessageDatabaseService by SMS"
+        onload="run_test();">
+  <title>Test MobileMessageDatabaseService by SMS</title>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript"><![CDATA[
+
+function run_test() {
+  SimpleTest.waitForExplicitFinish();
+  run_next_test();
+}
+
+let gTests = [];
+
+function add_test(func) {
+  gTests.push(func);
+}
+
+function run_next_test() {
+  let func = gTests.shift();
+  if (!func) {
+    SimpleTest.finish();
+    return;
+  }
+  SimpleTest.executeSoon(func);
+}
+
+
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+let gMobileMessageDatabaseService = Cc["@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1"]
+                                      .getService(Ci.nsIMobileMessageDatabaseService);
+
+let gRegistrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+
+
+let SmsRequestManagerImpl = {
+  notifySmsSent: function notifySmsSent(requestId, message) {
+    ok(false, "Unexpected notifySmsSent.");
+  },
+  notifySmsSendFailed: function notifySmsSendFailed(requestId, error) {
+    ok(false, "Unexpected notifySmsSendFailed.");
+  },
+  notifyGotSms: function notifyGotSms(requestId, message) {
+    ok(false, "Unexpected notifyGotSms.");
+  },
+  notifyGetSmsFailed: function notifyGetSmsFailed(requestId, error) {
+    ok(false, "Unexpected notifyGetSmsFailed." + k);
+  },
+  notifySmsDeleted: function notifySmsDeleted(requestId, message) {
+    ok(false, "Unexpected notifySmsSent.");
+  },
+  notifySmsDeleteFailed: function notifySmsDeleteFailed(requestId, error) {
+    ok(false, "Unexpected notifySmsDeleteFailed.");
+  },
+  notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+    ok(false, "Unexpected notifyNoMessageInList.");
+  },
+  noitfyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                            listId,
+                                                            message) {
+    ok(false, "Unexpected notifyCreateMessageList.");
+  },
+  notifyGotNextMessage: function notifyGotNextMessage(requestId, message) {
+    ok(false, "Unexpected notifyGotNextMessage.");
+  },
+  notifyReadMessageListFailed: function notifyReadMessageListFailed(requestId, error) {
+    ok(false, "Unexpected notifyReadMessageListFailed.");
+  }
+};
+
+let FakeSmsRequestManagerService = {
+  contractID: "@mozilla.org/sms/smsrequestmanager;1",
+  //get CID() { return gRegistrar.contractIDToCID(this.contractID); },
+  CID: Components.ID("{a97a3129-1e0b-45da-a385-cfe5b0b1c48f}"),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsISmsRequestManager,
+                                         Ci.nsIFactory]),
+  createInstance: function createInstance(outer, iid) {
+    if (outer != null) {
+      throw Cr.NS_ERROR_NO_AGGREGATION;
+    }
+    return this;
+  },
+  __proto__: SmsRequestManagerImpl
+};
+
+/**
+ * Create and register a new fake nsISmsRequestManager service.
+ *
+ * Example:
+ *
+ *   fakeSmsRequestManager({
+ *     notifySmsSent: function notifySmsSent() {
+ *       ...
+ *     }
+ *   });
+ */
+function fakeSmsRequestManager(obj) {
+  let service = FakeSmsRequestManagerService;
+
+  // Clean previous methods from the service, then copy new ones onto it.
+  for (let name in SmsRequestManagerImpl) {
+    delete service[name];
+  }
+  for (let name in obj) {
+    service[name] = obj[name];
+  }
+
+  // Register service
+  let oldFactory = Components.manager.getClassObject(Cc[service.contractID],
+                                                     Ci.nsIFactory);
+  gRegistrar.unregisterFactory(service.CID, oldFactory);
+  gRegistrar.registerFactory(service.CID,
+                             "Fake SmsRequestManager",
+                             service.contractID,
+                             service);
+}
+
+const DB_NAME = "sms";
+const DB_VERSION = 2;
+const STORE_NAME = "sms";
+const MAX_SMS = 3;
+const LONG_MAX = 2147483647;
+
+let _db;
+function ensureDB(callback) {
+  if (_db) {
+    callback(_db);
+    return;
+  }
+  let request;
+  try {
+    request = indexedDB.open(DB_NAME, DB_VERSION);
+  } catch (ex) {
+    ok(false, ex);
+  }
+  request.onsuccess = function onsuccess(event) {
+    _db = request.result;
+    callback(_db);
+  };
+  request.onerror =
+  request.onupgradeneeded =
+  request.onblocked = function onerror(event) {
+    ok(false, "Opening DB failed: " + request.errorCode);
+  };
+};
+
+function checkDB(callback) {
+  ensureDB(function (db) {
+    let txn = db.transaction([STORE_NAME], "readwrite");
+    let store = txn.objectStore(STORE_NAME);
+    txn.oncomplete = run_next_test;
+    txn.onerror = function onerror(event) {
+      ok(false, "Transaction failed: " + event.target.errorCode);
+    };
+    callback(store);
+  });
+}
+
+function newRandomId() {
+  return Math.floor(Math.random() * LONG_MAX);
+};
+
+let sms = [
+  {
+    type: "sms",
+    sender: "+34666000000",
+    receiver: "+34666111000",
+    body: "message 0",
+    messageClass: "normal",
+    timestamp: 1329999861762
+  },
+  {
+    type: "sms",
+    sender: "+34666000111",
+    receiver: "+34666111111",
+    body: "message 1",
+    messageClass: "normal",
+    timestamp: 1329999861763
+  },
+  {
+    type: "sms",
+    sender: "+34666000222",
+    receiver: "+34666111222",
+    body: "message 2",
+    messageClass: "normal",
+    timestamp: 1329999861764
+  },
+];
+
+/**
+ * nsIMobileMessageDatabaseService.saveReceivedMessage
+ */
+add_test(function test_saveReceivedMessage() {
+  info("test_saveReceivedMessage");
+  let messageId = gMobileMessageDatabaseService.saveReceivedMessage(sms[0]);
+  checkDB(function (store) {
+    let request = store.get(messageId);
+    request.onsuccess = function onsuccess() {
+      let data = request.result;
+      isnot(data, null);
+      is(data.id,        messageId);
+      is(data.sender,    sms[0].sender);
+      is(data.receiver,  null);
+      is(data.body,      sms[0].body);
+      is(data.timestamp, sms[0].timestamp);
+      is(data.read,      false);
+    };
+  });
+});
+
+/**
+ * nsIMobileMessageDatabaseService.saveSentMessage
+ */
+add_test(function test_saveSentMessage() {
+  info("test_saveSentMessage");
+  let messageId = gMobileMessageDatabaseService.saveSentMessage(sms[1].receiver,
+                                                                sms[1].body,
+                                                                sms[1].timestamp);
+
+  checkDB(function (store) {
+    let request = store.get(messageId);
+    request.onsuccess = function onsuccess() {
+      let data = request.result;
+      isnot(data, null);
+      is(data.id,        messageId);
+      is(data.sender,    null);
+      is(data.receiver,  sms[1].receiver);
+      is(data.body,      sms[1].body);
+      is(data.timestamp, sms[1].timestamp);
+      is(data.read,      true);
+    };
+  });
+});
+
+/**
+ * nsIMobileMessageDatabaseService.getMessage
+ */
+add_test(function test_getMessage_success() {
+  info("test_getMessage_success");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyGotSms: function notifyGotSms(requestId, message) {
+      is(requestId, fakeRequestId);
+      ok(message instanceof Ci.nsIDOMMozSmsMessage);
+      is(message.id,       messageId);
+      is(message.delivery, "received");
+      is(message.sender,   sms[2].sender);
+      is(message.receiver, null);
+      is(message.body,     sms[2].body);
+      is(message.read,     false);
+      run_next_test();
+    }
+  });
+  let messageId = gMobileMessageDatabaseService.saveReceivedMessage(sms[2]);
+  SimpleTest.executeSoon(function () {
+    gMobileMessageDatabaseService.getMessage(messageId, fakeRequestId);
+  });
+});
+
+add_test(function test_getMessage_failed() {
+  info("test_getMessage_failed");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyGetSmsFailed: function notifyGetSmsFailed(requestId, error) {
+      is(requestId, fakeRequestId);
+      is(error, Ci.nsISmsRequestManager.NOT_FOUND_ERROR);
+      run_next_test();
+    }
+  });
+  gMobileMessageDatabaseService.getMessage(-1, fakeRequestId);
+});
+
+/**
+ * nsIMobileMessageDatabaseService.createMessageList
+ */
+function checkReceivedSms(message, i) {
+  ok(message instanceof Ci.nsIDOMMozSmsMessage);
+  is(message.sender,              sms[i].sender);
+  is(message.receiver,            null);
+  is(message.body,                sms[i].body);
+  is(message.timestamp.getTime(), sms[i].timestamp);
+  is(message.read,                false);
+}
+
+function checkSentSms(message, i) {
+  ok(message instanceof Ci.nsIDOMMozSmsMessage);
+  is(message.sender,              null);
+  is(message.receiver,            sms[i].receiver);
+  is(message.body,                sms[i].body);
+  is(message.timestamp.getTime(), sms[i].timestamp);
+  is(message.read,                true);
+}
+
+add_test(function test_createMessageList_empty_filter() {
+  info("test_createMessageList_empty_filter");
+  let fakeRequestId = newRandomId();
+  let auxListId;
+  let i = 0;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, i);
+      auxListId = listId;
+      i += 1;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId,
+                                                        message) {
+      is(requestId, fakeRequestId);
+      ok(message instanceof Ci.nsIDOMMozSmsMessage);
+      i % 2 ? checkSentSms(message, i) : checkReceivedSms(message, i);
+      i += 1;
+      gMobileMessageDatabaseService.getNextMessageInList(auxListId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      is(i, MAX_SMS);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_empty_filter_reverse() {
+  info("test_createMessageList_empty_filter_reverse");
+  let fakeRequestId = newRandomId();
+  let auxListId;
+  let i = 2;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, i);
+      auxListId = listId;
+      i -= 1;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId,
+                                                        message) {
+      is(requestId, fakeRequestId);
+      ok(message instanceof Ci.nsIDOMMozSmsMessage);
+      i % 2 ? checkSentSms(message, i) : checkReceivedSms(message, i);
+      i -= 1;
+      gMobileMessageDatabaseService.getNextMessageInList(auxListId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      is(i, -1);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  gMobileMessageDatabaseService.createMessageList(filter, true, fakeRequestId);
+});
+
+add_test(function test_createMessageList_complete_filter_one_result() {
+  info("test_createMessageList_complete_filter_one_result");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 0);
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId,
+                                                        message) {
+      is(requestId, fakeRequestId);
+      ok(false, "No more messages expected");
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.startDate = new Date(sms[0].timestamp);
+  filter.endDate = new Date(sms[0].timestamp);
+  filter.numbers = [sms[0].sender];
+  filter.delivery = "received";
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_complete_filter_multi_result() {
+  info("test_createMessageList_complete_filter_multi_result");
+  let fakeRequestId = newRandomId();
+  let auxListId;
+  let secondMessage = false;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 0);
+      auxListId = listId;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId, message) {
+      ok(!secondMessage);
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 2);
+      secondMessage = true;
+      gMobileMessageDatabaseService.getNextMessageInList(auxListId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      ok(secondMessage);
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.startDate = new Date(sms[0].timestamp);
+  filter.endDate = new Date(sms[2].timestamp);
+  filter.numbers = [sms[0].sender, sms[2].sender];
+  filter.delivery = "received";
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_complete_filter_no_result() {
+  info("test_createMessageList_complete_filter_no_result");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    },
+  });
+  let filter = new MozSmsFilter();
+  filter.startDate = new Date(sms[0].timestamp);
+  filter.endDate = new Date(sms[0].timestamp);
+  filter.numbers = [sms[0].sender];
+  filter.delivery = "sent";
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_delivery_sent_filter_success() {
+  info("test_createMessageList_delivery_sent_filter_success");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkSentSms(message, 1);
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.delivery = "sent";
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_delivery_received_filter_success() {
+  info("test_createMessageList_delivery_received_filter_success");
+  let fakeRequestId = newRandomId();
+  let auxListId;
+  let secondMessage = false;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 0);
+      auxListId = listId;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId, message) {
+      ok(!secondMessage);
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 2);
+      secondMessage = true;
+      gMobileMessageDatabaseService.getNextMessageInList(auxListId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      ok(secondMessage);
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.delivery = "received";
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_startDate_filter_success() {
+  info("test_createMessageList_startDate_filter_success");
+  let fakeRequestId = newRandomId();
+  let auxListId;
+  let i = 0;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, i);
+      auxListId = listId;
+      i += 1;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId,
+                                                        message) {
+      is(requestId, fakeRequestId);
+      i % 2 ? checkSentSms(message, i) : checkReceivedSms(message, i);
+      i += 1;
+      gMobileMessageDatabaseService.getNextMessageInList(auxListId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      is(i, MAX_SMS);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.startDate = new Date(sms[0].timestamp);
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_startDate_filter_failed() {
+  info("test_createMessageList_startDate_filter_failed");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    },
+  });
+  let filter = new MozSmsFilter();
+  filter.startDate = new Date(sms[2].timestamp + 1);
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_endDate_filter_success() {
+  info("test_createMessageList_endDate_filter_success");
+  let fakeRequestId = newRandomId();
+  let auxListId;
+  let i = 0;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, i);
+      auxListId = listId;
+      i += 1;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId,
+                                                        message) {
+      is(requestId, fakeRequestId);
+      i % 2 ? checkSentSms(message, i) : checkReceivedSms(message, i);
+      i += 1;
+      gMobileMessageDatabaseService.getNextMessageInList(auxListId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      is(i, MAX_SMS);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.endDate = new Date(sms[2].timestamp);
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_endDate_filter_failed() {
+  info("test_createMessageList_endDate_filter_failed");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+     notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.endDate = new Date(sms[0].timestamp - 1);
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_fullDate_filter_success() {
+  info("test_createMessageList_fullDate_filter_success");
+  let fakeRequestId = newRandomId();
+  let auxListId;
+  let i = 0;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, i);
+      auxListId = listId;
+      i += 1;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId,
+                                                        message) {
+      is(requestId, fakeRequestId);
+      i % 2 ? checkSentSms(message, i) : checkReceivedSms(message, i);
+      i += 1;
+      gMobileMessageDatabaseService.getNextMessageInList(auxListId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      is(i, MAX_SMS);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.startDate = new Date(sms[0].timestamp);
+  filter.endDate = new Date(sms[MAX_SMS - 1].timestamp);
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_fullDate_filter_failed() {
+  info("test_createMessageList_fullDate_filter_failed");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+     notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.startDate = new Date(sms[MAX_SMS - 1] + 1);
+  filter.endDate = new Date(sms[MAX_SMS - 1] + 1);
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_single_number_success() {
+  info("test_createMessageList_single_number_success");
+  let fakeRequestId = newRandomId();
+  let firstMessage = false;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(firstMessage, false);
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 0);
+      firstMessage = true;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      ok(firstMessage);
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.numbers = [sms[0].sender];
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_single_number_failed() {
+  info("test_createMessageList_single_number_failed");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+     notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.numbers = ["00000000000"];
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_multi_number_success() {
+  info("test_createMessageList_multi_number_success");
+  let fakeRequestId = newRandomId();
+  let auxListId;
+  let secondMessage = false;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 0);
+      auxListId = listId;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId, message) {
+      ok(!secondMessage);
+      is(requestId, fakeRequestId);
+      checkSentSms(message, 1);
+      secondMessage = true;
+      gMobileMessageDatabaseService.getNextMessageInList(auxListId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      ok(secondMessage);
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.numbers = [sms[0].sender, sms[1].receiver];
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_multi_number_wrong_number_success() {
+  info("test_createMessageList_multi_number_wrong_number_success");
+  let fakeRequestId = newRandomId();
+  let firstMessage = false;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(firstMessage, false);
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 0);
+      firstMessage = true;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      ok(firstMessage);
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.numbers = ["00000000000", sms[0].sender];
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+add_test(function test_createMessageList_multi_number_failed() {
+  info("test_createMessageList_multi_number_failed");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+     notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  let filter = new MozSmsFilter();
+  filter.numbers = ["00000000000", "11111111111"];
+  gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+});
+
+
+add_test(function test_createMessageList_read_filter_success() {
+  info("test_createMessageList_read_filter_success");
+  let fakeRequestId = newRandomId();
+  let lId;
+  let secondMessage = false;
+  fakeSmsRequestManager({
+    notifyCreateMessageList: function notifyCreateMessageList(requestId,
+                                                              listId,
+                                                              message) {
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 0);
+      lId = listId;
+      gMobileMessageDatabaseService.getNextMessageInList(listId, requestId);
+    },
+    notifyGotNextMessage: function notifyGotNextMessage(requestId, message) {
+      ok(!secondMessage);
+      is(requestId, fakeRequestId);
+      checkReceivedSms(message, 2);
+      secondMessage = true;
+      gMobileMessageDatabaseService.getNextMessageInList(lId, requestId);
+    },
+    notifyNoMessageInList: function notifyNoMessageInList(requestId) {
+      ok(secondMessage);
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  SimpleTest.executeSoon(function () {
+    let filter = new MozSmsFilter();
+    filter.read = false;
+    gMobileMessageDatabaseService.createMessageList(filter, false, fakeRequestId);
+  });
+});
+
+/**
+ * nsIMobileMessageDatabaseService.getNextMessageInList
+ */
+add_test(function test_getNextMessageInList_unknown_list() {
+  info("test_getNextMessageInList_unknown_list");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyReadMessageListFailed:
+      function notifyReadMessageListFailed(requestId) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  gMobileMessageDatabaseService.getNextMessageInList(-1, fakeRequestId);
+});
+
+/**
+ * nsIMobileMessageDatabaseService.deleteMessage
+ */
+add_test(function test_deleteMessage_success() {
+  info("test_deleteMessage_success");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifySmsDeleted: function notifySmsDeleted(requestId, deleted) {
+      is(requestId, fakeRequestId);
+      ok(deleted);
+      run_next_test();
+    }
+  });
+  let messageId = gMobileMessageDatabaseService.saveReceivedMessage(sms[0]);
+  SimpleTest.executeSoon(function () {
+    gMobileMessageDatabaseService.deleteMessage(messageId, fakeRequestId);
+  });
+});
+
+add_test(function test_deleteMessage_failed() {
+  info("test_deleteMessage_failed");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifySmsDeleted: function notifySmsDeleted(requestId, deleted) {
+      is(requestId, fakeRequestId);
+      is(deleted, false);
+      run_next_test();
+    }
+  });
+  gMobileMessageDatabaseService.deleteMessage(-1, fakeRequestId);
+});
+
+add_test(function test_markMessageRead_success() {
+  info("test_markMessageRead_success");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyMarkedMessageRead: function notifyMarkedMessageRead(requestId, read) {
+      is(requestId, fakeRequestId);
+      is(read, true);
+      run_next_test();
+    }
+  });
+  let messageId = gMobileMessageDatabaseService.saveReceivedMessage(sms[2]); 
+  SimpleTest.executeSoon(function () {
+    gMobileMessageDatabaseService.markMessageRead(messageId, true, fakeRequestId);
+  });
+});
+
+add_test(function test_markMessageRead_failed() {
+  info("test_markMessageRead_failed");
+  let fakeRequestId = newRandomId();
+  fakeSmsRequestManager({
+    notifyMarkMessageReadFailed: function notifyMarkMessageReadFailed(requestId, error) {
+      is(requestId, fakeRequestId);
+      run_next_test();
+    }
+  });
+  SimpleTest.executeSoon(function () {
+    gMobileMessageDatabaseService.markMessageRead(-1, true, fakeRequestId);
+  });
+});
+
+]]></script>
+  <body xmlns="http://www.w3.org/1999/xhtml">
+    <p id="display"></p>
+    <div id="content" style="display: none"></div>
+    <pre id="test"></pre>
+  </body>
+</window>
--- a/dom/mobilemessage/tests/xpcshell.ini
+++ b/dom/mobilemessage/tests/xpcshell.ini
@@ -1,13 +1,14 @@
 [DEFAULT]
 head = header_helpers.js
 tail =
 support-files =
   test_sms_basics.html
+  test_smsdatabaseservice.xul
   test_smsfilter.html
 
 [test_smsservice_createsmsmessage.js]
 [test_wsp_pdu_helper.js]
 run-if = toolkit == "gonk"
 [test_mms_pdu_helper.js]
 run-if = toolkit == "gonk"
 [test_mms_service.js]