Bug 1043250 - Part 5: Update marionette test cases. r=btseng

test_set_smsc_address / test_smsc_address:
- Update the test cases to reflect the interface change.
This commit is contained in:
Samael Wang 2015-07-14 14:57:57 +08:00
parent c4b27691b2
commit 027e6133a6
2 changed files with 55 additions and 117 deletions

View File

@ -14,59 +14,53 @@ const SMSC_DEF_TEXT = '"+123456789",145';
const SMSC_TON_UNKNOWN = '0407485455'
const SMSC_TON_UNKNOWN_TEXT = '"0407485455",129';
function getSmscAddress() {
return new Promise((resolve, reject) => {
let req = manager.getSmscAddress();
if (!req) {
reject("manager.getSmscAddress() returns null.");
}
function verifySmscAddress(smsc, expectedAddr, expectedTon, expectedNpi) {
is(smsc.address, expectedAddr);
is(smsc.typeOfAddress.typeOfNumber, expectedTon);
is(smsc.typeOfAddress.numberPlanIdentification, expectedNpi);
}
req.onsuccess = function() {
resolve(this.result);
};
startTestCommon(function testCaseMain() {
return Promise.resolve()
req.onerror = function() {
reject(this.error);
};
});
};
// Verify setting AT&T SMSC address.
.then(() => manager.setSmscAddress({ address:SMSC_ATT }))
.then(() => manager.getSmscAddress())
.then((result) =>
verifySmscAddress(result, SMSC_ATT, "international", "isdn"))
startTestBase(function testCaseMain() {
return ensureMobileMessage()
// Verify setting O2 SMSC address.
.then(() => manager.setSmscAddress({ address:SMSC_O2 }))
.then(() => manager.getSmscAddress())
.then((result) =>
verifySmscAddress(result, SMSC_O2, "international", "isdn"))
// Verify setting AT&T SMSC address.
.then(() => manager.setSmscAddress({ address:SMSC_ATT }))
.then(() => getSmscAddress())
.then((result) => is(result, SMSC_ATT_TEXT))
// Verify setting AT&T SMSC address with extra illegal characters.
.then(() => manager.setSmscAddress({ address:SMSC_ATT_TYPO }))
.then(() => manager.getSmscAddress())
.then((result) =>
verifySmscAddress(result, SMSC_ATT, "international", "isdn"))
// Verify setting O2 SMSC address.
.then(() => manager.setSmscAddress({ address:SMSC_O2 }))
.then(() => getSmscAddress())
.then((result) => is(result, SMSC_O2_TEXT))
// Verify setting a SMSC address with TON=unknown.
.then(() => manager.setSmscAddress({ address:SMSC_TON_UNKNOWN }))
.then(() => manager.getSmscAddress())
.then((result) =>
verifySmscAddress(result, SMSC_TON_UNKNOWN, "unknown", "isdn"))
// Verify setting AT&T SMSC address with extra illegal characters.
.then(() => manager.setSmscAddress({ address:SMSC_ATT_TYPO }))
.then(() => getSmscAddress())
.then((result) => is(result, SMSC_ATT_TEXT))
// Verify setting invalid SMSC address.
.then(() => manager.setSmscAddress({}))
.then(() => Promise.reject("Expect for an error."),
(err) => log("Got expected error: " + err))
.then(() => manager.setSmscAddress({ address:"" }))
.then(() => Promise.reject("Expect for an error."),
(err) => log("Got expected error: " + err))
.then(() => manager.setSmscAddress({ address:"???" }))
.then(() => Promise.reject("Expect for an error."),
(err) => log("Got expected error: " + err))
// Verify setting a SMSC address with TON=unknown.
.then(() => manager.setSmscAddress({ address:SMSC_TON_UNKNOWN }))
.then(() => getSmscAddress())
.then((result) => is(result, SMSC_TON_UNKNOWN_TEXT))
// Verify setting invalid SMSC address.
.then(() => manager.setSmscAddress({}))
.then(() => Promise.reject("Expect for an error."),
(err) => log("Got expected error: " + err))
.then(() => manager.setSmscAddress({ address:"" }))
.then(() => Promise.reject("Expect for an error."),
(err) => log("Got expected error: " + err))
.then(() => manager.setSmscAddress({ address:"???" }))
.then(() => Promise.reject("Expect for an error."),
(err) => log("Got expected error: " + err))
// Restore to default emulator SMSC address.
.then(() => manager.setSmscAddress({ address:SMSC_DEF }))
.then(() => getSmscAddress())
.then((result) => is(result, SMSC_DEF_TEXT));
// Restore to default emulator SMSC address.
.then(() => manager.setSmscAddress({ address:SMSC_DEF }))
.then(() => manager.getSmscAddress())
.then((result) =>
verifySmscAddress(result, SMSC_DEF, "international", "isdn"));
});

View File

@ -2,77 +2,21 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
SpecialPowers.addPermission("sms", true, document);
MARIONETTE_HEAD_JS = 'head.js';
// Expected SMSC addresses of emulator
const SMSC = "\"+123456789\",145";
const SMSC = "+123456789";
const TON = "international";
const NPI = "isdn";
let manager = window.navigator.mozMobileMessage;
function verifySmscAddress(smsc, expectedAddr, expectedTon, expectedNpi) {
is(smsc.address, expectedAddr);
is(smsc.typeOfAddress.typeOfNumber, expectedTon);
is(smsc.typeOfAddress.numberPlanIdentification, expectedNpi);
}
let tasks = {
// List of test fuctions. Each of them should call |tasks.next()| when
// completed or |tasks.finish()| to jump to the last one.
_tasks: [],
_nextTaskIndex: 0,
push: function(func) {
this._tasks.push(func);
},
next: function() {
let index = this._nextTaskIndex++;
let task = this._tasks[index];
try {
task();
} catch (ex) {
ok(false, "test task[" + index + "] throws: " + ex);
// Run last task as clean up if possible.
if (index != this._tasks.length - 1) {
this.finish();
}
}
},
finish: function() {
this._tasks[this._tasks.length - 1]();
},
run: function() {
this.next();
}
};
tasks.push(function init() {
log("Initialize test object.");
ok(manager instanceof MozMobileMessageManager,
"manager is instance of " + manager.constructor);
tasks.next();
startTestCommon(function testCaseMain() {
return Promise.resolve()
.then(() => manager.getSmscAddress())
.then((result) => verifySmscAddress(result, SMSC, TON, NPI));
});
tasks.push(function readSmscAddress() {
log("read SMSC address");
let req = manager.getSmscAddress();
ok(req, "DOMRequest object for getting smsc address");
req.onsuccess = function(e) {
is(e.target.result, SMSC, "SMSC address");
tasks.next();
};
req.onerror = function(error) {
ok(false, "readSmscAddress(): Received 'onerror'");
tasks.finish();
};
});
// WARNING: All tasks should be pushed before this!!!
tasks.push(function cleanUp() {
manager.onreceived = null;
SpecialPowers.removePermission("sms", document);
finish();
});
// Start the test
tasks.run();