browser/devtools/commandline/test/browser_gcli_js.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-testJs.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 javascript = require('gcli/types/javascript');
    47 var tempWindow;
    49 exports.setup = function(options) {
    50   if (options.isNoDom) {
    51     return;
    52   }
    54   tempWindow = javascript.getGlobalObject();
    55   Object.defineProperty(options.window, 'donteval', {
    56     get: function() {
    57       assert.ok(false, 'donteval should not be used');
    58       return { cant: '', touch: '', 'this': '' };
    59     },
    60     enumerable: true,
    61     configurable : true
    62   });
    63   javascript.setGlobalObject(options.window);
    64 };
    66 exports.shutdown = function(options) {
    67   if (options.isNoDom) {
    68     return;
    69   }
    71   javascript.setGlobalObject(tempWindow);
    72   tempWindow = undefined;
    73   delete options.window.donteval;
    74 };
    76 function jsTestAllowed(options) {
    77   return options.isRemote || options.isNoDom ||
    78          options.requisition.canon.getCommand('{') == null;
    79 }
    81 exports.testBasic = function(options) {
    82   return helpers.audit(options, [
    83     {
    84       skipRemainingIf: jsTestAllowed,
    85       setup:    '{',
    86       check: {
    87         input:  '{',
    88         hints:   '',
    89         markup: 'V',
    90         cursor: 1,
    91         current: 'javascript',
    92         status: 'ERROR',
    93         predictions: [ ],
    94         unassigned: [ ],
    95         args: {
    96           command: { name: '{' },
    97           javascript: {
    98             value: undefined,
    99             arg: '{',
   100             status: 'INCOMPLETE'
   101           }
   102         }
   103       }
   104     },
   105     {
   106       setup:    '{ ',
   107       check: {
   108         input:  '{ ',
   109         hints:    '',
   110         markup: 'VV',
   111         cursor: 2,
   112         current: 'javascript',
   113         status: 'ERROR',
   114         predictions: [ ],
   115         unassigned: [ ],
   116         args: {
   117           command: { name: '{' },
   118           javascript: {
   119             value: undefined,
   120             arg: '{ ',
   121             status: 'INCOMPLETE'
   122           }
   123         }
   124       }
   125     },
   126     {
   127       setup:    '{ w',
   128       check: {
   129         input:  '{ w',
   130         hints:     'indow',
   131         markup: 'VVI',
   132         cursor: 3,
   133         current: 'javascript',
   134         status: 'ERROR',
   135         predictionsContains: [ 'window' ],
   136         unassigned: [ ],
   137         args: {
   138           command: { name: '{' },
   139           javascript: {
   140             value: 'w',
   141             arg: '{ w',
   142             status: 'INCOMPLETE'
   143           }
   144         }
   145       }
   146     },
   147     {
   148       setup:    '{ windo',
   149       check: {
   150         input:  '{ windo',
   151         hints:         'w',
   152         markup: 'VVIIIII',
   153         cursor: 7,
   154         current: 'javascript',
   155         status: 'ERROR',
   156         predictions: [ 'window' ],
   157         unassigned: [ ],
   158         args: {
   159           command: { name: '{' },
   160           javascript: {
   161             value: 'windo',
   162             arg: '{ windo',
   163             status: 'INCOMPLETE'
   164           }
   165         }
   166       }
   167     },
   168     {
   169       setup:    '{ window',
   170       check: {
   171         input:  '{ window',
   172         hints:          '',
   173         markup: 'VVVVVVVV',
   174         cursor: 8,
   175         current: 'javascript',
   176         status: 'VALID',
   177         predictions: [ ],
   178         unassigned: [ ],
   179         args: {
   180           command: { name: '{' },
   181           javascript: {
   182             value: 'window',
   183             arg: '{ window',
   184             status: 'VALID',
   185             message: ''
   186           }
   187         }
   188       }
   189     },
   190     {
   191       setup:    '{ window.do',
   192       check: {
   193         input:  '{ window.do',
   194         hints:             'cument',
   195         markup: 'VVIIIIIIIII',
   196         cursor: 11,
   197         current: 'javascript',
   198         status: 'ERROR',
   199         predictionsContains: [ 'window.document' ],
   200         unassigned: [ ],
   201         args: {
   202           command: { name: '{' },
   203           javascript: {
   204             value: 'window.do',
   205             arg: '{ window.do',
   206             status: 'INCOMPLETE'
   207           }
   208         }
   209       }
   210     },
   211     {
   212       setup:    '{ window.document.title',
   213       check: {
   214         input:  '{ window.document.title',
   215         hints:                         '',
   216         markup: 'VVVVVVVVVVVVVVVVVVVVVVV',
   217         cursor: 23,
   218         current: 'javascript',
   219         status: 'VALID',
   220         predictions: [ ],
   221         unassigned: [ ],
   222         args: {
   223           command: { name: '{' },
   224           javascript: {
   225             value: 'window.document.title',
   226             arg: '{ window.document.title',
   227             status: 'VALID',
   228             message: ''
   229           }
   230         }
   231       }
   232     }
   233   ]);
   234 };
   236 exports.testDocument = function(options) {
   237   return helpers.audit(options, [
   238     {
   239       skipRemainingIf: jsTestAllowed,
   240       setup:    '{ docu',
   241       check: {
   242         input:  '{ docu',
   243         hints:        'ment',
   244         markup: 'VVIIII',
   245         cursor: 6,
   246         current: 'javascript',
   247         status: 'ERROR',
   248         predictions: [ 'document' ],
   249         unassigned: [ ],
   250         args: {
   251           command: { name: '{' },
   252           javascript: {
   253             value: 'docu',
   254             arg: '{ docu',
   255             status: 'INCOMPLETE'
   256           }
   257         }
   258       }
   259     },
   260     {
   261       setup: '{ docu<TAB>',
   262       check: {
   263         input:  '{ document',
   264         hints:            '',
   265         markup: 'VVVVVVVVVV',
   266         cursor: 10,
   267         current: 'javascript',
   268         status: 'VALID',
   269         predictions: [ ],
   270         unassigned: [ ],
   271         args: {
   272           command: { name: '{' },
   273           javascript: {
   274             value: 'document',
   275             arg: '{ document',
   276             status: 'VALID',
   277             message: ''
   278           }
   279         }
   280       }
   281     },
   282     {
   283       setup:    '{ document.titl',
   284       check: {
   285         input:  '{ document.titl',
   286         hints:                 'e',
   287         markup: 'VVIIIIIIIIIIIII',
   288         cursor: 15,
   289         current: 'javascript',
   290         status: 'ERROR',
   291         predictions: [ 'document.title' ],
   292         unassigned: [ ],
   293         args: {
   294           command: { name: '{' },
   295           javascript: {
   296             value: 'document.titl',
   297             arg: '{ document.titl',
   298             status: 'INCOMPLETE'
   299           }
   300         }
   301       }
   302     },
   303     {
   304       setup: '{ document.titl<TAB>',
   305       check: {
   306         input:  '{ document.title ',
   307         hints:                   '',
   308         markup: 'VVVVVVVVVVVVVVVVV',
   309         cursor: 17,
   310         current: 'javascript',
   311         status: 'VALID',
   312         predictions: [ ],
   313         unassigned: [ ],
   314         args: {
   315           command: { name: '{' },
   316           javascript: {
   317             value: 'document.title',
   318             arg: '{ document.title ',
   319             status: 'VALID',
   320             message: ''
   321           }
   322         }
   323       }
   324     },
   325     {
   326       setup:    '{ document.title',
   327       check: {
   328         input:  '{ document.title',
   329         hints:                  '',
   330         markup: 'VVVVVVVVVVVVVVVV',
   331         cursor: 16,
   332         current: 'javascript',
   333         status: 'VALID',
   334         predictions: [ ],
   335         unassigned: [ ],
   336         args: {
   337           command: { name: '{' },
   338           javascript: {
   339             value: 'document.title',
   340             arg: '{ document.title',
   341             status: 'VALID',
   342             message: ''
   343           }
   344         }
   345       }
   346     }
   347   ]);
   348 };
   350 exports.testDonteval = function(options) {
   351   if (!options.isNoDom) {
   352     // nodom causes an eval here, maybe that's node/v8?
   353     assert.ok('donteval' in options.window, 'donteval exists');
   354   }
   356   return helpers.audit(options, [
   357     {
   358       skipRemainingIf: jsTestAllowed,
   359       setup:    '{ don',
   360       check: {
   361         input:  '{ don',
   362         hints:       'teval',
   363         markup: 'VVIII',
   364         cursor: 5,
   365         current: 'javascript',
   366         status: 'ERROR',
   367         predictions: [ 'donteval' ],
   368         unassigned: [ ],
   369         args: {
   370           command: { name: '{' },
   371           javascript: {
   372             value: 'don',
   373             arg: '{ don',
   374             status: 'INCOMPLETE'
   375           }
   376         }
   377       }
   378     },
   379     {
   380       setup:    '{ donteval',
   381       check: {
   382         input:  '{ donteval',
   383         hints:            '',
   384         markup: 'VVVVVVVVVV',
   385         cursor: 10,
   386         current: 'javascript',
   387         status: 'VALID',
   388         predictions: [ ],
   389         unassigned: [ ],
   390         args: {
   391           command: { name: '{' },
   392           javascript: {
   393             value: 'donteval',
   394             arg: '{ donteval',
   395             status: 'VALID',
   396             message: ''
   397           }
   398         }
   399       }
   400     },
   401     /*
   402     // This is a controversial test - technically we can tell that it's an error
   403     // because 'donteval.' is a syntax error, however donteval is unsafe so we
   404     // are playing safe by bailing out early. It's enough of a corner case that
   405     // I don't think it warrants fixing
   406     {
   407       setup:    '{ donteval.',
   408       check: {
   409         input:  '{ donteval.',
   410         hints:             '',
   411         markup: 'VVVVVVVVVVV',
   412         cursor: 11,
   413         current: 'javascript',
   414         status: 'VALID',
   415         predictions: [ ],
   416         unassigned: [ ],
   417         args: {
   418           command: { name: '{' },
   419           javascript: {
   420             value: 'donteval.',
   421             arg: '{ donteval.',
   422             status: 'VALID',
   423             message: ''
   424           }
   425         }
   426       }
   427     },
   428     */
   429     {
   430       setup:    '{ donteval.cant',
   431       check: {
   432         input:  '{ donteval.cant',
   433         hints:                 '',
   434         markup: 'VVVVVVVVVVVVVVV',
   435         cursor: 15,
   436         current: 'javascript',
   437         status: 'VALID',
   438         predictions: [ ],
   439         unassigned: [ ],
   440         args: {
   441           command: { name: '{' },
   442           javascript: {
   443             value: 'donteval.cant',
   444             arg: '{ donteval.cant',
   445             status: 'VALID',
   446             message: ''
   447           }
   448         }
   449       }
   450     },
   451     {
   452       setup:    '{ donteval.xxx',
   453       check: {
   454         input:  '{ donteval.xxx',
   455         hints:                '',
   456         markup: 'VVVVVVVVVVVVVV',
   457         cursor: 14,
   458         current: 'javascript',
   459         status: 'VALID',
   460         predictions: [ ],
   461         unassigned: [ ],
   462         args: {
   463           command: { name: '{' },
   464           javascript: {
   465             value: 'donteval.xxx',
   466             arg: '{ donteval.xxx',
   467             status: 'VALID',
   468             message: ''
   469           }
   470         }
   471       }
   472     }
   473   ]);
   474 };
   476 exports.testExec = function(options) {
   477   return helpers.audit(options, [
   478     {
   479       skipRemainingIf: jsTestAllowed,
   480       setup:    '{ 1+1',
   481       check: {
   482         input:  '{ 1+1',
   483         hints:       '',
   484         markup: 'VVVVV',
   485         cursor: 5,
   486         current: 'javascript',
   487         status: 'VALID',
   488         options: [ ],
   489         message: '',
   490         predictions: [ ],
   491         unassigned: [ ],
   492         args: {
   493           javascript: {
   494             value: '1+1',
   495             arg: '{ 1+1',
   496             status: 'VALID',
   497             message: ''
   498           }
   499         }
   500       },
   501       exec: {
   502         output: '2',
   503         type: 'number',
   504         error: false
   505       }
   506     },
   507     {
   508       setup:    '{ 1+1 }',
   509       check: {
   510         input:  '{ 1+1 }',
   511         hints:         '',
   512         markup: 'VVVVVVV',
   513         cursor: 7,
   514         current: 'javascript',
   515         status: 'VALID',
   516         options: [ ],
   517         message: '',
   518         predictions: [ ],
   519         unassigned: [ ],
   520         args: {
   521           javascript: {
   522             value: '1+1',
   523             arg: '{ 1+1 }',
   524             status: 'VALID',
   525             message: ''
   526           }
   527         }
   528       },
   529       exec: {
   530         output: '2',
   531         type: 'number',
   532         error: false
   533       }
   534     },
   535     {
   536       setup:    '{ "hello"',
   537       check: {
   538         input:  '{ "hello"',
   539         hints:           '',
   540         markup: 'VVVVVVVVV',
   541         cursor: 9,
   542         current: 'javascript',
   543         status: 'VALID',
   544         options: [ ],
   545         message: '',
   546         predictions: [ ],
   547         unassigned: [ ],
   548         args: {
   549           javascript: {
   550             value: '"hello"',
   551             arg: '{ "hello"',
   552             status: 'VALID',
   553             message: ''
   554           }
   555         }
   556       },
   557       exec: {
   558         output: 'hello',
   559         type: 'string',
   560         error: false
   561       }
   562     },
   563     {
   564       setup:    '{ "hello" + 1',
   565       check: {
   566         input:  '{ "hello" + 1',
   567         hints:               '',
   568         markup: 'VVVVVVVVVVVVV',
   569         cursor: 13,
   570         current: 'javascript',
   571         status: 'VALID',
   572         options: [ ],
   573         message: '',
   574         predictions: [ ],
   575         unassigned: [ ],
   576         args: {
   577           javascript: {
   578             value: '"hello" + 1',
   579             arg: '{ "hello" + 1',
   580             status: 'VALID',
   581             message: ''
   582           }
   583         }
   584       },
   585       exec: {
   586         output: 'hello1',
   587         type: 'string',
   588         error: false
   589       }
   590     }
   591   ]);
   592 };

mercurial