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 = 20000; michael@0: michael@0: SpecialPowers.addPermission("mobileconnection", true, document); michael@0: michael@0: // Permission changes can't change existing Navigator.prototype michael@0: // objects, so grab our objects from a new Navigator michael@0: let ifr = document.createElement("iframe"); michael@0: let mobileConnection; michael@0: ifr.onload = function() { michael@0: mobileConnection = ifr.contentWindow.navigator.mozMobileConnections[0]; michael@0: michael@0: tasks.run(); michael@0: }; michael@0: document.body.appendChild(ifr); michael@0: michael@0: let tasks = { michael@0: // List of test functions. Each of them should call |tasks.next()| when michael@0: // completed or |tasks.abort()| 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.abort(); michael@0: } michael@0: } michael@0: }, michael@0: michael@0: abort: 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 verifyInitialState() { michael@0: log("Verifying initial state."); michael@0: michael@0: ok(mobileConnection instanceof ifr.contentWindow.MozMobileConnection, michael@0: "mobileConnection is instanceof " + mobileConnection.constructor); michael@0: michael@0: tasks.next(); michael@0: }); michael@0: michael@0: tasks.push(function testGettingIMEI() { michael@0: log("Test *#06# ..."); michael@0: michael@0: let request = mobileConnection.sendMMI("*#06#"); michael@0: ok(request instanceof DOMRequest, michael@0: "request is instanceof " + request.constructor); michael@0: michael@0: request.onsuccess = function onsuccess(event) { michael@0: ok(true, "request success"); michael@0: is(typeof event.target.result, "object", "typeof result object"); michael@0: ok(event.target.result instanceof Object, "result instanceof Object"); michael@0: is(event.target.result.statusMessage, "000000000000000", "Emulator IMEI"); michael@0: is(event.target.result.serviceCode, "scImei", "Service code IMEI"); michael@0: is(event.target.result.additionalInformation, undefined, michael@0: "No additional information"); michael@0: tasks.next(); michael@0: } michael@0: request.onerror = function onerror() { michael@0: ok(false, "request should not error"); michael@0: tasks.abort(); michael@0: }; michael@0: }); michael@0: michael@0: tasks.push(function testInvalidMMICode(){ michael@0: log("Test invalid MMI code ..."); michael@0: michael@0: let request = mobileConnection.sendMMI("InvalidMMICode"); michael@0: ok(request instanceof DOMRequest, michael@0: "request is instanceof " + request.constructor); michael@0: michael@0: request.onsuccess = function onsuccess(event) { michael@0: ok(false, "request should not success"); michael@0: tasks.abort(); michael@0: }; michael@0: michael@0: request.onerror = function onerror() { michael@0: ok(true, "request error"); michael@0: is(request.error.name, "emMmiError", "MMI error name"); michael@0: tasks.next(); michael@0: }; michael@0: }); michael@0: michael@0: // WARNING: All tasks should be pushed before this!!! michael@0: tasks.push(function cleanUp() { michael@0: SpecialPowers.removePermission("mobileconnection", document); michael@0: finish(); michael@0: });