browser/devtools/commandline/test/mockCommands.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright 2012, Mozilla Foundation and contributors
     3  *
     4  * Licensed under the Apache License, Version 2.0 (the "License");
     5  * you may not use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  * http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.
    15  */
    17 'use strict';
    18 // <INJECTED SOURCE:START>
    20 // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
    21 // DO NOT EDIT IT DIRECTLY
    23 // <INJECTED SOURCE:END>
    26 var mockCommands = {};
    28 // We use an alias for exports here because this module is used in Firefox
    29 // mochitests where we don't have define/require
    31 /**
    32  * Registration and de-registration.
    33  */
    34 mockCommands.setup = function(requisition) {
    35   mockCommands.items.forEach(function(item) {
    36     if (item.item === 'command') {
    37       requisition.canon.addCommand(item);
    38     }
    39     else if (item.item === 'type') {
    40       requisition.types.addType(item);
    41     }
    42     else {
    43       console.error('Ignoring item ', item);
    44     }
    45   });
    46 };
    48 mockCommands.shutdown = function(requisition) {
    49   mockCommands.items.forEach(function(item) {
    50     if (item.item === 'command') {
    51       requisition.canon.removeCommand(item);
    52     }
    53     else if (item.item === 'type') {
    54       requisition.types.removeType(item);
    55     }
    56     else {
    57       console.error('Ignoring item ', item);
    58     }
    59   });
    60 };
    62 function createExec(name) {
    63   return function(args, executionContext) {
    64     var argsOut = Object.keys(args).map(function(key) {
    65       return key + '=' + args[key];
    66     }).join(', ');
    67     return 'Exec: ' + name + ' ' + argsOut;
    68   };
    69 }
    71 mockCommands.items = [
    72   {
    73     item: 'type',
    74     name: 'optionType',
    75     parent: 'selection',
    76     lookup: [
    77       {
    78         name: 'option1',
    79         value: 'string'
    80       },
    81       {
    82         name: 'option2',
    83         value: 'number'
    84       },
    85       {
    86         name: 'option3',
    87         value: {
    88           name: 'selection',
    89           lookup: [
    90             { name: 'one', value: 1 },
    91             { name: 'two', value: 2 },
    92             { name: 'three', value: 3 }
    93           ]
    94         }
    95       }
    96     ]
    97   },
    98   {
    99     item: 'type',
   100     name: 'optionValue',
   101     parent: 'delegate',
   102     delegateType: function(executionContext) {
   103       if (executionContext != null) {
   104         var option = executionContext.getArgsObject().optionType;
   105         if (option != null) {
   106           return option;
   107         }
   108       }
   109       return 'blank';
   110     }
   111   },
   112   {
   113     item: 'command',
   114     name: 'tsv',
   115     params: [
   116       { name: 'optionType', type: 'optionType' },
   117       { name: 'optionValue', type: 'optionValue' }
   118     ],
   119     exec: createExec('tsv')
   120   },
   121   {
   122     item: 'command',
   123     name: 'tsr',
   124     params: [ { name: 'text', type: 'string' } ],
   125     exec: createExec('tsr')
   126   },
   127   {
   128     item: 'command',
   129     name: 'tsrsrsr',
   130     params: [
   131       { name: 'p1', type: 'string' },
   132       { name: 'p2', type: 'string' },
   133       { name: 'p3', type: { name: 'string', allowBlank: true} },
   134     ],
   135     exec: createExec('tsrsrsr')
   136   },
   137   {
   138     item: 'command',
   139     name: 'tso',
   140     params: [ { name: 'text', type: 'string', defaultValue: null } ],
   141     exec: createExec('tso')
   142   },
   143   {
   144     item: 'command',
   145     name: 'tse',
   146     params: [
   147       { name: 'node', type: 'node' },
   148       {
   149         group: 'options',
   150         params: [
   151           { name: 'nodes', type: { name: 'nodelist' } },
   152           { name: 'nodes2', type: { name: 'nodelist', allowEmpty: true } }
   153         ]
   154       }
   155     ],
   156     exec: createExec('tse')
   157   },
   158   {
   159     item: 'command',
   160     name: 'tsj',
   161     params: [ { name: 'javascript', type: 'javascript' } ],
   162     exec: createExec('tsj')
   163   },
   164   {
   165     item: 'command',
   166     name: 'tsb',
   167     params: [ { name: 'toggle', type: 'boolean' } ],
   168     exec: createExec('tsb')
   169   },
   170   {
   171     item: 'command',
   172     name: 'tss',
   173     exec: createExec('tss')
   174   },
   175   {
   176     item: 'command',
   177     name: 'tsu',
   178     params: [
   179       {
   180         name: 'num',
   181         type: {
   182           name: 'number',
   183           max: 10,
   184           min: -5,
   185           step: 3
   186         }
   187       }
   188     ],
   189     exec: createExec('tsu')
   190   },
   191   {
   192     item: 'command',
   193     name: 'tsf',
   194     params: [
   195       {
   196         name: 'num',
   197         type: {
   198           name: 'number',
   199           allowFloat: true,
   200           max: 11.5,
   201           min: -6.5,
   202           step: 1.5
   203         }
   204       }
   205     ],
   206     exec: createExec('tsf')
   207   },
   208   {
   209     item: 'command',
   210     name: 'tsn'
   211   },
   212   {
   213     item: 'command',
   214     name: 'tsn dif',
   215     params: [ { name: 'text', type: 'string', description: 'tsn dif text' } ],
   216     exec: createExec('tsnDif')
   217   },
   218   {
   219     item: 'command',
   220     name: 'tsn hidden',
   221     hidden: true,
   222     exec: createExec('tsnHidden')
   223   },
   224   {
   225     item: 'command',
   226     name: 'tsn ext',
   227     params: [ { name: 'text', type: 'string' } ],
   228     exec: createExec('tsnExt')
   229   },
   230   {
   231     item: 'command',
   232     name: 'tsn exte',
   233     params: [ { name: 'text', type: 'string' } ],
   234     exec: createExec('tsnExte')
   235   },
   236   {
   237     item: 'command',
   238     name: 'tsn exten',
   239     params: [ { name: 'text', type: 'string' } ],
   240     exec: createExec('tsnExten')
   241   },
   242   {
   243     item: 'command',
   244     name: 'tsn extend',
   245     params: [ { name: 'text', type: 'string' } ],
   246     exec: createExec('tsnExtend')
   247   },
   248   {
   249     item: 'command',
   250     name: 'tsn deep'
   251   },
   252   {
   253     item: 'command',
   254     name: 'tsn deep down'
   255   },
   256   {
   257     item: 'command',
   258     name: 'tsn deep down nested'
   259   },
   260   {
   261     item: 'command',
   262     name: 'tsn deep down nested cmd',
   263     exec: createExec('tsnDeepDownNestedCmd')
   264   },
   265   {
   266     item: 'command',
   267     name: 'tshidden',
   268     hidden: true,
   269     params: [
   270       {
   271         group: 'Options',
   272         params: [
   273           {
   274             name: 'visible',
   275             type: 'string',
   276             short: 'v',
   277             defaultValue: null,
   278             description: 'visible'
   279           },
   280           {
   281             name: 'invisiblestring',
   282             type: 'string',
   283             short: 'i',
   284             description: 'invisiblestring',
   285             defaultValue: null,
   286             hidden: true
   287           },
   288           {
   289             name: 'invisibleboolean',
   290             short: 'b',
   291             type: 'boolean',
   292             description: 'invisibleboolean',
   293             hidden: true
   294           }
   295         ]
   296       }
   297     ],
   298     exec: createExec('tshidden')
   299   },
   300   {
   301     item: 'command',
   302     name: 'tselarr',
   303     params: [
   304       { name: 'num', type: { name: 'selection', data: [ '1', '2', '3' ] } },
   305       { name: 'arr', type: { name: 'array', subtype: 'string' } }
   306     ],
   307     exec: createExec('tselarr')
   308   },
   309   {
   310     item: 'command',
   311     name: 'tsm',
   312     description: 'a 3-param test selection|string|number',
   313     params: [
   314       { name: 'abc', type: { name: 'selection', data: [ 'a', 'b', 'c' ] } },
   315       { name: 'txt', type: 'string' },
   316       { name: 'num', type: { name: 'number', max: 42, min: 0 } }
   317     ],
   318     exec: createExec('tsm')
   319   },
   320   {
   321     item: 'command',
   322     name: 'tsg',
   323     description: 'a param group test',
   324     params: [
   325       {
   326         name: 'solo',
   327         type: { name: 'selection', data: [ 'aaa', 'bbb', 'ccc' ] },
   328         description: 'solo param'
   329       },
   330       {
   331         group: 'First',
   332         params: [
   333           {
   334             name: 'txt1',
   335             type: 'string',
   336             defaultValue: null,
   337             description: 'txt1 param'
   338           },
   339           {
   340             name: 'bool',
   341             type: 'boolean',
   342             description: 'bool param'
   343           }
   344         ]
   345       },
   346       {
   347         name: 'txt2',
   348         type: 'string',
   349         defaultValue: 'd',
   350         description: 'txt2 param',
   351         option: 'Second'
   352       },
   353       {
   354         name: 'num',
   355         type: { name: 'number', min: 40 },
   356         defaultValue: 42,
   357         description: 'num param',
   358         option: 'Second'
   359       }
   360     ],
   361     exec: createExec('tsg')
   362   },
   363   {
   364     item: 'command',
   365     name: 'tscook',
   366     description: 'param group test to catch problems with cookie command',
   367     params: [
   368       {
   369         name: 'key',
   370         type: 'string',
   371         description: 'tscookKeyDesc'
   372       },
   373       {
   374         name: 'value',
   375         type: 'string',
   376         description: 'tscookValueDesc'
   377       },
   378       {
   379         group: 'tscookOptionsDesc',
   380         params: [
   381           {
   382             name: 'path',
   383             type: 'string',
   384             defaultValue: '/',
   385             description: 'tscookPathDesc'
   386           },
   387           {
   388             name: 'domain',
   389             type: 'string',
   390             defaultValue: null,
   391             description: 'tscookDomainDesc'
   392           },
   393           {
   394             name: 'secure',
   395             type: 'boolean',
   396             description: 'tscookSecureDesc'
   397           }
   398         ]
   399       }
   400     ],
   401     exec: createExec('tscook')
   402   },
   403   {
   404     item: 'command',
   405     name: 'tslong',
   406     description: 'long param tests to catch problems with the jsb command',
   407     params: [
   408       {
   409         name: 'msg',
   410         type: 'string',
   411         description: 'msg Desc'
   412       },
   413       {
   414         group: 'Options Desc',
   415         params: [
   416           {
   417             name: 'num',
   418             short: 'n',
   419             type: 'number',
   420             description: 'num Desc',
   421             defaultValue: 2
   422           },
   423           {
   424             name: 'sel',
   425             short: 's',
   426             type: {
   427               name: 'selection',
   428               lookup: [
   429                 { name: 'space', value: ' ' },
   430                 { name: 'tab', value: '\t' }
   431               ]
   432             },
   433             description: 'sel Desc',
   434             defaultValue: ' '
   435           },
   436           {
   437             name: 'bool',
   438             short: 'b',
   439             type: 'boolean',
   440             description: 'bool Desc'
   441           },
   442           {
   443             name: 'num2',
   444             short: 'm',
   445             type: 'number',
   446             description: 'num2 Desc',
   447             defaultValue: -1
   448           },
   449           {
   450             name: 'bool2',
   451             short: 'c',
   452             type: 'boolean',
   453             description: 'bool2 Desc'
   454           },
   455           {
   456             name: 'sel2',
   457             short: 't',
   458             type: {
   459               name: 'selection',
   460               data: [ 'collapse', 'basic', 'with space', 'with two spaces' ]
   461             },
   462             description: 'sel2 Desc',
   463             defaultValue: 'collapse'
   464           }
   465         ]
   466       }
   467     ],
   468     exec: createExec('tslong')
   469   },
   470   {
   471     item: 'command',
   472     name: 'tsdate',
   473     description: 'long param tests to catch problems with the jsb command',
   474     params: [
   475       {
   476         name: 'd1',
   477         type: 'date',
   478       },
   479       {
   480         name: 'd2',
   481         type: {
   482           name: 'date',
   483           min: '1 jan 2000',
   484           max: '28 feb 2000',
   485           step: 2
   486         }
   487       },
   488     ],
   489     exec: createExec('tsdate')
   490   },
   491   {
   492     item: 'command',
   493     name: 'tsfail',
   494     description: 'test errors',
   495     params: [
   496       {
   497         name: 'method',
   498         type: {
   499           name: 'selection',
   500           data: [
   501             'reject', 'rejecttyped',
   502             'throwerror', 'throwstring', 'throwinpromise',
   503             'noerror'
   504           ]
   505         }
   506       }
   507     ],
   508     exec: function(args, context) {
   509       var deferred;
   510       if (args.method === 'reject') {
   511         deferred = context.defer();
   512         setTimeout(function() {
   513           deferred.reject('rejected promise');
   514         }, 10);
   515         return deferred.promise;
   516       }
   518       if (args.method === 'rejecttyped') {
   519         deferred = context.defer();
   520         setTimeout(function() {
   521           deferred.reject(context.typedData('number', 54));
   522         }, 10);
   523         return deferred.promise;
   524       }
   526       if (args.method === 'throwinpromise') {
   527         deferred = context.defer();
   528         setTimeout(function() {
   529           deferred.resolve('should be lost');
   530         }, 10);
   531         return deferred.promise.then(function() {
   532           var t = null;
   533           return t.foo;
   534         });
   535       }
   537       if (args.method === 'throwerror') {
   538         throw new Error('thrown error');
   539       }
   541       if (args.method === 'throwstring') {
   542         throw 'thrown string';
   543       }
   545       return 'no error';
   546     }
   547   },
   548   {
   549     item: 'command',
   550     name: 'tsfile',
   551     description: 'test file params',
   552   },
   553   {
   554     item: 'command',
   555     name: 'tsfile open',
   556     description: 'a file param in open mode',
   557     params: [
   558       {
   559         name: 'p1',
   560         type: {
   561           name: 'file',
   562           filetype: 'file',
   563           existing: 'yes'
   564         }
   565       }
   566     ],
   567     exec: createExec('tsfile open')
   568   },
   569   {
   570     item: 'command',
   571     name: 'tsfile saveas',
   572     description: 'a file param in saveas mode',
   573     params: [
   574       {
   575         name: 'p1',
   576         type: {
   577           name: 'file',
   578           filetype: 'file',
   579           existing: 'no'
   580         }
   581       }
   582     ],
   583     exec: createExec('tsfile saveas')
   584   },
   585   {
   586     item: 'command',
   587     name: 'tsfile save',
   588     description: 'a file param in save mode',
   589     params: [
   590       {
   591         name: 'p1',
   592         type: {
   593           name: 'file',
   594           filetype: 'file',
   595           existing: 'maybe'
   596         }
   597       }
   598     ],
   599     exec: createExec('tsfile save')
   600   },
   601   {
   602     item: 'command',
   603     name: 'tsfile cd',
   604     description: 'a file param in cd mode',
   605     params: [
   606       {
   607         name: 'p1',
   608         type: {
   609           name: 'file',
   610           filetype: 'directory',
   611           existing: 'yes'
   612         }
   613       }
   614     ],
   615     exec: createExec('tsfile cd')
   616   },
   617   {
   618     item: 'command',
   619     name: 'tsfile mkdir',
   620     description: 'a file param in mkdir mode',
   621     params: [
   622       {
   623         name: 'p1',
   624         type: {
   625           name: 'file',
   626           filetype: 'directory',
   627           existing: 'no'
   628         }
   629       }
   630     ],
   631     exec: createExec('tsfile mkdir')
   632   },
   633   {
   634     item: 'command',
   635     name: 'tsfile rm',
   636     description: 'a file param in rm mode',
   637     params: [
   638       {
   639         name: 'p1',
   640         type: {
   641           name: 'file',
   642           filetype: 'any',
   643           existing: 'yes'
   644         }
   645       }
   646     ],
   647     exec: createExec('tsfile rm')
   648   },
   649   {
   650     item: 'command',
   651     name: 'tsslow',
   652     params: [
   653       {
   654         name: 'hello',
   655         type: {
   656           name: 'selection',
   657           data: function(context) {
   658             var deferred = context.defer();
   660             var resolve = function() {
   661               deferred.resolve([
   662                 'Shalom', 'Namasté', 'Hallo', 'Dydd-da',
   663                 'Chào', 'Hej', 'Saluton', 'Sawubona'
   664               ]);
   665             };
   667             setTimeout(resolve, 10);
   668             return deferred.promise;
   669           }
   670         }
   671       }
   672     ],
   673     exec: function(args, context) {
   674       return 'Test completed';
   675     }
   676   }
   677 ];

mercurial