browser/devtools/commandline/test/browser_gcli_js.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/commandline/test/browser_gcli_js.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,592 @@
     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 +var exports = {};
    1.27 +
    1.28 +var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testJs.js</p>";
    1.29 +
    1.30 +function test() {
    1.31 +  return Task.spawn(function() {
    1.32 +    let options = yield helpers.openTab(TEST_URI);
    1.33 +    yield helpers.openToolbar(options);
    1.34 +    gcli.addItems(mockCommands.items);
    1.35 +
    1.36 +    yield helpers.runTests(options, exports);
    1.37 +
    1.38 +    gcli.removeItems(mockCommands.items);
    1.39 +    yield helpers.closeToolbar(options);
    1.40 +    yield helpers.closeTab(options);
    1.41 +  }).then(finish, helpers.handleError);
    1.42 +}
    1.43 +
    1.44 +// <INJECTED SOURCE:END>
    1.45 +
    1.46 +// var assert = require('../testharness/assert');
    1.47 +// var helpers = require('./helpers');
    1.48 +var javascript = require('gcli/types/javascript');
    1.49 +
    1.50 +var tempWindow;
    1.51 +
    1.52 +exports.setup = function(options) {
    1.53 +  if (options.isNoDom) {
    1.54 +    return;
    1.55 +  }
    1.56 +
    1.57 +  tempWindow = javascript.getGlobalObject();
    1.58 +  Object.defineProperty(options.window, 'donteval', {
    1.59 +    get: function() {
    1.60 +      assert.ok(false, 'donteval should not be used');
    1.61 +      return { cant: '', touch: '', 'this': '' };
    1.62 +    },
    1.63 +    enumerable: true,
    1.64 +    configurable : true
    1.65 +  });
    1.66 +  javascript.setGlobalObject(options.window);
    1.67 +};
    1.68 +
    1.69 +exports.shutdown = function(options) {
    1.70 +  if (options.isNoDom) {
    1.71 +    return;
    1.72 +  }
    1.73 +
    1.74 +  javascript.setGlobalObject(tempWindow);
    1.75 +  tempWindow = undefined;
    1.76 +  delete options.window.donteval;
    1.77 +};
    1.78 +
    1.79 +function jsTestAllowed(options) {
    1.80 +  return options.isRemote || options.isNoDom ||
    1.81 +         options.requisition.canon.getCommand('{') == null;
    1.82 +}
    1.83 +
    1.84 +exports.testBasic = function(options) {
    1.85 +  return helpers.audit(options, [
    1.86 +    {
    1.87 +      skipRemainingIf: jsTestAllowed,
    1.88 +      setup:    '{',
    1.89 +      check: {
    1.90 +        input:  '{',
    1.91 +        hints:   '',
    1.92 +        markup: 'V',
    1.93 +        cursor: 1,
    1.94 +        current: 'javascript',
    1.95 +        status: 'ERROR',
    1.96 +        predictions: [ ],
    1.97 +        unassigned: [ ],
    1.98 +        args: {
    1.99 +          command: { name: '{' },
   1.100 +          javascript: {
   1.101 +            value: undefined,
   1.102 +            arg: '{',
   1.103 +            status: 'INCOMPLETE'
   1.104 +          }
   1.105 +        }
   1.106 +      }
   1.107 +    },
   1.108 +    {
   1.109 +      setup:    '{ ',
   1.110 +      check: {
   1.111 +        input:  '{ ',
   1.112 +        hints:    '',
   1.113 +        markup: 'VV',
   1.114 +        cursor: 2,
   1.115 +        current: 'javascript',
   1.116 +        status: 'ERROR',
   1.117 +        predictions: [ ],
   1.118 +        unassigned: [ ],
   1.119 +        args: {
   1.120 +          command: { name: '{' },
   1.121 +          javascript: {
   1.122 +            value: undefined,
   1.123 +            arg: '{ ',
   1.124 +            status: 'INCOMPLETE'
   1.125 +          }
   1.126 +        }
   1.127 +      }
   1.128 +    },
   1.129 +    {
   1.130 +      setup:    '{ w',
   1.131 +      check: {
   1.132 +        input:  '{ w',
   1.133 +        hints:     'indow',
   1.134 +        markup: 'VVI',
   1.135 +        cursor: 3,
   1.136 +        current: 'javascript',
   1.137 +        status: 'ERROR',
   1.138 +        predictionsContains: [ 'window' ],
   1.139 +        unassigned: [ ],
   1.140 +        args: {
   1.141 +          command: { name: '{' },
   1.142 +          javascript: {
   1.143 +            value: 'w',
   1.144 +            arg: '{ w',
   1.145 +            status: 'INCOMPLETE'
   1.146 +          }
   1.147 +        }
   1.148 +      }
   1.149 +    },
   1.150 +    {
   1.151 +      setup:    '{ windo',
   1.152 +      check: {
   1.153 +        input:  '{ windo',
   1.154 +        hints:         'w',
   1.155 +        markup: 'VVIIIII',
   1.156 +        cursor: 7,
   1.157 +        current: 'javascript',
   1.158 +        status: 'ERROR',
   1.159 +        predictions: [ 'window' ],
   1.160 +        unassigned: [ ],
   1.161 +        args: {
   1.162 +          command: { name: '{' },
   1.163 +          javascript: {
   1.164 +            value: 'windo',
   1.165 +            arg: '{ windo',
   1.166 +            status: 'INCOMPLETE'
   1.167 +          }
   1.168 +        }
   1.169 +      }
   1.170 +    },
   1.171 +    {
   1.172 +      setup:    '{ window',
   1.173 +      check: {
   1.174 +        input:  '{ window',
   1.175 +        hints:          '',
   1.176 +        markup: 'VVVVVVVV',
   1.177 +        cursor: 8,
   1.178 +        current: 'javascript',
   1.179 +        status: 'VALID',
   1.180 +        predictions: [ ],
   1.181 +        unassigned: [ ],
   1.182 +        args: {
   1.183 +          command: { name: '{' },
   1.184 +          javascript: {
   1.185 +            value: 'window',
   1.186 +            arg: '{ window',
   1.187 +            status: 'VALID',
   1.188 +            message: ''
   1.189 +          }
   1.190 +        }
   1.191 +      }
   1.192 +    },
   1.193 +    {
   1.194 +      setup:    '{ window.do',
   1.195 +      check: {
   1.196 +        input:  '{ window.do',
   1.197 +        hints:             'cument',
   1.198 +        markup: 'VVIIIIIIIII',
   1.199 +        cursor: 11,
   1.200 +        current: 'javascript',
   1.201 +        status: 'ERROR',
   1.202 +        predictionsContains: [ 'window.document' ],
   1.203 +        unassigned: [ ],
   1.204 +        args: {
   1.205 +          command: { name: '{' },
   1.206 +          javascript: {
   1.207 +            value: 'window.do',
   1.208 +            arg: '{ window.do',
   1.209 +            status: 'INCOMPLETE'
   1.210 +          }
   1.211 +        }
   1.212 +      }
   1.213 +    },
   1.214 +    {
   1.215 +      setup:    '{ window.document.title',
   1.216 +      check: {
   1.217 +        input:  '{ window.document.title',
   1.218 +        hints:                         '',
   1.219 +        markup: 'VVVVVVVVVVVVVVVVVVVVVVV',
   1.220 +        cursor: 23,
   1.221 +        current: 'javascript',
   1.222 +        status: 'VALID',
   1.223 +        predictions: [ ],
   1.224 +        unassigned: [ ],
   1.225 +        args: {
   1.226 +          command: { name: '{' },
   1.227 +          javascript: {
   1.228 +            value: 'window.document.title',
   1.229 +            arg: '{ window.document.title',
   1.230 +            status: 'VALID',
   1.231 +            message: ''
   1.232 +          }
   1.233 +        }
   1.234 +      }
   1.235 +    }
   1.236 +  ]);
   1.237 +};
   1.238 +
   1.239 +exports.testDocument = function(options) {
   1.240 +  return helpers.audit(options, [
   1.241 +    {
   1.242 +      skipRemainingIf: jsTestAllowed,
   1.243 +      setup:    '{ docu',
   1.244 +      check: {
   1.245 +        input:  '{ docu',
   1.246 +        hints:        'ment',
   1.247 +        markup: 'VVIIII',
   1.248 +        cursor: 6,
   1.249 +        current: 'javascript',
   1.250 +        status: 'ERROR',
   1.251 +        predictions: [ 'document' ],
   1.252 +        unassigned: [ ],
   1.253 +        args: {
   1.254 +          command: { name: '{' },
   1.255 +          javascript: {
   1.256 +            value: 'docu',
   1.257 +            arg: '{ docu',
   1.258 +            status: 'INCOMPLETE'
   1.259 +          }
   1.260 +        }
   1.261 +      }
   1.262 +    },
   1.263 +    {
   1.264 +      setup: '{ docu<TAB>',
   1.265 +      check: {
   1.266 +        input:  '{ document',
   1.267 +        hints:            '',
   1.268 +        markup: 'VVVVVVVVVV',
   1.269 +        cursor: 10,
   1.270 +        current: 'javascript',
   1.271 +        status: 'VALID',
   1.272 +        predictions: [ ],
   1.273 +        unassigned: [ ],
   1.274 +        args: {
   1.275 +          command: { name: '{' },
   1.276 +          javascript: {
   1.277 +            value: 'document',
   1.278 +            arg: '{ document',
   1.279 +            status: 'VALID',
   1.280 +            message: ''
   1.281 +          }
   1.282 +        }
   1.283 +      }
   1.284 +    },
   1.285 +    {
   1.286 +      setup:    '{ document.titl',
   1.287 +      check: {
   1.288 +        input:  '{ document.titl',
   1.289 +        hints:                 'e',
   1.290 +        markup: 'VVIIIIIIIIIIIII',
   1.291 +        cursor: 15,
   1.292 +        current: 'javascript',
   1.293 +        status: 'ERROR',
   1.294 +        predictions: [ 'document.title' ],
   1.295 +        unassigned: [ ],
   1.296 +        args: {
   1.297 +          command: { name: '{' },
   1.298 +          javascript: {
   1.299 +            value: 'document.titl',
   1.300 +            arg: '{ document.titl',
   1.301 +            status: 'INCOMPLETE'
   1.302 +          }
   1.303 +        }
   1.304 +      }
   1.305 +    },
   1.306 +    {
   1.307 +      setup: '{ document.titl<TAB>',
   1.308 +      check: {
   1.309 +        input:  '{ document.title ',
   1.310 +        hints:                   '',
   1.311 +        markup: 'VVVVVVVVVVVVVVVVV',
   1.312 +        cursor: 17,
   1.313 +        current: 'javascript',
   1.314 +        status: 'VALID',
   1.315 +        predictions: [ ],
   1.316 +        unassigned: [ ],
   1.317 +        args: {
   1.318 +          command: { name: '{' },
   1.319 +          javascript: {
   1.320 +            value: 'document.title',
   1.321 +            arg: '{ document.title ',
   1.322 +            status: 'VALID',
   1.323 +            message: ''
   1.324 +          }
   1.325 +        }
   1.326 +      }
   1.327 +    },
   1.328 +    {
   1.329 +      setup:    '{ document.title',
   1.330 +      check: {
   1.331 +        input:  '{ document.title',
   1.332 +        hints:                  '',
   1.333 +        markup: 'VVVVVVVVVVVVVVVV',
   1.334 +        cursor: 16,
   1.335 +        current: 'javascript',
   1.336 +        status: 'VALID',
   1.337 +        predictions: [ ],
   1.338 +        unassigned: [ ],
   1.339 +        args: {
   1.340 +          command: { name: '{' },
   1.341 +          javascript: {
   1.342 +            value: 'document.title',
   1.343 +            arg: '{ document.title',
   1.344 +            status: 'VALID',
   1.345 +            message: ''
   1.346 +          }
   1.347 +        }
   1.348 +      }
   1.349 +    }
   1.350 +  ]);
   1.351 +};
   1.352 +
   1.353 +exports.testDonteval = function(options) {
   1.354 +  if (!options.isNoDom) {
   1.355 +    // nodom causes an eval here, maybe that's node/v8?
   1.356 +    assert.ok('donteval' in options.window, 'donteval exists');
   1.357 +  }
   1.358 +
   1.359 +  return helpers.audit(options, [
   1.360 +    {
   1.361 +      skipRemainingIf: jsTestAllowed,
   1.362 +      setup:    '{ don',
   1.363 +      check: {
   1.364 +        input:  '{ don',
   1.365 +        hints:       'teval',
   1.366 +        markup: 'VVIII',
   1.367 +        cursor: 5,
   1.368 +        current: 'javascript',
   1.369 +        status: 'ERROR',
   1.370 +        predictions: [ 'donteval' ],
   1.371 +        unassigned: [ ],
   1.372 +        args: {
   1.373 +          command: { name: '{' },
   1.374 +          javascript: {
   1.375 +            value: 'don',
   1.376 +            arg: '{ don',
   1.377 +            status: 'INCOMPLETE'
   1.378 +          }
   1.379 +        }
   1.380 +      }
   1.381 +    },
   1.382 +    {
   1.383 +      setup:    '{ donteval',
   1.384 +      check: {
   1.385 +        input:  '{ donteval',
   1.386 +        hints:            '',
   1.387 +        markup: 'VVVVVVVVVV',
   1.388 +        cursor: 10,
   1.389 +        current: 'javascript',
   1.390 +        status: 'VALID',
   1.391 +        predictions: [ ],
   1.392 +        unassigned: [ ],
   1.393 +        args: {
   1.394 +          command: { name: '{' },
   1.395 +          javascript: {
   1.396 +            value: 'donteval',
   1.397 +            arg: '{ donteval',
   1.398 +            status: 'VALID',
   1.399 +            message: ''
   1.400 +          }
   1.401 +        }
   1.402 +      }
   1.403 +    },
   1.404 +    /*
   1.405 +    // This is a controversial test - technically we can tell that it's an error
   1.406 +    // because 'donteval.' is a syntax error, however donteval is unsafe so we
   1.407 +    // are playing safe by bailing out early. It's enough of a corner case that
   1.408 +    // I don't think it warrants fixing
   1.409 +    {
   1.410 +      setup:    '{ donteval.',
   1.411 +      check: {
   1.412 +        input:  '{ donteval.',
   1.413 +        hints:             '',
   1.414 +        markup: 'VVVVVVVVVVV',
   1.415 +        cursor: 11,
   1.416 +        current: 'javascript',
   1.417 +        status: 'VALID',
   1.418 +        predictions: [ ],
   1.419 +        unassigned: [ ],
   1.420 +        args: {
   1.421 +          command: { name: '{' },
   1.422 +          javascript: {
   1.423 +            value: 'donteval.',
   1.424 +            arg: '{ donteval.',
   1.425 +            status: 'VALID',
   1.426 +            message: ''
   1.427 +          }
   1.428 +        }
   1.429 +      }
   1.430 +    },
   1.431 +    */
   1.432 +    {
   1.433 +      setup:    '{ donteval.cant',
   1.434 +      check: {
   1.435 +        input:  '{ donteval.cant',
   1.436 +        hints:                 '',
   1.437 +        markup: 'VVVVVVVVVVVVVVV',
   1.438 +        cursor: 15,
   1.439 +        current: 'javascript',
   1.440 +        status: 'VALID',
   1.441 +        predictions: [ ],
   1.442 +        unassigned: [ ],
   1.443 +        args: {
   1.444 +          command: { name: '{' },
   1.445 +          javascript: {
   1.446 +            value: 'donteval.cant',
   1.447 +            arg: '{ donteval.cant',
   1.448 +            status: 'VALID',
   1.449 +            message: ''
   1.450 +          }
   1.451 +        }
   1.452 +      }
   1.453 +    },
   1.454 +    {
   1.455 +      setup:    '{ donteval.xxx',
   1.456 +      check: {
   1.457 +        input:  '{ donteval.xxx',
   1.458 +        hints:                '',
   1.459 +        markup: 'VVVVVVVVVVVVVV',
   1.460 +        cursor: 14,
   1.461 +        current: 'javascript',
   1.462 +        status: 'VALID',
   1.463 +        predictions: [ ],
   1.464 +        unassigned: [ ],
   1.465 +        args: {
   1.466 +          command: { name: '{' },
   1.467 +          javascript: {
   1.468 +            value: 'donteval.xxx',
   1.469 +            arg: '{ donteval.xxx',
   1.470 +            status: 'VALID',
   1.471 +            message: ''
   1.472 +          }
   1.473 +        }
   1.474 +      }
   1.475 +    }
   1.476 +  ]);
   1.477 +};
   1.478 +
   1.479 +exports.testExec = function(options) {
   1.480 +  return helpers.audit(options, [
   1.481 +    {
   1.482 +      skipRemainingIf: jsTestAllowed,
   1.483 +      setup:    '{ 1+1',
   1.484 +      check: {
   1.485 +        input:  '{ 1+1',
   1.486 +        hints:       '',
   1.487 +        markup: 'VVVVV',
   1.488 +        cursor: 5,
   1.489 +        current: 'javascript',
   1.490 +        status: 'VALID',
   1.491 +        options: [ ],
   1.492 +        message: '',
   1.493 +        predictions: [ ],
   1.494 +        unassigned: [ ],
   1.495 +        args: {
   1.496 +          javascript: {
   1.497 +            value: '1+1',
   1.498 +            arg: '{ 1+1',
   1.499 +            status: 'VALID',
   1.500 +            message: ''
   1.501 +          }
   1.502 +        }
   1.503 +      },
   1.504 +      exec: {
   1.505 +        output: '2',
   1.506 +        type: 'number',
   1.507 +        error: false
   1.508 +      }
   1.509 +    },
   1.510 +    {
   1.511 +      setup:    '{ 1+1 }',
   1.512 +      check: {
   1.513 +        input:  '{ 1+1 }',
   1.514 +        hints:         '',
   1.515 +        markup: 'VVVVVVV',
   1.516 +        cursor: 7,
   1.517 +        current: 'javascript',
   1.518 +        status: 'VALID',
   1.519 +        options: [ ],
   1.520 +        message: '',
   1.521 +        predictions: [ ],
   1.522 +        unassigned: [ ],
   1.523 +        args: {
   1.524 +          javascript: {
   1.525 +            value: '1+1',
   1.526 +            arg: '{ 1+1 }',
   1.527 +            status: 'VALID',
   1.528 +            message: ''
   1.529 +          }
   1.530 +        }
   1.531 +      },
   1.532 +      exec: {
   1.533 +        output: '2',
   1.534 +        type: 'number',
   1.535 +        error: false
   1.536 +      }
   1.537 +    },
   1.538 +    {
   1.539 +      setup:    '{ "hello"',
   1.540 +      check: {
   1.541 +        input:  '{ "hello"',
   1.542 +        hints:           '',
   1.543 +        markup: 'VVVVVVVVV',
   1.544 +        cursor: 9,
   1.545 +        current: 'javascript',
   1.546 +        status: 'VALID',
   1.547 +        options: [ ],
   1.548 +        message: '',
   1.549 +        predictions: [ ],
   1.550 +        unassigned: [ ],
   1.551 +        args: {
   1.552 +          javascript: {
   1.553 +            value: '"hello"',
   1.554 +            arg: '{ "hello"',
   1.555 +            status: 'VALID',
   1.556 +            message: ''
   1.557 +          }
   1.558 +        }
   1.559 +      },
   1.560 +      exec: {
   1.561 +        output: 'hello',
   1.562 +        type: 'string',
   1.563 +        error: false
   1.564 +      }
   1.565 +    },
   1.566 +    {
   1.567 +      setup:    '{ "hello" + 1',
   1.568 +      check: {
   1.569 +        input:  '{ "hello" + 1',
   1.570 +        hints:               '',
   1.571 +        markup: 'VVVVVVVVVVVVV',
   1.572 +        cursor: 13,
   1.573 +        current: 'javascript',
   1.574 +        status: 'VALID',
   1.575 +        options: [ ],
   1.576 +        message: '',
   1.577 +        predictions: [ ],
   1.578 +        unassigned: [ ],
   1.579 +        args: {
   1.580 +          javascript: {
   1.581 +            value: '"hello" + 1',
   1.582 +            arg: '{ "hello" + 1',
   1.583 +            status: 'VALID',
   1.584 +            message: ''
   1.585 +          }
   1.586 +        }
   1.587 +      },
   1.588 +      exec: {
   1.589 +        output: 'hello1',
   1.590 +        type: 'string',
   1.591 +        error: false
   1.592 +      }
   1.593 +    }
   1.594 +  ]);
   1.595 +};

mercurial