Bug 794090 - Develop WebSMS test to verify getMesage, update manifest; r=jgriffin, DONTBUILD(NPOTB)
authorRob Wood <rwood@mozilla.com>
Thu, 11 Oct 2012 12:44:33 -0400
changeset 110367 cd3270dc35cc4d623a62ba6f0d49d20964d87fa0
parent 110366 5f4a6a4744556201c38d0869381fe4ab1454fa0f
child 110511 8f145599e4bf81de2d0421c071b5863175a585dc
child 111116 3f7f13073bdede63539420244974dcca76b13d2a
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjgriffin, DONTBUILD
bugs794090
milestone19.0a1
Bug 794090 - Develop WebSMS test to verify getMesage, update manifest; r=jgriffin, DONTBUILD(NPOTB)
dom/sms/tests/marionette/manifest.ini
dom/sms/tests/marionette/test_getmessage.js
dom/sms/tests/marionette/test_getmessage_notfound.js
--- a/dom/sms/tests/marionette/manifest.ini
+++ b/dom/sms/tests/marionette/manifest.ini
@@ -4,8 +4,10 @@ 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]
+[test_getmessage.js]
+[test_getmessage_notfound.js]
new file mode 100644
--- /dev/null
+++ b/dom/sms/tests/marionette/test_getmessage.js
@@ -0,0 +1,204 @@
+/* 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 myNumber = "15555215554";
+let inText = "Incoming SMS message. Mozilla Firefox OS!";
+let remoteNumber = "5559997777";
+let outText = "Outgoing SMS message. Mozilla Firefox OS!";
+let gotSmsOnsent = false;
+let gotReqOnsuccess = false;
+let inSmsid = 0;
+let outSmsid = 0;
+let inSmsTimeStamp;
+let outSmsTimeStamp;
+
+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");
+    inSmsId = incomingSms.id;
+    log("Received SMS (id: " + inSmsId + ").");
+    is(incomingSms.body, inText, "msg body");
+    is(incomingSms.delivery, "received", "delivery");
+    is(incomingSms.read, false, "read");
+    is(incomingSms.receiver, null, "receiver");
+    is(incomingSms.sender, remoteNumber, "sender");
+    ok(incomingSms.timestamp instanceof Date, "timestamp is instanceof date");
+    inSmsTimeStamp = incomingSms.timestamp;
+    sendSms();
+  };
+  // Simulate incoming sms sent from remoteNumber to our emulator
+  runEmulatorCmd("sms send " + remoteNumber + " " + inText, function(result) {
+    is(result[0], "OK", "emulator output");
+  });
+}
+
+function sendSms() {
+  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");
+    outSmsId = sentSms.id;
+    log("Sent SMS (id: " + outSmsId + ").");
+    is(sentSms.body, outText, "msg body");
+    is(sentSms.delivery, "sent", "delivery");
+    is(sentSms.read, true, "read");
+    is(sentSms.receiver, remoteNumber, "receiver");
+    is(sentSms.sender, null, "sender");
+    ok(sentSms.timestamp instanceof Date, "timestamp is instanceof date");  
+    outSmsTimeStamp = sentSms.timestamp;
+
+    if (gotSmsOnsent && gotReqOnsuccess) { getReceivedSms(); }
+  };
+
+  let requestRet = sms.send(remoteNumber, outText);
+  ok(requestRet, "smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    gotReqOnsuccess = true;
+    if(event.target.result){
+      if (gotSmsOnsent && gotReqOnsuccess) { getReceivedSms(); }
+    } 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 getReceivedSms() {
+  log("Getting the received SMS message (id: " + inSmsId + ").");
+
+  let requestRet = sms.getMessage(inSmsId);
+  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, inSmsId, "SMS id matches");
+    log("Got SMS (id: " + foundSms.id + ").");
+    is(foundSms.body, inText, "SMS msg text matches");
+    is(foundSms.delivery, "received", "delivery");
+    is(foundSms.read, false, "read");
+    is(foundSms.receiver, myNumber, "receiver");
+    is(foundSms.sender, remoteNumber, "sender");
+    ok(foundSms.timestamp instanceof Date, "timestamp is instanceof date");
+    is(foundSms.timestamp.getTime(), inSmsTimeStamp.getTime(), "timestamp matches");
+    getSentSms();
+  };
+
+  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: " + inSmsId + ") but should have.");
+    ok(false,"Could not get received SMS");
+    cleanUp();
+  };
+}
+
+function getSentSms() {
+  log("Getting the sent SMS message (id: " + outSmsId + ").");
+  let requestRet = sms.getMessage(outSmsId);
+  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, outSmsId, "SMS id matches");
+    log("Got SMS (id: " + foundSms.id + ").");
+    is(foundSms.body, outText, "SMS msg text matches");
+    is(foundSms.delivery, "sent", "delivery");
+    is(foundSms.read, true, "read");
+    is(foundSms.receiver, remoteNumber, "receiver");
+    is(foundSms.sender, myNumber, "sender");
+    ok(foundSms.timestamp instanceof Date, "timestamp is instanceof date");
+    is(foundSms.timestamp.getTime(), outSmsTimeStamp.getTime(), "timestamp matches");
+    deleteMsgs();
+  };
+
+  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: " + outSmsId + ") but should have.");
+    ok(false,"Could not get sent SMS");
+    cleanUp();
+  };
+}
+
+function deleteMsgs() {
+  log("Deleting SMS (id: " + inSmsId + ").");
+  let requestRet = sms.delete(inSmsId);
+  ok(requestRet,"smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    if(event.target.result){
+      log("Deleting SMS (id: " + outSmsId + ").");
+      let nextReqRet = sms.delete(outSmsId);
+      ok(nextReqRet,"smsrequest obj returned");
+
+      nextReqRet.onsuccess = function(event) {
+        log("Received 'onsuccess' smsrequest event.");
+        if(event.target.result) {
+          cleanUp();
+        } else {
+          log("smsrequest returned false for sms.delete");
+          ok(false,"SMS delete failed");
+        }
+      };
+    } else {
+      log("smsrequest returned false for sms.delete");
+      ok(false,"SMS delete failed");
+    }
+  };
+
+  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 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_getmessage_notfound.js
@@ -0,0 +1,119 @@
+/* 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 myNumber = "15555215554";
+let inText = "Incoming SMS message. Mozilla Firefox OS!";
+let remoteNumber = "5559997777";
+let inSmsId = 0;
+
+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");
+    inSmsId = incomingSms.id;
+    log("Received SMS (id: " + inSmsId + ").");
+    is(incomingSms.body, inText, "msg body");
+    is(incomingSms.delivery, "received", "delivery");
+    getNonExistentMsg();
+  };
+  // Simulate incoming sms sent from remoteNumber to our emulator
+  runEmulatorCmd("sms send " + remoteNumber + " " + inText, function(result) {
+    is(result[0], "OK", "emulator output");
+  });
+}
+
+function getNonExistentMsg() {
+  let msgIdNoExist = inSmsId + 1;
+  log("Attempting to get non-existent message (id: " + msgIdNoExist + ").");
+  let requestRet = sms.getMessage(msgIdNoExist);
+  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;
+    log("Got SMS (id: " + foundSms.id + ") but should not have.");
+    ok(false, "Smsrequest successful when tried to get non-existent sms");
+    getMsgInvalidId();
+  };
+
+  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: " + msgIdNoExist + ") as expected.");
+    getMsgInvalidId();
+  };
+}  
+
+function getMsgInvalidId() {
+  invalidId = -1;
+  log("Attempting to get sms with invalid id (id: " + invalidId + ").");
+  let requestRet = sms.getMessage(invalidId);
+  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;
+    log("Got SMS (id: " + foundSms.id + ") but should not have.");
+    ok(false, "Smsrequest successful when tried to get message with " +
+    		"invalid id (id: " + invalidId + ").");
+    deleteMsg();
+  };
+
+  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: -1) as expected.");
+    deleteMsg();
+  };
+}
+
+function deleteMsg() {
+  log("Deleting SMS (id: " + inSmsId + ").");
+  let requestRet = sms.delete(inSmsId);
+  ok(requestRet,"smsrequest obj returned");
+
+  requestRet.onsuccess = function(event) {
+    log("Received 'onsuccess' smsrequest event.");
+    if(event.target.result){
+      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 cleanUp() {
+  sms.onreceived = null;
+  SpecialPowers.removePermission("sms", document);
+  SpecialPowers.setBoolPref("dom.sms.enabled", false);
+  finish();
+}
+
+// Start the test
+verifyInitialState();