Bug 792495 - Develop tests for delete sms, update manifest; r=jgriffin, DONTBUILD(NPOTB), a=approval-mozilla-aurora+
authorRob Wood <rwood@mozilla.com>
Thu, 04 Oct 2012 11:15:10 -0400
changeset 113290 3d56940e185992d29472b1a6915ef493c1a217f2
parent 113289 153f9364f85ba855ab0127c867dcd86cda2f0c84
child 113291 cf470cfd18ca86aeffa8f577110e7d9741cffe57
push id2261
push userjgriffin@mozilla.com
push dateWed, 10 Oct 2012 22:04:34 +0000
treeherdermozilla-aurora@3d56940e1859 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin, DONTBUILD, approval-mozilla-aurora
bugs792495
milestone18.0a2
Bug 792495 - Develop tests for delete sms, update manifest; r=jgriffin, DONTBUILD(NPOTB), a=approval-mozilla-aurora+
dom/sms/tests/marionette/manifest.ini
dom/sms/tests/marionette/test_incoming_delete.js
dom/sms/tests/marionette/test_outgoing_delete.js
--- a/dom/sms/tests/marionette/manifest.ini
+++ b/dom/sms/tests/marionette/manifest.ini
@@ -2,8 +2,10 @@
 b2g = true
 browser = false
 qemu = true
 
 [test_between_emulators.py]
 [test_incoming.js]
 [test_outgoing.js]
 [test_message_classes.js]
