browser/devtools/commandline/test/mockCommands.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/commandline/test/mockCommands.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,677 @@
     1.4 +/*
     1.5 + * Copyright 2012, Mozilla Foundation and contributors
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + * http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +'use strict';
    1.21 +// <INJECTED SOURCE:START>
    1.22 +
    1.23 +// THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
    1.24 +// DO NOT EDIT IT DIRECTLY
    1.25 +
    1.26 +// <INJECTED SOURCE:END>
    1.27 +
    1.28 +
    1.29 +var mockCommands = {};
    1.30 +
    1.31 +// We use an alias for exports here because this module is used in Firefox
    1.32 +// mochitests where we don't have define/require
    1.33 +
    1.34 +/**
    1.35 + * Registration and de-registration.
    1.36 + */
    1.37 +mockCommands.setup = function(requisition) {
    1.38 +  mockCommands.items.forEach(function(item) {
    1.39 +    if (item.item === 'command') {
    1.40 +      requisition.canon.addCommand(item);
    1.41 +    }
    1.42 +    else if (item.item === 'type') {
    1.43 +      requisition.types.addType(item);
    1.44 +    }
    1.45 +    else {
    1.46 +      console.error('Ignoring item ', item);
    1.47 +    }
    1.48 +  });
    1.49 +};
    1.50 +
    1.51 +mockCommands.shutdown = function(requisition) {
    1.52 +  mockCommands.items.forEach(function(item) {
    1.53 +    if (item.item === 'command') {
    1.54 +      requisition.canon.removeCommand(item);
    1.55 +    }
    1.56 +    else if (item.item === 'type') {
    1.57 +      requisition.types.removeType(item);
    1.58 +    }
    1.59 +    else {
    1.60 +      console.error('Ignoring item ', item);
    1.61 +    }
    1.62 +  });
    1.63 +};
    1.64 +
    1.65 +function createExec(name) {
    1.66 +  return function(args, executionContext) {
    1.67 +    var argsOut = Object.keys(args).map(function(key) {
    1.68 +      return key + '=' + args[key];
    1.69 +    }).join(', ');
    1.70 +    return 'Exec: ' + name + ' ' + argsOut;
    1.71 +  };
    1.72 +}
    1.73 +
    1.74 +mockCommands.items = [
    1.75 +  {
    1.76 +    item: 'type',
    1.77 +    name: 'optionType',
    1.78 +    parent: 'selection',
    1.79 +    lookup: [
    1.80 +      {
    1.81 +        name: 'option1',
    1.82 +        value: 'string'
    1.83 +      },
    1.84 +      {
    1.85 +        name: 'option2',
    1.86 +        value: 'number'
    1.87 +      },
    1.88 +      {
    1.89 +        name: 'option3',
    1.90 +        value: {
    1.91 +          name: 'selection',
    1.92 +          lookup: [
    1.93 +            { name: 'one', value: 1 },
    1.94 +            { name: 'two', value: 2 },
    1.95 +            { name: 'three', value: 3 }
    1.96 +          ]
    1.97 +        }
    1.98 +      }
    1.99 +    ]
   1.100 +  },
   1.101 +  {
   1.102 +    item: 'type',
   1.103 +    name: 'optionValue',
   1.104 +    parent: 'delegate',
   1.105 +    delegateType: function(executionContext) {
   1.106 +      if (executionContext != null) {
   1.107 +        var option = executionContext.getArgsObject().optionType;
   1.108 +        if (option != null) {
   1.109 +          return option;
   1.110 +        }
   1.111 +      }
   1.112 +      return 'blank';
   1.113 +    }
   1.114 +  },
   1.115 +  {
   1.116 +    item: 'command',
   1.117 +    name: 'tsv',
   1.118 +    params: [
   1.119 +      { name: 'optionType', type: 'optionType' },
   1.120 +      { name: 'optionValue', type: 'optionValue' }
   1.121 +    ],
   1.122 +    exec: createExec('tsv')
   1.123 +  },
   1.124 +  {
   1.125 +    item: 'command',
   1.126 +    name: 'tsr',
   1.127 +    params: [ { name: 'text', type: 'string' } ],
   1.128 +    exec: createExec('tsr')
   1.129 +  },
   1.130 +  {
   1.131 +    item: 'command',
   1.132 +    name: 'tsrsrsr',
   1.133 +    params: [
   1.134 +      { name: 'p1', type: 'string' },
   1.135 +      { name: 'p2', type: 'string' },
   1.136 +      { name: 'p3', type: { name: 'string', allowBlank: true} },
   1.137 +    ],
   1.138 +    exec: createExec('tsrsrsr')
   1.139 +  },
   1.140 +  {
   1.141 +    item: 'command',
   1.142 +    name: 'tso',
   1.143 +    params: [ { name: 'text', type: 'string', defaultValue: null } ],
   1.144 +    exec: createExec('tso')
   1.145 +  },
   1.146 +  {
   1.147 +    item: 'command',
   1.148 +    name: 'tse',
   1.149 +    params: [
   1.150 +      { name: 'node', type: 'node' },
   1.151 +      {
   1.152 +        group: 'options',
   1.153 +        params: [
   1.154 +          { name: 'nodes', type: { name: 'nodelist' } },
   1.155 +          { name: 'nodes2', type: { name: 'nodelist', allowEmpty: true } }
   1.156 +        ]
   1.157 +      }
   1.158 +    ],
   1.159 +    exec: createExec('tse')
   1.160 +  },
   1.161 +  {
   1.162 +    item: 'command',
   1.163 +    name: 'tsj',
   1.164 +    params: [ { name: 'javascript', type: 'javascript' } ],
   1.165 +    exec: createExec('tsj')
   1.166 +  },
   1.167 +  {
   1.168 +    item: 'command',
   1.169 +    name: 'tsb',
   1.170 +    params: [ { name: 'toggle', type: 'boolean' } ],
   1.171 +    exec: createExec('tsb')
   1.172 +  },
   1.173 +  {
   1.174 +    item: 'command',
   1.175 +    name: 'tss',
   1.176 +    exec: createExec('tss')
   1.177 +  },
   1.178 +  {
   1.179 +    item: 'command',
   1.180 +    name: 'tsu',
   1.181 +    params: [
   1.182 +      {
   1.183 +        name: 'num',
   1.184 +        type: {
   1.185 +          name: 'number',
   1.186 +          max: 10,
   1.187 +          min: -5,
   1.188 +          step: 3
   1.189 +        }
   1.190 +      }
   1.191 +    ],
   1.192 +    exec: createExec('tsu')
   1.193 +  },
   1.194 +  {
   1.195 +    item: 'command',
   1.196 +    name: 'tsf',
   1.197 +    params: [
   1.198 +      {
   1.199 +        name: 'num',
   1.200 +        type: {
   1.201 +          name: 'number',
   1.202 +          allowFloat: true,
   1.203 +          max: 11.5,
   1.204 +          min: -6.5,
   1.205 +          step: 1.5
   1.206 +        }
   1.207 +      }
   1.208 +    ],
   1.209 +    exec: createExec('tsf')
   1.210 +  },
   1.211 +  {
   1.212 +    item: 'command',
   1.213 +    name: 'tsn'
   1.214 +  },
   1.215 +  {
   1.216 +    item: 'command',
   1.217 +    name: 'tsn dif',
   1.218 +    params: [ { name: 'text', type: 'string', description: 'tsn dif text' } ],
   1.219 +    exec: createExec('tsnDif')
   1.220 +  },
   1.221 +  {
   1.222 +    item: 'command',
   1.223 +    name: 'tsn hidden',
   1.224 +    hidden: true,
   1.225 +    exec: createExec('tsnHidden')
   1.226 +  },
   1.227 +  {
   1.228 +    item: 'command',
   1.229 +    name: 'tsn ext',
   1.230 +    params: [ { name: 'text', type: 'string' } ],
   1.231 +    exec: createExec('tsnExt')
   1.232 +  },
   1.233 +  {
   1.234 +    item: 'command',
   1.235 +    name: 'tsn exte',
   1.236 +    params: [ { name: 'text', type: 'string' } ],
   1.237 +    exec: createExec('tsnExte')
   1.238 +  },
   1.239 +  {
   1.240 +    item: 'command',
   1.241 +    name: 'tsn exten',
   1.242 +    params: [ { name: 'text', type: 'string' } ],
   1.243 +    exec: createExec('tsnExten')
   1.244 +  },
   1.245 +  {
   1.246 +    item: 'command',
   1.247 +    name: 'tsn extend',
   1.248 +    params: [ { name: 'text', type: 'string' } ],
   1.249 +    exec: createExec('tsnExtend')
   1.250 +  },
   1.251 +  {
   1.252 +    item: 'command',
   1.253 +    name: 'tsn deep'
   1.254 +  },
   1.255 +  {
   1.256 +    item: 'command',
   1.257 +    name: 'tsn deep down'
   1.258 +  },
   1.259 +  {
   1.260 +    item: 'command',
   1.261 +    name: 'tsn deep down nested'
   1.262 +  },
   1.263 +  {
   1.264 +    item: 'command',
   1.265 +    name: 'tsn deep down nested cmd',
   1.266 +    exec: createExec('tsnDeepDownNestedCmd')
   1.267 +  },
   1.268 +  {
   1.269 +    item: 'command',
   1.270 +    name: 'tshidden',
   1.271 +    hidden: true,
   1.272 +    params: [
   1.273 +      {
   1.274 +        group: 'Options',
   1.275 +        params: [
   1.276 +          {
   1.277 +            name: 'visible',
   1.278 +            type: 'string',
   1.279 +            short: 'v',
   1.280 +            defaultValue: null,
   1.281 +            description: 'visible'
   1.282 +          },
   1.283 +          {
   1.284 +            name: 'invisiblestring',
   1.285 +            type: 'string',
   1.286 +            short: 'i',
   1.287 +            description: 'invisiblestring',
   1.288 +            defaultValue: null,
   1.289 +            hidden: true
   1.290 +          },
   1.291 +          {
   1.292 +            name: 'invisibleboolean',
   1.293 +            short: 'b',
   1.294 +            type: 'boolean',
   1.295 +            description: 'invisibleboolean',
   1.296 +            hidden: true
   1.297 +          }
   1.298 +        ]
   1.299 +      }
   1.300 +    ],
   1.301 +    exec: createExec('tshidden')
   1.302 +  },
   1.303 +  {
   1.304 +    item: 'command',
   1.305 +    name: 'tselarr',
   1.306 +    params: [
   1.307 +      { name: 'num', type: { name: 'selection', data: [ '1', '2', '3' ] } },
   1.308 +      { name: 'arr', type: { name: 'array', subtype: 'string' } }
   1.309 +    ],
   1.310 +    exec: createExec('tselarr')
   1.311 +  },
   1.312 +  {
   1.313 +    item: 'command',
   1.314 +    name: 'tsm',
   1.315 +    description: 'a 3-param test selection|string|number',
   1.316 +    params: [
   1.317 +      { name: 'abc', type: { name: 'selection', data: [ 'a', 'b', 'c' ] } },
   1.318 +      { name: 'txt', type: 'string' },
   1.319 +      { name: 'num', type: { name: 'number', max: 42, min: 0 } }
   1.320 +    ],
   1.321 +    exec: createExec('tsm')
   1.322 +  },
   1.323 +  {
   1.324 +    item: 'command',
   1.325 +    name: 'tsg',
   1.326 +    description: 'a param group test',
   1.327 +    params: [
   1.328 +      {
   1.329 +        name: 'solo',
   1.330 +        type: { name: 'selection', data: [ 'aaa', 'bbb', 'ccc' ] },
   1.331 +        description: 'solo param'
   1.332 +      },
   1.333 +      {
   1.334 +        group: 'First',
   1.335 +        params: [
   1.336 +          {
   1.337 +            name: 'txt1',
   1.338 +            type: 'string',
   1.339 +            defaultValue: null,
   1.340 +            description: 'txt1 param'
   1.341 +          },
   1.342 +          {
   1.343 +            name: 'bool',
   1.344 +            type: 'boolean',
   1.345 +            description: 'bool param'
   1.346 +          }
   1.347 +        ]
   1.348 +      },
   1.349 +      {
   1.350 +        name: 'txt2',
   1.351 +        type: 'string',
   1.352 +        defaultValue: 'd',
   1.353 +        description: 'txt2 param',
   1.354 +        option: 'Second'
   1.355 +      },
   1.356 +      {
   1.357 +        name: 'num',
   1.358 +        type: { name: 'number', min: 40 },
   1.359 +        defaultValue: 42,
   1.360 +        description: 'num param',
   1.361 +        option: 'Second'
   1.362 +      }
   1.363 +    ],
   1.364 +    exec: createExec('tsg')
   1.365 +  },
   1.366 +  {
   1.367 +    item: 'command',
   1.368 +    name: 'tscook',
   1.369 +    description: 'param group test to catch problems with cookie command',
   1.370 +    params: [
   1.371 +      {
   1.372 +        name: 'key',
   1.373 +        type: 'string',
   1.374 +        description: 'tscookKeyDesc'
   1.375 +      },
   1.376 +      {
   1.377 +        name: 'value',
   1.378 +        type: 'string',
   1.379 +        description: 'tscookValueDesc'
   1.380 +      },
   1.381 +      {
   1.382 +        group: 'tscookOptionsDesc',
   1.383 +        params: [
   1.384 +          {
   1.385 +            name: 'path',
   1.386 +            type: 'string',
   1.387 +            defaultValue: '/',
   1.388 +            description: 'tscookPathDesc'
   1.389 +          },
   1.390 +          {
   1.391 +            name: 'domain',
   1.392 +            type: 'string',
   1.393 +            defaultValue: null,
   1.394 +            description: 'tscookDomainDesc'
   1.395 +          },
   1.396 +          {
   1.397 +            name: 'secure',
   1.398 +            type: 'boolean',
   1.399 +            description: 'tscookSecureDesc'
   1.400 +          }
   1.401 +        ]
   1.402 +      }
   1.403 +    ],
   1.404 +    exec: createExec('tscook')
   1.405 +  },
   1.406 +  {
   1.407 +    item: 'command',
   1.408 +    name: 'tslong',
   1.409 +    description: 'long param tests to catch problems with the jsb command',
   1.410 +    params: [
   1.411 +      {
   1.412 +        name: 'msg',
   1.413 +        type: 'string',
   1.414 +        description: 'msg Desc'
   1.415 +      },
   1.416 +      {
   1.417 +        group: 'Options Desc',
   1.418 +        params: [
   1.419 +          {
   1.420 +            name: 'num',
   1.421 +            short: 'n',
   1.422 +            type: 'number',
   1.423 +            description: 'num Desc',
   1.424 +            defaultValue: 2
   1.425 +          },
   1.426 +          {
   1.427 +            name: 'sel',
   1.428 +            short: 's',
   1.429 +            type: {
   1.430 +              name: 'selection',
   1.431 +              lookup: [
   1.432 +                { name: 'space', value: ' ' },
   1.433 +                { name: 'tab', value: '\t' }
   1.434 +              ]
   1.435 +            },
   1.436 +            description: 'sel Desc',
   1.437 +            defaultValue: ' '
   1.438 +          },
   1.439 +          {
   1.440 +            name: 'bool',
   1.441 +            short: 'b',
   1.442 +            type: 'boolean',
   1.443 +            description: 'bool Desc'
   1.444 +          },
   1.445 +          {
   1.446 +            name: 'num2',
   1.447 +            short: 'm',
   1.448 +            type: 'number',
   1.449 +            description: 'num2 Desc',
   1.450 +            defaultValue: -1
   1.451 +          },
   1.452 +          {
   1.453 +            name: 'bool2',
   1.454 +            short: 'c',
   1.455 +            type: 'boolean',
   1.456 +            description: 'bool2 Desc'
   1.457 +          },
   1.458 +          {
   1.459 +            name: 'sel2',
   1.460 +            short: 't',
   1.461 +            type: {
   1.462 +              name: 'selection',
   1.463 +              data: [ 'collapse', 'basic', 'with space', 'with two spaces' ]
   1.464 +            },
   1.465 +            description: 'sel2 Desc',
   1.466 +            defaultValue: 'collapse'
   1.467 +          }
   1.468 +        ]
   1.469 +      }
   1.470 +    ],
   1.471 +    exec: createExec('tslong')
   1.472 +  },
   1.473 +  {
   1.474 +    item: 'command',
   1.475 +    name: 'tsdate',
   1.476 +    description: 'long param tests to catch problems with the jsb command',
   1.477 +    params: [
   1.478 +      {
   1.479 +        name: 'd1',
   1.480 +        type: 'date',
   1.481 +      },
   1.482 +      {
   1.483 +        name: 'd2',
   1.484 +        type: {
   1.485 +          name: 'date',
   1.486 +          min: '1 jan 2000',
   1.487 +          max: '28 feb 2000',
   1.488 +          step: 2
   1.489 +        }
   1.490 +      },
   1.491 +    ],
   1.492 +    exec: createExec('tsdate')
   1.493 +  },
   1.494 +  {
   1.495 +    item: 'command',
   1.496 +    name: 'tsfail',
   1.497 +    description: 'test errors',
   1.498 +    params: [
   1.499 +      {
   1.500 +        name: 'method',
   1.501 +        type: {
   1.502 +          name: 'selection',
   1.503 +          data: [
   1.504 +            'reject', 'rejecttyped',
   1.505 +            'throwerror', 'throwstring', 'throwinpromise',
   1.506 +            'noerror'
   1.507 +          ]
   1.508 +        }
   1.509 +      }
   1.510 +    ],
   1.511 +    exec: function(args, context) {
   1.512 +      var deferred;
   1.513 +      if (args.method === 'reject') {
   1.514 +        deferred = context.defer();
   1.515 +        setTimeout(function() {
   1.516 +          deferred.reject('rejected promise');
   1.517 +        }, 10);
   1.518 +        return deferred.promise;
   1.519 +      }
   1.520 +
   1.521 +      if (args.method === 'rejecttyped') {
   1.522 +        deferred = context.defer();
   1.523 +        setTimeout(function() {
   1.524 +          deferred.reject(context.typedData('number', 54));
   1.525 +        }, 10);
   1.526 +        return deferred.promise;
   1.527 +      }
   1.528 +
   1.529 +      if (args.method === 'throwinpromise') {
   1.530 +        deferred = context.defer();
   1.531 +        setTimeout(function() {
   1.532 +          deferred.resolve('should be lost');
   1.533 +        }, 10);
   1.534 +        return deferred.promise.then(function() {
   1.535 +          var t = null;
   1.536 +          return t.foo;
   1.537 +        });
   1.538 +      }
   1.539 +
   1.540 +      if (args.method === 'throwerror') {
   1.541 +        throw new Error('thrown error');
   1.542 +      }
   1.543 +
   1.544 +      if (args.method === 'throwstring') {
   1.545 +        throw 'thrown string';
   1.546 +      }
   1.547 +
   1.548 +      return 'no error';
   1.549 +    }
   1.550 +  },
   1.551 +  {
   1.552 +    item: 'command',
   1.553 +    name: 'tsfile',
   1.554 +    description: 'test file params',
   1.555 +  },
   1.556 +  {
   1.557 +    item: 'command',
   1.558 +    name: 'tsfile open',
   1.559 +    description: 'a file param in open mode',
   1.560 +    params: [
   1.561 +      {
   1.562 +        name: 'p1',
   1.563 +        type: {
   1.564 +          name: 'file',
   1.565 +          filetype: 'file',
   1.566 +          existing: 'yes'
   1.567 +        }
   1.568 +      }
   1.569 +    ],
   1.570 +    exec: createExec('tsfile open')
   1.571 +  },
   1.572 +  {
   1.573 +    item: 'command',
   1.574 +    name: 'tsfile saveas',
   1.575 +    description: 'a file param in saveas mode',
   1.576 +    params: [
   1.577 +      {
   1.578 +        name: 'p1',
   1.579 +        type: {
   1.580 +          name: 'file',
   1.581 +          filetype: 'file',
   1.582 +          existing: 'no'
   1.583 +        }
   1.584 +      }
   1.585 +    ],
   1.586 +    exec: createExec('tsfile saveas')
   1.587 +  },
   1.588 +  {
   1.589 +    item: 'command',
   1.590 +    name: 'tsfile save',
   1.591 +    description: 'a file param in save mode',
   1.592 +    params: [
   1.593 +      {
   1.594 +        name: 'p1',
   1.595 +        type: {
   1.596 +          name: 'file',
   1.597 +          filetype: 'file',
   1.598 +          existing: 'maybe'
   1.599 +        }
   1.600 +      }
   1.601 +    ],
   1.602 +    exec: createExec('tsfile save')
   1.603 +  },
   1.604 +  {
   1.605 +    item: 'command',
   1.606 +    name: 'tsfile cd',
   1.607 +    description: 'a file param in cd mode',
   1.608 +    params: [
   1.609 +      {
   1.610 +        name: 'p1',
   1.611 +        type: {
   1.612 +          name: 'file',
   1.613 +          filetype: 'directory',
   1.614 +          existing: 'yes'
   1.615 +        }
   1.616 +      }
   1.617 +    ],
   1.618 +    exec: createExec('tsfile cd')
   1.619 +  },
   1.620 +  {
   1.621 +    item: 'command',
   1.622 +    name: 'tsfile mkdir',
   1.623 +    description: 'a file param in mkdir mode',
   1.624 +    params: [
   1.625 +      {
   1.626 +        name: 'p1',
   1.627 +        type: {
   1.628 +          name: 'file',
   1.629 +          filetype: 'directory',
   1.630 +          existing: 'no'
   1.631 +        }
   1.632 +      }
   1.633 +    ],
   1.634 +    exec: createExec('tsfile mkdir')
   1.635 +  },
   1.636 +  {
   1.637 +    item: 'command',
   1.638 +    name: 'tsfile rm',
   1.639 +    description: 'a file param in rm mode',
   1.640 +    params: [
   1.641 +      {
   1.642 +        name: 'p1',
   1.643 +        type: {
   1.644 +          name: 'file',
   1.645 +          filetype: 'any',
   1.646 +          existing: 'yes'
   1.647 +        }
   1.648 +      }
   1.649 +    ],
   1.650 +    exec: createExec('tsfile rm')
   1.651 +  },
   1.652 +  {
   1.653 +    item: 'command',
   1.654 +    name: 'tsslow',
   1.655 +    params: [
   1.656 +      {
   1.657 +        name: 'hello',
   1.658 +        type: {
   1.659 +          name: 'selection',
   1.660 +          data: function(context) {
   1.661 +            var deferred = context.defer();
   1.662 +
   1.663 +            var resolve = function() {
   1.664 +              deferred.resolve([
   1.665 +                'Shalom', 'Namasté', 'Hallo', 'Dydd-da',
   1.666 +                'Chào', 'Hej', 'Saluton', 'Sawubona'
   1.667 +              ]);
   1.668 +            };
   1.669 +
   1.670 +            setTimeout(resolve, 10);
   1.671 +            return deferred.promise;
   1.672 +          }
   1.673 +        }
   1.674 +      }
   1.675 +    ],
   1.676 +    exec: function(args, context) {
   1.677 +      return 'Test completed';
   1.678 +    }
   1.679 +  }
   1.680 +];

mercurial