browser/devtools/commandline/test/browser_gcli_exec.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-testExec.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 assert = require('../testharness/assert');
    44 // var helpers = require('./helpers');
    45 var nodetype = require('gcli/types/node');
    47 var mockBody = {
    48   style: {}
    49 };
    51 var mockEmptyNodeList = {
    52   length: 0,
    53   item: function() { return null; }
    54 };
    56 var mockRootNodeList = {
    57   length: 1,
    58   item: function(i) { return mockBody; }
    59 };
    61 var mockDoc = {
    62   querySelectorAll: function(css) {
    63     return (css === ':root') ? mockRootNodeList : mockEmptyNodeList;
    64   }
    65 };
    67 exports.testParamGroup = function(options) {
    68   var tsg = options.requisition.canon.getCommand('tsg');
    70   assert.is(tsg.params[0].groupName, null, 'tsg param 0 group null');
    71   assert.is(tsg.params[1].groupName, 'First', 'tsg param 1 group First');
    72   assert.is(tsg.params[2].groupName, 'First', 'tsg param 2 group First');
    73   assert.is(tsg.params[3].groupName, 'Second', 'tsg param 3 group Second');
    74   assert.is(tsg.params[4].groupName, 'Second', 'tsg param 4 group Second');
    75 };
    77 exports.testWithHelpers = function(options) {
    78   return helpers.audit(options, [
    79     {
    80       setup:    'tss',
    81       check: {
    82         input:  'tss',
    83         hints:     '',
    84         markup: 'VVV',
    85         cursor: 3,
    86         current: '__command',
    87         status: 'VALID',
    88         unassigned: [ ],
    89         args: {
    90           command: { name: 'tss' },
    91         }
    92       },
    93       exec: {
    94         output: /^Exec: tss/,
    95       }
    96     },
    97     {
    98       setup:    'tsv option1 10',
    99       check: {
   100         input:  'tsv option1 10',
   101         hints:                '',
   102         markup: 'VVVVVVVVVVVVVV',
   103         cursor: 14,
   104         current: 'optionValue',
   105         status: 'VALID',
   106         predictions: [ ],
   107         unassigned: [ ],
   108         args: {
   109           command: { name: 'tsv' },
   110           optionType: {
   111             value: 'string',
   112             arg: ' option1',
   113             status: 'VALID',
   114             message: ''
   115           },
   116           optionValue: {
   117             arg: ' 10',
   118             status: 'VALID',
   119             message: ''
   120           }
   121         }
   122       },
   123       exec: {
   124         output: 'Exec: tsv optionType=string, optionValue=10'
   125       }
   126     },
   127     {
   128       setup:    'tsv option2 10',
   129       check: {
   130         input:  'tsv option2 10',
   131         hints:                '',
   132         markup: 'VVVVVVVVVVVVVV',
   133         cursor: 14,
   134         current: 'optionValue',
   135         status: 'VALID',
   136         predictions: [ ],
   137         unassigned: [ ],
   138         args: {
   139           command: { name: 'tsv' },
   140           optionType: {
   141             value: 'number',
   142             arg: ' option2',
   143             status: 'VALID',
   144             message: ''
   145           },
   146           optionValue: {
   147             arg: ' 10',
   148             status: 'VALID',
   149             message: ''
   150           }
   151         }
   152       },
   153       exec: {
   154         output: 'Exec: tsv optionType=number, optionValue=10'
   155       }
   156     },
   157     // Delegated remote types can't transfer value types so we only test for
   158     // the value of optionValue when we're local
   159     {
   160       skipIf: options.isRemote,
   161       setup: 'tsv option1 10',
   162       check: {
   163         args: { optionValue: { value: '10' } }
   164       },
   165       exec: {
   166         output: 'Exec: tsv optionType=string, optionValue=10'
   167       }
   168     },
   169     {
   170       skipIf: options.isRemote,
   171       setup: 'tsv option2 10',
   172       check: {
   173         args: { optionValue: { value: 10 } }
   174       },
   175       exec: {
   176         output: 'Exec: tsv optionType=number, optionValue=10'
   177       }
   178     }
   179   ]);
   180 };
   182 exports.testExecText = function(options) {
   183   return helpers.audit(options, [
   184     {
   185       setup:    'tsr fred',
   186       check: {
   187         input:  'tsr fred',
   188         hints:          '',
   189         markup: 'VVVVVVVV',
   190         cursor: 8,
   191         current: 'text',
   192         status: 'VALID',
   193         predictions: [ ],
   194         unassigned: [ ],
   195         args: {
   196           command: { name: 'tsr' },
   197           text: {
   198             value: 'fred',
   199             arg: ' fred',
   200             status: 'VALID',
   201             message: ''
   202           }
   203         }
   204       },
   205       exec: {
   206         output: 'Exec: tsr text=fred'
   207       }
   208     },
   209     {
   210       setup:    'tsr fred bloggs',
   211       check: {
   212         input:  'tsr fred bloggs',
   213         hints:                 '',
   214         markup: 'VVVVVVVVVVVVVVV',
   215         cursor: 15,
   216         current: 'text',
   217         status: 'VALID',
   218         predictions: [ ],
   219         unassigned: [ ],
   220         args: {
   221           command: { name: 'tsr' },
   222           text: {
   223             value: 'fred bloggs',
   224             arg: ' fred bloggs',
   225             status: 'VALID',
   226             message: ''
   227           }
   228         }
   229       },
   230       exec: {
   231         output: 'Exec: tsr text=fred bloggs'
   232       }
   233     },
   234     {
   235       setup:    'tsr "fred bloggs"',
   236       check: {
   237         input:  'tsr "fred bloggs"',
   238         hints:                   '',
   239         markup: 'VVVVVVVVVVVVVVVVV',
   240         cursor: 17,
   241         current: 'text',
   242         status: 'VALID',
   243         predictions: [ ],
   244         unassigned: [ ],
   245         args: {
   246           command: { name: 'tsr' },
   247           text: {
   248             value: 'fred bloggs',
   249             arg: ' "fred bloggs"',
   250             status: 'VALID',
   251             message: ''
   252           }
   253         }
   254       },
   255       exec: {
   256         output: 'Exec: tsr text=fred bloggs'
   257       }
   258     },
   259     {
   260       setup:    'tsr "fred bloggs',
   261       check: {
   262         input:  'tsr "fred bloggs',
   263         hints:                  '',
   264         markup: 'VVVVVVVVVVVVVVVV',
   265         cursor: 16,
   266         current: 'text',
   267         status: 'VALID',
   268         predictions: [ ],
   269         unassigned: [ ],
   270         args: {
   271           command: { name: 'tsr' },
   272           text: {
   273             value: 'fred bloggs',
   274             arg: ' "fred bloggs',
   275             status: 'VALID',
   276             message: ''
   277           }
   278         }
   279       },
   280       exec: {
   281         output: 'Exec: tsr text=fred bloggs'
   282       }
   283     }
   284   ]);
   285 };
   287 exports.testExecBoolean = function(options) {
   288   return helpers.audit(options, [
   289     {
   290       setup:    'tsb',
   291       check: {
   292         input:  'tsb',
   293         hints:     ' [toggle]',
   294         markup: 'VVV',
   295         cursor: 3,
   296         current: '__command',
   297         status: 'VALID',
   298         predictions: [ ],
   299         unassigned: [ ],
   300         args: {
   301           command: { name: 'tsb' },
   302           toggle: {
   303             value: false,
   304             arg: '',
   305             status: 'VALID',
   306             message: ''
   307           }
   308         }
   309       },
   310       exec: {
   311         output: 'Exec: tsb toggle=false'
   312       }
   313     },
   314     {
   315       setup:    'tsb --toggle',
   316       check: {
   317         input:  'tsb --toggle',
   318         hints:              '',
   319         markup: 'VVVVVVVVVVVV',
   320         cursor: 12,
   321         current: 'toggle',
   322         status: 'VALID',
   323         predictions: [ ],
   324         unassigned: [ ],
   325         outputState: 'false:default',
   326         args: {
   327           command: { name: 'tsb' },
   328           toggle: {
   329             value: true,
   330             arg: ' --toggle',
   331             status: 'VALID',
   332             message: ''
   333           }
   334         }
   335       },
   336       exec: {
   337         output: 'Exec: tsb toggle=true'
   338       }
   339     }
   340   ]);
   341 };
   343 exports.testExecNumber = function(options) {
   344   return helpers.audit(options, [
   345     {
   346       setup:    'tsu 10',
   347       check: {
   348         input:  'tsu 10',
   349         hints:        '',
   350         markup: 'VVVVVV',
   351         cursor: 6,
   352         current: 'num',
   353         status: 'VALID',
   354         predictions: [ ],
   355         unassigned: [ ],
   356         args: {
   357           command: { name: 'tsu' },
   358           num: { value: 10, arg: ' 10', status: 'VALID', message: '' }
   359         }
   360       },
   361       exec: {
   362         output: 'Exec: tsu num=10'
   363       }
   364     },
   365     {
   366       setup:    'tsu --num 10',
   367       check: {
   368         input:  'tsu --num 10',
   369         hints:              '',
   370         markup: 'VVVVVVVVVVVV',
   371         cursor: 12,
   372         current: 'num',
   373         status: 'VALID',
   374         predictions: [ ],
   375         unassigned: [ ],
   376         args: {
   377           command: { name: 'tsu' },
   378           num: { value: 10, arg: ' --num 10', status: 'VALID', message: '' }
   379         }
   380       },
   381       exec: {
   382         output: 'Exec: tsu num=10'
   383       }
   384     }
   385   ]);
   386 };
   388 exports.testExecScript = function(options) {
   389   return helpers.audit(options, [
   390     {
   391       // Bug 704829 - Enable GCLI Javascript parameters
   392       // The answer to this should be 2
   393       setup:    'tsj { 1 + 1 }',
   394       check: {
   395         input:  'tsj { 1 + 1 }',
   396         hints:               '',
   397         markup: 'VVVVVVVVVVVVV',
   398         cursor: 13,
   399         current: 'javascript',
   400         status: 'VALID',
   401         predictions: [ ],
   402         unassigned: [ ],
   403         args: {
   404           command: { name: 'tsj' },
   405           javascript: {
   406             value: '1 + 1',
   407             arg: ' { 1 + 1 }',
   408             status: 'VALID',
   409             message: ''
   410           }
   411         }
   412       },
   413       exec: {
   414         output: 'Exec: tsj javascript=1 + 1'
   415       }
   416     }
   417   ]);
   418 };
   420 exports.testExecNode = function(options) {
   421   var origDoc = nodetype.getDocument();
   422   nodetype.setDocument(mockDoc);
   424   return helpers.audit(options, [
   425     {
   426       skipIf: options.isRemote, // No DOM on server
   427       setup:    'tse :root',
   428       check: {
   429         input:  'tse :root',
   430         hints:           ' [options]',
   431         markup: 'VVVVVVVVV',
   432         cursor: 9,
   433         current: 'node',
   434         status: 'VALID',
   435         predictions: [ ],
   436         unassigned: [ ],
   437         args: {
   438           command: { name: 'tse' },
   439           node: {
   440             value: mockBody,
   441             arg: ' :root',
   442             status: 'VALID',
   443             message: ''
   444           },
   445           nodes: {
   446             value: mockEmptyNodeList,
   447             arg: '',
   448             status: 'VALID',
   449             message: ''
   450           },
   451           nodes2: {
   452             value: mockEmptyNodeList,
   453             arg: '',
   454             status: 'VALID',
   455             message: ''
   456           }
   457         }
   458       },
   459       exec: {
   460         output: /^Exec: tse/
   461       },
   462       post: function() {
   463         nodetype.setDocument(origDoc);
   464       }
   465     }
   466   ]);
   467 };
   469 exports.testExecSubCommand = function(options) {
   470   return helpers.audit(options, [
   471     {
   472       setup:    'tsn dif fred',
   473       check: {
   474         input:  'tsn dif fred',
   475         hints:              '',
   476         markup: 'VVVVVVVVVVVV',
   477         cursor: 12,
   478         current: 'text',
   479         status: 'VALID',
   480         predictions: [ ],
   481         unassigned: [ ],
   482         args: {
   483           command: { name: 'tsn dif' },
   484           text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' }
   485         }
   486       },
   487       exec: {
   488         output: 'Exec: tsnDif text=fred'
   489       }
   490     },
   491     {
   492       setup:    'tsn exten fred',
   493       check: {
   494         input:  'tsn exten fred',
   495         hints:                '',
   496         markup: 'VVVVVVVVVVVVVV',
   497         cursor: 14,
   498         current: 'text',
   499         status: 'VALID',
   500         predictions: [ ],
   501         unassigned: [ ],
   502         args: {
   503           command: { name: 'tsn exten' },
   504           text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' },
   505         }
   506       },
   507       exec: {
   508         output: 'Exec: tsnExten text=fred'
   509       }
   510     },
   511     {
   512       setup:    'tsn extend fred',
   513       check: {
   514         input:  'tsn extend fred',
   515         hints:                 '',
   516         markup: 'VVVVVVVVVVVVVVV',
   517         cursor: 15,
   518         current: 'text',
   519         status: 'VALID',
   520         predictions: [ ],
   521         unassigned: [ ],
   522         args: {
   523           command: { name: 'tsn extend' },
   524           text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' },
   525         }
   526       },
   527       exec: {
   528         output: 'Exec: tsnExtend text=fred'
   529       }
   530     }
   531   ]);
   532 };
   534 exports.testExecArray = function(options) {
   535   return helpers.audit(options, [
   536     {
   537       setup:    'tselarr 1',
   538       check: {
   539         input:  'tselarr 1',
   540         hints:           '',
   541         markup: 'VVVVVVVVV',
   542         cursor: 9,
   543         current: 'num',
   544         status: 'VALID',
   545         predictions: ['1'],
   546         unassigned: [ ],
   547         outputState: 'false:default',
   548         args: {
   549           command: { name: 'tselarr' },
   550           num: { value: '1', arg: ' 1', status: 'VALID', message: '' },
   551           arr: { /*value:,*/ arg: '{}', status: 'VALID', message: '' },
   552         }
   553       },
   554       exec: {
   555         output: 'Exec: tselarr num=1, arr='
   556       }
   557     },
   558     {
   559       setup:    'tselarr 1 a',
   560       check: {
   561         input:  'tselarr 1 a',
   562         hints:             '',
   563         markup: 'VVVVVVVVVVV',
   564         cursor: 11,
   565         current: 'arr',
   566         status: 'VALID',
   567         predictions: [ ],
   568         unassigned: [ ],
   569         args: {
   570           command: { name: 'tselarr' },
   571           num: { value: '1', arg: ' 1', status: 'VALID', message: '' },
   572           arr: { /*value:a,*/ arg: '{ a}', status: 'VALID', message: '' },
   573         }
   574       },
   575       exec: {
   576         output: 'Exec: tselarr num=1, arr=a'
   577       }
   578     },
   579     {
   580       setup:    'tselarr 1 a b',
   581       check: {
   582         input:  'tselarr 1 a b',
   583         hints:               '',
   584         markup: 'VVVVVVVVVVVVV',
   585         cursor: 13,
   586         current: 'arr',
   587         status: 'VALID',
   588         predictions: [ ],
   589         unassigned: [ ],
   590         args: {
   591           command: { name: 'tselarr' },
   592           num: { value: '1', arg: ' 1', status: 'VALID', message: '' },
   593           arr: { /*value:a,b,*/ arg: '{ a, b}', status: 'VALID', message: '' },
   594         }
   595       },
   596       exec: {
   597         output: 'Exec: tselarr num=1, arr=a,b'
   598       }
   599     }
   600   ]);
   601 };
   603 exports.testExecMultiple = function(options) {
   604   return helpers.audit(options, [
   605     {
   606       setup:    'tsm a 10 10',
   607       check: {
   608         input:  'tsm a 10 10',
   609         hints:             '',
   610         markup: 'VVVVVVVVVVV',
   611         cursor: 11,
   612         current: 'num',
   613         status: 'VALID',
   614         predictions: [ ],
   615         unassigned: [ ],
   616         args: {
   617           command: { name: 'tsm' },
   618           abc: { value: 'a', arg: ' a', status: 'VALID', message: '' },
   619           txt: { value: '10', arg: ' 10', status: 'VALID', message: '' },
   620           num: { value: 10, arg: ' 10', status: 'VALID', message: '' },
   621         }
   622       },
   623       exec: {
   624         output: 'Exec: tsm abc=a, txt=10, num=10'
   625       }
   626     }
   627   ]);
   628 };
   630 exports.testExecDefaults = function(options) {
   631   return helpers.audit(options, [
   632     {
   633       // Bug 707009 - GCLI doesn't always fill in default parameters properly
   634       setup:    'tsg aaa',
   635       check: {
   636         input:  'tsg aaa',
   637         hints:         ' [options]',
   638         markup: 'VVVVVVV',
   639         cursor: 7,
   640         current: 'solo',
   641         status: 'VALID',
   642         predictions: ['aaa'],
   643         unassigned: [ ],
   644         args: {
   645           command: { name: 'tsg' },
   646           solo: { value: 'aaa', arg: ' aaa', status: 'VALID', message: '' },
   647           txt1: { value: undefined, arg: '', status: 'VALID', message: '' },
   648           bool: { value: false, arg: '', status: 'VALID', message: '' },
   649           txt2: { value: undefined, arg: '', status: 'VALID', message: '' },
   650           num: { value: undefined, arg: '', status: 'VALID', message: '' },
   651         }
   652       },
   653       exec: {
   654         output: 'Exec: tsg solo=aaa, txt1=null, bool=false, txt2=d, num=42'
   655       }
   656     }
   657   ]);
   659 };

mercurial