+[test_incoming_delete.js]
+[test_outgoing_delete.js]
new file mode 100644
--- /dev/null
+++ b/dom/sms/tests/marionette/test_incoming_delete.js
@@ -0,0 +1,125 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+SpecialPowers.setBoolPref("dom.sms.enabled", true);
+SpecialPowers.addPermission("sms", true, document);
+
+let sms = window.navigator.mozSms;
+let fromNumber = "5551234567";
+let msgText = "Mozilla Firefox OS!";
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(sms, "mozSms");
+  simulateIncomingSms();  
+}
+
+function simulateIncomingSms() {
+  log("Simulating incoming SMS.");
+
+  sms.onreceived = function onreceived(event) {
+    log("Received 'onreceived' smsmanager event.");
+    let incomingSms = event.message;
+    ok(incomingSms, "incoming sms");
+    ok(incomingSms.id, "sms id");
+    log("Received SMS (id: " + incomingSms.id + ").");
+    is(incomingSms.body, msgText, "msg body");
+    is(incomingSms.delivery, "received", "delivery");
+    is(incomingSms.read, false, "read");
+    is(incomingSms.receiver, null, "receiver");
+    is(incomingSms.sender, fromNumber, "sender");
+    ok(incomingSms.timestamp instanceof Date, "timestamp is istanceof date");
+
+    verifySmsExists(incomingSms);
+  };
+  runEmulatorCmd("sms send " + fromNumber + " " + msgText, function(result) {
+    is(result[0], "OK", "emulator output");
+  });
+}
+
+function verifySmsExists(incomingSms) {
+  log("Getting SMS (id: " + incomingSms.id + ").");
+  let requestRet = sms.getMessage(incomingSms.id);
+  ok(requestRet, "smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    ok(event.target.result, "smsrequest event.target.result");
+    let foundSms = event.target.result;
+    is(foundSms.id, incomingSms.id, "found SMS id matches");
+    is(foundSms.body, msgText, "found SMS msg text matches");
+    log("Got SMS (id: " + foundSms.id + ") as expected.");
+    deleteSms(incomingSms);
+  };
+
+  requestRet.onerror = function(event) {
+    log("Received 'onerror' smsrequest event.");
+    ok(event.target.error, "domerror obj");
+    is(event.target.error.name, "NotFoundError", "error returned");
+    log("Could not get SMS (id: " + incomingSms.id + ") but should have.");
+    ok(false,"SMS was not found");
+    cleanUp();
+  };
+}
+
+function deleteSms(smsMsgObj){
+  log("Deleting SMS (id: " + smsMsgObj.id + ") using smsmsg obj parameter.");
+  let requestRet = sms.delete(smsMsgObj);
+  ok(requestRet,"smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    if(event.target.result){
+      verifySmsDeleted(smsMsgObj.id);
+    } else {
+      log("smsrequest returned false for sms.delete");
+      ok(false,"SMS delete failed");
+      cleanUp();
+    }
+  };
+
+  requestRet.onerror = function(event) {
+    log("Received 'onerror' smsrequest event.");
+    ok(event.target.error, "domerror obj");
+    ok(false, "sms.delete request returned unexpected error: "
+        + event.target.error.name );
+    cleanUp();
+  };
+}
+
+function verifySmsDeleted(smsId) {
+  log("Getting SMS (id: " + smsId + ").");
+  let requestRet = sms.getMessage(smsId);
+  ok(requestRet, "smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    ok(event.target.result, "smsrequest event.target.result");
+    let foundSms = event.target.result;
+    is(foundSms.id, smsId, "found SMS id matches");
+    is(foundSms.body, msgText, "found SMS msg text matches");
+    log("Got SMS (id: " + foundSms.id + ") but should not have.");
+    ok(false, "SMS was not deleted");
+    cleanUp();
+  };
+
+  requestRet.onerror = function(event) {
+    log("Received 'onerror' smsrequest event.");
+    ok(event.target.error, "domerror obj");
+    is(event.target.error.name, "NotFoundError", "error returned");
+    log("Could not get SMS (id: " + smsId + ") as expected.");
+    cleanUp();
+  };
+}
+
+function cleanUp() {
+  sms.onreceived = null;
+  SpecialPowers.removePermission("sms", document);
+  SpecialPowers.setBoolPref("dom.sms.enabled", false);
+  finish();
+}
+
+// Start the test
+verifyInitialState();
new file mode 100644
--- /dev/null
+++ b/dom/sms/tests/marionette/test_outgoing_delete.js
@@ -0,0 +1,150 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+SpecialPowers.setBoolPref("dom.sms.enabled", true);
+SpecialPowers.addPermission("sms", true, document);
+
+let sms = window.navigator.mozSms;
+let destNumber = "5551117777";
+let msgText = "Mozilla Firefox OS!";
+let gotSmsOnsent = false;
+let gotReqOnsuccess = false;
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(sms, "mozSms");
+  sendSms();
+}
+
+function sendSms() {
+  let smsId = 0;
+
+  log("Sending an SMS.");
+  sms.onsent = function(event) {
+    log("Received 'onsent' smsmanager event.");
+    gotSmsOnsent = true;
+    let sentSms = event.message;
+    ok(sentSms, "outgoing sms");
+    ok(sentSms.id, "sms id");
+    smsId = sentSms.id;
+    log("Sent SMS (id: " + smsId + ").");
+    is(sentSms.body, msgText, "msg body");
+    is(sentSms.delivery, "sent", "delivery");
+    is(sentSms.read, true, "read");
+    is(sentSms.receiver, destNumber, "receiver");
+    is(sentSms.sender, null, "sender");
+    ok(sentSms.timestamp instanceof Date, "timestamp is istanceof date");
+
+    if (gotSmsOnsent && gotReqOnsuccess) { verifySmsExists(smsId); }
+  };
+
+  let requestRet = sms.send(destNumber, msgText);
+  ok(requestRet, "smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    gotReqOnsuccess = true;
+    if(event.target.result){
+      if (gotSmsOnsent && gotReqOnsuccess) { verifySmsExists(smsId); }
+    } else {
+      log("smsrequest returned false for sms.send");
+      ok(false,"SMS send failed");
+      cleanUp();
+    }
+  };
+
+  requestRet.onerror = function(event) {
+    log("Received 'onerror' smsrequest event.");
+    ok(event.target.error, "domerror obj");
+    ok(false, "sms.send request returned unexpected error: "
+        + event.target.error.name );
+    cleanUp();
+  };
+}
+
+function verifySmsExists(smsId) {
+  log("Getting SMS (id: " + smsId + ").");
+  let requestRet = sms.getMessage(smsId);
+  ok(requestRet, "smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    ok(event.target.result, "smsrequest event.target.result");
+    let foundSms = event.target.result;
+    is(foundSms.id, smsId, "found SMS id matches");
+    is(foundSms.body, msgText, "found SMS msg text matches");
+    log("Got SMS (id: " + foundSms.id + ") as expected.");
+    deleteSms(smsId);
+  };
+
+  requestRet.onerror = function(event) {
+    log("Received 'onerror' smsrequest event.");
+    ok(event.target.error, "domerror obj");
+    is(event.target.error.name, "NotFoundError", "error returned");
+    log("Could not get SMS (id: " + smsId + ") but should have.");
+    ok(false,"SMS was not found");
+    cleanUp();
+  };
+}
+
+function deleteSms(smsId){
+  log("Deleting SMS (id: " + smsId + ") using sms id parameter.");
+  let requestRet = sms.delete(smsId);
+  ok(requestRet,"smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    if(event.target.result){
+      verifySmsDeleted(smsId);
+    } else {
+      log("smsrequest returned false for sms.delete");
+      ok(false,"SMS delete failed");
+      cleanUp();
+    }
+  };
+
+  requestRet.onerror = function(event) {
+    log("Received 'onerror' smsrequest event.");
+    ok(event.target.error, "domerror obj");
+    ok(false, "sms.delete request returned unexpected error: "
+        + event.target.error.name );
+    cleanUp();
+  };
+}
+
+function verifySmsDeleted(smsId) {
+  log("Getting SMS (id: " + smsId + ").");
+  let requestRet = sms.getMessage(smsId);
+  ok(requestRet, "smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    ok(event.target.result, "smsrequest event.target.result");
+    let foundSms = event.target.result;
+    is(foundSms.id, smsId, "found SMS id matches");
+    is(foundSms.body, msgText, "found SMS msg text matches");
+    log("Got SMS (id: " + foundSms.id + ") but should not have.");
+    ok(false, "SMS was not deleted");
+    cleanUp();
+  };
+
+  requestRet.onerror = function(event) {
+    log("Received 'onerror' smsrequest event.");
+    ok(event.target.error, "domerror obj");
+    is(event.target.error.name, "NotFoundError", "error returned");
+    log("Could not get SMS (id: " + smsId + ") as expected.");
+    cleanUp();
+  };
+}
+
+function cleanUp() {
+  sms.onsent = null;
+  SpecialPowers.removePermission("sms", document);
+  SpecialPowers.setBoolPref("dom.sms.enabled", false);
+  finish();
+}
+
+// Start the test
+verifyInitialState();