diff --git a/b2g/simulator/lib/main.js b/b2g/simulator/lib/main.js index f4762e6adc0..0e35c86be67 100644 --- a/b2g/simulator/lib/main.js +++ b/b2g/simulator/lib/main.js @@ -34,20 +34,22 @@ function close() { return p.kill(); } -let appinfo = {}; +let name; AddonManager.getAddonByID(require("addon").id, function (addon) { - appinfo.label = addon.name.replace(" Simulator", ""); + name = addon.name.replace(" Simulator", ""); - Simulator.register(appinfo.label, { - appinfo: appinfo, + Simulator.register(name, { + // We keep the deprecated `appinfo` object so that recent simulator addons + // remain forward-compatible with older Firefox. + appinfo: { label: name }, launch: launch, close: close }); }); exports.shutdown = function () { - Simulator.unregister(appinfo.label); + Simulator.unregister(name); close(); } diff --git a/browser/devtools/app-manager/content/connection-footer.js b/browser/devtools/app-manager/content/connection-footer.js index 52d34025a7c..c95dd46ddb9 100644 --- a/browser/devtools/app-manager/content/connection-footer.js +++ b/browser/devtools/app-manager/content/connection-footer.js @@ -137,7 +137,7 @@ let UI = { startSimulator: function(version) { this._portBeforeSimulatorStarted = this.connection.port; let port = ConnectionManager.getFreeTCPPort(); - let simulator = Simulator.getByVersion(version); + let simulator = Simulator.getByName(version); if (!simulator) { this.connection.log("Error: can't find simulator: " + version); return; diff --git a/browser/devtools/app-manager/simulators-store.js b/browser/devtools/app-manager/simulators-store.js index 6fc757330b9..86ea14aba3e 100644 --- a/browser/devtools/app-manager/simulators-store.js +++ b/browser/devtools/app-manager/simulators-store.js @@ -9,11 +9,11 @@ const {Simulator} = Cu.import("resource://gre/modules/devtools/Simulator.jsm"); let store = new ObservableObject({versions:[]}); function feedStore() { - store.object.versions = Simulator.availableVersions().map(v => { - let simulator = Simulator.getByVersion(v); + store.object.versions = Simulator.availableNames().map(name => { + let simulator = Simulator.getByName(name); return { - version: v, - label: simulator.appinfo.label + version: name, + label: simulator ? name : "Unknown" } }); } diff --git a/browser/devtools/webide/modules/addons.js b/browser/devtools/webide/modules/addons.js index 6f8f1684098..d09a370caef 100644 --- a/browser/devtools/webide/modules/addons.js +++ b/browser/devtools/webide/modules/addons.js @@ -6,8 +6,6 @@ const {Cu} = require("chrome"); const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm"); const {AddonManager} = Cu.import("resource://gre/modules/AddonManager.jsm"); const {EventEmitter} = Cu.import("resource://gre/modules/devtools/event-emitter.js"); -const {Simulator} = Cu.import("resource://gre/modules/devtools/Simulator.jsm"); -const {Devices} = Cu.import("resource://gre/modules/devtools/Devices.jsm"); const {Services} = Cu.import("resource://gre/modules/Services.jsm"); const {GetAddonsJSON} = require("devtools/webide/remote-resources"); diff --git a/browser/devtools/webide/modules/runtimes.js b/browser/devtools/webide/modules/runtimes.js index a7b107f6509..aed3ef265fe 100644 --- a/browser/devtools/webide/modules/runtimes.js +++ b/browser/devtools/webide/modules/runtimes.js @@ -205,8 +205,8 @@ let SimulatorScanner = { _updateRuntimes() { this._runtimes = []; - for (let version of Simulator.availableVersions()) { - this._runtimes.push(new SimulatorRuntime(version)); + for (let name of Simulator.availableNames()) { + this._runtimes.push(new SimulatorRuntime(name)); } this._emitUpdated(); }, @@ -463,15 +463,15 @@ WiFiRuntime.prototype = { // For testing use only exports._WiFiRuntime = WiFiRuntime; -function SimulatorRuntime(version) { - this.version = version; +function SimulatorRuntime(name) { + this.name = name; } SimulatorRuntime.prototype = { type: RuntimeTypes.SIMULATOR, connect: function(connection) { let port = ConnectionManager.getFreeTCPPort(); - let simulator = Simulator.getByVersion(this.version); + let simulator = Simulator.getByName(this.name); if (!simulator || !simulator.launch) { return promise.reject("Can't find simulator: " + this.name); } @@ -484,14 +484,7 @@ SimulatorRuntime.prototype = { }); }, get id() { - return this.version; - }, - get name() { - let simulator = Simulator.getByVersion(this.version); - if (!simulator) { - return "Unknown"; - } - return Simulator.getByVersion(this.version).appinfo.label; + return this.name; }, }; diff --git a/browser/devtools/webide/test/test_addons.html b/browser/devtools/webide/test/test_addons.html index 5af951998dd..44ae43daa98 100644 --- a/browser/devtools/webide/test/test_addons.html +++ b/browser/devtools/webide/test/test_addons.html @@ -28,10 +28,14 @@ adbAddonsInstalled.resolve(); }); - function onSimulatorInstalled(version) { + function getVersion(name) { + return name.match(/(\d+\.\d+)/)[0]; + } + + function onSimulatorInstalled(name) { let deferred = promise.defer(); Simulator.on("register", function onUpdate() { - if (Simulator.getByVersion(version)) { + if (Simulator.getByName(name)) { Simulator.off("register", onUpdate); nextTick().then(deferred.resolve); } @@ -39,17 +43,17 @@ return deferred.promise; } - function installSimulatorFromUI(doc, version) { - let li = doc.querySelector('[addon="simulator-' + version + '"]'); + function installSimulatorFromUI(doc, name) { + let li = doc.querySelector('[addon="simulator-' + getVersion(name) + '"]'); li.querySelector(".install-button").click(); - return onSimulatorInstalled(version); + return onSimulatorInstalled(name); } - function uninstallSimulatorFromUI(doc, version) { + function uninstallSimulatorFromUI(doc, name) { let deferred = promise.defer(); Simulator.on("unregister", function onUpdate() { nextTick().then(() => { - let li = doc.querySelector('[status="uninstalled"][addon="simulator-' + version + '"]'); + let li = doc.querySelector('[status="uninstalled"][addon="simulator-' + getVersion(name) + '"]'); if (li) { Simulator.off("unregister", onUpdate); deferred.resolve(); @@ -58,7 +62,7 @@ } }) }); - let li = doc.querySelector('[status="installed"][addon="simulator-' + version + '"]'); + let li = doc.querySelector('[status="installed"][addon="simulator-' + getVersion(name) + '"]'); li.querySelector(".uninstall-button").click(); return deferred.promise; } @@ -100,7 +104,7 @@ let sim10 = addons.simulators.filter(a => a.version == "1.0")[0]; sim10.install(); - yield onSimulatorInstalled("1.0"); + yield onSimulatorInstalled("Firefox OS 1.0"); win.Cmds.showAddons(); @@ -119,11 +123,11 @@ info("Uninstalling Simulator 2.0"); - yield installSimulatorFromUI(addonDoc, "2.0"); + yield installSimulatorFromUI(addonDoc, "Firefox OS 2.0"); info("Uninstalling Simulator 3.0"); - yield installSimulatorFromUI(addonDoc, "3.0"); + yield installSimulatorFromUI(addonDoc, "Firefox OS 3.0"); yield nextTick(); @@ -136,9 +140,9 @@ items = panelNode.querySelectorAll(".runtime-panel-item-simulator"); is(items.length, 3, "Found 3 simulators button"); - yield uninstallSimulatorFromUI(addonDoc, "1.0"); - yield uninstallSimulatorFromUI(addonDoc, "2.0"); - yield uninstallSimulatorFromUI(addonDoc, "3.0"); + yield uninstallSimulatorFromUI(addonDoc, "Firefox OS 1.0"); + yield uninstallSimulatorFromUI(addonDoc, "Firefox OS 2.0"); + yield uninstallSimulatorFromUI(addonDoc, "Firefox OS 3.0"); items = panelNode.querySelectorAll(".runtime-panel-item-simulator"); is(items.length, 0, "No simulator listed"); diff --git a/toolkit/devtools/apps/Simulator.jsm b/toolkit/devtools/apps/Simulator.jsm index c7f51be355a..5a9ea6459c4 100644 --- a/toolkit/devtools/apps/Simulator.jsm +++ b/toolkit/devtools/apps/Simulator.jsm @@ -8,33 +8,27 @@ Components.utils.import("resource://gre/modules/devtools/event-emitter.js"); const EXPORTED_SYMBOLS = ["Simulator"]; -function getVersionNumber(fullVersion) { - return fullVersion.match(/(\d+\.\d+)/)[0]; -} - const Simulator = { _simulators: {}, - register: function (label, simulator) { + register: function (name, simulator) { // simulators register themselves as "Firefox OS X.Y" - let versionNumber = getVersionNumber(label); - this._simulators[versionNumber] = simulator; - this.emit("register", versionNumber); + this._simulators[name] = simulator; + this.emit("register", name); }, - unregister: function (label) { - let versionNumber = getVersionNumber(label); - delete this._simulators[versionNumber]; - this.emit("unregister", versionNumber); + unregister: function (name) { + delete this._simulators[name]; + this.emit("unregister", name); }, - availableVersions: function () { + availableNames: function () { return Object.keys(this._simulators).sort(); }, - getByVersion: function (version) { - return this._simulators[version]; - } + getByName: function (name) { + return this._simulators[name]; + }, }; EventEmitter.decorate(Simulator);