michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: SpecialPowers.addPermission("mobileconnection", true, document); michael@0: michael@0: // In single sim scenario, there is only one mobileConnection, we can always use michael@0: // the first instance. michael@0: let mobileConnection = window.navigator.mozMobileConnections[0]; michael@0: ok(mobileConnection instanceof MozMobileConnection, michael@0: "mobileConnection is instanceof " + mobileConnection.constructor); michael@0: michael@0: let _pendingEmulatorCmdCount = 0; michael@0: michael@0: /* Remove permission and execute finish() */ michael@0: let cleanUp = function() { michael@0: waitFor(function() { michael@0: SpecialPowers.removePermission("mobileconnection", document); michael@0: finish(); michael@0: }, function() { michael@0: return _pendingEmulatorCmdCount === 0; michael@0: }); michael@0: }; michael@0: michael@0: /* Helper for tasks */ michael@0: let taskHelper = { michael@0: tasks: [], michael@0: michael@0: push: function(task) { michael@0: this.tasks.push(task); michael@0: }, michael@0: michael@0: runNext: function() { michael@0: let task = this.tasks.shift(); michael@0: if (!task) { michael@0: cleanUp(); michael@0: return; michael@0: } michael@0: michael@0: if (typeof task === "function") { michael@0: task(); michael@0: } michael@0: }, michael@0: }; michael@0: michael@0: /* Helper for emulator console command */ michael@0: let emulatorHelper = { michael@0: sendCommand: function(cmd, callback) { michael@0: _pendingEmulatorCmdCount++; michael@0: runEmulatorCmd(cmd, function(results) { michael@0: _pendingEmulatorCmdCount--; michael@0: michael@0: let result = results[results.length - 1]; michael@0: is(result, "OK", "'"+ cmd +"' returns '" + result + "'"); michael@0: michael@0: if (callback && typeof callback === "function") { michael@0: callback(results); michael@0: } michael@0: }); michael@0: }, michael@0: };