browser/devtools/commandline/test/browser_gcli_cli2.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 var exports = {};
    25 var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testCli2.js</p>";
    27 function test() {
    28   return Task.spawn(function() {
    29     let options = yield helpers.openTab(TEST_URI);
    30     yield helpers.openToolbar(options);
    31     gcli.addItems(mockCommands.items);
    33     yield helpers.runTests(options, exports);
    35     gcli.removeItems(mockCommands.items);
    36     yield helpers.closeToolbar(options);
    37     yield helpers.closeTab(options);
    38   }).then(finish, helpers.handleError);
    39 }
    41 // <INJECTED SOURCE:END>
    43 // var helpers = require('./helpers');
    45 var nodetype = require('gcli/types/node');
    47 exports.setup = function(options) {
    48   if (options.window) {
    49     nodetype.setDocument(options.window.document);
    50   }
    51 };
    53 exports.shutdown = function(options) {
    54   nodetype.unsetDocument();
    55 };
    57 exports.testSingleString = function(options) {
    58   return helpers.audit(options, [
    59     {
    60       setup:    'tsr',
    61       check: {
    62         input:  'tsr',
    63         hints:     ' <text>',
    64         markup: 'VVV',
    65         cursor: 3,
    66         current: '__command',
    67         status: 'ERROR',
    68         unassigned: [ ],
    69         args: {
    70           command: { name: 'tsr' },
    71           text: {
    72             value: undefined,
    73             arg: '',
    74             status: 'INCOMPLETE',
    75             message: 'Value required for \'text\'.'
    76           }
    77         }
    78       }
    79     },
    80     {
    81       setup:    'tsr ',
    82       check: {
    83         input:  'tsr ',
    84         hints:      '<text>',
    85         markup: 'VVVV',
    86         cursor: 4,
    87         current: 'text',
    88         status: 'ERROR',
    89         predictions: [ ],
    90         unassigned: [ ],
    91         args: {
    92           command: { name: 'tsr' },
    93           text: {
    94             value: undefined,
    95             arg: '',
    96             status: 'INCOMPLETE',
    97             message: 'Value required for \'text\'.'
    98           }
    99         }
   100       }
   101     },
   102     {
   103       setup:    'tsr h',
   104       check: {
   105         input:  'tsr h',
   106         hints:       '',
   107         markup: 'VVVVV',
   108         cursor: 5,
   109         current: 'text',
   110         status: 'VALID',
   111         predictions: [ ],
   112         unassigned: [ ],
   113         args: {
   114           command: { name: 'tsr' },
   115           text: {
   116             value: 'h',
   117             arg: ' h',
   118             status: 'VALID',
   119             message: ''
   120           }
   121         }
   122       }
   123     },
   124     {
   125       setup:    'tsr "h h"',
   126       check: {
   127         input:  'tsr "h h"',
   128         hints:           '',
   129         markup: 'VVVVVVVVV',
   130         cursor: 9,
   131         current: 'text',
   132         status: 'VALID',
   133         predictions: [ ],
   134         unassigned: [ ],
   135         args: {
   136           command: { name: 'tsr' },
   137           text: {
   138             value: 'h h',
   139             arg: ' "h h"',
   140             status: 'VALID',
   141             message: ''
   142           }
   143         }
   144       }
   145     },
   146     {
   147       setup:    'tsr h h h',
   148       check: {
   149         input:  'tsr h h h',
   150         hints:           '',
   151         markup: 'VVVVVVVVV',
   152         cursor: 9,
   153         current: 'text',
   154         status: 'VALID',
   155         predictions: [ ],
   156         unassigned: [ ],
   157         args: {
   158           command: { name: 'tsr' },
   159           text: {
   160             value: 'h h h',
   161             arg: ' h h h',
   162             status: 'VALID',
   163             message: ''
   164           }
   165         }
   166       }
   167     }
   168   ]);
   169 };
   171 exports.testSingleNumber = function(options) {
   172   return helpers.audit(options, [
   173     {
   174       setup:    'tsu',
   175       check: {
   176         input:  'tsu',
   177         hints:     ' <num>',
   178         markup: 'VVV',
   179         cursor: 3,
   180         current: '__command',
   181         status: 'ERROR',
   182         predictions: [ ],
   183         unassigned: [ ],
   184         args: {
   185           command: { name: 'tsu' },
   186           num: {
   187             value: undefined,
   188             arg: '',
   189             status: 'INCOMPLETE',
   190             message: 'Value required for \'num\'.'
   191           }
   192         }
   193       }
   194     },
   195     {
   196       setup:    'tsu ',
   197       check: {
   198         input:  'tsu ',
   199         hints:      '<num>',
   200         markup: 'VVVV',
   201         cursor: 4,
   202         current: 'num',
   203         status: 'ERROR',
   204         predictions: [ ],
   205         unassigned: [ ],
   206         args: {
   207           command: { name: 'tsu' },
   208           num: {
   209             value: undefined,
   210             arg: '',
   211             status: 'INCOMPLETE',
   212             message: 'Value required for \'num\'.'
   213           }
   214         }
   215       }
   216     },
   217     {
   218       setup:    'tsu 1',
   219       check: {
   220         input:  'tsu 1',
   221         hints:       '',
   222         markup: 'VVVVV',
   223         cursor: 5,
   224         current: 'num',
   225         status: 'VALID',
   226         predictions: [ ],
   227         unassigned: [ ],
   228         args: {
   229           command: { name: 'tsu' },
   230           num: { value: 1, arg: ' 1', status: 'VALID', message: '' }
   231         }
   232       }
   233     },
   234     {
   235       setup:    'tsu x',
   236       check: {
   237         input:  'tsu x',
   238         hints:       '',
   239         markup: 'VVVVE',
   240         cursor: 5,
   241         current: 'num',
   242         status: 'ERROR',
   243         predictions: [ ],
   244         unassigned: [ ],
   245         tooltipState: 'true:isError',
   246         args: {
   247           command: { name: 'tsu' },
   248           num: {
   249             value: undefined,
   250             arg: ' x',
   251             status: 'ERROR',
   252             message: 'Can\'t convert "x" to a number.'
   253           }
   254         }
   255       }
   256     },
   257     {
   258       setup:    'tsu 1.5',
   259       check: {
   260         input:  'tsu 1.5',
   261         hints:       '',
   262         markup: 'VVVVEEE',
   263         cursor: 7,
   264         current: 'num',
   265         status: 'ERROR',
   266         predictions: [ ],
   267         unassigned: [ ],
   268         args: {
   269           command: { name: 'tsu' },
   270           num: {
   271             value: undefined,
   272             arg: ' 1.5',
   273             status: 'ERROR',
   274             message: 'Can\'t convert "1.5" to an integer.'
   275           }
   276         }
   277       }
   278     }
   279   ]);
   280 };
   282 exports.testSingleFloat = function(options) {
   283   return helpers.audit(options, [
   284     {
   285       setup:    'tsf',
   286       check: {
   287         input:  'tsf',
   288         hints:     ' <num>',
   289         markup: 'VVV',
   290         cursor: 3,
   291         current: '__command',
   292         status: 'ERROR',
   293         error: '',
   294         unassigned: [ ],
   295         args: {
   296           command: { name: 'tsf' },
   297           num: {
   298             value: undefined,
   299             arg: '',
   300             status: 'INCOMPLETE',
   301             message: 'Value required for \'num\'.'
   302           }
   303         }
   304       }
   305     },
   306     {
   307       setup:    'tsf 1',
   308       check: {
   309         input:  'tsf 1',
   310         hints:       '',
   311         markup: 'VVVVV',
   312         cursor: 5,
   313         current: 'num',
   314         status: 'VALID',
   315         error: '',
   316         predictions: [ ],
   317         unassigned: [ ],
   318         args: {
   319           command: { name: 'tsf' },
   320           num: { value: 1, arg: ' 1', status: 'VALID', message: '' }
   321         }
   322       }
   323     },
   324     {
   325       setup:    'tsf 1.',
   326       check: {
   327         input:  'tsf 1.',
   328         hints:        '',
   329         markup: 'VVVVVV',
   330         cursor: 6,
   331         current: 'num',
   332         status: 'VALID',
   333         error: '',
   334         predictions: [ ],
   335         unassigned: [ ],
   336         args: {
   337           command: { name: 'tsf' },
   338           num: { value: 1, arg: ' 1.', status: 'VALID', message: '' }
   339         }
   340       }
   341     },
   342     {
   343       setup:    'tsf 1.5',
   344       check: {
   345         input:  'tsf 1.5',
   346         hints:         '',
   347         markup: 'VVVVVVV',
   348         cursor: 7,
   349         current: 'num',
   350         status: 'VALID',
   351         error: '',
   352         predictions: [ ],
   353         unassigned: [ ],
   354         args: {
   355           command: { name: 'tsf' },
   356           num: { value: 1.5, arg: ' 1.5', status: 'VALID', message: '' }
   357         }
   358       }
   359     },
   360     {
   361       setup:    'tsf 1.5x',
   362       check: {
   363         input:  'tsf 1.5x',
   364         hints:          '',
   365         markup: 'VVVVVVVV',
   366         cursor: 8,
   367         current: 'num',
   368         status: 'VALID',
   369         error: '',
   370         predictions: [ ],
   371         unassigned: [ ],
   372         args: {
   373           command: { name: 'tsf' },
   374           num: { value: 1.5, arg: ' 1.5x', status: 'VALID', message: '' }
   375         }
   376       }
   377     },
   378     {
   379       skipRemainingIf: options.isNoDom,
   380       name: 'tsf x (cursor=4)',
   381       setup: function() {
   382         return helpers.setInput(options, 'tsf x', 4);
   383       },
   384       check: {
   385         input:  'tsf x',
   386         hints:       '',
   387         markup: 'VVVVE',
   388         cursor: 4,
   389         current: 'num',
   390         status: 'ERROR',
   391         error: 'Can\'t convert "x" to a number.',
   392         predictions: [ ],
   393         unassigned: [ ],
   394         args: {
   395           command: { name: 'tsf' },
   396           num: {
   397             value: undefined,
   398             arg: ' x',
   399             status: 'ERROR',
   400             message: 'Can\'t convert "x" to a number.'
   401           }
   402         }
   403       }
   404     }
   405   ]);
   406 };
   408 exports.testElementWeb = function(options) {
   409   var inputElement = options.isNoDom ?
   410       null :
   411       options.window.document.getElementById('gcli-input');
   413   return helpers.audit(options, [
   414     {
   415       skipIf: function gcliInputElementExists() {
   416         return inputElement == null;
   417       },
   418       setup:    'tse #gcli-input',
   419       check: {
   420         input:  'tse #gcli-input',
   421         hints:                 ' [options]',
   422         markup: 'VVVVVVVVVVVVVVV',
   423         cursor: 15,
   424         current: 'node',
   425         status: 'VALID',
   426         predictions: [ ],
   427         unassigned: [ ],
   428         args: {
   429           command: { name: 'tse' },
   430           node: {
   431             value: inputElement,
   432             arg: ' #gcli-input',
   433             status: 'VALID',
   434             message: ''
   435           },
   436           nodes: { arg: '', status: 'VALID', message: '' },
   437           nodes2: { arg: '', status: 'VALID', message: '' },
   438         }
   439       }
   440     }
   441   ]);
   442 };
   444 exports.testElement = function(options) {
   445   return helpers.audit(options, [
   446     {
   447       skipRemainingIf: options.isNoDom,
   448       setup:    'tse',
   449       check: {
   450         input:  'tse',
   451         hints:     ' <node> [options]',
   452         markup: 'VVV',
   453         cursor: 3,
   454         current: '__command',
   455         status: 'ERROR',
   456         predictions: [ 'tse', 'tselarr' ],
   457         unassigned: [ ],
   458         args: {
   459           command: { name: 'tse' },
   460           node: { value: undefined, arg: '', status: 'INCOMPLETE' },
   461           nodes: { arg: '', status: 'VALID', message: '' },
   462           nodes2: { arg: '', status: 'VALID', message: '' },
   463         }
   464       }
   465     },
   466     {
   467       setup:    'tse #gcli-nomatch',
   468       check: {
   469         input:  'tse #gcli-nomatch',
   470         hints:                   ' [options]',
   471         markup: 'VVVVIIIIIIIIIIIII',
   472         cursor: 17,
   473         current: 'node',
   474         status: 'ERROR',
   475         predictions: [ ],
   476         unassigned: [ ],
   477         outputState: 'false:default',
   478         tooltipState: 'true:isError',
   479         args: {
   480           command: { name: 'tse' },
   481           node: {
   482             value: undefined,
   483             arg: ' #gcli-nomatch',
   484             // This is somewhat debatable because this input can't be corrected
   485             // simply by typing so it's and error rather than incomplete,
   486             // however without digging into the CSS engine we can't tell that
   487             // so we default to incomplete
   488             status: 'INCOMPLETE',
   489             message: 'No matches'
   490           },
   491           nodes: { arg: '', status: 'VALID', message: '' },
   492           nodes2: { arg: '', status: 'VALID', message: '' },
   493         }
   494       }
   495     },
   496     {
   497       setup:    'tse #',
   498       check: {
   499         input:  'tse #',
   500         hints:       ' [options]',
   501         markup: 'VVVVE',
   502         cursor: 5,
   503         current: 'node',
   504         status: 'ERROR',
   505         predictions: [ ],
   506         unassigned: [ ],
   507         tooltipState: 'true:isError',
   508         args: {
   509           command: { name: 'tse' },
   510           node: {
   511             value: undefined,
   512             arg: ' #',
   513             status: 'ERROR',
   514             message: 'Syntax error in CSS query'
   515           },
   516           nodes: { arg: '', status: 'VALID', message: '' },
   517           nodes2: { arg: '', status: 'VALID', message: '' },
   518         }
   519       }
   520     },
   521     {
   522       setup:    'tse .',
   523       check: {
   524         input:  'tse .',
   525         hints:       ' [options]',
   526         markup: 'VVVVE',
   527         cursor: 5,
   528         current: 'node',
   529         status: 'ERROR',
   530         predictions: [ ],
   531         unassigned: [ ],
   532         tooltipState: 'true:isError',
   533         args: {
   534           command: { name: 'tse' },
   535           node: {
   536             value: undefined,
   537             arg: ' .',
   538             status: 'ERROR',
   539             message: 'Syntax error in CSS query'
   540           },
   541           nodes: { arg: '', status: 'VALID', message: '' },
   542           nodes2: { arg: '', status: 'VALID', message: '' },
   543         }
   544       }
   545     },
   546     {
   547       setup:    'tse *',
   548       check: {
   549         input:  'tse *',
   550         hints:       ' [options]',
   551         markup: 'VVVVE',
   552         cursor: 5,
   553         current: 'node',
   554         status: 'ERROR',
   555         predictions: [ ],
   556         unassigned: [ ],
   557         tooltipState: 'true:isError',
   558         args: {
   559           command: { name: 'tse' },
   560           node: {
   561             value: undefined,
   562             arg: ' *',
   563             status: 'ERROR',
   564             message: /^Too many matches \([0-9]*\)/
   565           },
   566           nodes: { arg: '', status: 'VALID', message: '' },
   567           nodes2: { arg: '', status: 'VALID', message: '' },
   568         }
   569       }
   570     }
   571   ]);
   572 };
   574 exports.testNestedCommand = function(options) {
   575   return helpers.audit(options, [
   576     {
   577       setup:    'tsn',
   578       check: {
   579         input:  'tsn',
   580         hints:     ' deep down nested cmd',
   581         markup: 'III',
   582         cursor: 3,
   583         current: '__command',
   584         status: 'ERROR',
   585         predictionsInclude: [
   586           'tsn deep', 'tsn deep down', 'tsn deep down nested',
   587           'tsn deep down nested cmd', 'tsn dif'
   588         ],
   589         unassigned: [ ],
   590         args: {
   591           command: { name: 'tsn' }
   592         }
   593       }
   594     },
   595     {
   596       setup:    'tsn ',
   597       check: {
   598         input:  'tsn ',
   599         hints:      ' deep down nested cmd',
   600         markup: 'IIIV',
   601         cursor: 4,
   602         current: '__command',
   603         status: 'ERROR',
   604         unassigned: [ ]
   605       }
   606     },
   607     {
   608       skipIf: options.isPhantomjs,
   609       setup:    'tsn x',
   610       check: {
   611         input:  'tsn x',
   612         hints:       ' -> tsn ext',
   613         markup: 'IIIVI',
   614         cursor: 5,
   615         current: '__command',
   616         status: 'ERROR',
   617         predictions: [ 'tsn ext' ],
   618         unassigned: [ ]
   619       }
   620     },
   621     {
   622       setup:    'tsn dif',
   623       check: {
   624         input:  'tsn dif',
   625         hints:         ' <text>',
   626         markup: 'VVVVVVV',
   627         cursor: 7,
   628         current: '__command',
   629         status: 'ERROR',
   630         predictions: [ ],
   631         unassigned: [ ],
   632         args: {
   633           command: { name: 'tsn dif' },
   634           text: {
   635             value: undefined,
   636             arg: '',
   637             status: 'INCOMPLETE',
   638             message: 'Value required for \'text\'.'
   639           }
   640         }
   641       }
   642     },
   643     {
   644       setup:    'tsn dif ',
   645       check: {
   646         input:  'tsn dif ',
   647         hints:          '<text>',
   648         markup: 'VVVVVVVV',
   649         cursor: 8,
   650         current: 'text',
   651         status: 'ERROR',
   652         predictions: [ ],
   653         unassigned: [ ],
   654         args: {
   655           command: { name: 'tsn dif' },
   656           text: {
   657             value: undefined,
   658             arg: '',
   659             status: 'INCOMPLETE',
   660             message: 'Value required for \'text\'.'
   661           }
   662         }
   663       }
   664     },
   665     {
   666       setup:    'tsn dif x',
   667       check: {
   668         input:  'tsn dif x',
   669         hints:           '',
   670         markup: 'VVVVVVVVV',
   671         cursor: 9,
   672         current: 'text',
   673         status: 'VALID',
   674         predictions: [ ],
   675         unassigned: [ ],
   676         args: {
   677           command: { name: 'tsn dif' },
   678           text: { value: 'x', arg: ' x', status: 'VALID', message: '' }
   679         }
   680       }
   681     },
   682     {
   683       setup:    'tsn ext',
   684       check: {
   685         input:  'tsn ext',
   686         hints:         ' <text>',
   687         markup: 'VVVVVVV',
   688         cursor: 7,
   689         current: '__command',
   690         status: 'ERROR',
   691         predictions: [ 'tsn ext', 'tsn exte', 'tsn exten', 'tsn extend' ],
   692         unassigned: [ ],
   693         args: {
   694           command: { name: 'tsn ext' },
   695           text: {
   696             value: undefined,
   697             arg: '',
   698             status: 'INCOMPLETE',
   699             message: 'Value required for \'text\'.'
   700           }
   701         }
   702       }
   703     },
   704     {
   705       setup:    'tsn exte',
   706       check: {
   707         input:  'tsn exte',
   708         hints:          ' <text>',
   709         markup: 'VVVVVVVV',
   710         cursor: 8,
   711         current: '__command',
   712         status: 'ERROR',
   713         predictions: [ 'tsn exte', 'tsn exten', 'tsn extend' ],
   714         unassigned: [ ],
   715         args: {
   716           command: { name: 'tsn exte' },
   717           text: {
   718             value: undefined,
   719             arg: '',
   720             status: 'INCOMPLETE',
   721             message: 'Value required for \'text\'.'
   722           }
   723         }
   724       }
   725     },
   726     {
   727       setup:    'tsn exten',
   728       check: {
   729         input:  'tsn exten',
   730         hints:           ' <text>',
   731         markup: 'VVVVVVVVV',
   732         cursor: 9,
   733         current: '__command',
   734         status: 'ERROR',
   735         predictions: [ 'tsn exten', 'tsn extend' ],
   736         unassigned: [ ],
   737         args: {
   738           command: { name: 'tsn exten' },
   739           text: {
   740             value: undefined,
   741             arg: '',
   742             status: 'INCOMPLETE',
   743             message: 'Value required for \'text\'.'
   744           }
   745         }
   746       }
   747     },
   748     {
   749       setup:    'tsn extend',
   750       check: {
   751         input:  'tsn extend',
   752         hints:            ' <text>',
   753         markup: 'VVVVVVVVVV',
   754         cursor: 10,
   755         current: '__command',
   756         status: 'ERROR',
   757         predictions: [ ],
   758         unassigned: [ ],
   759         args: {
   760           command: { name: 'tsn extend' },
   761           text: {
   762             value: undefined,
   763             arg: '',
   764             status: 'INCOMPLETE',
   765             message: 'Value required for \'text\'.'
   766           }
   767         }
   768       }
   769     },
   770     {
   771       setup:    'ts ',
   772       check: {
   773         input:  'ts ',
   774         hints:     '',
   775         markup: 'EEV',
   776         cursor: 3,
   777         current: '__command',
   778         status: 'ERROR',
   779         predictions: [ ],
   780         unassigned: [ ],
   781         tooltipState: 'true:isError'
   782       }
   783     },
   784   ]);
   785 };
   787 // From Bug 664203
   788 exports.testDeeplyNested = function(options) {
   789   return helpers.audit(options, [
   790     {
   791       setup:    'tsn deep down nested',
   792       check: {
   793         input:  'tsn deep down nested',
   794         hints:                      ' cmd',
   795         markup: 'IIIVIIIIVIIIIVIIIIII',
   796         cursor: 20,
   797         current: '__command',
   798         status: 'ERROR',
   799         predictions: [ 'tsn deep down nested cmd' ],
   800         unassigned: [ ],
   801         outputState: 'false:default',
   802         tooltipState: 'false:default',
   803         args: {
   804           command: { name: 'tsn deep down nested' },
   805         }
   806       }
   807     },
   808     {
   809       setup:    'tsn deep down nested cmd',
   810       check: {
   811         input:  'tsn deep down nested cmd',
   812         hints:                          '',
   813         markup: 'VVVVVVVVVVVVVVVVVVVVVVVV',
   814         cursor: 24,
   815         current: '__command',
   816         status: 'VALID',
   817         predictions: [ ],
   818         unassigned: [ ],
   819         args: {
   820           command: { name: 'tsn deep down nested cmd' },
   821         }
   822       }
   823     }
   824   ]);
   825 };

mercurial