michael@0: /* michael@0: * Copyright 2012, Mozilla Foundation and contributors michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: 'use strict'; michael@0: // michael@0: michael@0: // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT michael@0: // DO NOT EDIT IT DIRECTLY michael@0: michael@0: // michael@0: michael@0: michael@0: var mockCommands = {}; michael@0: michael@0: // We use an alias for exports here because this module is used in Firefox michael@0: // mochitests where we don't have define/require michael@0: michael@0: /** michael@0: * Registration and de-registration. michael@0: */ michael@0: mockCommands.setup = function(requisition) { michael@0: mockCommands.items.forEach(function(item) { michael@0: if (item.item === 'command') { michael@0: requisition.canon.addCommand(item); michael@0: } michael@0: else if (item.item === 'type') { michael@0: requisition.types.addType(item); michael@0: } michael@0: else { michael@0: console.error('Ignoring item ', item); michael@0: } michael@0: }); michael@0: }; michael@0: michael@0: mockCommands.shutdown = function(requisition) { michael@0: mockCommands.items.forEach(function(item) { michael@0: if (item.item === 'command') { michael@0: requisition.canon.removeCommand(item); michael@0: } michael@0: else if (item.item === 'type') { michael@0: requisition.types.removeType(item); michael@0: } michael@0: else { michael@0: console.error('Ignoring item ', item); michael@0: } michael@0: }); michael@0: }; michael@0: michael@0: function createExec(name) { michael@0: return function(args, executionContext) { michael@0: var argsOut = Object.keys(args).map(function(key) { michael@0: return key + '=' + args[key]; michael@0: }).join(', '); michael@0: return 'Exec: ' + name + ' ' + argsOut; michael@0: }; michael@0: } michael@0: michael@0: mockCommands.items = [ michael@0: { michael@0: item: 'type', michael@0: name: 'optionType', michael@0: parent: 'selection', michael@0: lookup: [ michael@0: { michael@0: name: 'option1', michael@0: value: 'string' michael@0: }, michael@0: { michael@0: name: 'option2', michael@0: value: 'number' michael@0: }, michael@0: { michael@0: name: 'option3', michael@0: value: { michael@0: name: 'selection', michael@0: lookup: [ michael@0: { name: 'one', value: 1 }, michael@0: { name: 'two', value: 2 }, michael@0: { name: 'three', value: 3 } michael@0: ] michael@0: } michael@0: } michael@0: ] michael@0: }, michael@0: { michael@0: item: 'type', michael@0: name: 'optionValue', michael@0: parent: 'delegate', michael@0: delegateType: function(executionContext) { michael@0: if (executionContext != null) { michael@0: var option = executionContext.getArgsObject().optionType; michael@0: if (option != null) { michael@0: return option; michael@0: } michael@0: } michael@0: return 'blank'; michael@0: } michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsv', michael@0: params: [ michael@0: { name: 'optionType', type: 'optionType' }, michael@0: { name: 'optionValue', type: 'optionValue' } michael@0: ], michael@0: exec: createExec('tsv') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsr', michael@0: params: [ { name: 'text', type: 'string' } ], michael@0: exec: createExec('tsr') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsrsrsr', michael@0: params: [ michael@0: { name: 'p1', type: 'string' }, michael@0: { name: 'p2', type: 'string' }, michael@0: { name: 'p3', type: { name: 'string', allowBlank: true} }, michael@0: ], michael@0: exec: createExec('tsrsrsr') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tso', michael@0: params: [ { name: 'text', type: 'string', defaultValue: null } ], michael@0: exec: createExec('tso') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tse', michael@0: params: [ michael@0: { name: 'node', type: 'node' }, michael@0: { michael@0: group: 'options', michael@0: params: [ michael@0: { name: 'nodes', type: { name: 'nodelist' } }, michael@0: { name: 'nodes2', type: { name: 'nodelist', allowEmpty: true } } michael@0: ] michael@0: } michael@0: ], michael@0: exec: createExec('tse') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsj', michael@0: params: [ { name: 'javascript', type: 'javascript' } ], michael@0: exec: createExec('tsj') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsb', michael@0: params: [ { name: 'toggle', type: 'boolean' } ], michael@0: exec: createExec('tsb') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tss', michael@0: exec: createExec('tss') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsu', michael@0: params: [ michael@0: { michael@0: name: 'num', michael@0: type: { michael@0: name: 'number', michael@0: max: 10, michael@0: min: -5, michael@0: step: 3 michael@0: } michael@0: } michael@0: ], michael@0: exec: createExec('tsu') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsf', michael@0: params: [ michael@0: { michael@0: name: 'num', michael@0: type: { michael@0: name: 'number', michael@0: allowFloat: true, michael@0: max: 11.5, michael@0: min: -6.5, michael@0: step: 1.5 michael@0: } michael@0: } michael@0: ], michael@0: exec: createExec('tsf') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn' michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn dif', michael@0: params: [ { name: 'text', type: 'string', description: 'tsn dif text' } ], michael@0: exec: createExec('tsnDif') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn hidden', michael@0: hidden: true, michael@0: exec: createExec('tsnHidden') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn ext', michael@0: params: [ { name: 'text', type: 'string' } ], michael@0: exec: createExec('tsnExt') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn exte', michael@0: params: [ { name: 'text', type: 'string' } ], michael@0: exec: createExec('tsnExte') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn exten', michael@0: params: [ { name: 'text', type: 'string' } ], michael@0: exec: createExec('tsnExten') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn extend', michael@0: params: [ { name: 'text', type: 'string' } ], michael@0: exec: createExec('tsnExtend') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn deep' michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn deep down' michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn deep down nested' michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsn deep down nested cmd', michael@0: exec: createExec('tsnDeepDownNestedCmd') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tshidden', michael@0: hidden: true, michael@0: params: [ michael@0: { michael@0: group: 'Options', michael@0: params: [ michael@0: { michael@0: name: 'visible', michael@0: type: 'string', michael@0: short: 'v', michael@0: defaultValue: null, michael@0: description: 'visible' michael@0: }, michael@0: { michael@0: name: 'invisiblestring', michael@0: type: 'string', michael@0: short: 'i', michael@0: description: 'invisiblestring', michael@0: defaultValue: null, michael@0: hidden: true michael@0: }, michael@0: { michael@0: name: 'invisibleboolean', michael@0: short: 'b', michael@0: type: 'boolean', michael@0: description: 'invisibleboolean', michael@0: hidden: true michael@0: } michael@0: ] michael@0: } michael@0: ], michael@0: exec: createExec('tshidden') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tselarr', michael@0: params: [ michael@0: { name: 'num', type: { name: 'selection', data: [ '1', '2', '3' ] } }, michael@0: { name: 'arr', type: { name: 'array', subtype: 'string' } } michael@0: ], michael@0: exec: createExec('tselarr') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsm', michael@0: description: 'a 3-param test selection|string|number', michael@0: params: [ michael@0: { name: 'abc', type: { name: 'selection', data: [ 'a', 'b', 'c' ] } }, michael@0: { name: 'txt', type: 'string' }, michael@0: { name: 'num', type: { name: 'number', max: 42, min: 0 } } michael@0: ], michael@0: exec: createExec('tsm') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsg', michael@0: description: 'a param group test', michael@0: params: [ michael@0: { michael@0: name: 'solo', michael@0: type: { name: 'selection', data: [ 'aaa', 'bbb', 'ccc' ] }, michael@0: description: 'solo param' michael@0: }, michael@0: { michael@0: group: 'First', michael@0: params: [ michael@0: { michael@0: name: 'txt1', michael@0: type: 'string', michael@0: defaultValue: null, michael@0: description: 'txt1 param' michael@0: }, michael@0: { michael@0: name: 'bool', michael@0: type: 'boolean', michael@0: description: 'bool param' michael@0: } michael@0: ] michael@0: }, michael@0: { michael@0: name: 'txt2', michael@0: type: 'string', michael@0: defaultValue: 'd', michael@0: description: 'txt2 param', michael@0: option: 'Second' michael@0: }, michael@0: { michael@0: name: 'num', michael@0: type: { name: 'number', min: 40 }, michael@0: defaultValue: 42, michael@0: description: 'num param', michael@0: option: 'Second' michael@0: } michael@0: ], michael@0: exec: createExec('tsg') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tscook', michael@0: description: 'param group test to catch problems with cookie command', michael@0: params: [ michael@0: { michael@0: name: 'key', michael@0: type: 'string', michael@0: description: 'tscookKeyDesc' michael@0: }, michael@0: { michael@0: name: 'value', michael@0: type: 'string', michael@0: description: 'tscookValueDesc' michael@0: }, michael@0: { michael@0: group: 'tscookOptionsDesc', michael@0: params: [ michael@0: { michael@0: name: 'path', michael@0: type: 'string', michael@0: defaultValue: '/', michael@0: description: 'tscookPathDesc' michael@0: }, michael@0: { michael@0: name: 'domain', michael@0: type: 'string', michael@0: defaultValue: null, michael@0: description: 'tscookDomainDesc' michael@0: }, michael@0: { michael@0: name: 'secure', michael@0: type: 'boolean', michael@0: description: 'tscookSecureDesc' michael@0: } michael@0: ] michael@0: } michael@0: ], michael@0: exec: createExec('tscook') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tslong', michael@0: description: 'long param tests to catch problems with the jsb command', michael@0: params: [ michael@0: { michael@0: name: 'msg', michael@0: type: 'string', michael@0: description: 'msg Desc' michael@0: }, michael@0: { michael@0: group: 'Options Desc', michael@0: params: [ michael@0: { michael@0: name: 'num', michael@0: short: 'n', michael@0: type: 'number', michael@0: description: 'num Desc', michael@0: defaultValue: 2 michael@0: }, michael@0: { michael@0: name: 'sel', michael@0: short: 's', michael@0: type: { michael@0: name: 'selection', michael@0: lookup: [ michael@0: { name: 'space', value: ' ' }, michael@0: { name: 'tab', value: '\t' } michael@0: ] michael@0: }, michael@0: description: 'sel Desc', michael@0: defaultValue: ' ' michael@0: }, michael@0: { michael@0: name: 'bool', michael@0: short: 'b', michael@0: type: 'boolean', michael@0: description: 'bool Desc' michael@0: }, michael@0: { michael@0: name: 'num2', michael@0: short: 'm', michael@0: type: 'number', michael@0: description: 'num2 Desc', michael@0: defaultValue: -1 michael@0: }, michael@0: { michael@0: name: 'bool2', michael@0: short: 'c', michael@0: type: 'boolean', michael@0: description: 'bool2 Desc' michael@0: }, michael@0: { michael@0: name: 'sel2', michael@0: short: 't', michael@0: type: { michael@0: name: 'selection', michael@0: data: [ 'collapse', 'basic', 'with space', 'with two spaces' ] michael@0: }, michael@0: description: 'sel2 Desc', michael@0: defaultValue: 'collapse' michael@0: } michael@0: ] michael@0: } michael@0: ], michael@0: exec: createExec('tslong') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsdate', michael@0: description: 'long param tests to catch problems with the jsb command', michael@0: params: [ michael@0: { michael@0: name: 'd1', michael@0: type: 'date', michael@0: }, michael@0: { michael@0: name: 'd2', michael@0: type: { michael@0: name: 'date', michael@0: min: '1 jan 2000', michael@0: max: '28 feb 2000', michael@0: step: 2 michael@0: } michael@0: }, michael@0: ], michael@0: exec: createExec('tsdate') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsfail', michael@0: description: 'test errors', michael@0: params: [ michael@0: { michael@0: name: 'method', michael@0: type: { michael@0: name: 'selection', michael@0: data: [ michael@0: 'reject', 'rejecttyped', michael@0: 'throwerror', 'throwstring', 'throwinpromise', michael@0: 'noerror' michael@0: ] michael@0: } michael@0: } michael@0: ], michael@0: exec: function(args, context) { michael@0: var deferred; michael@0: if (args.method === 'reject') { michael@0: deferred = context.defer(); michael@0: setTimeout(function() { michael@0: deferred.reject('rejected promise'); michael@0: }, 10); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: if (args.method === 'rejecttyped') { michael@0: deferred = context.defer(); michael@0: setTimeout(function() { michael@0: deferred.reject(context.typedData('number', 54)); michael@0: }, 10); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: if (args.method === 'throwinpromise') { michael@0: deferred = context.defer(); michael@0: setTimeout(function() { michael@0: deferred.resolve('should be lost'); michael@0: }, 10); michael@0: return deferred.promise.then(function() { michael@0: var t = null; michael@0: return t.foo; michael@0: }); michael@0: } michael@0: michael@0: if (args.method === 'throwerror') { michael@0: throw new Error('thrown error'); michael@0: } michael@0: michael@0: if (args.method === 'throwstring') { michael@0: throw 'thrown string'; michael@0: } michael@0: michael@0: return 'no error'; michael@0: } michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsfile', michael@0: description: 'test file params', michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsfile open', michael@0: description: 'a file param in open mode', michael@0: params: [ michael@0: { michael@0: name: 'p1', michael@0: type: { michael@0: name: 'file', michael@0: filetype: 'file', michael@0: existing: 'yes' michael@0: } michael@0: } michael@0: ], michael@0: exec: createExec('tsfile open') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsfile saveas', michael@0: description: 'a file param in saveas mode', michael@0: params: [ michael@0: { michael@0: name: 'p1', michael@0: type: { michael@0: name: 'file', michael@0: filetype: 'file', michael@0: existing: 'no' michael@0: } michael@0: } michael@0: ], michael@0: exec: createExec('tsfile saveas') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsfile save', michael@0: description: 'a file param in save mode', michael@0: params: [ michael@0: { michael@0: name: 'p1', michael@0: type: { michael@0: name: 'file', michael@0: filetype: 'file', michael@0: existing: 'maybe' michael@0: } michael@0: } michael@0: ], michael@0: exec: createExec('tsfile save') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsfile cd', michael@0: description: 'a file param in cd mode', michael@0: params: [ michael@0: { michael@0: name: 'p1', michael@0: type: { michael@0: name: 'file', michael@0: filetype: 'directory', michael@0: existing: 'yes' michael@0: } michael@0: } michael@0: ], michael@0: exec: createExec('tsfile cd') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsfile mkdir', michael@0: description: 'a file param in mkdir mode', michael@0: params: [ michael@0: { michael@0: name: 'p1', michael@0: type: { michael@0: name: 'file', michael@0: filetype: 'directory', michael@0: existing: 'no' michael@0: } michael@0: } michael@0: ], michael@0: exec: createExec('tsfile mkdir') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsfile rm', michael@0: description: 'a file param in rm mode', michael@0: params: [ michael@0: { michael@0: name: 'p1', michael@0: type: { michael@0: name: 'file', michael@0: filetype: 'any', michael@0: existing: 'yes' michael@0: } michael@0: } michael@0: ], michael@0: exec: createExec('tsfile rm') michael@0: }, michael@0: { michael@0: item: 'command', michael@0: name: 'tsslow', michael@0: params: [ michael@0: { michael@0: name: 'hello', michael@0: type: { michael@0: name: 'selection', michael@0: data: function(context) { michael@0: var deferred = context.defer(); michael@0: michael@0: var resolve = function() { michael@0: deferred.resolve([ michael@0: 'Shalom', 'Namasté', 'Hallo', 'Dydd-da', michael@0: 'Chào', 'Hej', 'Saluton', 'Sawubona' michael@0: ]); michael@0: }; michael@0: michael@0: setTimeout(resolve, 10); michael@0: return deferred.promise; michael@0: } michael@0: } michael@0: } michael@0: ], michael@0: exec: function(args, context) { michael@0: return 'Test completed'; michael@0: } michael@0: } michael@0: ];