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