Bug 810083 - Develop WebSMS test to verify receiving multipart SMS, update manifest. r=jgriffin, a=NPOTB
authorRob Wood <rwood@mozilla.com>
Fri, 09 Nov 2012 10:54:24 -0800
changeset 118486 f7d72ef613c081931878a6c9a03b41a6ae36e0bd
parent 118485 5a057c06e1724c77013b24dc2eeef481ecdfdd6f
child 118487 1fb4d36d2ca466a5b69b643c585c8cc7efcbb2d0
push id2817
push userryanvm@gmail.com
push dateFri, 30 Nov 2012 02:18:56 +0000
treeherdermozilla-aurora@f7d72ef613c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin, NPOTB
bugs810083
milestone19.0a2
Bug 810083 - Develop WebSMS test to verify receiving multipart SMS, update manifest. r=jgriffin, a=NPOTB
dom/sms/tests/marionette/manifest.ini
dom/sms/tests/marionette/test_incoming_multipart.js
--- a/dom/sms/tests/marionette/manifest.ini
+++ b/dom/sms/tests/marionette/manifest.ini
@@ -6,16 +6,17 @@ 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]
+[test_incoming_multipart.js]
 [test_getmessages.js]
 [test_filter_date.js]
 [test_filter_date_notfound.js]
 [test_filter_number_single.js]
 [test_filter_number_multiple.js]
 [test_filter_received.js]
 [test_filter_sent.js]
 [test_filter_read.js]
new file mode 100644
--- /dev/null
+++ b/dom/sms/tests/marionette/test_incoming_multipart.js
@@ -0,0 +1,106 @@
+/* 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;
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(sms, "mozSms");
+  simulateIncomingSms();  
+}
+
+function simulateIncomingSms() {
+  let fromNumber = "5551234567";
+  let msgText = "";
+
+  log("Simulating incoming SMS.");
+
+  // Have message text > max SMS size (160 char) so will be a multi-part SMS
+  for (var x = 1; x <= 24; x++) {
+    msgText += 'FirefoxOS ';
+  }
+
+  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, incomingSms.body, "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){
+      cleanUp();
+    } 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 cleanUp() {
+  sms.onreceived = null;
+  SpecialPowers.removePermission("sms", document);
+  SpecialPowers.clearUserPref("dom.sms.enabled");
+  finish();
+}
+
+// Start the test
+verifyInitialState();