Backed out changeset d6249744132e (bug 839862) because xpcshell bustage

This commit is contained in:
Joe Walker 2013-05-09 17:46:27 +01:00
parent 2021cdcbd7
commit 67bb224aa6
31 changed files with 1343 additions and 2727 deletions

View File

@ -9,14 +9,12 @@ const BRAND_SHORT_NAME = Cc["@mozilla.org/intl/stringbundle;1"]
.createBundle("chrome://branding/locale/brand.properties") .createBundle("chrome://branding/locale/brand.properties")
.GetStringFromName("brandShortName"); .GetStringFromName("brandShortName");
this.EXPORTED_SYMBOLS = [ "CmdAddonFlags", "CmdCommands", "DEFAULT_DEBUG_PORT", "connect" ]; this.EXPORTED_SYMBOLS = [ "CmdAddonFlags", "CmdCommands" ];
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
Cu.import("resource://gre/modules/osfile.jsm")
Cu.import("resource:///modules/devtools/gcli.jsm"); Cu.import("resource:///modules/devtools/gcli.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/osfile.jsm");
Cu.import("resource:///modules/devtools/shared/event-emitter.js"); Cu.import("resource:///modules/devtools/shared/event-emitter.js");
XPCOMUtils.defineLazyModuleGetter(this, "gDevTools", XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
@ -39,16 +37,16 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}; };
/** /**
* 'addon' command. * 'addon' command.
*/ */
gcli.addCommand({ gcli.addCommand({
name: "addon", name: "addon",
description: gcli.lookup("addonDesc") description: gcli.lookup("addonDesc")
}); });
/** /**
* 'addon list' command. * 'addon list' command.
*/ */
gcli.addCommand({ gcli.addCommand({
name: "addon list", name: "addon list",
description: gcli.lookup("addonListDesc"), description: gcli.lookup("addonListDesc"),
@ -263,11 +261,11 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
params: [nameParameter], params: [nameParameter],
exec: function(aArgs, context) { exec: function(aArgs, context) {
/** /**
* Enables the addon in the passed list which has a name that matches * Enables the addon in the passed list which has a name that matches
* according to the passed name comparer, and resolves the promise which * according to the passed name comparer, and resolves the promise which
* is the scope (this) of this function to display the result of this * is the scope (this) of this function to display the result of this
* enable attempt. * enable attempt.
*/ */
function enable(aName, addons) { function enable(aName, addons) {
// Find the add-on. // Find the add-on.
let addon = null; let addon = null;
@ -300,8 +298,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* 'addon disable' command. * 'addon disable' command.
*/ */
gcli.addCommand({ gcli.addCommand({
name: "addon disable", name: "addon disable",
description: gcli.lookup("addonDisableDesc"), description: gcli.lookup("addonDisableDesc"),
@ -412,22 +410,22 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
let debuggers = []; let debuggers = [];
/** /**
* 'calllog' command * 'calllog' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "calllog", name: "calllog",
description: gcli.lookup("calllogDesc") description: gcli.lookup("calllogDesc")
}) })
/** /**
* 'calllog start' command * 'calllog start' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "calllog start", name: "calllog start",
description: gcli.lookup("calllogStartDesc"), description: gcli.lookup("calllogStartDesc"),
exec: function(args, context) { exec: function(args, context) {
let contentWindow = context.environment.window; let contentWindow = context.environment.contentDocument.defaultView;
let dbg = new Debugger(contentWindow); let dbg = new Debugger(contentWindow);
dbg.onEnterFrame = function(frame) { dbg.onEnterFrame = function(frame) {
@ -469,8 +467,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* 'calllog stop' command * 'calllog stop' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "calllog stop", name: "calllog stop",
description: gcli.lookup("calllogStopDesc"), description: gcli.lookup("calllogStopDesc"),
@ -508,8 +506,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
let sandboxes = []; let sandboxes = [];
/** /**
* 'calllog chromestart' command * 'calllog chromestart' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "calllog chromestart", name: "calllog chromestart",
description: gcli.lookup("calllogChromeStartDesc"), description: gcli.lookup("calllogChromeStartDesc"),
@ -531,7 +529,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
], ],
exec: function(args, context) { exec: function(args, context) {
let globalObj; let globalObj;
let contentWindow = context.environment.window; let contentWindow = context.environment.contentDocument.defaultView;
if (args.sourceType == "jsm") { if (args.sourceType == "jsm") {
try { try {
@ -610,8 +608,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* 'calllog chromestop' command * 'calllog chromestop' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "calllog chromestop", name: "calllog chromestop",
description: gcli.lookup("calllogChromeStopDesc"), description: gcli.lookup("calllogChromeStopDesc"),
@ -654,22 +652,22 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
const PREF_DIR = "devtools.commands.dir"; const PREF_DIR = "devtools.commands.dir";
/** /**
* A place to store the names of the commands that we have added as a result of * A place to store the names of the commands that we have added as a result of
* calling refreshAutoCommands(). Used by refreshAutoCommands to remove the * calling refreshAutoCommands(). Used by refreshAutoCommands to remove the
* added commands. * added commands.
*/ */
let commands = []; let commands = [];
/** /**
* Exported API * Exported API
*/ */
this.CmdCommands = { this.CmdCommands = {
/** /**
* Called to look in a directory pointed at by the devtools.commands.dir pref * Called to look in a directory pointed at by the devtools.commands.dir pref
* for *.mozcmd files which are then loaded. * for *.mozcmd files which are then loaded.
* @param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which * @param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which
* we eval the script from the .mozcmd file. This should be a chrome window. * we eval the script from the .mozcmd file. This should be a chrome window.
*/ */
refreshAutoCommands: function GC_refreshAutoCommands(aSandboxPrincipal) { refreshAutoCommands: function GC_refreshAutoCommands(aSandboxPrincipal) {
// First get rid of the last set of commands // First get rid of the last set of commands
commands.forEach(function(name) { commands.forEach(function(name) {
@ -736,12 +734,12 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}; };
/** /**
* Load the commands from a single file * Load the commands from a single file
* @param OS.File.DirectoryIterator.Entry aFileEntry The DirectoryIterator * @param OS.File.DirectoryIterator.Entry aFileEntry The DirectoryIterator
* Entry of the file containing the commands that we should read * Entry of the file containing the commands that we should read
* @param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which * @param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which
* we eval the script from the .mozcmd file. This should be a chrome window. * we eval the script from the .mozcmd file. This should be a chrome window.
*/ */
function loadCommandFile(aFileEntry, aSandboxPrincipal) { function loadCommandFile(aFileEntry, aSandboxPrincipal) {
let promise = OS.File.read(aFileEntry.path); let promise = OS.File.read(aFileEntry.path);
promise = promise.then( promise = promise.then(
@ -775,8 +773,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
} }
/** /**
* 'cmd' command * 'cmd' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "cmd", name: "cmd",
get hidden() { return !prefBranch.prefHasUserValue(PREF_DIR); }, get hidden() { return !prefBranch.prefHasUserValue(PREF_DIR); },
@ -784,8 +782,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* 'cmd refresh' command * 'cmd refresh' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "cmd refresh", name: "cmd refresh",
description: gcli.lookup("cmdRefreshDesc"), description: gcli.lookup("cmdRefreshDesc"),
@ -804,8 +802,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
"resource:///modules/HUDService.jsm"); "resource:///modules/HUDService.jsm");
/** /**
* 'console' command * 'console' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "console", name: "console",
description: gcli.lookup("consoleDesc"), description: gcli.lookup("consoleDesc"),
@ -813,13 +811,14 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* 'console clear' command * 'console clear' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "console clear", name: "console clear",
description: gcli.lookup("consoleclearDesc"), description: gcli.lookup("consoleclearDesc"),
exec: function Command_consoleClear(args, context) { exec: function Command_consoleClear(args, context) {
let hud = HUDService.getHudByWindow(context.environment.window); let window = context.environment.contentDocument.defaultView;
let hud = HUDService.getHudByWindow(window);
// hud will be null if the web console has not been opened for this window // hud will be null if the web console has not been opened for this window
if (hud) { if (hud) {
hud.jsterm.clearOutput(); hud.jsterm.clearOutput();
@ -828,8 +827,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* 'console close' command * 'console close' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "console close", name: "console close",
description: gcli.lookup("consolecloseDesc"), description: gcli.lookup("consolecloseDesc"),
@ -841,8 +840,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* 'console open' command * 'console open' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "console open", name: "console open",
description: gcli.lookup("consoleopenDesc"), description: gcli.lookup("consoleopenDesc"),
@ -1024,7 +1023,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
let cookies = []; let cookies = [];
while (enm.hasMoreElements()) { while (enm.hasMoreElements()) {
let cookie = enm.getNext().QueryInterface(Ci.nsICookie); let cookie = enm.getNext().QueryInterface(Components.interfaces.nsICookie);
if (isCookieAtHost(cookie, host)) { if (isCookieAtHost(cookie, host)) {
if (cookie.name == args.name) { if (cookie.name == args.name) {
cookieMgr.remove(cookie.host, cookie.name, cookie.path, false); cookieMgr.remove(cookie.host, cookie.name, cookie.path, false);
@ -1157,21 +1156,45 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
} }
}(this)); }(this));
/* CmdEcho ----------------------------------------------------------------- */
(function(module) {
/**
* 'echo' command
*/
gcli.addCommand({
name: "echo",
description: gcli.lookup("echoDesc"),
params: [
{
name: "message",
type: "string",
description: gcli.lookup("echoMessageDesc")
}
],
returnType: "string",
hidden: true,
exec: function Command_echo(args, context) {
return args.message;
}
});
}(this));
/* CmdExport --------------------------------------------------------------- */ /* CmdExport --------------------------------------------------------------- */
(function(module) { (function(module) {
/** /**
* 'export' command * 'export' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "export", name: "export",
description: gcli.lookup("exportDesc"), description: gcli.lookup("exportDesc"),
}); });
/** /**
* The 'export html' command. This command allows the user to export the page to * The 'export html' command. This command allows the user to export the page to
* HTML after they do DOM changes. * HTML after they do DOM changes.
*/ */
gcli.addCommand({ gcli.addCommand({
name: "export html", name: "export html",
description: gcli.lookup("exportHtmlDesc"), description: gcli.lookup("exportHtmlDesc"),
@ -1193,8 +1216,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
"resource:///modules/devtools/Jsbeautify.jsm"); "resource:///modules/devtools/Jsbeautify.jsm");
/** /**
* jsb command. * jsb command.
*/ */
gcli.addCommand({ gcli.addCommand({
name: 'jsb', name: 'jsb',
description: gcli.lookup('jsbDesc'), description: gcli.lookup('jsbDesc'),
@ -1320,17 +1343,17 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
(function(module) { (function(module) {
/** /**
* 'pagemod' command * 'pagemod' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "pagemod", name: "pagemod",
description: gcli.lookup("pagemodDesc"), description: gcli.lookup("pagemodDesc"),
}); });
/** /**
* The 'pagemod replace' command. This command allows the user to search and * The 'pagemod replace' command. This command allows the user to search and
* replace within text nodes and attributes. * replace within text nodes and attributes.
*/ */
gcli.addCommand({ gcli.addCommand({
name: "pagemod replace", name: "pagemod replace",
description: gcli.lookup("pagemodReplaceDesc"), description: gcli.lookup("pagemodReplaceDesc"),
@ -1380,6 +1403,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}, },
], ],
exec: function(args, context) { exec: function(args, context) {
let document = context.environment.contentDocument;
let searchTextNodes = !args.attrOnly; let searchTextNodes = !args.attrOnly;
let searchAttributes = !args.contentOnly; let searchAttributes = !args.contentOnly;
let regexOptions = args.ignoreCase ? 'ig' : 'g'; let regexOptions = args.ignoreCase ? 'ig' : 'g';
@ -1389,7 +1413,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
attributeRegex = new RegExp(args.attributes, regexOptions); attributeRegex = new RegExp(args.attributes, regexOptions);
} }
let root = args.root || context.environment.document; let root = args.root || document;
let elements = root.querySelectorAll(args.selector); let elements = root.querySelectorAll(args.selector);
elements = Array.prototype.slice.call(elements); elements = Array.prototype.slice.call(elements);
@ -1436,8 +1460,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* 'pagemod remove' command * 'pagemod remove' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "pagemod remove", name: "pagemod remove",
description: gcli.lookup("pagemodRemoveDesc"), description: gcli.lookup("pagemodRemoveDesc"),
@ -1445,8 +1469,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
/** /**
* The 'pagemod remove element' command. * The 'pagemod remove element' command.
*/ */
gcli.addCommand({ gcli.addCommand({
name: "pagemod remove element", name: "pagemod remove element",
description: gcli.lookup("pagemodRemoveElementDesc"), description: gcli.lookup("pagemodRemoveElementDesc"),
@ -1474,7 +1498,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}, },
], ],
exec: function(args, context) { exec: function(args, context) {
let root = args.root || context.environment.document; let document = context.environment.contentDocument;
let root = args.root || document;
let elements = Array.prototype.slice.call(root.querySelectorAll(args.search)); let elements = Array.prototype.slice.call(root.querySelectorAll(args.search));
let removed = 0; let removed = 0;
@ -1501,8 +1526,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* The 'pagemod remove attribute' command. * The 'pagemod remove attribute' command.
*/ */
gcli.addCommand({ gcli.addCommand({
name: "pagemod remove attribute", name: "pagemod remove attribute",
description: gcli.lookup("pagemodRemoveAttributeDesc"), description: gcli.lookup("pagemodRemoveAttributeDesc"),
@ -1530,7 +1555,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}, },
], ],
exec: function(args, context) { exec: function(args, context) {
let root = args.root || context.environment.document; let document = context.environment.contentDocument;
let root = args.root || document;
let regexOptions = args.ignoreCase ? 'ig' : 'g'; let regexOptions = args.ignoreCase ? 'ig' : 'g';
let attributeRegex = new RegExp(args.searchAttributes, regexOptions); let attributeRegex = new RegExp(args.searchAttributes, regexOptions);
let elements = root.querySelectorAll(args.searchElements); let elements = root.querySelectorAll(args.searchElements);
@ -1559,13 +1586,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
/** /**
* Make a given string safe to use in a regular expression. * Make a given string safe to use in a regular expression.
* *
* @param string aString * @param string aString
* The string you want to use in a regex. * The string you want to use in a regex.
* @return string * @return string
* The equivalent of |aString| but safe to use in a regex. * The equivalent of |aString| but safe to use in a regex.
*/ */
function escapeRegex(aString) { function escapeRegex(aString) {
return aString.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); return aString.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
} }
@ -1595,21 +1622,22 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
], ],
returnType: "string", returnType: "string",
exec: function(args, context) { exec: function(args, context) {
return OS.File.exists(args.srcdir + "/CLOBBER").then(function(exists) { let promise = context.createPromise();
let existsPromise = OS.File.exists(args.srcdir + "/CLOBBER");
existsPromise.then(function(exists) {
if (exists) { if (exists) {
let str = Cc["@mozilla.org/supports-string;1"] var str = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString); .createInstance(Ci.nsISupportsString);
str.data = args.srcdir; str.data = args.srcdir;
Services.prefs.setComplexValue("devtools.loader.srcdir", Services.prefs.setComplexValue("devtools.loader.srcdir",
Ci.nsISupportsString, str); Components.interfaces.nsISupportsString, str);
devtools.reload(); devtools.reload();
promise.resolve(gcli.lookupFormat("toolsSrcdirReloaded", [args.srcdir]));
let msg = gcli.lookupFormat("toolsSrcdirReloaded", [args.srcdir]); return;
throw new Error(msg);
} }
promise.reject(gcli.lookupFormat("toolsSrcdirNotFound", [args.srcdir]));
return gcli.lookupFormat("toolsSrcdirNotFound", [args.srcdir]);
}); });
return promise;
} }
}); });
@ -1643,17 +1671,18 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
(function(module) { (function(module) {
/** /**
* Restart command * Restart command
* *
* @param boolean nocache * @param boolean nocache
* Disables loading content from cache upon restart. * Disables loading content from cache upon restart.
* *
* Examples : * Examples :
* >> restart * >> restart
* - restarts browser immediately * - restarts browser immediately
* >> restart --nocache * >> restart --nocache
* - restarts immediately and starts Firefox without using cache * - restarts immediately and starts Firefox without using cache
*/ */
gcli.addCommand({ gcli.addCommand({
name: "restart", name: "restart",
description: gcli.lookupFormat("restartBrowserDesc", [BRAND_SHORT_NAME]), description: gcli.lookupFormat("restartBrowserDesc", [BRAND_SHORT_NAME]),
@ -1698,13 +1727,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
const FILENAME_DEFAULT_VALUE = " "; const FILENAME_DEFAULT_VALUE = " ";
/** /**
* 'screenshot' command * 'screenshot' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: "screenshot", name: "screenshot",
description: gcli.lookup("screenshotDesc"), description: gcli.lookup("screenshotDesc"),
manual: gcli.lookup("screenshotManual"), manual: gcli.lookup("screenshotManual"),
returnType: "dom", returnType: "html",
params: [ params: [
{ {
name: "filename", name: "filename",
@ -1759,7 +1788,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
throw new Error(gcli.lookup("screenshotSelectorChromeConflict")); throw new Error(gcli.lookup("screenshotSelectorChromeConflict"));
} }
var document = args.chrome? context.environment.chromeDocument var document = args.chrome? context.environment.chromeDocument
: context.environment.document; : context.environment.contentDocument;
if (args.delay > 0) { if (args.delay > 0) {
var deferred = context.defer(); var deferred = context.defer();
document.defaultView.setTimeout(function Command_screenshotDelay() { document.defaultView.setTimeout(function Command_screenshotDelay() {
@ -1774,7 +1803,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
args.fullpage, args.selector); args.fullpage, args.selector);
} }
}, },
grabScreen: function(document, filename, clipboard, fullpage, node) { grabScreen:
function Command_screenshotGrabScreen(document, filename, clipboard,
fullpage, node) {
let window = document.defaultView; let window = document.defaultView;
let canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas"); let canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
let left = 0; let left = 0;
@ -1917,205 +1948,13 @@ XPCOMUtils.defineLazyModuleGetter(this, "AppCacheUtils",
}); });
}(this)); }(this));
/* Remoting ----------------------------------------------------------- */
const { DebuggerServer } = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
/**
* 'listen' command
*/
gcli.addCommand({
name: "listen",
description: gcli.lookup("listenDesc"),
manual: gcli.lookup("listenManual"),
params: [
{
name: "port",
type: "number",
get defaultValue() {
return Services.prefs.getIntPref("devtools.debugger.chrome-debugging-port");
},
description: gcli.lookup("listenPortDesc"),
}
],
exec: function Command_screenshot(args, context) {
if (!DebuggerServer.initialized) {
DebuggerServer.init();
DebuggerServer.addBrowserActors();
}
var reply = DebuggerServer.openListener(args.port);
if (!reply) {
throw new Error(gcli.lookup("listenDisabledOutput"));
}
if (DebuggerServer.initialized) {
return gcli.lookupFormat("listenInitOutput", [ '' + args.port ]);
}
return gcli.lookup("listenNoInitOutput");
},
});
const {
debuggerSocketConnect, DebuggerClient
} = Cu.import('resource://gre/modules/devtools/dbg-client.jsm', {});
/**
* Create a Connection object and initiate a connection.
*/
function connect(prefix, host, port) {
let connection = new Connection(prefix, host, port);
return connection.connect().then(function() {
return connection;
});
}
/**
* Manage a named connection to an HTTP server over web-sockets using socket.io
*/
function Connection(prefix, host, port) {
this.prefix = prefix;
this.host = host;
this.port = port;
// Properties setup by connect()
this.actor = undefined;
this.transport = undefined;
this.client = undefined;
this.requests = {};
this.nextRequestId = 0;
}
/**
* Setup socket.io, retrieve the list of remote commands and register them with
* the local canon.
* @return a promise which resolves (to undefined) when the connection is made
* or is rejected (with an error message) if the connection fails
*/
Connection.prototype.connect = function() {
let deferred = Promise.defer();
this.transport = debuggerSocketConnect(this.host, this.port);
this.client = new DebuggerClient(this.transport);
this.client.connect(() => {
this.client.listTabs(response => {
this.actor = response.gcliActor;
deferred.resolve();
});
});
return deferred.promise;
};
/**
* Retrieve the list of remote commands.
* @return a promise of an array of commandSpecs
*/
Connection.prototype.getCommandSpecs = function() {
let deferred = Promise.defer();
let request = { to: this.actor, type: 'getCommandSpecs' };
this.client.request(request, (response) => {
deferred.resolve(response.commandSpecs);
});
return deferred.promise;
};
/**
* Send an execute request. Replies are handled by the setup in connect()
*/
Connection.prototype.execute = function(typed, cmdArgs) {
let deferred = Promise.defer();
let request = {
to: this.actor,
type: 'execute',
typed: typed,
args: cmdArgs
};
this.client.request(request, (response) => {
deferred.resolve(response.reply);
});
return deferred.promise;
};
/**
* Send an execute request.
*/
Connection.prototype.execute = function(typed, cmdArgs) {
var request = new Request(this.actor, typed, cmdArgs);
this.requests[request.json.id] = request;
this.client.request(request.json, (response) => {
let request = this.requests[response.id];
delete this.requests[response.id];
request.complete(response.error, response.type, response.data);
});
return request.promise;
};
/**
* Kill this connection
*/
Connection.prototype.disconnect = function() {
let deferred = Promise.defer();
this.client.close(() => {
deferred.resolve();
});
return request.promise;
};
/**
* A Request is a command typed at the client which lives until the command
* has finished executing on the server
*/
function Request(actor, typed, args) {
this.json = {
to: actor,
type: 'execute',
typed: typed,
args: args,
id: Request._nextRequestId++,
};
this._deferred = Promise.defer();
this.promise = this._deferred.promise;
}
Request._nextRequestId = 0;
/**
* Called by the connection when a remote command has finished executing
* @param error boolean indicating output state
* @param type the type of the returned data
* @param data the data itself
*/
Request.prototype.complete = function(error, type, data) {
this._deferred.resolve({
error: error,
type: type,
data: data
});
};
/* CmdPaintFlashing ------------------------------------------------------- */ /* CmdPaintFlashing ------------------------------------------------------- */
(function(module) { (function(module) {
/** /**
* 'paintflashing' command * 'paintflashing' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: 'paintflashing', name: 'paintflashing',
description: gcli.lookup('paintflashingDesc') description: gcli.lookup('paintflashingDesc')
@ -2137,13 +1976,15 @@ Request.prototype.complete = function(error, type, data) {
] ]
}], }],
exec: function(args, context) { exec: function(args, context) {
var window = args.chrome ? var window;
context.environment.chromeWindow : if (args.chrome) {
context.environment.window; window = context.environment.chromeDocument.defaultView;
} else {
window.QueryInterface(Ci.nsIInterfaceRequestor) window = context.environment.contentDocument.defaultView;
.getInterface(Ci.nsIDOMWindowUtils) }
.paintFlashing = true; window.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils).
paintFlashing = true;
onPaintFlashingChanged(context); onPaintFlashingChanged(context);
} }
}); });
@ -2164,13 +2005,14 @@ Request.prototype.complete = function(error, type, data) {
] ]
}], }],
exec: function(args, context) { exec: function(args, context) {
var window = args.chrome ? if (args.chrome) {
context.environment.chromeWindow : var window = context.environment.chromeDocument.defaultView;
context.environment.window; } else {
var window = context.environment.contentDocument.defaultView;
window.QueryInterface(Ci.nsIInterfaceRequestor) }
.getInterface(Ci.nsIDOMWindowUtils) window.QueryInterface(Ci.nsIInterfaceRequestor).
.paintFlashing = false; getInterface(Ci.nsIDOMWindowUtils).
paintFlashing = false;
onPaintFlashingChanged(context); onPaintFlashingChanged(context);
} }
}); });
@ -2229,8 +2071,8 @@ Request.prototype.complete = function(error, type, data) {
(function(module) { (function(module) {
/** /**
* 'appcache' command * 'appcache' command
*/ */
gcli.addCommand({ gcli.addCommand({
name: 'appcache', name: 'appcache',
@ -2283,19 +2125,20 @@ Request.prototype.complete = function(error, type, data) {
}], }],
exec: function(args, context) { exec: function(args, context) {
let utils; let utils;
let deferred = context.defer(); let promise = context.createPromise();
if (args.uri) { if (args.uri) {
utils = new AppCacheUtils(args.uri); utils = new AppCacheUtils(args.uri);
} else { } else {
utils = new AppCacheUtils(context.environment.document); let doc = context.environment.contentDocument;
utils = new AppCacheUtils(doc);
} }
utils.validateManifest().then(function(errors) { utils.validateManifest().then(function(errors) {
deferred.resolve([errors, utils.manifestURI || "-"]); promise.resolve([errors, utils.manifestURI || "-"]);
}); });
return deferred.promise; return promise;
} }
}); });
@ -2395,8 +2238,11 @@ Request.prototype.complete = function(error, type, data) {
] ]
}], }],
exec: function(args, context) { exec: function(args, context) {
let doc = context.environment.contentDocument;
let utils = new AppCacheUtils(); let utils = new AppCacheUtils();
return utils.listEntries(args.search);
let entries = utils.listEntries(args.search);
return entries;
} }
}); });
@ -2413,8 +2259,13 @@ Request.prototype.complete = function(error, type, data) {
} }
], ],
exec: function(args, context) { exec: function(args, context) {
let doc = context.environment.contentDocument;
let utils = new AppCacheUtils(); let utils = new AppCacheUtils();
return utils.viewEntry(args.key);
let result = utils.viewEntry(args.key);
if (result) {
return result;
}
} }
}); });

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,6 @@ MOCHITEST_BROWSER_FILES = \
browser_cmd_appcache_valid_page2.html \ browser_cmd_appcache_valid_page2.html \
browser_cmd_appcache_valid_page3.html \ browser_cmd_appcache_valid_page3.html \
browser_cmd_commands.js \ browser_cmd_commands.js \
browser_cmd_cookie.html \
browser_cmd_cookie.js \ browser_cmd_cookie.js \
browser_cmd_jsb.js \ browser_cmd_jsb.js \
browser_cmd_jsb_script.jsi \ browser_cmd_jsb_script.jsi \

View File

@ -56,8 +56,8 @@ function test() {
exec: { exec: {
output: [ /page1/, /page2/, /page3/ ] output: [ /page1/, /page2/, /page3/ ]
}, },
post: function(output, text) { post: function(output) {
ok(!text.contains("index"), "index is not contained in output"); ok(!output.contains("index"), "index is not contained in output");
} }
}, },
@ -118,11 +118,11 @@ function test() {
exec: { exec: {
output: [ /no results/ ] output: [ /no results/ ]
}, },
post: function(output, text) { post: function(output) {
ok(!text.contains("index"), "index is not contained in output"); ok(!output.contains("index"), "index is not contained in output");
ok(!text.contains("page1"), "page1 is not contained in output"); ok(!output.contains("page1"), "page1 is not contained in output");
ok(!text.contains("page2"), "page1 is not contained in output"); ok(!output.contains("page2"), "page1 is not contained in output");
ok(!text.contains("page3"), "page1 is not contained in output"); ok(!output.contains("page3"), "page1 is not contained in output");
} }
}, },

View File

@ -15,6 +15,17 @@ function test() {
}).then(finish); }).then(finish);
} }
tests.testEcho = function(options) {
return helpers.audit(options, [
{
setup: "echo message",
exec: {
output: "message",
}
}
]);
};
tests.testConsole = function(options) { tests.testConsole = function(options) {
let deferred = Promise.defer(); let deferred = Promise.defer();
let hud = null; let hud = null;

View File

@ -1,18 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GCLI cookie command test</title>
</head>
<body>
<p>Cookie test</p>
<p id=result></p>
<script type="text/javascript">
document.cookie = "zap=zep";
document.cookie = "zip=zop";
document.getElementById("result").innerHTML = document.cookie;
</script>
</body>
</html>

View File

@ -3,8 +3,7 @@
// Tests that the cookie commands works as they should // Tests that the cookie commands works as they should
const TEST_URI = "http://example.com/browser/browser/devtools/commandline/"+ const TEST_URI = "data:text/html;charset=utf-8,gcli-cookie";
"test/browser_cmd_cookie.html";
function test() { function test() {
helpers.addTabWithToolbar(TEST_URI, function(options) { helpers.addTabWithToolbar(TEST_URI, function(options) {
@ -80,14 +79,14 @@ function test() {
{ {
setup: "cookie list", setup: "cookie list",
exec: { exec: {
output: [ /zap=zep/, /zip=zop/, /Edit/ ] output: 'No cookies found for host'
} }
}, },
{ {
setup: "cookie set zup banana", setup: "cookie set fruit banana",
check: { check: {
args: { args: {
name: { value: 'zup' }, name: { value: 'fruit' },
value: { value: 'banana' }, value: { value: 'banana' },
} }
}, },
@ -98,56 +97,24 @@ function test() {
{ {
setup: "cookie list", setup: "cookie list",
exec: { exec: {
output: [ /zap=zep/, /zip=zop/, /zup=banana/, /Edit/ ] output: [ /fruit=banana/, /Expires:/, /Edit/ ]
} }
}, },
{ {
setup: "cookie remove zip", setup: "cookie remove fruit",
exec: { }, check: {
args: {
name: { value: 'fruit' },
}
},
exec: {
output: ""
}
}, },
{ {
setup: "cookie list", setup: "cookie list",
exec: { exec: {
output: [ /zap=zep/, /zup=banana/, /Edit/ ] output: 'No cookies found for host'
},
post: function(output, text) {
ok(!text.contains("zip"), "");
ok(!text.contains("zop"), "");
}
},
{
setup: "cookie remove zap",
exec: { },
},
{
setup: "cookie list",
exec: {
output: [ /zup=banana/, /Edit/ ]
},
post: function(output, text) {
ok(!text.contains("zap"), "");
ok(!text.contains("zep"), "");
ok(!text.contains("zip"), "");
ok(!text.contains("zop"), "");
}
},
{
setup: "cookie remove zup",
exec: { }
},
{
setup: "cookie list",
exec: {
output: 'No cookies found for host example.com'
},
post: function(output, text) {
ok(!text.contains("zap"), "");
ok(!text.contains("zep"), "");
ok(!text.contains("zip"), "");
ok(!text.contains("zop"), "");
ok(!text.contains("zup"), "");
ok(!text.contains("banana"), "");
ok(!text.contains("Edit"), "");
} }
}, },
]); ]);

View File

@ -38,7 +38,6 @@ function test() {
// var helpers = require('gclitest/helpers'); // var helpers = require('gclitest/helpers');
var canon = require('gcli/canon'); var canon = require('gcli/canon');
// var assert = require('test/assert'); // var assert = require('test/assert');
var Canon = canon.Canon;
var startCount = undefined; var startCount = undefined;
var events = undefined; var events = undefined;
@ -158,6 +157,8 @@ exports.testAddRemove2 = function(options) {
return helpers.audit(options, [ return helpers.audit(options, [
{ {
setup: 'testadd', setup: 'testadd',
check: {
},
exec: { exec: {
output: /^3$/ output: /^3$/
}, },
@ -198,74 +199,4 @@ exports.testAddRemove3 = function(options) {
canon.onCanonChange.remove(canonChange); canon.onCanonChange.remove(canonChange);
}; };
exports.testAltCanon = function(options) {
var altCanon = new Canon();
var tss = {
name: 'tss',
params: [
{ name: 'str', type: 'string' },
{ name: 'num', type: 'number' },
{ name: 'opt', type: { name: 'selection', data: [ '1', '2', '3' ] } },
],
exec: function(args, context) {
return context.commandName + ':' +
args.str + ':' + args.num + ':' + args.opt;
}
};
altCanon.addCommand(tss);
var commandSpecs = altCanon.getCommandSpecs();
assert.is(JSON.stringify(commandSpecs),
'{"tss":{"name":"tss","params":[' +
'{"name":"str","type":"string"},' +
'{"name":"num","type":"number"},' +
'{"name":"opt","type":{"name":"selection","data":["1","2","3"]}}]}}',
'JSON.stringify(commandSpecs)');
var remoter = function(args, context) {
assert.is(context.commandName, 'tss', 'commandName is tss');
var cmd = altCanon.getCommand(context.commandName);
return cmd.exec(args, context);
};
canon.addProxyCommands('proxy', commandSpecs, remoter, 'test');
var parent = canon.getCommand('proxy');
assert.is(parent.name, 'proxy', 'Parent command called proxy');
var child = canon.getCommand('proxy tss');
assert.is(child.name, 'proxy tss', 'child command called proxy tss');
return helpers.audit(options, [
{
setup: 'proxy tss foo 6 3',
check: {
input: 'proxy tss foo 6 3',
hints: '',
markup: 'VVVVVVVVVVVVVVVVV',
cursor: 17,
status: 'VALID',
args: {
str: { value: 'foo', status: 'VALID' },
num: { value: 6, status: 'VALID' },
opt: { value: '3', status: 'VALID' }
}
},
exec: {
output: 'tss:foo:6:3'
},
post: function() {
canon.removeCommand('proxy');
canon.removeCommand('proxy tss');
assert.is(canon.getCommand('proxy'), undefined, 'remove proxy');
assert.is(canon.getCommand('proxy tss'), undefined, 'remove proxy tss');
}
}
]);
};
// }); // });

View File

@ -758,6 +758,7 @@ exports.testSingleFloat = function(options) {
current: '__command', current: '__command',
status: 'ERROR', status: 'ERROR',
error: '', error: '',
predictions: [ ],
unassigned: [ ], unassigned: [ ],
args: { args: {
command: { name: 'tsf' }, command: { name: 'tsf' },

View File

@ -519,9 +519,9 @@ exports.testSpaceComplete = function(options) {
msg: { status: 'INCOMPLETE', message: '' }, msg: { status: 'INCOMPLETE', message: '' },
num: { status: 'VALID' }, num: { status: 'VALID' },
sel: { status: 'VALID' }, sel: { status: 'VALID' },
bool: { value: false, status: 'VALID' }, bool: { value: false,status: 'VALID' },
num2: { status: 'VALID' }, num2: { status: 'VALID' },
bool2: { value: false, status: 'VALID' }, bool2: { value: false,status: 'VALID' },
sel2: { sel2: {
value: 'with space', value: 'with space',
arg: ' --sel2 \'with space\' ', arg: ' --sel2 \'with space\' ',

View File

@ -1,276 +0,0 @@
/*
* Copyright 2012, Mozilla Foundation and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// define(function(require, exports, module) {
// <INJECTED SOURCE:START>
// THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
// DO NOT EDIT IT DIRECTLY
var exports = {};
const TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testContext.js</p>";
function test() {
helpers.addTabWithToolbar(TEST_URI, function(options) {
return helpers.runTests(options, exports);
}).then(finish);
}
// <INJECTED SOURCE:END>
'use strict';
// var helpers = require('gclitest/helpers');
// var mockCommands = require('gclitest/mockCommands');
var cli = require('gcli/cli');
var origLogErrors = undefined;
exports.setup = function(options) {
mockCommands.setup();
origLogErrors = cli.logErrors;
cli.logErrors = false;
};
exports.shutdown = function(options) {
mockCommands.shutdown();
cli.logErrors = origLogErrors;
origLogErrors = undefined;
};
exports.testBaseline = function(options) {
helpers.audit(options, [
// These 3 establish a baseline for comparison when we have used the
// context command
{
setup: 'ext',
check: {
input: 'ext',
hints: ' -> context',
markup: 'III',
message: '',
predictions: [ 'context', 'tsn ext', 'tsn exte', 'tsn exten', 'tsn extend' ],
unassigned: [ ],
}
},
{
setup: 'ext test',
check: {
input: 'ext test',
hints: '',
markup: 'IIIVEEEE',
status: 'ERROR',
message: 'Too many arguments',
unassigned: [ ' test' ],
}
},
{
setup: 'tsn',
check: {
input: 'tsn',
hints: '',
markup: 'III',
cursor: 3,
current: '__command',
status: 'ERROR',
predictionsContains: [ 'tsn', 'tsn deep', 'tsn ext', 'tsn exte' ],
args: {
command: { name: 'tsn' },
}
}
}
]);
};
exports.testContext = function(options) {
helpers.audit(options, [
// Use the 'tsn' context
{
setup: 'context tsn',
check: {
input: 'context tsn',
hints: '',
markup: 'VVVVVVVVVVV',
message: '',
predictionsContains: [ 'tsn', 'tsn deep', 'tsn ext', 'tsn exte' ],
args: {
command: { name: 'context' },
prefix: {
value: mockCommands.commands.tsn,
status: 'VALID',
message: ''
},
}
},
exec: {
output: 'Using tsn as a command prefix',
completed: true,
}
},
// For comparison with earlier
{
setup: 'ext',
check: {
input: 'ext',
hints: ' <text>',
markup: 'VVV',
predictions: [ 'tsn ext', 'tsn exte', 'tsn exten', 'tsn extend' ],
args: {
command: { name: 'tsn ext' },
text: {
value: undefined,
arg: '',
status: 'INCOMPLETE',
message: ''
},
}
}
},
{
setup: 'ext test',
check: {
input: 'ext test',
hints: '',
markup: 'VVVVVVVV',
args: {
command: { name: 'tsn ext' },
text: {
value: 'test',
arg: ' test',
status: 'VALID',
message: ''
},
}
},
exec: {
output: 'Exec: tsnExt text=test',
completed: true,
}
},
{
setup: 'tsn',
check: {
input: 'tsn',
hints: '',
markup: 'III',
message: '',
predictionsContains: [ 'tsn', 'tsn deep', 'tsn ext', 'tsn exte' ],
args: {
command: { name: 'tsn' },
}
}
},
// Does it actually work?
{
setup: 'tsb true',
check: {
input: 'tsb true',
hints: '',
markup: 'VVVVVVVV',
options: [ 'true' ],
message: '',
predictions: [ 'true' ],
unassigned: [ ],
args: {
command: { name: 'tsb' },
toggle: { value: true, arg: ' true', status: 'VALID', message: '' },
}
}
},
{
// Bug 866710 - GCLI should allow argument merging for non-string parameters
setup: 'context tsn ext',
skip: true
},
{
setup: 'context "tsn ext"',
check: {
input: 'context "tsn ext"',
hints: '',
markup: 'VVVVVVVVVVVVVVVVV',
message: '',
predictions: [ ],
unassigned: [ ],
args: {
command: { name: 'context' },
prefix: {
value: mockCommands.commands.tsnExt,
status: 'VALID',
message: ''
}
}
},
exec: {
output: 'Error: Can\'t use \'tsn ext\' as a prefix because it is not a parent command.',
completed: true,
error: true
}
},
/*
{
setup: 'context "tsn deep"',
check: {
input: 'context "tsn deep"',
hints: '',
markup: 'VVVVVVVVVVVVVVVVVV',
status: 'ERROR',
message: '',
predictions: [ 'tsn deep' ],
unassigned: [ ],
args: {
command: { name: 'context' },
prefix: {
value: mockCommands.commands.tsnDeep,
status: 'VALID',
message: ''
}
}
},
exec: {
output: '',
completed: true,
}
},
*/
{
setup: 'context',
check: {
input: 'context',
hints: ' [prefix]',
markup: 'VVVVVVV',
status: 'VALID',
unassigned: [ ],
args: {
command: { name: 'context' },
prefix: { value: undefined, arg: '', status: 'VALID', message: '' },
}
},
exec: {
output: 'Command prefix is unset',
completed: true,
type: 'string',
error: false
}
}
]);
};
// });

View File

@ -1,99 +0,0 @@
/*
* Copyright 2009-2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE.txt or:
* http://opensource.org/licenses/BSD-3-Clause
*/
// define(function(require, exports, module) {
// <INJECTED SOURCE:START>
// THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
// DO NOT EDIT IT DIRECTLY
var exports = {};
const TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testFail.js</p>";
function test() {
helpers.addTabWithToolbar(TEST_URI, function(options) {
return helpers.runTests(options, exports);
}).then(finish);
}
// <INJECTED SOURCE:END>
'use strict';
// var helpers = require('gclitest/helpers');
// var mockCommands = require('gclitest/mockCommands');
var cli = require('gcli/cli');
var origLogErrors = undefined;
exports.setup = function(options) {
mockCommands.setup();
origLogErrors = cli.logErrors;
cli.logErrors = false;
};
exports.shutdown = function(options) {
mockCommands.shutdown();
cli.logErrors = origLogErrors;
origLogErrors = undefined;
};
exports.testBasic = function(options) {
return helpers.audit(options, [
{
setup: 'tsfail reject',
exec: {
completed: false,
output: 'rejected promise',
type: 'error',
error: true
}
},
{
setup: 'tsfail rejecttyped',
exec: {
completed: false,
output: '54',
type: 'number',
error: true
}
},
{
setup: 'tsfail throwerror',
exec: {
completed: true,
output: 'Error: thrown error',
type: 'error',
error: true
}
},
{
setup: 'tsfail throwstring',
exec: {
completed: true,
output: 'thrown string',
type: 'error',
error: true
}
},
{
setup: 'tsfail noerror',
exec: {
completed: true,
output: 'no error',
type: 'string',
error: false
}
}
]);
};
// });

View File

@ -40,15 +40,22 @@ var KeyEvent = require('util/util').KeyEvent;
// var mockCommands = require('gclitest/mockCommands'); // var mockCommands = require('gclitest/mockCommands');
var latestEvent = undefined; var latestEvent = undefined;
var latestOutput = undefined;
var latestData = undefined; var latestData = undefined;
var outputted = function(ev) { var outputted = function(ev) {
latestEvent = ev; function updateData() {
latestData = latestOutput.data;
}
ev.output.promise.then(function() { if (latestOutput != null) {
latestData = ev.output.data; ev.output.onChange.remove(updateData);
ev.output.onClose(); }
});
latestEvent = ev;
latestOutput = ev.output;
ev.output.onChange.add(updateData);
}; };
@ -64,6 +71,7 @@ exports.shutdown = function(options) {
exports.testOutput = function(options) { exports.testOutput = function(options) {
latestEvent = undefined; latestEvent = undefined;
latestOutput = undefined;
latestData = undefined; latestData = undefined;
var inputter = options.display.inputter; var inputter = options.display.inputter;
@ -95,6 +103,8 @@ exports.testOutput = function(options) {
var ev3 = { keyCode: KeyEvent.DOM_VK_ESCAPE }; var ev3 = { keyCode: KeyEvent.DOM_VK_ESCAPE };
return inputter.handleKeyUp(ev3).then(function() { return inputter.handleKeyUp(ev3).then(function() {
assert.ok(!focusManager._helpRequested, 'ESCAPE = anti help'); assert.ok(!focusManager._helpRequested, 'ESCAPE = anti help');
latestOutput.onClose();
}); });
}); });

View File

@ -61,7 +61,7 @@ exports.testAllPredictions1 = function(options) {
return; return;
} }
var resource = types.createType('resource'); var resource = types.getType('resource');
return resource.getLookup().then(function(opts) { return resource.getLookup().then(function(opts) {
assert.ok(opts.length > 1, 'have all resources'); assert.ok(opts.length > 1, 'have all resources');
@ -77,7 +77,7 @@ exports.testScriptPredictions = function(options) {
return; return;
} }
var resource = types.createType({ name: 'resource', include: 'text/javascript' }); var resource = types.getType({ name: 'resource', include: 'text/javascript' });
return resource.getLookup().then(function(opts) { return resource.getLookup().then(function(opts) {
assert.ok(opts.length > 1, 'have js resources'); assert.ok(opts.length > 1, 'have js resources');
@ -93,7 +93,7 @@ exports.testStylePredictions = function(options) {
return; return;
} }
var resource = types.createType({ name: 'resource', include: 'text/css' }); var resource = types.getType({ name: 'resource', include: 'text/css' });
return resource.getLookup().then(function(opts) { return resource.getLookup().then(function(opts) {
assert.ok(opts.length >= 1, 'have css resources'); assert.ok(opts.length >= 1, 'have css resources');
@ -109,11 +109,11 @@ exports.testAllPredictions2 = function(options) {
return; return;
} }
var scriptRes = types.createType({ name: 'resource', include: 'text/javascript' }); var scriptRes = types.getType({ name: 'resource', include: 'text/javascript' });
return scriptRes.getLookup().then(function(scriptOptions) { return scriptRes.getLookup().then(function(scriptOptions) {
var styleRes = types.createType({ name: 'resource', include: 'text/css' }); var styleRes = types.getType({ name: 'resource', include: 'text/css' });
return styleRes.getLookup().then(function(styleOptions) { return styleRes.getLookup().then(function(styleOptions) {
var allRes = types.createType({ name: 'resource' }); var allRes = types.getType({ name: 'resource' });
return allRes.getLookup().then(function(allOptions) { return allRes.getLookup().then(function(allOptions) {
assert.is(scriptOptions.length + styleOptions.length, assert.is(scriptOptions.length + styleOptions.length,
allOptions.length, allOptions.length,
@ -129,9 +129,9 @@ exports.testAllPredictions3 = function(options) {
return; return;
} }
var res1 = types.createType({ name: 'resource' }); var res1 = types.getType({ name: 'resource' });
return res1.getLookup().then(function(options1) { return res1.getLookup().then(function(options1) {
var res2 = types.createType('resource'); var res2 = types.getType('resource');
return res2.getLookup().then(function(options2) { return res2.getLookup().then(function(options2) {
assert.is(options1.length, options2.length, 'type spec'); assert.is(options1.length, options2.length, 'type spec');
}); });

View File

@ -36,7 +36,6 @@ function test() {
'use strict'; 'use strict';
// var assert = require('test/assert'); // var assert = require('test/assert');
var cli = require('gcli/cli');
var Requisition = require('gcli/cli').Requisition; var Requisition = require('gcli/cli').Requisition;
var canon = require('gcli/canon'); var canon = require('gcli/canon');
// var mockCommands = require('gclitest/mockCommands'); // var mockCommands = require('gclitest/mockCommands');
@ -52,26 +51,26 @@ exports.shutdown = function(options) {
exports.testSplitSimple = function(options) { exports.testSplitSimple = function(options) {
var args; var args;
var requisition = new Requisition(); var requ = new Requisition();
args = cli.tokenize('s'); args = requ._tokenize('s');
requisition._split(args); requ._split(args);
assert.is(0, args.length); assert.is(0, args.length);
assert.is('s', requisition.commandAssignment.arg.text); assert.is('s', requ.commandAssignment.arg.text);
}; };
exports.testFlatCommand = function(options) { exports.testFlatCommand = function(options) {
var args; var args;
var requisition = new Requisition(); var requ = new Requisition();
args = cli.tokenize('tsv'); args = requ._tokenize('tsv');
requisition._split(args); requ._split(args);
assert.is(0, args.length); assert.is(0, args.length);
assert.is('tsv', requisition.commandAssignment.value.name); assert.is('tsv', requ.commandAssignment.value.name);
args = cli.tokenize('tsv a b'); args = requ._tokenize('tsv a b');
requisition._split(args); requ._split(args);
assert.is('tsv', requisition.commandAssignment.value.name); assert.is('tsv', requ.commandAssignment.value.name);
assert.is(2, args.length); assert.is(2, args.length);
assert.is('a', args[0].text); assert.is('a', args[0].text);
assert.is('b', args[1].text); assert.is('b', args[1].text);
@ -84,14 +83,14 @@ exports.testJavascript = function(options) {
} }
var args; var args;
var requisition = new Requisition(); var requ = new Requisition();
args = cli.tokenize('{'); args = requ._tokenize('{');
requisition._split(args); requ._split(args);
assert.is(1, args.length); assert.is(1, args.length);
assert.is('', args[0].text); assert.is('', args[0].text);
assert.is('', requisition.commandAssignment.arg.text); assert.is('', requ.commandAssignment.arg.text);
assert.is('{', requisition.commandAssignment.value.name); assert.is('{', requ.commandAssignment.value.name);
}; };
// BUG 663081 - add tests for sub commands // BUG 663081 - add tests for sub commands

View File

@ -36,18 +36,19 @@ function test() {
'use strict'; 'use strict';
// var assert = require('test/assert'); // var assert = require('test/assert');
var cli = require('gcli/cli'); var Requisition = require('gcli/cli').Requisition;
exports.testBlanks = function(options) { exports.testBlanks = function(options) {
var args; var args;
var requ = new Requisition();
args = cli.tokenize(''); args = requ._tokenize('');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('', args[0].text); assert.is('', args[0].text);
assert.is('', args[0].prefix); assert.is('', args[0].prefix);
assert.is('', args[0].suffix); assert.is('', args[0].suffix);
args = cli.tokenize(' '); args = requ._tokenize(' ');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('', args[0].text); assert.is('', args[0].text);
assert.is(' ', args[0].prefix); assert.is(' ', args[0].prefix);
@ -56,15 +57,16 @@ exports.testBlanks = function(options) {
exports.testTokSimple = function(options) { exports.testTokSimple = function(options) {
var args; var args;
var requ = new Requisition();
args = cli.tokenize('s'); args = requ._tokenize('s');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('s', args[0].text); assert.is('s', args[0].text);
assert.is('', args[0].prefix); assert.is('', args[0].prefix);
assert.is('', args[0].suffix); assert.is('', args[0].suffix);
assert.is('Argument', args[0].type); assert.is('Argument', args[0].type);
args = cli.tokenize('s s'); args = requ._tokenize('s s');
assert.is(2, args.length); assert.is(2, args.length);
assert.is('s', args[0].text); assert.is('s', args[0].text);
assert.is('', args[0].prefix); assert.is('', args[0].prefix);
@ -78,22 +80,23 @@ exports.testTokSimple = function(options) {
exports.testJavascript = function(options) { exports.testJavascript = function(options) {
var args; var args;
var requ = new Requisition();
args = cli.tokenize('{x}'); args = requ._tokenize('{x}');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('x', args[0].text); assert.is('x', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
assert.is('}', args[0].suffix); assert.is('}', args[0].suffix);
assert.is('ScriptArgument', args[0].type); assert.is('ScriptArgument', args[0].type);
args = cli.tokenize('{ x }'); args = requ._tokenize('{ x }');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('x', args[0].text); assert.is('x', args[0].text);
assert.is('{ ', args[0].prefix); assert.is('{ ', args[0].prefix);
assert.is(' }', args[0].suffix); assert.is(' }', args[0].suffix);
assert.is('ScriptArgument', args[0].type); assert.is('ScriptArgument', args[0].type);
args = cli.tokenize('{x} {y}'); args = requ._tokenize('{x} {y}');
assert.is(2, args.length); assert.is(2, args.length);
assert.is('x', args[0].text); assert.is('x', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
@ -104,7 +107,7 @@ exports.testJavascript = function(options) {
assert.is('}', args[1].suffix); assert.is('}', args[1].suffix);
assert.is('ScriptArgument', args[1].type); assert.is('ScriptArgument', args[1].type);
args = cli.tokenize('{x}{y}'); args = requ._tokenize('{x}{y}');
assert.is(2, args.length); assert.is(2, args.length);
assert.is('x', args[0].text); assert.is('x', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
@ -115,21 +118,21 @@ exports.testJavascript = function(options) {
assert.is('}', args[1].suffix); assert.is('}', args[1].suffix);
assert.is('ScriptArgument', args[1].type); assert.is('ScriptArgument', args[1].type);
args = cli.tokenize('{'); args = requ._tokenize('{');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('', args[0].text); assert.is('', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
assert.is('', args[0].suffix); assert.is('', args[0].suffix);
assert.is('ScriptArgument', args[0].type); assert.is('ScriptArgument', args[0].type);
args = cli.tokenize('{ '); args = requ._tokenize('{ ');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('', args[0].text); assert.is('', args[0].text);
assert.is('{ ', args[0].prefix); assert.is('{ ', args[0].prefix);
assert.is('', args[0].suffix); assert.is('', args[0].suffix);
assert.is('ScriptArgument', args[0].type); assert.is('ScriptArgument', args[0].type);
args = cli.tokenize('{x'); args = requ._tokenize('{x');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('x', args[0].text); assert.is('x', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
@ -139,29 +142,30 @@ exports.testJavascript = function(options) {
exports.testRegularNesting = function(options) { exports.testRegularNesting = function(options) {
var args; var args;
var requ = new Requisition();
args = cli.tokenize('{"x"}'); args = requ._tokenize('{"x"}');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('"x"', args[0].text); assert.is('"x"', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
assert.is('}', args[0].suffix); assert.is('}', args[0].suffix);
assert.is('ScriptArgument', args[0].type); assert.is('ScriptArgument', args[0].type);
args = cli.tokenize('{\'x\'}'); args = requ._tokenize('{\'x\'}');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('\'x\'', args[0].text); assert.is('\'x\'', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
assert.is('}', args[0].suffix); assert.is('}', args[0].suffix);
assert.is('ScriptArgument', args[0].type); assert.is('ScriptArgument', args[0].type);
args = cli.tokenize('"{x}"'); args = requ._tokenize('"{x}"');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('{x}', args[0].text); assert.is('{x}', args[0].text);
assert.is('"', args[0].prefix); assert.is('"', args[0].prefix);
assert.is('"', args[0].suffix); assert.is('"', args[0].suffix);
assert.is('Argument', args[0].type); assert.is('Argument', args[0].type);
args = cli.tokenize('\'{x}\''); args = requ._tokenize('\'{x}\'');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('{x}', args[0].text); assert.is('{x}', args[0].text);
assert.is('\'', args[0].prefix); assert.is('\'', args[0].prefix);
@ -171,22 +175,23 @@ exports.testRegularNesting = function(options) {
exports.testDeepNesting = function(options) { exports.testDeepNesting = function(options) {
var args; var args;
var requ = new Requisition();
args = cli.tokenize('{{}}'); args = requ._tokenize('{{}}');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('{}', args[0].text); assert.is('{}', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
assert.is('}', args[0].suffix); assert.is('}', args[0].suffix);
assert.is('ScriptArgument', args[0].type); assert.is('ScriptArgument', args[0].type);
args = cli.tokenize('{{x} {y}}'); args = requ._tokenize('{{x} {y}}');
assert.is(1, args.length); assert.is(1, args.length);
assert.is('{x} {y}', args[0].text); assert.is('{x} {y}', args[0].text);
assert.is('{', args[0].prefix); assert.is('{', args[0].prefix);
assert.is('}', args[0].suffix); assert.is('}', args[0].suffix);
assert.is('ScriptArgument', args[0].type); assert.is('ScriptArgument', args[0].type);
args = cli.tokenize('{{w} {{{x}}}} {y} {{{z}}}'); args = requ._tokenize('{{w} {{{x}}}} {y} {{{z}}}');
assert.is(3, args.length); assert.is(3, args.length);
@ -205,7 +210,7 @@ exports.testDeepNesting = function(options) {
assert.is('}', args[2].suffix); assert.is('}', args[2].suffix);
assert.is('ScriptArgument', args[2].type); assert.is('ScriptArgument', args[2].type);
args = cli.tokenize('{{w} {{{x}}} {y} {{{z}}}'); args = requ._tokenize('{{w} {{{x}}} {y} {{{z}}}');
assert.is(1, args.length); assert.is(1, args.length);
@ -217,9 +222,10 @@ exports.testDeepNesting = function(options) {
exports.testStrangeNesting = function(options) { exports.testStrangeNesting = function(options) {
var args; var args;
var requ = new Requisition();
// Note: When we get real JS parsing this should break // Note: When we get real JS parsing this should break
args = cli.tokenize('{"x}"}'); args = requ._tokenize('{"x}"}');
assert.is(2, args.length); assert.is(2, args.length);
@ -236,8 +242,9 @@ exports.testStrangeNesting = function(options) {
exports.testComplex = function(options) { exports.testComplex = function(options) {
var args; var args;
var requ = new Requisition();
args = cli.tokenize(' 1234 \'12 34\''); args = requ._tokenize(' 1234 \'12 34\'');
assert.is(2, args.length); assert.is(2, args.length);
@ -251,7 +258,7 @@ exports.testComplex = function(options) {
assert.is('\'', args[1].suffix); assert.is('\'', args[1].suffix);
assert.is('Argument', args[1].type); assert.is('Argument', args[1].type);
args = cli.tokenize('12\'34 "12 34" \\'); // 12'34 "12 34" \ args = requ._tokenize('12\'34 "12 34" \\'); // 12'34 "12 34" \
assert.is(3, args.length); assert.is(3, args.length);
@ -273,8 +280,9 @@ exports.testComplex = function(options) {
exports.testPathological = function(options) { exports.testPathological = function(options) {
var args; var args;
var requ = new Requisition();
args = cli.tokenize('a\\ b \\t\\n\\r \\\'x\\\" \'d'); // a_b \t\n\r \'x\" 'd args = requ._tokenize('a\\ b \\t\\n\\r \\\'x\\\" \'d'); // a_b \t\n\r \'x\" 'd
assert.is(4, args.length); assert.is(4, args.length);

View File

@ -49,22 +49,15 @@ function forEachType(options, typeSpec, callback) {
} }
else if (name === 'delegate') { else if (name === 'delegate') {
typeSpec.delegateType = function() { typeSpec.delegateType = function() {
return types.createType('string'); return types.getType('string');
}; };
} }
else if (name === 'array') { else if (name === 'array') {
typeSpec.subtype = 'string'; typeSpec.subtype = 'string';
} }
var type = types.createType(typeSpec); var type = types.getType(typeSpec);
callback(type); callback(type);
// Clean up
delete typeSpec.name;
delete typeSpec.requisition;
delete typeSpec.data;
delete typeSpec.delegateType;
delete typeSpec.subtype;
}); });
} }

View File

@ -24,7 +24,8 @@ let require = (Cu.import("resource://gre/modules/devtools/Require.jsm", {})).req
Components.utils.import("resource:///modules/devtools/gcli.jsm", {}); Components.utils.import("resource:///modules/devtools/gcli.jsm", {});
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console; let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
let TargetFactory = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools.TargetFactory; let devtools = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools;
let TargetFactory = devtools.TargetFactory;
let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise; let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise;
let assert = { ok: ok, is: is, log: info }; let assert = { ok: ok, is: is, log: info };
@ -157,7 +158,6 @@ helpers.runTests = function(options, tests) {
}); });
var recover = function(error) { var recover = function(error) {
ok(false, error);
console.error(error); console.error(error);
}; };
@ -341,7 +341,7 @@ helpers._createDebugCheck = function(options) {
output += ' current: \'' + helpers._actual.current(options) + '\',\n'; output += ' current: \'' + helpers._actual.current(options) + '\',\n';
output += ' status: \'' + helpers._actual.status(options) + '\',\n'; output += ' status: \'' + helpers._actual.status(options) + '\',\n';
output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n'; output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n';
output += ' message: \'' + helpers._actual.message(options) + '\',\n'; output += ' error: \'' + helpers._actual.message(options) + '\',\n';
output += ' predictions: ' + outputArray(predictions) + ',\n'; output += ' predictions: ' + outputArray(predictions) + ',\n';
output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n'; output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n';
output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n'; output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n';
@ -378,8 +378,6 @@ helpers._createDebugCheck = function(options) {
output += ' exec: {\n'; output += ' exec: {\n';
output += ' output: \'\',\n'; output += ' output: \'\',\n';
output += ' completed: true,\n'; output += ' completed: true,\n';
output += ' type: \'string\',\n';
output += ' error: false\n';
output += ' }\n'; output += ' }\n';
output += ' }\n'; output += ' }\n';
output += ']);'; output += ']);';
@ -704,7 +702,7 @@ helpers._check = function(options, name, checks) {
*/ */
helpers._exec = function(options, name, expected) { helpers._exec = function(options, name, expected) {
if (expected == null) { if (expected == null) {
return Promise.resolve({}); return Promise.resolve();
} }
var output = options.display.requisition.exec({ hidden: true }); var output = options.display.requisition.exec({ hidden: true });
@ -717,32 +715,20 @@ helpers._exec = function(options, name, expected) {
if (!options.window.document.createElement) { if (!options.window.document.createElement) {
assert.log('skipping output tests (missing doc.createElement) for ' + name); assert.log('skipping output tests (missing doc.createElement) for ' + name);
return Promise.resolve({ output: output }); return Promise.resolve();
} }
if (!('output' in expected)) { if (!('output' in expected)) {
return Promise.resolve({ output: output }); return Promise.resolve();
} }
var deferred = Promise.defer();
var checkOutput = function() { var checkOutput = function() {
var div = options.window.document.createElement('div'); var div = options.window.document.createElement('div');
var conversionContext = options.display.requisition.conversionContext; var nodePromise = converters.convert(output.data, output.type, 'dom',
options.display.requisition.context);
if ('type' in expected) { nodePromise.then(function(node) {
assert.is(output.type,
expected.type,
'output.type for: ' + name);
}
if ('error' in expected) {
assert.is(output.error,
expected.error,
'output.error for: ' + name);
}
var convertPromise = converters.convert(output.data, output.type, 'dom',
conversionContext);
return convertPromise.then(function(node) {
div.appendChild(node); div.appendChild(node);
var actualOutput = div.textContent.trim(); var actualOutput = div.textContent.trim();
@ -771,11 +757,24 @@ helpers._exec = function(options, name, expected) {
doTest(expected.output, actualOutput); doTest(expected.output, actualOutput);
} }
return { output: output, text: actualOutput }; deferred.resolve(actualOutput);
}); });
}; };
return output.promise.then(checkOutput, checkOutput); if (output.completed !== false) {
checkOutput();
}
else {
var changed = function() {
if (output.completed !== false) {
checkOutput();
output.onChange.remove(changed);
}
};
output.onChange.add(changed);
}
return deferred.promise;
}; };
/** /**
@ -790,15 +789,15 @@ helpers._setup = function(options, name, action) {
return Promise.resolve(action()); return Promise.resolve(action());
} }
return Promise.reject('\'setup\' property must be a string or a function. Is ' + action); return Promise.reject('setup must be a string or a function');
}; };
/** /**
* Helper to shutdown the test * Helper to shutdown the test
*/ */
helpers._post = function(name, action, data) { helpers._post = function(name, action, output) {
if (typeof action === 'function') { if (typeof action === 'function') {
return Promise.resolve(action(data.output, data.text)); return Promise.resolve(action(output));
} }
return Promise.resolve(action); return Promise.resolve(action);
}; };
@ -944,22 +943,19 @@ helpers.audit = function(options, audits) {
if (typeof chunkLen !== 'number') { if (typeof chunkLen !== 'number') {
chunkLen = 1; chunkLen = 1;
} }
var responseTime = (new Date().getTime() - start) / chunkLen;
if (assert.currentTest) { totalResponseTime += responseTime;
var responseTime = (new Date().getTime() - start) / chunkLen; if (responseTime > maxResponseTime) {
totalResponseTime += responseTime; maxResponseTime = responseTime;
if (responseTime > maxResponseTime) { maxResponseCulprit = assert.currentTest + '/' + name;
maxResponseTime = responseTime;
maxResponseCulprit = assert.currentTest + '/' + name;
}
averageOver++;
} }
averageOver++;
var checkDone = helpers._check(options, name, audit.check); var checkDone = helpers._check(options, name, audit.check);
return checkDone.then(function() { return checkDone.then(function() {
var execDone = helpers._exec(options, name, audit.exec); var execDone = helpers._exec(options, name, audit.exec);
return execDone.then(function(data) { return execDone.then(function(output) {
return helpers._post(name, audit.post, data).then(function() { return helpers._post(name, audit.post, output).then(function() {
if (assert.testLogging) { if (assert.testLogging) {
log('- END \'' + name + '\' in ' + assert.currentTest); log('- END \'' + name + '\' in ' + assert.currentTest);
} }
@ -967,8 +963,9 @@ helpers.audit = function(options, audits) {
}); });
}); });
}); });
}).then(function() { }).then(null, function(ex) {
return options.display.inputter.setInput(''); console.error(ex.stack);
throw(ex);
}); });
}; };

View File

@ -29,50 +29,127 @@ Cu.import("resource:///modules/devtools/gcli.jsm", {});
var mockCommands = {}; var mockCommands = {};
// We use an alias for exports here because this module is used in Firefox
// mochitests where we don't have define/require
'use strict';
var util = require('util/util'); var util = require('util/util');
var canon = require('gcli/canon'); var canon = require('gcli/canon');
var types = require('gcli/types'); var types = require('gcli/types');
var SelectionType = require('gcli/types/selection').SelectionType;
var DelegateType = require('gcli/types/basic').DelegateType;
mockCommands.option1 = { };
mockCommands.option2 = { };
mockCommands.option3 = { };
mockCommands.optionType = { /**
* Registration and de-registration.
*/
mockCommands.setup = function(opts) {
// setup/shutdown needs to register/unregister types, however that means we
// need to re-initialize mockCommands.option1 and mockCommands.option2 with
// the actual types
mockCommands.option1.type = types.getType('string');
mockCommands.option2.type = types.getType('number');
types.registerType(mockCommands.optionType);
types.registerType(mockCommands.optionValue);
canon.addCommand(mockCommands.tsv);
canon.addCommand(mockCommands.tsr);
canon.addCommand(mockCommands.tso);
canon.addCommand(mockCommands.tse);
canon.addCommand(mockCommands.tsj);
canon.addCommand(mockCommands.tsb);
canon.addCommand(mockCommands.tss);
canon.addCommand(mockCommands.tsu);
canon.addCommand(mockCommands.tsf);
canon.addCommand(mockCommands.tsn);
canon.addCommand(mockCommands.tsnDif);
canon.addCommand(mockCommands.tsnExt);
canon.addCommand(mockCommands.tsnExte);
canon.addCommand(mockCommands.tsnExten);
canon.addCommand(mockCommands.tsnExtend);
canon.addCommand(mockCommands.tsnDeep);
canon.addCommand(mockCommands.tsnDeepDown);
canon.addCommand(mockCommands.tsnDeepDownNested);
canon.addCommand(mockCommands.tsnDeepDownNestedCmd);
canon.addCommand(mockCommands.tselarr);
canon.addCommand(mockCommands.tsm);
canon.addCommand(mockCommands.tsg);
canon.addCommand(mockCommands.tshidden);
canon.addCommand(mockCommands.tscook);
canon.addCommand(mockCommands.tslong);
};
mockCommands.shutdown = function(opts) {
canon.removeCommand(mockCommands.tsv);
canon.removeCommand(mockCommands.tsr);
canon.removeCommand(mockCommands.tso);
canon.removeCommand(mockCommands.tse);
canon.removeCommand(mockCommands.tsj);
canon.removeCommand(mockCommands.tsb);
canon.removeCommand(mockCommands.tss);
canon.removeCommand(mockCommands.tsu);
canon.removeCommand(mockCommands.tsf);
canon.removeCommand(mockCommands.tsn);
canon.removeCommand(mockCommands.tsnDif);
canon.removeCommand(mockCommands.tsnExt);
canon.removeCommand(mockCommands.tsnExte);
canon.removeCommand(mockCommands.tsnExten);
canon.removeCommand(mockCommands.tsnExtend);
canon.removeCommand(mockCommands.tsnDeep);
canon.removeCommand(mockCommands.tsnDeepDown);
canon.removeCommand(mockCommands.tsnDeepDownNested);
canon.removeCommand(mockCommands.tsnDeepDownNestedCmd);
canon.removeCommand(mockCommands.tselarr);
canon.removeCommand(mockCommands.tsm);
canon.removeCommand(mockCommands.tsg);
canon.removeCommand(mockCommands.tshidden);
canon.removeCommand(mockCommands.tscook);
canon.removeCommand(mockCommands.tslong);
types.deregisterType(mockCommands.optionType);
types.deregisterType(mockCommands.optionValue);
};
mockCommands.option1 = { type: types.getType('string') };
mockCommands.option2 = { type: types.getType('number') };
mockCommands.option3 = { type: types.getType({
name: 'selection',
lookup: [
{ name: 'one', value: 1 },
{ name: 'two', value: 2 },
{ name: 'three', value: 3 }
]
})};
mockCommands.optionType = new SelectionType({
name: 'optionType', name: 'optionType',
parent: 'selection',
lookup: [ lookup: [
{ name: 'option1', value: mockCommands.option1 }, { name: 'option1', value: mockCommands.option1 },
{ name: 'option2', value: mockCommands.option2 }, { name: 'option2', value: mockCommands.option2 },
{ name: 'option3', value: mockCommands.option3 } { name: 'option3', value: mockCommands.option3 }
] ]
}; });
mockCommands.optionValue = { mockCommands.optionValue = new DelegateType({
name: 'optionValue', name: 'optionValue',
parent: 'delegate', delegateType: function(context) {
delegateType: function(executionContext) { if (context != null) {
if (executionContext != null) { var option = context.getArgsObject().optionType;
var option = executionContext.getArgsObject().optionType;
if (option != null) { if (option != null) {
return option.type; return option.type;
} }
} }
return types.createType('blank'); return types.getType('blank');
} }
}; });
mockCommands.onCommandExec = util.createEvent('commands.onCommandExec'); mockCommands.onCommandExec = util.createEvent('commands.onCommandExec');
function createExec(name) { function createExec(name) {
return function(args, executionContext) { return function(args, context) {
var data = { var data = {
command: mockCommands[name],
args: args, args: args,
context: executionContext context: context
}; };
mockCommands.onCommandExec(data); mockCommands.onCommandExec(data);
var argsOut = Object.keys(args).map(function(key) { var argsOut = Object.keys(args).map(function(key) {
@ -82,7 +159,7 @@ function createExec(name) {
}; };
} }
var tsv = { mockCommands.tsv = {
name: 'tsv', name: 'tsv',
params: [ params: [
{ name: 'optionType', type: 'optionType' }, { name: 'optionType', type: 'optionType' },
@ -91,19 +168,19 @@ var tsv = {
exec: createExec('tsv') exec: createExec('tsv')
}; };
var tsr = { mockCommands.tsr = {
name: 'tsr', name: 'tsr',
params: [ { name: 'text', type: 'string' } ], params: [ { name: 'text', type: 'string' } ],
exec: createExec('tsr') exec: createExec('tsr')
}; };
var tso = { mockCommands.tso = {
name: 'tso', name: 'tso',
params: [ { name: 'text', type: 'string', defaultValue: null } ], params: [ { name: 'text', type: 'string', defaultValue: null } ],
exec: createExec('tso') exec: createExec('tso')
}; };
var tse = { mockCommands.tse = {
name: 'tse', name: 'tse',
params: [ params: [
{ name: 'node', type: 'node' }, { name: 'node', type: 'node' },
@ -118,88 +195,88 @@ var tse = {
exec: createExec('tse') exec: createExec('tse')
}; };
var tsj = { mockCommands.tsj = {
name: 'tsj', name: 'tsj',
params: [ { name: 'javascript', type: 'javascript' } ], params: [ { name: 'javascript', type: 'javascript' } ],
exec: createExec('tsj') exec: createExec('tsj')
}; };
var tsb = { mockCommands.tsb = {
name: 'tsb', name: 'tsb',
params: [ { name: 'toggle', type: 'boolean' } ], params: [ { name: 'toggle', type: 'boolean' } ],
exec: createExec('tsb') exec: createExec('tsb')
}; };
var tss = { mockCommands.tss = {
name: 'tss', name: 'tss',
exec: createExec('tss') exec: createExec('tss')
}; };
var tsu = { mockCommands.tsu = {
name: 'tsu', name: 'tsu',
params: [ { name: 'num', type: { name: 'number', max: 10, min: -5, step: 3 } } ], params: [ { name: 'num', type: { name: 'number', max: 10, min: -5, step: 3 } } ],
exec: createExec('tsu') exec: createExec('tsu')
}; };
var tsf = { mockCommands.tsf = {
name: 'tsf', name: 'tsf',
params: [ { name: 'num', type: { name: 'number', allowFloat: true, max: 11.5, min: -6.5, step: 1.5 } } ], params: [ { name: 'num', type: { name: 'number', allowFloat: true, max: 11.5, min: -6.5, step: 1.5 } } ],
exec: createExec('tsf') exec: createExec('tsf')
}; };
var tsn = { mockCommands.tsn = {
name: 'tsn' name: 'tsn'
}; };
var tsnDif = { mockCommands.tsnDif = {
name: 'tsn dif', name: 'tsn dif',
description: 'tsn dif', description: 'tsn dif',
params: [ { name: 'text', type: 'string', description: 'tsn dif text' } ], params: [ { name: 'text', type: 'string', description: 'tsn dif text' } ],
exec: createExec('tsnDif') exec: createExec('tsnDif')
}; };
var tsnExt = { mockCommands.tsnExt = {
name: 'tsn ext', name: 'tsn ext',
params: [ { name: 'text', type: 'string' } ], params: [ { name: 'text', type: 'string' } ],
exec: createExec('tsnExt') exec: createExec('tsnExt')
}; };
var tsnExte = { mockCommands.tsnExte = {
name: 'tsn exte', name: 'tsn exte',
params: [ { name: 'text', type: 'string' } ], params: [ { name: 'text', type: 'string' } ],
exec: createExec('tsnExte') exec: createExec('tsnExte')
}; };
var tsnExten = { mockCommands.tsnExten = {
name: 'tsn exten', name: 'tsn exten',
params: [ { name: 'text', type: 'string' } ], params: [ { name: 'text', type: 'string' } ],
exec: createExec('tsnExten') exec: createExec('tsnExten')
}; };
var tsnExtend = { mockCommands.tsnExtend = {
name: 'tsn extend', name: 'tsn extend',
params: [ { name: 'text', type: 'string' } ], params: [ { name: 'text', type: 'string' } ],
exec: createExec('tsnExtend') exec: createExec('tsnExtend')
}; };
var tsnDeep = { mockCommands.tsnDeep = {
name: 'tsn deep' name: 'tsn deep'
}; };
var tsnDeepDown = { mockCommands.tsnDeepDown = {
name: 'tsn deep down' name: 'tsn deep down'
}; };
var tsnDeepDownNested = { mockCommands.tsnDeepDownNested = {
name: 'tsn deep down nested' name: 'tsn deep down nested'
}; };
var tsnDeepDownNestedCmd = { mockCommands.tsnDeepDownNestedCmd = {
name: 'tsn deep down nested cmd', name: 'tsn deep down nested cmd',
exec: createExec('tsnDeepDownNestedCmd') exec: createExec('tsnDeepDownNestedCmd')
}; };
var tshidden = { mockCommands.tshidden = {
name: 'tshidden', name: 'tshidden',
hidden: true, hidden: true,
params: [ params: [
@ -231,7 +308,7 @@ var tshidden = {
exec: createExec('tshidden') exec: createExec('tshidden')
}; };
var tselarr = { mockCommands.tselarr = {
name: 'tselarr', name: 'tselarr',
params: [ params: [
{ name: 'num', type: { name: 'selection', data: [ '1', '2', '3' ] } }, { name: 'num', type: { name: 'selection', data: [ '1', '2', '3' ] } },
@ -240,7 +317,7 @@ var tselarr = {
exec: createExec('tselarr') exec: createExec('tselarr')
}; };
var tsm = { mockCommands.tsm = {
name: 'tsm', name: 'tsm',
description: 'a 3-param test selection|string|number', description: 'a 3-param test selection|string|number',
params: [ params: [
@ -251,7 +328,7 @@ var tsm = {
exec: createExec('tsm') exec: createExec('tsm')
}; };
var tsg = { mockCommands.tsg = {
name: 'tsg', name: 'tsg',
description: 'a param group test', description: 'a param group test',
params: [ params: [
@ -294,7 +371,7 @@ var tsg = {
exec: createExec('tsg') exec: createExec('tsg')
}; };
var tscook = { mockCommands.tscook = {
name: 'tscook', name: 'tscook',
description: 'param group test to catch problems with cookie command', description: 'param group test to catch problems with cookie command',
params: [ params: [
@ -334,9 +411,10 @@ var tscook = {
exec: createExec('tscook') exec: createExec('tscook')
}; };
var tslong = { mockCommands.tslong = {
name: 'tslong', name: 'tslong',
description: 'long param tests to catch problems with the jsb command', description: 'long param tests to catch problems with the jsb command',
returnValue:'string',
params: [ params: [
{ {
name: 'msg', name: 'msg',
@ -395,146 +473,5 @@ var tslong = {
exec: createExec('tslong') exec: createExec('tslong')
}; };
var tsfail = {
name: 'tsfail',
description: 'test errors',
params: [
{
name: 'method',
type: {
name: 'selection',
data: [
'reject', 'rejecttyped',
'throwerror', 'throwstring', 'throwinpromise',
'noerror'
]
}
}
],
exec: function(args, context) {
if (args.method === 'reject') {
var deferred = context.defer();
setTimeout(function() {
deferred.reject('rejected promise');
}, 10);
return deferred.promise;
}
if (args.method === 'rejecttyped') {
var deferred = context.defer();
setTimeout(function() {
deferred.reject(context.typedData('number', 54));
}, 10);
return deferred.promise;
}
if (args.method === 'throwinpromise') {
var deferred = context.defer();
setTimeout(function() {
deferred.resolve('should be lost');
}, 10);
return deferred.promise.then(function() {
var t = null;
return t.foo;
});
}
if (args.method === 'throwerror') {
throw new Error('thrown error');
}
if (args.method === 'throwstring') {
throw 'thrown string';
}
return 'no error';
}
};
mockCommands.commands = {};
/**
* Registration and de-registration.
*/
mockCommands.setup = function(opts) {
// setup/shutdown needs to register/unregister types, however that means we
// need to re-initialize mockCommands.option1 and mockCommands.option2 with
// the actual types
mockCommands.option1.type = types.createType('string');
mockCommands.option2.type = types.createType('number');
mockCommands.option3.type = types.createType({
name: 'selection',
lookup: [
{ name: 'one', value: 1 },
{ name: 'two', value: 2 },
{ name: 'three', value: 3 }
]
});
types.addType(mockCommands.optionType);
types.addType(mockCommands.optionValue);
mockCommands.commands.tsv = canon.addCommand(tsv);
mockCommands.commands.tsr = canon.addCommand(tsr);
mockCommands.commands.tso = canon.addCommand(tso);
mockCommands.commands.tse = canon.addCommand(tse);
mockCommands.commands.tsj = canon.addCommand(tsj);
mockCommands.commands.tsb = canon.addCommand(tsb);
mockCommands.commands.tss = canon.addCommand(tss);
mockCommands.commands.tsu = canon.addCommand(tsu);
mockCommands.commands.tsf = canon.addCommand(tsf);
mockCommands.commands.tsn = canon.addCommand(tsn);
mockCommands.commands.tsnDif = canon.addCommand(tsnDif);
mockCommands.commands.tsnExt = canon.addCommand(tsnExt);
mockCommands.commands.tsnExte = canon.addCommand(tsnExte);
mockCommands.commands.tsnExten = canon.addCommand(tsnExten);
mockCommands.commands.tsnExtend = canon.addCommand(tsnExtend);
mockCommands.commands.tsnDeep = canon.addCommand(tsnDeep);
mockCommands.commands.tsnDeepDown = canon.addCommand(tsnDeepDown);
mockCommands.commands.tsnDeepDownNested = canon.addCommand(tsnDeepDownNested);
mockCommands.commands.tsnDeepDownNestedCmd = canon.addCommand(tsnDeepDownNestedCmd);
mockCommands.commands.tselarr = canon.addCommand(tselarr);
mockCommands.commands.tsm = canon.addCommand(tsm);
mockCommands.commands.tsg = canon.addCommand(tsg);
mockCommands.commands.tshidden = canon.addCommand(tshidden);
mockCommands.commands.tscook = canon.addCommand(tscook);
mockCommands.commands.tslong = canon.addCommand(tslong);
mockCommands.commands.tsfail = canon.addCommand(tsfail);
};
mockCommands.shutdown = function(opts) {
canon.removeCommand(tsv);
canon.removeCommand(tsr);
canon.removeCommand(tso);
canon.removeCommand(tse);
canon.removeCommand(tsj);
canon.removeCommand(tsb);
canon.removeCommand(tss);
canon.removeCommand(tsu);
canon.removeCommand(tsf);
canon.removeCommand(tsn);
canon.removeCommand(tsnDif);
canon.removeCommand(tsnExt);
canon.removeCommand(tsnExte);
canon.removeCommand(tsnExten);
canon.removeCommand(tsnExtend);
canon.removeCommand(tsnDeep);
canon.removeCommand(tsnDeepDown);
canon.removeCommand(tsnDeepDownNested);
canon.removeCommand(tsnDeepDownNestedCmd);
canon.removeCommand(tselarr);
canon.removeCommand(tsm);
canon.removeCommand(tsg);
canon.removeCommand(tshidden);
canon.removeCommand(tscook);
canon.removeCommand(tslong);
canon.removeCommand(tsfail);
types.removeType(mockCommands.optionType);
types.removeType(mockCommands.optionValue);
mockCommands.commands = {};
};
// }); // });

View File

@ -157,7 +157,7 @@ gcli.addCommand({
description: gcli.lookup("breakaddlineLineDesc") description: gcli.lookup("breakaddlineLineDesc")
} }
], ],
returnType: "string", returnType: "html",
exec: function(args, context) { exec: function(args, context) {
args.type = "line"; args.type = "line";
@ -201,7 +201,7 @@ gcli.addCommand({
description: gcli.lookup("breakdelBreakidDesc") description: gcli.lookup("breakdelBreakidDesc")
} }
], ],
returnType: "string", returnType: "html",
exec: function(args, context) { exec: function(args, context) {
let dbg = getPanel(context, "jsdebugger"); let dbg = getPanel(context, "jsdebugger");
if (!dbg) { if (!dbg) {
@ -381,7 +381,7 @@ gcli.addCommand({
name: "dbg list", name: "dbg list",
description: gcli.lookup("dbgListSourcesDesc"), description: gcli.lookup("dbgListSourcesDesc"),
params: [], params: [],
returnType: "dom", returnType: "html",
exec: function(args, context) { exec: function(args, context) {
let dbg = getPanel(context, "jsdebugger"); let dbg = getPanel(context, "jsdebugger");
let doc = context.environment.chromeDocument; let doc = context.environment.chromeDocument;

View File

@ -24,7 +24,8 @@ let require = (Cu.import("resource://gre/modules/devtools/Require.jsm", {})).req
Components.utils.import("resource:///modules/devtools/gcli.jsm", {}); Components.utils.import("resource:///modules/devtools/gcli.jsm", {});
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console; let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
let TargetFactory = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools.TargetFactory; let devtools = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools;
let TargetFactory = devtools.TargetFactory;
let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise; let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise;
let assert = { ok: ok, is: is, log: info }; let assert = { ok: ok, is: is, log: info };
@ -157,7 +158,6 @@ helpers.runTests = function(options, tests) {
}); });
var recover = function(error) { var recover = function(error) {
ok(false, error);
console.error(error); console.error(error);
}; };
@ -341,7 +341,7 @@ helpers._createDebugCheck = function(options) {
output += ' current: \'' + helpers._actual.current(options) + '\',\n'; output += ' current: \'' + helpers._actual.current(options) + '\',\n';
output += ' status: \'' + helpers._actual.status(options) + '\',\n'; output += ' status: \'' + helpers._actual.status(options) + '\',\n';
output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n'; output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n';
output += ' message: \'' + helpers._actual.message(options) + '\',\n'; output += ' error: \'' + helpers._actual.message(options) + '\',\n';
output += ' predictions: ' + outputArray(predictions) + ',\n'; output += ' predictions: ' + outputArray(predictions) + ',\n';
output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n'; output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n';
output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n'; output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n';
@ -378,8 +378,6 @@ helpers._createDebugCheck = function(options) {
output += ' exec: {\n'; output += ' exec: {\n';
output += ' output: \'\',\n'; output += ' output: \'\',\n';
output += ' completed: true,\n'; output += ' completed: true,\n';
output += ' type: \'string\',\n';
output += ' error: false\n';
output += ' }\n'; output += ' }\n';
output += ' }\n'; output += ' }\n';
output += ']);'; output += ']);';
@ -704,7 +702,7 @@ helpers._check = function(options, name, checks) {
*/ */
helpers._exec = function(options, name, expected) { helpers._exec = function(options, name, expected) {
if (expected == null) { if (expected == null) {
return Promise.resolve({}); return Promise.resolve();
} }
var output = options.display.requisition.exec({ hidden: true }); var output = options.display.requisition.exec({ hidden: true });
@ -717,32 +715,20 @@ helpers._exec = function(options, name, expected) {
if (!options.window.document.createElement) { if (!options.window.document.createElement) {
assert.log('skipping output tests (missing doc.createElement) for ' + name); assert.log('skipping output tests (missing doc.createElement) for ' + name);
return Promise.resolve({ output: output }); return Promise.resolve();
} }
if (!('output' in expected)) { if (!('output' in expected)) {
return Promise.resolve({ output: output }); return Promise.resolve();
} }
var deferred = Promise.defer();
var checkOutput = function() { var checkOutput = function() {
var div = options.window.document.createElement('div'); var div = options.window.document.createElement('div');
var conversionContext = options.display.requisition.conversionContext; var nodePromise = converters.convert(output.data, output.type, 'dom',
options.display.requisition.context);
if ('type' in expected) { nodePromise.then(function(node) {
assert.is(output.type,
expected.type,
'output.type for: ' + name);
}
if ('error' in expected) {
assert.is(output.error,
expected.error,
'output.error for: ' + name);
}
var convertPromise = converters.convert(output.data, output.type, 'dom',
conversionContext);
return convertPromise.then(function(node) {
div.appendChild(node); div.appendChild(node);
var actualOutput = div.textContent.trim(); var actualOutput = div.textContent.trim();
@ -771,11 +757,24 @@ helpers._exec = function(options, name, expected) {
doTest(expected.output, actualOutput); doTest(expected.output, actualOutput);
} }
return { output: output, text: actualOutput }; deferred.resolve(actualOutput);
}); });
}; };
return output.promise.then(checkOutput, checkOutput); if (output.completed !== false) {
checkOutput();
}
else {
var changed = function() {
if (output.completed !== false) {
checkOutput();
output.onChange.remove(changed);
}
};
output.onChange.add(changed);
}
return deferred.promise;
}; };
/** /**
@ -790,15 +789,15 @@ helpers._setup = function(options, name, action) {
return Promise.resolve(action()); return Promise.resolve(action());
} }
return Promise.reject('\'setup\' property must be a string or a function. Is ' + action); return Promise.reject('setup must be a string or a function');
}; };
/** /**
* Helper to shutdown the test * Helper to shutdown the test
*/ */
helpers._post = function(name, action, data) { helpers._post = function(name, action, output) {
if (typeof action === 'function') { if (typeof action === 'function') {
return Promise.resolve(action(data.output, data.text)); return Promise.resolve(action(output));
} }
return Promise.resolve(action); return Promise.resolve(action);
}; };
@ -944,22 +943,19 @@ helpers.audit = function(options, audits) {
if (typeof chunkLen !== 'number') { if (typeof chunkLen !== 'number') {
chunkLen = 1; chunkLen = 1;
} }
var responseTime = (new Date().getTime() - start) / chunkLen;
if (assert.currentTest) { totalResponseTime += responseTime;
var responseTime = (new Date().getTime() - start) / chunkLen; if (responseTime > maxResponseTime) {
totalResponseTime += responseTime; maxResponseTime = responseTime;
if (responseTime > maxResponseTime) { maxResponseCulprit = assert.currentTest + '/' + name;
maxResponseTime = responseTime;
maxResponseCulprit = assert.currentTest + '/' + name;
}
averageOver++;
} }
averageOver++;
var checkDone = helpers._check(options, name, audit.check); var checkDone = helpers._check(options, name, audit.check);
return checkDone.then(function() { return checkDone.then(function() {
var execDone = helpers._exec(options, name, audit.exec); var execDone = helpers._exec(options, name, audit.exec);
return execDone.then(function(data) { return execDone.then(function(output) {
return helpers._post(name, audit.post, data).then(function() { return helpers._post(name, audit.post, output).then(function() {
if (assert.testLogging) { if (assert.testLogging) {
log('- END \'' + name + '\' in ' + assert.currentTest); log('- END \'' + name + '\' in ' + assert.currentTest);
} }
@ -967,8 +963,9 @@ helpers.audit = function(options, audits) {
}); });
}); });
}); });
}).then(function() { }).then(null, function(ex) {
return options.display.inputter.setInput(''); console.error(ex.stack);
throw(ex);
}); });
}; };

View File

@ -24,7 +24,8 @@ let require = (Cu.import("resource://gre/modules/devtools/Require.jsm", {})).req
Components.utils.import("resource:///modules/devtools/gcli.jsm", {}); Components.utils.import("resource:///modules/devtools/gcli.jsm", {});
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console; let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
let TargetFactory = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools.TargetFactory; let devtools = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools;
let TargetFactory = devtools.TargetFactory;
let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise; let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise;
let assert = { ok: ok, is: is, log: info }; let assert = { ok: ok, is: is, log: info };
@ -157,7 +158,6 @@ helpers.runTests = function(options, tests) {
}); });
var recover = function(error) { var recover = function(error) {
ok(false, error);
console.error(error); console.error(error);
}; };
@ -341,7 +341,7 @@ helpers._createDebugCheck = function(options) {
output += ' current: \'' + helpers._actual.current(options) + '\',\n'; output += ' current: \'' + helpers._actual.current(options) + '\',\n';
output += ' status: \'' + helpers._actual.status(options) + '\',\n'; output += ' status: \'' + helpers._actual.status(options) + '\',\n';
output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n'; output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n';
output += ' message: \'' + helpers._actual.message(options) + '\',\n'; output += ' error: \'' + helpers._actual.message(options) + '\',\n';
output += ' predictions: ' + outputArray(predictions) + ',\n'; output += ' predictions: ' + outputArray(predictions) + ',\n';
output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n'; output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n';
output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n'; output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n';
@ -378,8 +378,6 @@ helpers._createDebugCheck = function(options) {
output += ' exec: {\n'; output += ' exec: {\n';
output += ' output: \'\',\n'; output += ' output: \'\',\n';
output += ' completed: true,\n'; output += ' completed: true,\n';
output += ' type: \'string\',\n';
output += ' error: false\n';
output += ' }\n'; output += ' }\n';
output += ' }\n'; output += ' }\n';
output += ']);'; output += ']);';
@ -704,7 +702,7 @@ helpers._check = function(options, name, checks) {
*/ */
helpers._exec = function(options, name, expected) { helpers._exec = function(options, name, expected) {
if (expected == null) { if (expected == null) {
return Promise.resolve({}); return Promise.resolve();
} }
var output = options.display.requisition.exec({ hidden: true }); var output = options.display.requisition.exec({ hidden: true });
@ -717,32 +715,20 @@ helpers._exec = function(options, name, expected) {
if (!options.window.document.createElement) { if (!options.window.document.createElement) {
assert.log('skipping output tests (missing doc.createElement) for ' + name); assert.log('skipping output tests (missing doc.createElement) for ' + name);
return Promise.resolve({ output: output }); return Promise.resolve();
} }
if (!('output' in expected)) { if (!('output' in expected)) {
return Promise.resolve({ output: output }); return Promise.resolve();
} }
var deferred = Promise.defer();
var checkOutput = function() { var checkOutput = function() {
var div = options.window.document.createElement('div'); var div = options.window.document.createElement('div');
var conversionContext = options.display.requisition.conversionContext; var nodePromise = converters.convert(output.data, output.type, 'dom',
options.display.requisition.context);
if ('type' in expected) { nodePromise.then(function(node) {
assert.is(output.type,
expected.type,
'output.type for: ' + name);
}
if ('error' in expected) {
assert.is(output.error,
expected.error,
'output.error for: ' + name);
}
var convertPromise = converters.convert(output.data, output.type, 'dom',
conversionContext);
return convertPromise.then(function(node) {
div.appendChild(node); div.appendChild(node);
var actualOutput = div.textContent.trim(); var actualOutput = div.textContent.trim();
@ -771,11 +757,24 @@ helpers._exec = function(options, name, expected) {
doTest(expected.output, actualOutput); doTest(expected.output, actualOutput);
} }
return { output: output, text: actualOutput }; deferred.resolve(actualOutput);
}); });
}; };
return output.promise.then(checkOutput, checkOutput); if (output.completed !== false) {
checkOutput();
}
else {
var changed = function() {
if (output.completed !== false) {
checkOutput();
output.onChange.remove(changed);
}
};
output.onChange.add(changed);
}
return deferred.promise;
}; };
/** /**
@ -790,15 +789,15 @@ helpers._setup = function(options, name, action) {
return Promise.resolve(action()); return Promise.resolve(action());
} }
return Promise.reject('\'setup\' property must be a string or a function. Is ' + action); return Promise.reject('setup must be a string or a function');
}; };
/** /**
* Helper to shutdown the test * Helper to shutdown the test
*/ */
helpers._post = function(name, action, data) { helpers._post = function(name, action, output) {
if (typeof action === 'function') { if (typeof action === 'function') {
return Promise.resolve(action(data.output, data.text)); return Promise.resolve(action(output));
} }
return Promise.resolve(action); return Promise.resolve(action);
}; };
@ -944,22 +943,19 @@ helpers.audit = function(options, audits) {
if (typeof chunkLen !== 'number') { if (typeof chunkLen !== 'number') {
chunkLen = 1; chunkLen = 1;
} }
var responseTime = (new Date().getTime() - start) / chunkLen;
if (assert.currentTest) { totalResponseTime += responseTime;
var responseTime = (new Date().getTime() - start) / chunkLen; if (responseTime > maxResponseTime) {
totalResponseTime += responseTime; maxResponseTime = responseTime;
if (responseTime > maxResponseTime) { maxResponseCulprit = assert.currentTest + '/' + name;
maxResponseTime = responseTime;
maxResponseCulprit = assert.currentTest + '/' + name;
}
averageOver++;
} }
averageOver++;
var checkDone = helpers._check(options, name, audit.check); var checkDone = helpers._check(options, name, audit.check);
return checkDone.then(function() { return checkDone.then(function() {
var execDone = helpers._exec(options, name, audit.exec); var execDone = helpers._exec(options, name, audit.exec);
return execDone.then(function(data) { return execDone.then(function(output) {
return helpers._post(name, audit.post, data).then(function() { return helpers._post(name, audit.post, output).then(function() {
if (assert.testLogging) { if (assert.testLogging) {
log('- END \'' + name + '\' in ' + assert.currentTest); log('- END \'' + name + '\' in ' + assert.currentTest);
} }
@ -967,8 +963,9 @@ helpers.audit = function(options, audits) {
}); });
}); });
}); });
}).then(function() { }).then(null, function(ex) {
return options.display.inputter.setInput(''); console.error(ex.stack);
throw(ex);
}); });
}; };

View File

@ -24,7 +24,8 @@ let require = (Cu.import("resource://gre/modules/devtools/Require.jsm", {})).req
Components.utils.import("resource:///modules/devtools/gcli.jsm", {}); Components.utils.import("resource:///modules/devtools/gcli.jsm", {});
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console; let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
let TargetFactory = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools.TargetFactory; let devtools = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools;
let TargetFactory = devtools.TargetFactory;
let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise; let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise;
let assert = { ok: ok, is: is, log: info }; let assert = { ok: ok, is: is, log: info };
@ -157,7 +158,6 @@ helpers.runTests = function(options, tests) {
}); });
var recover = function(error) { var recover = function(error) {
ok(false, error);
console.error(error); console.error(error);
}; };
@ -341,7 +341,7 @@ helpers._createDebugCheck = function(options) {
output += ' current: \'' + helpers._actual.current(options) + '\',\n'; output += ' current: \'' + helpers._actual.current(options) + '\',\n';
output += ' status: \'' + helpers._actual.status(options) + '\',\n'; output += ' status: \'' + helpers._actual.status(options) + '\',\n';
output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n'; output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n';
output += ' message: \'' + helpers._actual.message(options) + '\',\n'; output += ' error: \'' + helpers._actual.message(options) + '\',\n';
output += ' predictions: ' + outputArray(predictions) + ',\n'; output += ' predictions: ' + outputArray(predictions) + ',\n';
output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n'; output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n';
output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n'; output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n';
@ -378,8 +378,6 @@ helpers._createDebugCheck = function(options) {
output += ' exec: {\n'; output += ' exec: {\n';
output += ' output: \'\',\n'; output += ' output: \'\',\n';
output += ' completed: true,\n'; output += ' completed: true,\n';
output += ' type: \'string\',\n';
output += ' error: false\n';
output += ' }\n'; output += ' }\n';
output += ' }\n'; output += ' }\n';
output += ']);'; output += ']);';
@ -704,7 +702,7 @@ helpers._check = function(options, name, checks) {
*/ */
helpers._exec = function(options, name, expected) { helpers._exec = function(options, name, expected) {
if (expected == null) { if (expected == null) {
return Promise.resolve({}); return Promise.resolve();
} }
var output = options.display.requisition.exec({ hidden: true }); var output = options.display.requisition.exec({ hidden: true });
@ -717,32 +715,20 @@ helpers._exec = function(options, name, expected) {
if (!options.window.document.createElement) { if (!options.window.document.createElement) {
assert.log('skipping output tests (missing doc.createElement) for ' + name); assert.log('skipping output tests (missing doc.createElement) for ' + name);
return Promise.resolve({ output: output }); return Promise.resolve();
} }
if (!('output' in expected)) { if (!('output' in expected)) {
return Promise.resolve({ output: output }); return Promise.resolve();
} }
var deferred = Promise.defer();
var checkOutput = function() { var checkOutput = function() {
var div = options.window.document.createElement('div'); var div = options.window.document.createElement('div');
var conversionContext = options.display.requisition.conversionContext; var nodePromise = converters.convert(output.data, output.type, 'dom',
options.display.requisition.context);
if ('type' in expected) { nodePromise.then(function(node) {
assert.is(output.type,
expected.type,
'output.type for: ' + name);
}
if ('error' in expected) {
assert.is(output.error,
expected.error,
'output.error for: ' + name);
}
var convertPromise = converters.convert(output.data, output.type, 'dom',
conversionContext);
return convertPromise.then(function(node) {
div.appendChild(node); div.appendChild(node);
var actualOutput = div.textContent.trim(); var actualOutput = div.textContent.trim();
@ -771,11 +757,24 @@ helpers._exec = function(options, name, expected) {
doTest(expected.output, actualOutput); doTest(expected.output, actualOutput);
} }
return { output: output, text: actualOutput }; deferred.resolve(actualOutput);
}); });
}; };
return output.promise.then(checkOutput, checkOutput); if (output.completed !== false) {
checkOutput();
}
else {
var changed = function() {
if (output.completed !== false) {
checkOutput();
output.onChange.remove(changed);
}
};
output.onChange.add(changed);
}
return deferred.promise;
}; };
/** /**
@ -790,15 +789,15 @@ helpers._setup = function(options, name, action) {
return Promise.resolve(action()); return Promise.resolve(action());
} }
return Promise.reject('\'setup\' property must be a string or a function. Is ' + action); return Promise.reject('setup must be a string or a function');
}; };
/** /**
* Helper to shutdown the test * Helper to shutdown the test
*/ */
helpers._post = function(name, action, data) { helpers._post = function(name, action, output) {
if (typeof action === 'function') { if (typeof action === 'function') {
return Promise.resolve(action(data.output, data.text)); return Promise.resolve(action(output));
} }
return Promise.resolve(action); return Promise.resolve(action);
}; };
@ -944,22 +943,19 @@ helpers.audit = function(options, audits) {
if (typeof chunkLen !== 'number') { if (typeof chunkLen !== 'number') {
chunkLen = 1; chunkLen = 1;
} }
var responseTime = (new Date().getTime() - start) / chunkLen;
if (assert.currentTest) { totalResponseTime += responseTime;
var responseTime = (new Date().getTime() - start) / chunkLen; if (responseTime > maxResponseTime) {
totalResponseTime += responseTime; maxResponseTime = responseTime;
if (responseTime > maxResponseTime) { maxResponseCulprit = assert.currentTest + '/' + name;
maxResponseTime = responseTime;
maxResponseCulprit = assert.currentTest + '/' + name;
}
averageOver++;
} }
averageOver++;
var checkDone = helpers._check(options, name, audit.check); var checkDone = helpers._check(options, name, audit.check);
return checkDone.then(function() { return checkDone.then(function() {
var execDone = helpers._exec(options, name, audit.exec); var execDone = helpers._exec(options, name, audit.exec);
return execDone.then(function(data) { return execDone.then(function(output) {
return helpers._post(name, audit.post, data).then(function() { return helpers._post(name, audit.post, output).then(function() {
if (assert.testLogging) { if (assert.testLogging) {
log('- END \'' + name + '\' in ' + assert.currentTest); log('- END \'' + name + '\' in ' + assert.currentTest);
} }
@ -967,8 +963,9 @@ helpers.audit = function(options, audits) {
}); });
}); });
}); });
}).then(function() { }).then(null, function(ex) {
return options.display.inputter.setInput(''); console.error(ex.stack);
throw(ex);
}); });
}; };

View File

@ -153,7 +153,7 @@ let CommandUtils = {
createEnvironment: function(chromeDocument, contentDocument) { createEnvironment: function(chromeDocument, contentDocument) {
let environment = { let environment = {
chromeDocument: chromeDocument, chromeDocument: chromeDocument,
chromeWindow: chromeDocument.defaultView, contentDocument: contentDocument, // Use of contentDocument is deprecated
document: contentDocument, document: contentDocument,
window: contentDocument.defaultView window: contentDocument.defaultView
@ -761,7 +761,6 @@ function OutputPanel(aDevToolbar, aLoadCallback)
this.displayedOutput = undefined; this.displayedOutput = undefined;
this._onload = this._onload.bind(this); this._onload = this._onload.bind(this);
this._update = this._update.bind(this);
this._frame.addEventListener("load", this._onload, true); this._frame.addEventListener("load", this._onload, true);
this.loaded = false; this.loaded = false;
@ -907,28 +906,18 @@ OutputPanel.prototype._outputChanged = function OP_outputChanged(aEvent)
this.remove(); this.remove();
this.displayedOutput = aEvent.output; this.displayedOutput = aEvent.output;
this.displayedOutput.onClose.add(this.remove, this); this.update();
if (this.displayedOutput.completed) { this.displayedOutput.onChange.add(this.update, this);
this._update(); this.displayedOutput.onClose.add(this.remove, this);
}
else {
this.displayedOutput.promise.then(this._update, this._update)
.then(null, console.error);
}
}; };
/** /**
* Called when displayed Output says it's changed or from outputChanged, which * Called when displayed Output says it's changed or from outputChanged, which
* happens when there is a new displayed Output. * happens when there is a new displayed Output.
*/ */
OutputPanel.prototype._update = function OP_update() OutputPanel.prototype.update = function OP_update()
{ {
// destroy has been called, bail out
if (this._div == null) {
return;
}
// Empty this._div // Empty this._div
while (this._div.hasChildNodes()) { while (this._div.hasChildNodes()) {
this._div.removeChild(this._div.firstChild); this._div.removeChild(this._div.firstChild);
@ -938,7 +927,7 @@ OutputPanel.prototype._update = function OP_update()
let requisition = this._devtoolbar.display.requisition; let requisition = this._devtoolbar.display.requisition;
let nodePromise = converters.convert(this.displayedOutput.data, let nodePromise = converters.convert(this.displayedOutput.data,
this.displayedOutput.type, 'dom', this.displayedOutput.type, 'dom',
requisition.conversionContext); requisition.context);
nodePromise.then(function(node) { nodePromise.then(function(node) {
while (this._div.hasChildNodes()) { while (this._div.hasChildNodes()) {
this._div.removeChild(this._div.firstChild); this._div.removeChild(this._div.firstChild);
@ -969,6 +958,7 @@ OutputPanel.prototype.remove = function OP_remove()
} }
if (this.displayedOutput) { if (this.displayedOutput) {
this.displayedOutput.onChange.remove(this.update, this);
this.displayedOutput.onClose.remove(this.remove, this); this.displayedOutput.onClose.remove(this.remove, this);
delete this.displayedOutput; delete this.displayedOutput;
} }

View File

@ -24,7 +24,8 @@ let require = (Cu.import("resource://gre/modules/devtools/Require.jsm", {})).req
Components.utils.import("resource:///modules/devtools/gcli.jsm", {}); Components.utils.import("resource:///modules/devtools/gcli.jsm", {});
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console; let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
let TargetFactory = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools.TargetFactory; let devtools = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools;
let TargetFactory = devtools.TargetFactory;
let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise; let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise;
let assert = { ok: ok, is: is, log: info }; let assert = { ok: ok, is: is, log: info };
@ -157,7 +158,6 @@ helpers.runTests = function(options, tests) {
}); });
var recover = function(error) { var recover = function(error) {
ok(false, error);
console.error(error); console.error(error);
}; };
@ -341,7 +341,7 @@ helpers._createDebugCheck = function(options) {
output += ' current: \'' + helpers._actual.current(options) + '\',\n'; output += ' current: \'' + helpers._actual.current(options) + '\',\n';
output += ' status: \'' + helpers._actual.status(options) + '\',\n'; output += ' status: \'' + helpers._actual.status(options) + '\',\n';
output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n'; output += ' options: ' + outputArray(helpers._actual.options(options)) + ',\n';
output += ' message: \'' + helpers._actual.message(options) + '\',\n'; output += ' error: \'' + helpers._actual.message(options) + '\',\n';
output += ' predictions: ' + outputArray(predictions) + ',\n'; output += ' predictions: ' + outputArray(predictions) + ',\n';
output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n'; output += ' unassigned: ' + outputArray(requisition._unassigned) + ',\n';
output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n'; output += ' outputState: \'' + helpers._actual.outputState(options) + '\',\n';
@ -378,8 +378,6 @@ helpers._createDebugCheck = function(options) {
output += ' exec: {\n'; output += ' exec: {\n';
output += ' output: \'\',\n'; output += ' output: \'\',\n';
output += ' completed: true,\n'; output += ' completed: true,\n';
output += ' type: \'string\',\n';
output += ' error: false\n';
output += ' }\n'; output += ' }\n';
output += ' }\n'; output += ' }\n';
output += ']);'; output += ']);';
@ -704,7 +702,7 @@ helpers._check = function(options, name, checks) {
*/ */
helpers._exec = function(options, name, expected) { helpers._exec = function(options, name, expected) {
if (expected == null) { if (expected == null) {
return Promise.resolve({}); return Promise.resolve();
} }
var output = options.display.requisition.exec({ hidden: true }); var output = options.display.requisition.exec({ hidden: true });
@ -717,32 +715,20 @@ helpers._exec = function(options, name, expected) {
if (!options.window.document.createElement) { if (!options.window.document.createElement) {
assert.log('skipping output tests (missing doc.createElement) for ' + name); assert.log('skipping output tests (missing doc.createElement) for ' + name);
return Promise.resolve({ output: output }); return Promise.resolve();
} }
if (!('output' in expected)) { if (!('output' in expected)) {
return Promise.resolve({ output: output }); return Promise.resolve();
} }
var deferred = Promise.defer();
var checkOutput = function() { var checkOutput = function() {
var div = options.window.document.createElement('div'); var div = options.window.document.createElement('div');
var conversionContext = options.display.requisition.conversionContext; var nodePromise = converters.convert(output.data, output.type, 'dom',
options.display.requisition.context);
if ('type' in expected) { nodePromise.then(function(node) {
assert.is(output.type,
expected.type,
'output.type for: ' + name);
}
if ('error' in expected) {
assert.is(output.error,
expected.error,
'output.error for: ' + name);
}
var convertPromise = converters.convert(output.data, output.type, 'dom',
conversionContext);
return convertPromise.then(function(node) {
div.appendChild(node); div.appendChild(node);
var actualOutput = div.textContent.trim(); var actualOutput = div.textContent.trim();
@ -771,11 +757,24 @@ helpers._exec = function(options, name, expected) {
doTest(expected.output, actualOutput); doTest(expected.output, actualOutput);
} }
return { output: output, text: actualOutput }; deferred.resolve(actualOutput);
}); });
}; };
return output.promise.then(checkOutput, checkOutput); if (output.completed !== false) {
checkOutput();
}
else {
var changed = function() {
if (output.completed !== false) {
checkOutput();
output.onChange.remove(changed);
}
};
output.onChange.add(changed);
}
return deferred.promise;
}; };
/** /**
@ -790,15 +789,15 @@ helpers._setup = function(options, name, action) {
return Promise.resolve(action()); return Promise.resolve(action());
} }
return Promise.reject('\'setup\' property must be a string or a function. Is ' + action); return Promise.reject('setup must be a string or a function');
}; };
/** /**
* Helper to shutdown the test * Helper to shutdown the test
*/ */
helpers._post = function(name, action, data) { helpers._post = function(name, action, output) {
if (typeof action === 'function') { if (typeof action === 'function') {
return Promise.resolve(action(data.output, data.text)); return Promise.resolve(action(output));
} }
return Promise.resolve(action); return Promise.resolve(action);
}; };
@ -944,22 +943,19 @@ helpers.audit = function(options, audits) {
if (typeof chunkLen !== 'number') { if (typeof chunkLen !== 'number') {
chunkLen = 1; chunkLen = 1;
} }
var responseTime = (new Date().getTime() - start) / chunkLen;
if (assert.currentTest) { totalResponseTime += responseTime;
var responseTime = (new Date().getTime() - start) / chunkLen; if (responseTime > maxResponseTime) {
totalResponseTime += responseTime; maxResponseTime = responseTime;
if (responseTime > maxResponseTime) { maxResponseCulprit = assert.currentTest + '/' + name;
maxResponseTime = responseTime;
maxResponseCulprit = assert.currentTest + '/' + name;
}
averageOver++;
} }
averageOver++;
var checkDone = helpers._check(options, name, audit.check); var checkDone = helpers._check(options, name, audit.check);
return checkDone.then(function() { return checkDone.then(function() {
var execDone = helpers._exec(options, name, audit.exec); var execDone = helpers._exec(options, name, audit.exec);
return execDone.then(function(data) { return execDone.then(function(output) {
return helpers._post(name, audit.post, data).then(function() { return helpers._post(name, audit.post, output).then(function() {
if (assert.testLogging) { if (assert.testLogging) {
log('- END \'' + name + '\' in ' + assert.currentTest); log('- END \'' + name + '\' in ' + assert.currentTest);
} }
@ -967,8 +963,9 @@ helpers.audit = function(options, audits) {
}); });
}); });
}); });
}).then(function() { }).then(null, function(ex) {
return options.display.inputter.setInput(''); console.error(ex.stack);
throw(ex);
}); });
}; };

View File

@ -19,20 +19,6 @@ canonDescNone=(No description)
# parameters. # parameters.
canonDefaultGroupName=Options canonDefaultGroupName=Options
# LOCALIZATION NOTE (canonProxyDesc): A very short description of a set of
# remote commands. This string is designed to be shown in a menu alongside the
# command name, which is why it should be as short as possible. See
# canonProxyManual for a fuller description of what it does.
canonProxyDesc=Execute a command on %S
# LOCALIZATION NOTE (canonProxyManual): A fuller description of a set of
# remote commands. Displayed when the user asks for help on what it does.
canonProxyManual=A set of commands that are executed on a remote system. The remote system is reached via %S
# LOCALIZATION NOTE (canonProxyExists): An error message displayed when we try
# to add new command (via a proxy) where one already exists in that name.
canonProxyExists=There is already a command called '%S'
# LOCALIZATION NOTE (cliEvalJavascript): The special '{' command allows entry # LOCALIZATION NOTE (cliEvalJavascript): The special '{' command allows entry
# of JavaScript like traditional developer tool command lines. This describes # of JavaScript like traditional developer tool command lines. This describes
# the '{' command. # the '{' command.
@ -204,92 +190,6 @@ subCommands=Sub-Commands
# fact has none # fact has none
subCommandsNone=None subCommandsNone=None
# LOCALIZATION NOTE (contextDesc): A very short description of the 'context'
# command. This string is designed to be shown in a menu alongside the command
# name, which is why it should be as short as possible. See contextManual for
# a fuller description of what it does.
contextDesc=Concentrate on a group of commands
# LOCALIZATION NOTE (contextManual): A fuller description of the 'context'
# command. Displayed when the user asks for help on what it does.
contextManual=Setup a default prefix to future commands. For example 'context git' would allow you to type 'commit' rather than 'git commit'.
# LOCALIZATION NOTE (contextPrefixDesc): A short description of the 'prefix'
# parameter to the 'context' command. This string is designed to be shown in a
# dialog with restricted space, which is why it should be as short as
# possible.
contextPrefixDesc=The command prefix
# LOCALIZATION NOTE (contextNotParentError): An error message displayed during
# the processing of the 'context' command, when the found command is not a
# parent command.
contextNotParentError=Can't use '%1$S' as a prefix because it is not a parent command.
# LOCALIZATION NOTE (contextReply): A message displayed during the processing
# of the 'context' command, to indicate success.
contextReply=Using %1$S as a command prefix
# LOCALIZATION NOTE (contextEmptyReply): A message displayed during the
# processing of the 'context' command, to indicate that there is no command
# prefix
contextEmptyReply=Command prefix is unset
# LOCALIZATION NOTE (connectDesc): A very short description of the 'connect'
# command. This string is designed to be shown in a menu alongside the command
# name, which is why it should be as short as possible. See connectManual for
# a fuller description of what it does.
connectDesc=Proxy commands to server
# LOCALIZATION NOTE (connectManual): A fuller description of the 'connect'
# command. Displayed when the user asks for help on what it does.
connectManual=Connect to the server, creating local versions of the commands on the server. Remote commands initially have a prefix to distinguish them from local commands (but see the context command to get past this)
# LOCALIZATION NOTE (connectPrefixDesc): A short description of the 'prefix'
# parameter to the 'connect' command. This string is designed to be shown in a
# dialog with restricted space, which is why it should be as short as
# possible.
connectPrefixDesc=Parent prefix for imported commands
# LOCALIZATION NOTE (connectPortDesc): A short description of the 'port'
# parameter to the 'connect' command. This string is designed to be shown in a
# dialog with restricted space, which is why it should be as short as
# possible.
connectPortDesc=The TCP port to listen on
# LOCALIZATION NOTE (connectHostDesc): A short description of the 'host'
# parameter to the 'connect' command. This string is designed to be shown in a
# dialog with restricted space, which is why it should be as short as
# possible.
connectHostDesc=The hostname to bind to
# LOCALIZATION NOTE (connectDupReply): An error condition from executing the
# 'connect' command
connectDupReply=Connection called %S already exists.
# LOCALIZATION NOTE (connectReply): The output of the 'connect' command,
# telling the user what it has done.
connectReply=Added %S commands.
# LOCALIZATION NOTE (disconnectDesc): A very short description of the
# 'disconnect' command. This string is designed to be shown in a menu
# alongside the command name, which is why it should be as short as possible.
# See connectManual for a fuller description of what it does.
disconnectDesc=Proxy commands to server
# LOCALIZATION NOTE (disconnectManual): A fuller description of the
# 'disconnect' command. Displayed when the user asks for help on what it does.
disconnectManual=Connect to the server, creating local versions of the commands on the server. Remote commands initially have a prefix to distinguish them from local commands (but see the context command to get past this)
# LOCALIZATION NOTE (disconnectPrefixDesc): A short description of the
# 'prefix' parameter to the 'disconnect' command. This string is designed to
# be shown in a dialog with restricted space, which is why it should be as
# short as possible.
disconnectPrefixDesc=Parent prefix for imported commands
# LOCALIZATION NOTE (disconnectReply): The output of the 'disconnect' command,
# telling the user what it's done.
disconnectReply=Removed %S commands.
# LOCALIZATION NOTE (prefDesc): A very short description of the 'pref' # LOCALIZATION NOTE (prefDesc): A very short description of the 'pref'
# command. This string is designed to be shown in a menu alongside the command # command. This string is designed to be shown in a menu alongside the command
# name, which is why it should be as short as possible. See prefManual for a # name, which is why it should be as short as possible. See prefManual for a

View File

@ -12,6 +12,14 @@
# A good criteria is the language in which you'd find the best # A good criteria is the language in which you'd find the best
# documentation on web development on the web. # documentation on web development on the web.
# LOCALIZATION NOTE (echoDesc) A very short string used to describe the
# function of the echo command.
echoDesc=Show a message
# LOCALIZATION NOTE (echoMessageDesc) A very short string used to describe the
# message parameter to the echo command.
echoMessageDesc=Message
# LOCALIZATION NOTE (helpDesc) A very short string used to describe the # LOCALIZATION NOTE (helpDesc) A very short string used to describe the
# function of the help command. # function of the help command.
helpDesc=Get help on the available commands helpDesc=Get help on the available commands
@ -1265,27 +1273,3 @@ profilerStopping2=Stopping…
# LOCALIZATION NOTE (profilerNotReady) A message that is displayed whenever # LOCALIZATION NOTE (profilerNotReady) A message that is displayed whenever
# an operation cannot be completed because the profiler has not been opened yet. # an operation cannot be completed because the profiler has not been opened yet.
profilerNotReady=For this command to work you need to open the profiler first profilerNotReady=For this command to work you need to open the profiler first
# LOCALIZATION NOTE (listenDesc) A very short string used to describe the
# function of the 'listen' command.
listenDesc=Open a remote debug port
# LOCALIZATION NOTE (listenManual) A longer description of the 'listen'
# command.
listenManual=Firefox can allow remote debugging over a TCP/IP connection. For security reasons this is turned off by default, but can be enabled using this command.
# LOCALIZATION NOTE (listenPortDesc) A very short string used to describe the
# function of 'port' parameter to the 'listen' command.
listenPortDesc=The TCP port to listen on
# LOCALIZATION NOTE (listenDisabledOutput) Text of a message output during the
# execution of the 'listen' command.
listenDisabledOutput=Listen is disabled by the devtools.debugger.remote-enabled preference
# LOCALIZATION NOTE (listenInitOutput) Text of a message output during the
# execution of the 'listen' command. %1$S is a port number
listenInitOutput=Listening on port %1$S
# LOCALIZATION NOTE (listenNoInitOutput) Text of a message output during the
# execution of the 'listen' command.
listenNoInitOutput=DebuggerServer not initialized

View File

@ -182,10 +182,6 @@ var DebuggerServer = {
this.addActors("chrome://global/content/devtools/dbg-webconsole-actors.js"); this.addActors("chrome://global/content/devtools/dbg-webconsole-actors.js");
this.addTabActor(this.WebConsoleActor, "consoleActor"); this.addTabActor(this.WebConsoleActor, "consoleActor");
this.addGlobalActor(this.WebConsoleActor, "consoleActor"); this.addGlobalActor(this.WebConsoleActor, "consoleActor");
this.addActors("chrome://global/content/devtools/dbg-gcli-actors.js");
this.addTabActor(this.GcliActor, "gcliActor");
this.addGlobalActor(this.GcliActor, "gcliActor");
#endif #endif
if ("nsIProfiler" in Ci) if ("nsIProfiler" in Ci)
this.addActors("chrome://global/content/devtools/dbg-profiler-actors.js"); this.addActors("chrome://global/content/devtools/dbg-profiler-actors.js");

View File

@ -1,12 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = @DEPTH@
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk

View File

@ -1,66 +0,0 @@
/* -*- Mode: js2; js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
let { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
let { require } = Cu.import("resource://gre/modules/devtools/Require.jsm", {});
Cu.import("resource:///modules/devtools/gcli.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "console",
"resource://gre/modules/devtools/Console.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "CommandUtils",
"resource:///modules/devtools/DeveloperToolbar.jsm");
let canon = require("gcli/canon");
let Requisition = require("gcli/cli").Requisition;
let util = require("util/util");
/**
* Manage remote connections that want to talk to GCLI
* @constructor
* @param connection The connection to the client, DebuggerServerConnection
* @param parentActor Optional, the parent actor
*/
function GcliActor(connection, parentActor) {
this.connection = connection;
}
GcliActor.prototype.actorPrefix = "gcli";
GcliActor.prototype.disconnect = function() {
};
GcliActor.prototype.getCommandSpecs = function(request) {
return { commandSpecs: canon.getCommandSpecs() };
};
GcliActor.prototype.execute = function(request) {
let windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
let chromeWindow = windowMediator.getMostRecentWindow("navigator:browser");
let contentWindow = chromeWindow.gBrowser.selectedTab.linkedBrowser.contentWindow;
let environment = CommandUtils.createEnvironment(chromeWindow.document,
contentWindow.document);
let requisition = new Requisition(environment);
let outputPromise = requisition.updateExec(request.typed);
let output = util.synchronize(outputPromise);
return {
id: request.id,
data: output.data,
type: output.type,
error: output.error
};
};
GcliActor.prototype.requestTypes = {
getCommandSpecs: GcliActor.prototype.getCommandSpecs,
execute: GcliActor.prototype.execute,
};

View File

@ -7,7 +7,6 @@ toolkit.jar:
* content/global/devtools/dbg-server.js (debugger/server/dbg-server.js) * content/global/devtools/dbg-server.js (debugger/server/dbg-server.js)
content/global/devtools/dbg-script-actors.js (debugger/server/dbg-script-actors.js) content/global/devtools/dbg-script-actors.js (debugger/server/dbg-script-actors.js)
content/global/devtools/dbg-browser-actors.js (debugger/server/dbg-browser-actors.js) content/global/devtools/dbg-browser-actors.js (debugger/server/dbg-browser-actors.js)
content/global/devtools/dbg-gcli-actors.js (gcli/dbg-gcli-actors.js)
content/global/devtools/dbg-webconsole-actors.js (webconsole/dbg-webconsole-actors.js) content/global/devtools/dbg-webconsole-actors.js (webconsole/dbg-webconsole-actors.js)
content/global/devtools/dbg-profiler-actors.js (debugger/server/dbg-profiler-actors.js) content/global/devtools/dbg-profiler-actors.js (debugger/server/dbg-profiler-actors.js)
content/global/devtools/dbg-styleeditor-actors.js (styleeditor/dbg-styleeditor-actors.js) content/global/devtools/dbg-styleeditor-actors.js (styleeditor/dbg-styleeditor-actors.js)