Bug 808865 - Develop WebSMS test for getNumberOfMessagesForText, update manifest. r=jgriffin, a=NPOTB
authorRob Wood <rwood@mozilla.com>
Tue, 13 Nov 2012 07:47:56 -0800
changeset 114219 9f9a19978b33922ed4b491cd93d2b15b937f1b9a
parent 114218 1f9ef298ceeb1bf14a5c23ddeea52945918cf10f
child 114220 c240e317ab41def58710d183a2fdd7e06139c6ae
push id2691
push userryanvm@gmail.com
push dateThu, 15 Nov 2012 03:10:29 +0000
treeherdermozilla-aurora@0cecfe1dde64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin, NPOTB
bugs808865
milestone18.0a2
Bug 808865 - Develop WebSMS test for getNumberOfMessagesForText, update manifest. r=jgriffin, a=NPOTB
dom/sms/tests/marionette/manifest.ini
dom/sms/tests/marionette/test_number_of_messages.js
--- a/dom/sms/tests/marionette/manifest.ini
+++ b/dom/sms/tests/marionette/manifest.ini
@@ -6,8 +6,9 @@ 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_number_of_messages.js]
new file mode 100644
--- /dev/null
+++ b/dom/sms/tests/marionette/test_number_of_messages.js
@@ -0,0 +1,76 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+SpecialPowers.addPermission("sms", true, document);
+SpecialPowers.setBoolPref("dom.sms.enabled", true);
+
+let sms = window.navigator.mozSms;
+
+// Specified here: https://developer.mozilla.org/en-US/docs/DOM/SmsManager
+let maxCharsPerSms = 160;
+
+function verifyInitialState() {
+  log("Verifying initial state.");
+  ok(sms, "mozSms");
+  // Ensure test is starting clean with no existing SMS messages
+  startTest();
+}
+
+function startTest() {
+  // Build test data strings
+  let testData = ["", "a",
+                  buildString("b", maxCharsPerSms / 2),
+                  buildString("c", maxCharsPerSms - 1),
+                  buildString("d", maxCharsPerSms),
+                  buildString("e", maxCharsPerSms + 1),
+                  buildString("f", maxCharsPerSms * 1.5),
+                  buildString("g", maxCharsPerSms * 10.5)];
+
+  // Test with each data string
+  testData.forEach(function(text){ testGetNumberOfMsgs(text); });
+
+  // We're done
+  cleanUp();
+}
+
+function buildString(char, numChars) {
+  // Build string that contains the specified character repeated x times
+  let string = new Array(numChars + 1).join(char);
+  return string;
+}
+
+function testGetNumberOfMsgs(text) {
+  // Test that getNumberOfMessagesForText returns expected value for given txt
+  log("getNumberOfMessagesForText length " + text.length + ".");
+
+  if (text.length) {
+    if (text.length > maxCharsPerSms) {
+      expNumSms = Math.ceil(text.length / maxCharsPerSms);
+    } else {
+      expNumSms = 1;
+    }
+  } else {
+    expNumSms = 0;
+  }
+
+  numMultiPartSms = sms.getNumberOfMessagesForText(text);
+
+  if (numMultiPartSms == expNumSms) {
+    log("Returned " + expNumSms + " as expected.");
+    ok(true, "getNumberOfMessagesForText returned expected value");
+  } else {
+    log("Returned " + numMultiPartSms + " but expected " + expNumSms + ".");
+    ok(false, "getNumberOfMessagesForText returned unexpected value");
+  }
+}
+
+function cleanUp() {
+  SpecialPowers.removePermission("sms", document);
+  SpecialPowers.clearUserPref("dom.sms.enabled");
+  finish();
+}
+
+// Start the test
+verifyInitialState();