Skip to content

Commit

Permalink
Bug 823010 - Fix test cases. r=jgriffin
Browse files Browse the repository at this point in the history
  • Loading branch information
philikon committed Jan 23, 2013
1 parent 81c429f commit 7d3ceaa
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 43 deletions.
36 changes: 16 additions & 20 deletions dom/sms/tests/marionette/test_getmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ MARIONETTE_TIMEOUT = 10000;
SpecialPowers.setBoolPref("dom.sms.enabled", true);
SpecialPowers.addPermission("sms", true, document);

const REMOTE = "5559997777";
const REMOTE_FMT = "+15559997777"; // the normalized remote number
const EMU_FMT = "+15555215554"; // the emulator's number

let sms = window.navigator.mozSms;
let myNumber = "15555215554";
let myNumberFormats = ["15555215554", "+15555215554"];
let inText = "Incoming SMS message. Mozilla Firefox OS!";
let remoteNumber = "5559997777";
let remoteNumberFormats = ["5559997777", "+15559997777"];
let outText = "Outgoing SMS message. Mozilla Firefox OS!";
let gotSmsOnsent = false;
let gotReqOnsuccess = false;
let inSmsid = 0;
let outSmsid = 0;
let inSmsId = 0;
let outSmsId = 0;
let inSmsTimeStamp;
let outSmsTimeStamp;

Expand All @@ -26,10 +26,6 @@ function verifyInitialState() {
simulateIncomingSms();
}

function isIn(aVal, aArray, aMsg) {
ok(aArray.indexOf(aVal) >= 0, aMsg);
}

