Bug 773347 - GCLI hidden commands don't execute properly; r=harth

This commit is contained in:
Joe Walker 2012-08-24 15:39:10 +01:00
parent 8f31a4fa6e
commit ff781144b2
5 changed files with 184 additions and 15 deletions

View File

@ -20,6 +20,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
XPCOMUtils.defineLazyModuleGetter(this, "console",
"resource:///modules/devtools/Console.jsm");
const PREF_DIR = "devtools.commands.dir";
/**
* 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
@ -43,8 +45,8 @@ let CmdCommands = {
gcli.removeCommand(name);
});
let dirName = prefBranch.getComplexValue("devtools.commands.dir",
Ci.nsISupportsString).data;
let dirName = prefBranch.getComplexValue(PREF_DIR,
Ci.nsISupportsString).data.trim();
if (dirName == "") {
return;
}
@ -109,8 +111,8 @@ function loadCommandFile(aFile, aSandboxPrincipal) {
*/
gcli.addCommand({
name: "cmd",
description: gcli.lookup("cmdDesc"),
hidden: true
get hidden() { return !prefBranch.prefHasUserValue(PREF_DIR); },
description: gcli.lookup("cmdDesc")
});
/**
@ -119,8 +121,9 @@ gcli.addCommand({
gcli.addCommand({
name: "cmd refresh",
description: gcli.lookup("cmdRefreshDesc"),
hidden: true,
get hidden() { return !prefBranch.prefHasUserValue(PREF_DIR); },
exec: function Command_cmdRefresh(args, context) {
GcliCmdCommands.refreshAutoCommands(context.environment.chromeDocument.defaultView);
let chromeWindow = context.environment.chromeDocument.defaultView;
GcliCommands.refreshAutoCommands(chromeWindow);
}
});

View File

@ -1797,19 +1797,30 @@ SelectionType.prototype._findPredictions = function(arg) {
}
}
// Exact hidden matches. If 'hidden: true' then we only allow exact matches
// All the tests after here check that !option.value.hidden
for (i = 0; i < lookup.length && predictions.length < maxPredictions; i++) {
option = lookup[i];
if (option.name === arg.text) {
this._addToPredictions(predictions, option, arg);
}
}
// Start with prefix matching
for (i = 0; i < lookup.length && predictions.length < maxPredictions; i++) {
option = lookup[i];
if (option._gcliLowerName.indexOf(match) === 0) {
if (option._gcliLowerName.indexOf(match) === 0 && !option.value.hidden) {
if (predictions.indexOf(option) === -1) {
this._addToPredictions(predictions, option, arg);
}
}
}
// Try infix matching if we get less half max matched
if (predictions.length < (maxPredictions / 2)) {
for (i = 0; i < lookup.length && predictions.length < maxPredictions; i++) {
option = lookup[i];
if (option._gcliLowerName.indexOf(match) !== -1) {
if (option._gcliLowerName.indexOf(match) !== -1 && !option.value.hidden) {
if (predictions.indexOf(option) === -1) {
this._addToPredictions(predictions, option, arg);
}
@ -2191,9 +2202,6 @@ CommandType.prototype.lookup = function() {
* Add an option to our list of predicted options
*/
CommandType.prototype._addToPredictions = function(predictions, option, arg) {
if (option.value.hidden) {
return;
}
// The command type needs to exclude sub-commands when the CLI
// is blank, but include them when we're filtering. This hack
// excludes matches when the filter text is '' and when the
@ -2509,6 +2517,16 @@ Object.defineProperty(Parameter.prototype, 'isDataRequired', {
enumerable: true
});
/**
* Reflect the paramSpec 'hidden' property (dynamically so it can change)
*/
Object.defineProperty(Parameter.prototype, 'hidden', {
get: function() {
return this.paramSpec.hidden;
},
enumerable: true
});
/**
* Are we allowed to assign data to this parameter using positional
* parameters?

View File

@ -13,13 +13,11 @@ function test() {
}
function testEcho() {
/*
DeveloperToolbarTest.exec({
typed: "echo message",
args: { message: "message" },
outputMatch: /^message$/,
});
*/
}
function testConsole(browser, tab) {

View File

@ -7,7 +7,7 @@ const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" +
"test/browser_cmd_jsb_script.jsi";
function test() {
DeveloperToolbarTest.test("about:blank", [ /*GJT_test*/ ]);
DeveloperToolbarTest.test("about:blank", [ GJT_test ]);
}
function GJT_test() {

View File

@ -1733,6 +1733,7 @@ exports.setup = function() {
canon.addCommand(exports.tselarr);
canon.addCommand(exports.tsm);
canon.addCommand(exports.tsg);
canon.addCommand(exports.tshidden);
canon.addCommand(exports.tscook);
};
@ -1757,6 +1758,7 @@ exports.shutdown = function() {
canon.removeCommand(exports.tselarr);
canon.removeCommand(exports.tsm);
canon.removeCommand(exports.tsg);
canon.removeCommand(exports.tshidden);
canon.removeCommand(exports.tscook);
types.deregisterType(exports.optionType);
@ -1911,6 +1913,38 @@ exports.tsnDeepDownNestedCmd = {
exec: createExec('tsnDeepDownNestedCmd')
};
exports.tshidden = {
name: 'tshidden',
hidden: true,
params: [
{
group: 'Options',
params: [
{
name: 'visible',
type: 'string',
defaultValue: null,
description: 'visible'
},
{
name: 'invisiblestring',
type: 'string',
description: 'invisiblestring',
defaultValue: null,
hidden: true
},
{
name: 'invisibleboolean',
type: 'boolean',
description: 'invisibleboolean',
hidden: true
}
]
}
],
exec: createExec('tshidden')
};
exports.tselarr = {
name: 'tselarr',
params: [
@ -3010,6 +3044,122 @@ exports.testIncomplete = function(options) {
'unassigned.isIncompleteName: tsg -');
};
exports.testHidden = function(options) {
helpers.setInput('tshidde');
helpers.check({
input: 'tshidde',
markup: 'EEEEEEE',
directTabText: '',
arrowTabText: '',
status: 'ERROR',
emptyParameters: [ ],
});
helpers.setInput('tshidden');
helpers.check({
input: 'tshidden',
markup: 'VVVVVVVV',
directTabText: '',
arrowTabText: '',
status: 'VALID',
emptyParameters: [ ],
args: {
visible: { value: undefined, status: 'VALID' },
invisiblestring: { value: undefined, status: 'VALID' },
invisibleboolean: { value: undefined, status: 'VALID' }
}
});
helpers.setInput('tshidden --vis');
helpers.check({
input: 'tshidden --vis',
markup: 'VVVVVVVVVIIIII',
directTabText: 'ible',
arrowTabText: '',
status: 'ERROR',
emptyParameters: [ ],
args: {
visible: { value: undefined, status: 'VALID' },
invisiblestring: { value: undefined, status: 'VALID' },
invisibleboolean: { value: undefined, status: 'VALID' }
}
});
helpers.setInput('tshidden --invisiblestrin');
helpers.check({
input: 'tshidden --invisiblestrin',
markup: 'VVVVVVVVVEEEEEEEEEEEEEEEE',
directTabText: '',
arrowTabText: '',
status: 'ERROR',
emptyParameters: [ ],
args: {
visible: { value: undefined, status: 'VALID' },
invisiblestring: { value: undefined, status: 'VALID' },
invisibleboolean: { value: undefined, status: 'VALID' }
}
});
helpers.setInput('tshidden --invisiblestring');
helpers.check({
input: 'tshidden --invisiblestring',
markup: 'VVVVVVVVVIIIIIIIIIIIIIIIII',
directTabText: '',
arrowTabText: '',
status: 'ERROR',
emptyParameters: [ ],
args: {
visible: { value: undefined, status: 'VALID' },
invisiblestring: { value: undefined, status: 'INCOMPLETE' },
invisibleboolean: { value: undefined, status: 'VALID' }
}
});
helpers.setInput('tshidden --invisiblestring x');
helpers.check({
input: 'tshidden --invisiblestring x',
markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVVV',
directTabText: '',
arrowTabText: '',
status: 'VALID',
emptyParameters: [ ],
args: {
visible: { value: undefined, status: 'VALID' },
invisiblestring: { value: 'x', status: 'VALID' },
invisibleboolean: { value: undefined, status: 'VALID' }
}
});
helpers.setInput('tshidden --invisibleboolea');
helpers.check({
input: 'tshidden --invisibleboolea',
markup: 'VVVVVVVVVEEEEEEEEEEEEEEEEE',
directTabText: '',
arrowTabText: '',
status: 'ERROR',
emptyParameters: [ ],
args: {
visible: { value: undefined, status: 'VALID' },
invisiblestring: { value: undefined, status: 'VALID' },
invisibleboolean: { value: undefined, status: 'VALID' }
}
});
helpers.setInput('tshidden --invisibleboolean');
helpers.check({
input: 'tshidden --invisibleboolean',
markup: 'VVVVVVVVVVVVVVVVVVVVVVVVVVV',
directTabText: '',
arrowTabText: '',
status: 'VALID',
emptyParameters: [ ],
args: {
visible: { value: undefined, status: 'VALID' },
invisiblestring: { value: undefined, status: 'VALID' },
invisibleboolean: { value: true, status: 'VALID' }
}
});
};
});
/*