Bug 808865 - Develop WebSMS test for getNumberOfMessagesForText, update manifest; r=jgriffin
authorRob Wood <rwood@mozilla.com>
Tue, 13 Nov 2012 07:47:56 -0800
changeset 113170 f6511d0a33eb55793e08ca154423c7ec7cbacd3b
parent 113169 5975bdf3a5afda6c5bb0d935642ae45abe96f715
child 113171 6e56236dfd3f200f0fb691036029e279e8d6f5a1
push id17983
push userjgriffin@mozilla.com
push dateWed, 14 Nov 2012 01:11:00 +0000
treeherdermozilla-inbound@f6511d0a33eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs808865
milestone19.0a1
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
Bug 808865 - Develop WebSMS test for getNumberOfMessagesForText, update manifest; r=jgriffin
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();