function simulateIncomingSms() {
log("Simulating incoming SMS.");

Expand All @@ -44,15 +40,15 @@ function simulateIncomingSms() {
is(incomingSms.delivery, "received", "delivery");
is(incomingSms.deliveryStatus, "success", "deliveryStatus");
is(incomingSms.read, false, "read");
is(incomingSms.receiver, null, "receiver");
isIn(incomingSms.sender, remoteNumberFormats, "sender");
is(incomingSms.receiver, EMU_FMT, "receiver");
is(incomingSms.sender, REMOTE_FMT, "sender");
is(incomingSms.messageClass, "normal", "messageClass");
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) {
runEmulatorCmd("sms send " + REMOTE + " " + inText, function(result) {
is(result[0], "OK", "emulator output");
});
}
Expand All @@ -71,16 +67,16 @@ function sendSms() {
is(sentSms.delivery, "sent", "delivery");
is(sentSms.deliveryStatus, "pending", "deliveryStatus");
is(sentSms.read, true, "read");
isIn(sentSms.receiver, remoteNumberFormats, "receiver");
is(sentSms.sender, null, "sender");
is(sentSms.receiver, REMOTE_FMT, "receiver");
is(sentSms.sender, EMU_FMT, "sender");
is(sentSms.messageClass, "normal", "messageClass");
ok(sentSms.timestamp instanceof Date, "timestamp is instanceof date");
outSmsTimeStamp = sentSms.timestamp;

if (gotSmsOnsent && gotReqOnsuccess) { getReceivedSms(); }
};

let requestRet = sms.send(remoteNumber, outText);
let requestRet = sms.send(REMOTE, outText);
ok(requestRet, "smsrequest obj returned");

requestRet.onsuccess = function(event) {
Expand Down Expand Up @@ -120,8 +116,8 @@ function getReceivedSms() {
is(foundSms.delivery, "received", "delivery");
is(foundSms.deliveryStatus, "success", "deliveryStatus");
is(foundSms.read, false, "read");
isIn(foundSms.receiver, myNumberFormats, "receiver");
isIn(foundSms.sender, remoteNumberFormats, "sender");
is(foundSms.receiver, EMU_FMT, "receiver");
is(foundSms.sender, REMOTE_FMT, "sender");
is(foundSms.messageClass, "normal", "messageClass");
ok(foundSms.timestamp instanceof Date, "timestamp is instanceof date");
is(foundSms.timestamp.getTime(), inSmsTimeStamp.getTime(), "timestamp matches");
Expand Down Expand Up @@ -153,8 +149,8 @@ function getSentSms() {
is(foundSms.delivery, "sent", "delivery");
is(foundSms.deliveryStatus, "pending", "deliveryStatus");
is(foundSms.read, true, "read");
isIn(foundSms.receiver, remoteNumberFormats, "receiver");
isIn(foundSms.sender, myNumberFormats, "sender");
is(foundSms.receiver, REMOTE_FMT, "receiver");
is(foundSms.sender, EMU_FMT, "sender");
is(foundSms.messageClass, "normal", "messageClass");
ok(foundSms.timestamp instanceof Date, "timestamp is instanceof date");
is(foundSms.timestamp.getTime(), outSmsTimeStamp.getTime(), "timestamp matches");
Expand Down
11 changes: 7 additions & 4 deletions dom/sms/tests/marionette/test_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ MARIONETTE_TIMEOUT = 10000;
SpecialPowers.setBoolPref("dom.sms.enabled", true);
SpecialPowers.addPermission("sms", true, document);

const REMOTE = "5555552368";
const SENDER = "+15555552368"; // the normalized remote number
const RECEIVER = "+15555215554"; // the emulator's number

let sms = window.navigator.mozSms;
let sender = "5555552368";
let body = "Hello SMS world!";
let now = Date.now();

let completed = false;
runEmulatorCmd("sms send " + sender + " " + body, function(result) {
runEmulatorCmd("sms send " + REMOTE + " " + body, function(result) {
log("Sent fake SMS: " + result);
is(result[0], "OK");
completed = true;
Expand All @@ -26,8 +29,8 @@ sms.onreceived = function onreceived(event) {

is(message.delivery, "received");
is(message.deliveryStatus, "success");
is(message.sender, sender);
is(message.receiver, null);
is(message.sender, SENDER);
is(message.receiver, RECEIVER);
is(message.body, body);
is(message.messageClass, "normal");
ok(message.timestamp instanceof Date);
Expand Down
17 changes: 13 additions & 4 deletions dom/sms/tests/marionette/test_incoming_delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ MARIONETTE_TIMEOUT = 10000;
SpecialPowers.setBoolPref("dom.sms.enabled", true);
SpecialPowers.addPermission("sms", true, document);

const REMOTE = "5555552368";
const SENDER = "+15555552368"; // the normalized remote number
const RECEIVER = "+15555215554"; // the emulator's number

let sms = window.navigator.mozSms;
let fromNumber = "5551234567";
let msgText = "Mozilla Firefox OS!";

function verifyInitialState() {
Expand All @@ -29,14 +32,14 @@ function simulateIncomingSms() {
is(incomingSms.delivery, "received", "delivery");
is(incomingSms.deliveryStatus, "success", "deliveryStatus");
is(incomingSms.read, false, "read");
is(incomingSms.receiver, null, "receiver");
is(incomingSms.sender, fromNumber, "sender");
is(incomingSms.receiver, RECEIVER, "receiver");
is(incomingSms.sender, SENDER, "sender");
is(incomingSms.messageClass, "normal", "messageClass");
ok(incomingSms.timestamp instanceof Date, "timestamp is istanceof date");

verifySmsExists(incomingSms);
};
runEmulatorCmd("sms send " + fromNumber + " " + msgText, function(result) {
runEmulatorCmd("sms send " + REMOTE + " " + msgText, function(result) {
is(result[0], "OK", "emulator output");
});
}
Expand All @@ -52,6 +55,12 @@ function verifySmsExists(incomingSms) {
let foundSms = event.target.result;
is(foundSms.id, incomingSms.id, "found SMS id matches");
is(foundSms.body, msgText, "found SMS msg text matches");
is(foundSms.delivery, "received", "delivery");
is(foundSms.deliveryStatus, "success", "deliveryStatus");
is(foundSms.read, false, "read");
is(foundSms.receiver, RECEIVER, "receiver");
is(foundSms.sender, SENDER, "sender");
is(foundSms.messageClass, "normal", "messageClass");
log("Got SMS (id: " + foundSms.id + ") as expected.");
deleteSms(incomingSms);
};
Expand Down
14 changes: 9 additions & 5 deletions dom/sms/tests/marionette/test_incoming_max_segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ let sms = window.navigator.mozSms;
let maxCharsPerSms = 160;
let maxSegments = 10; // 10 message segments concatenated into 1 multipart SMS

const REMOTE = "5551234567";
const REMOTE_FMT = "+15551234567"; // the normalized remote number
const EMU_FMT = "+15555215554"; // the emulator's number

function verifyInitialState() {
log("Verifying initial state.");
ok(sms, "mozSms");
simulateIncomingSms();
}

function simulateIncomingSms() {
let fromNumber = "5551234567";
let msgText = "";

// Build the message text
Expand All @@ -27,7 +30,9 @@ function simulateIncomingSms() {
" chars total).");

sms.onreceived = function onreceived(event) {
sms.onreceived = null;
log("Received 'onreceived' smsmanager event.");

let incomingSms = event.message;
ok(incomingSms, "incoming sms");
ok(incomingSms.id, "sms id");
Expand All @@ -36,13 +41,13 @@ function simulateIncomingSms() {
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");
is(incomingSms.receiver, EMU_FMT, "receiver");
is(incomingSms.sender, REMOTE_FMT, "sender");
ok(incomingSms.timestamp instanceof Date, "timestamp is instanceof date");

verifySmsExists(incomingSms);
};
runEmulatorCmd("sms send " + fromNumber + " " + msgText, function(result) {
runEmulatorCmd("sms send " + REMOTE + " " + msgText, function(result) {
is(result[0], "OK", "emulator output");
});
}
Expand Down Expand Up @@ -99,7 +104,6 @@ function deleteSms(smsMsgObj){
}

function cleanUp() {
sms.onreceived = null;
SpecialPowers.removePermission("sms", document);
SpecialPowers.clearUserPref("dom.sms.enabled");
finish();
Expand Down
15 changes: 11 additions & 4 deletions dom/sms/tests/marionette/test_incoming_multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ MARIONETTE_TIMEOUT = 10000;
SpecialPowers.setBoolPref("dom.sms.enabled", true);
SpecialPowers.addPermission("sms", true, document);

const REMOTE = "5555552368";
const SENDER = "+15555552368"; // the normalized remote number
const RECEIVER = "+15555215554"; // the emulator's number

let sms = window.navigator.mozSms;

function verifyInitialState() {
Expand All @@ -15,7 +19,6 @@ function verifyInitialState() {
}

function simulateIncomingSms() {
let fromNumber = "5551234567";
let msgText = "";

log("Simulating incoming SMS.");
Expand All @@ -34,13 +37,13 @@ function simulateIncomingSms() {
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");
is(incomingSms.receiver, RECEIVER, "receiver");
is(incomingSms.sender, SENDER, "sender");
ok(incomingSms.timestamp instanceof Date, "timestamp is istanceof date");

verifySmsExists(incomingSms);
};
runEmulatorCmd("sms send " + fromNumber + " " + msgText, function(result) {
runEmulatorCmd("sms send " + REMOTE + " " + msgText, function(result) {
is(result[0], "OK", "emulator output");
});
}
Expand All @@ -56,6 +59,10 @@ function verifySmsExists(incomingSms) {
let foundSms = event.target.result;
is(foundSms.id, incomingSms.id, "found SMS id matches");
is(foundSms.body, incomingSms.body, "found SMS msg text matches");
is(foundSms.delivery, "received", "delivery");
is(foundSms.read, false, "read");
is(foundSms.receiver, RECEIVER, "receiver");
is(foundSms.sender, SENDER, "sender");
log("Got SMS (id: " + foundSms.id + ") as expected.");
deleteSms(incomingSms);
};
Expand Down
4 changes: 3 additions & 1 deletion dom/sms/tests/marionette/test_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SpecialPowers.setBoolPref("dom.sms.enabled", true);
SpecialPowers.setBoolPref("dom.sms.strict7BitEncoding", false);
SpecialPowers.addPermission("sms", true, document);

const SENDER = "+15555215554"; // the emulator's number

let sms = window.navigator.mozSms;
const SHORT_BODY = "Hello SMS world!";
const LONG_BODY = "Let me not to the marriage of true minds\n"
Expand All @@ -32,7 +34,7 @@ function checkMessage(message, delivery, body) {
ok(message.id, "message.id");
is(message.delivery, delivery, "message.delivery");
is(message.deliveryStatus, "pending", "message.deliveryStatus");
is(message.sender, null, "message.sender");
is(message.sender, SENDER, "message.sender");
ok(message.receiver, "message.receiver");
is(message.body, body, "message.body");
is(message.messageClass, "normal", "message.messageClass");
Expand Down
16 changes: 12 additions & 4 deletions dom/sms/tests/marionette/test_outgoing_delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ MARIONETTE_TIMEOUT = 10000;
SpecialPowers.setBoolPref("dom.sms.enabled", true);
SpecialPowers.addPermission("sms", true, document);

const SENDER = "+15555215554"; // the emulator's number
const DEST = "5551117777";
const RECEIVER = "+15551117777"; // normalized destination number

let sms = window.navigator.mozSms;
let destNumber = "5551117777";
let msgText = "Mozilla Firefox OS!";
let gotSmsOnsent = false;
let gotReqOnsuccess = false;
Expand All @@ -34,15 +37,15 @@ function sendSms() {
is(sentSms.delivery, "sent", "delivery");
is(sentSms.deliveryStatus, "pending", "deliveryStatus");
is(sentSms.read, true, "read");
is(sentSms.receiver, destNumber, "receiver");
is(sentSms.sender, null, "sender");
is(sentSms.receiver, RECEIVER, "receiver");
is(sentSms.sender, SENDER, "sender");
is(sentSms.messageClass, "normal", "messageClass");
ok(sentSms.timestamp instanceof Date, "timestamp is istanceof date");

if (gotSmsOnsent && gotReqOnsuccess) { verifySmsExists(smsId); }
};

let requestRet = sms.send(destNumber, msgText);
let requestRet = sms.send(DEST, msgText);
ok(requestRet, "smsrequest obj returned");

requestRet.onsuccess = function(event) {
Expand Down Expand Up @@ -77,6 +80,11 @@ function verifySmsExists(smsId) {
let foundSms = event.target.result;
is(foundSms.id, smsId, "found SMS id matches");
is(foundSms.body, msgText, "found SMS msg text matches");
is(foundSms.delivery, "sent", "delivery");
is(foundSms.read, true, "read");
is(foundSms.receiver, RECEIVER, "receiver");
is(foundSms.sender, SENDER, "sender");
is(foundSms.messageClass, "normal", "messageClass");
log("Got SMS (id: " + foundSms.id + ") as expected.");
deleteSms(smsId);
};
Expand Down
3 changes: 2 additions & 1 deletion dom/sms/tests/marionette/test_outgoing_max_segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ function sendSms() {
log("Sending multipart SMS (" + msgText.length + " chars total).");

sms.onsent = function(event) {
sms.onsent = null;
log("Received 'onsent' smsmanager event.");

gotSmsOnSent = true;
sentSms = event.message;
ok(sentSms, "outgoing sms");
Expand Down Expand Up @@ -118,7 +120,6 @@ function deleteSms(smsMsgObj) {
}

function cleanUp() {
sms.onsent = null;
SpecialPowers.removePermission("sms", document);
SpecialPowers.clearUserPref("dom.sms.enabled");
finish();
Expand Down

0 comments on commit 7d3ceaa

Please sign in to comment.