1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/commandline/test/browser_gcli_exec.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,659 @@ 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-testExec.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 nodetype = require('gcli/types/node'); 1.49 + 1.50 +var mockBody = { 1.51 + style: {} 1.52 +}; 1.53 + 1.54 +var mockEmptyNodeList = { 1.55 + length: 0, 1.56 + item: function() { return null; } 1.57 +}; 1.58 + 1.59 +var mockRootNodeList = { 1.60 + length: 1, 1.61 + item: function(i) { return mockBody; } 1.62 +}; 1.63 + 1.64 +var mockDoc = { 1.65 + querySelectorAll: function(css) { 1.66 + return (css === ':root') ? mockRootNodeList : mockEmptyNodeList; 1.67 + } 1.68 +}; 1.69 + 1.70 +exports.testParamGroup = function(options) { 1.71 + var tsg = options.requisition.canon.getCommand('tsg'); 1.72 + 1.73 + assert.is(tsg.params[0].groupName, null, 'tsg param 0 group null'); 1.74 + assert.is(tsg.params[1].groupName, 'First', 'tsg param 1 group First'); 1.75 + assert.is(tsg.params[2].groupName, 'First', 'tsg param 2 group First'); 1.76 + assert.is(tsg.params[3].groupName, 'Second', 'tsg param 3 group Second'); 1.77 + assert.is(tsg.params[4].groupName, 'Second', 'tsg param 4 group Second'); 1.78 +}; 1.79 + 1.80 +exports.testWithHelpers = function(options) { 1.81 + return helpers.audit(options, [ 1.82 + { 1.83 + setup: 'tss', 1.84 + check: { 1.85 + input: 'tss', 1.86 + hints: '', 1.87 + markup: 'VVV', 1.88 + cursor: 3, 1.89 + current: '__command', 1.90 + status: 'VALID', 1.91 + unassigned: [ ], 1.92 + args: { 1.93 + command: { name: 'tss' }, 1.94 + } 1.95 + }, 1.96 + exec: { 1.97 + output: /^Exec: tss/, 1.98 + } 1.99 + }, 1.100 + { 1.101 + setup: 'tsv option1 10', 1.102 + check: { 1.103 + input: 'tsv option1 10', 1.104 + hints: '', 1.105 + markup: 'VVVVVVVVVVVVVV', 1.106 + cursor: 14, 1.107 + current: 'optionValue', 1.108 + status: 'VALID', 1.109 + predictions: [ ], 1.110 + unassigned: [ ], 1.111 + args: { 1.112 + command: { name: 'tsv' }, 1.113 + optionType: { 1.114 + value: 'string', 1.115 + arg: ' option1', 1.116 + status: 'VALID', 1.117 + message: '' 1.118 + }, 1.119 + optionValue: { 1.120 + arg: ' 10', 1.121 + status: 'VALID', 1.122 + message: '' 1.123 + } 1.124 + } 1.125 + }, 1.126 + exec: { 1.127 + output: 'Exec: tsv optionType=string, optionValue=10' 1.128 + } 1.129 + }, 1.130 + { 1.131 + setup: 'tsv option2 10', 1.132 + check: { 1.133 + input: 'tsv option2 10', 1.134 + hints: '', 1.135 + markup: 'VVVVVVVVVVVVVV', 1.136 + cursor: 14, 1.137 + current: 'optionValue', 1.138 + status: 'VALID', 1.139 + predictions: [ ], 1.140 + unassigned: [ ], 1.141 + args: { 1.142 + command: { name: 'tsv' }, 1.143 + optionType: { 1.144 + value: 'number', 1.145 + arg: ' option2', 1.146 + status: 'VALID', 1.147 + message: '' 1.148 + }, 1.149 + optionValue: { 1.150 + arg: ' 10', 1.151 + status: 'VALID', 1.152 + message: '' 1.153 + } 1.154 + } 1.155 + }, 1.156 + exec: { 1.157 + output: 'Exec: tsv optionType=number, optionValue=10' 1.158 + } 1.159 + }, 1.160 + // Delegated remote types can't transfer value types so we only test for 1.161 + // the value of optionValue when we're local 1.162 + { 1.163 + skipIf: options.isRemote, 1.164 + setup: 'tsv option1 10', 1.165 + check: { 1.166 + args: { optionValue: { value: '10' } } 1.167 + }, 1.168 + exec: { 1.169 + output: 'Exec: tsv optionType=string, optionValue=10' 1.170 + } 1.171 + }, 1.172 + { 1.173 + skipIf: options.isRemote, 1.174 + setup: 'tsv option2 10', 1.175 + check: { 1.176 + args: { optionValue: { value: 10 } } 1.177 + }, 1.178 + exec: { 1.179 + output: 'Exec: tsv optionType=number, optionValue=10' 1.180 + } 1.181 + } 1.182 + ]); 1.183 +}; 1.184 + 1.185 +exports.testExecText = function(options) { 1.186 + return helpers.audit(options, [ 1.187 + { 1.188 + setup: 'tsr fred', 1.189 + check: { 1.190 + input: 'tsr fred', 1.191 + hints: '', 1.192 + markup: 'VVVVVVVV', 1.193 + cursor: 8, 1.194 + current: 'text', 1.195 + status: 'VALID', 1.196 + predictions: [ ], 1.197 + unassigned: [ ], 1.198 + args: { 1.199 + command: { name: 'tsr' }, 1.200 + text: { 1.201 + value: 'fred', 1.202 + arg: ' fred', 1.203 + status: 'VALID', 1.204 + message: '' 1.205 + } 1.206 + } 1.207 + }, 1.208 + exec: { 1.209 + output: 'Exec: tsr text=fred' 1.210 + } 1.211 + }, 1.212 + { 1.213 + setup: 'tsr fred bloggs', 1.214 + check: { 1.215 + input: 'tsr fred bloggs', 1.216 + hints: '', 1.217 + markup: 'VVVVVVVVVVVVVVV', 1.218 + cursor: 15, 1.219 + current: 'text', 1.220 + status: 'VALID', 1.221 + predictions: [ ], 1.222 + unassigned: [ ], 1.223 + args: { 1.224 + command: { name: 'tsr' }, 1.225 + text: { 1.226 + value: 'fred bloggs', 1.227 + arg: ' fred bloggs', 1.228 + status: 'VALID', 1.229 + message: '' 1.230 + } 1.231 + } 1.232 + }, 1.233 + exec: { 1.234 + output: 'Exec: tsr text=fred bloggs' 1.235 + } 1.236 + }, 1.237 + { 1.238 + setup: 'tsr "fred bloggs"', 1.239 + check: { 1.240 + input: 'tsr "fred bloggs"', 1.241 + hints: '', 1.242 + markup: 'VVVVVVVVVVVVVVVVV', 1.243 + cursor: 17, 1.244 + current: 'text', 1.245 + status: 'VALID', 1.246 + predictions: [ ], 1.247 + unassigned: [ ], 1.248 + args: { 1.249 + command: { name: 'tsr' }, 1.250 + text: { 1.251 + value: 'fred bloggs', 1.252 + arg: ' "fred bloggs"', 1.253 + status: 'VALID', 1.254 + message: '' 1.255 + } 1.256 + } 1.257 + }, 1.258 + exec: { 1.259 + output: 'Exec: tsr text=fred bloggs' 1.260 + } 1.261 + }, 1.262 + { 1.263 + setup: 'tsr "fred bloggs', 1.264 + check: { 1.265 + input: 'tsr "fred bloggs', 1.266 + hints: '', 1.267 + markup: 'VVVVVVVVVVVVVVVV', 1.268 + cursor: 16, 1.269 + current: 'text', 1.270 + status: 'VALID', 1.271 + predictions: [ ], 1.272 + unassigned: [ ], 1.273 + args: { 1.274 + command: { name: 'tsr' }, 1.275 + text: { 1.276 + value: 'fred bloggs', 1.277 + arg: ' "fred bloggs', 1.278 + status: 'VALID', 1.279 + message: '' 1.280 + } 1.281 + } 1.282 + }, 1.283 + exec: { 1.284 + output: 'Exec: tsr text=fred bloggs' 1.285 + } 1.286 + } 1.287 + ]); 1.288 +}; 1.289 + 1.290 +exports.testExecBoolean = function(options) { 1.291 + return helpers.audit(options, [ 1.292 + { 1.293 + setup: 'tsb', 1.294 + check: { 1.295 + input: 'tsb', 1.296 + hints: ' [toggle]', 1.297 + markup: 'VVV', 1.298 + cursor: 3, 1.299 + current: '__command', 1.300 + status: 'VALID', 1.301 + predictions: [ ], 1.302 + unassigned: [ ], 1.303 + args: { 1.304 + command: { name: 'tsb' }, 1.305 + toggle: { 1.306 + value: false, 1.307 + arg: '', 1.308 + status: 'VALID', 1.309 + message: '' 1.310 + } 1.311 + } 1.312 + }, 1.313 + exec: { 1.314 + output: 'Exec: tsb toggle=false' 1.315 + } 1.316 + }, 1.317 + { 1.318 + setup: 'tsb --toggle', 1.319 + check: { 1.320 + input: 'tsb --toggle', 1.321 + hints: '', 1.322 + markup: 'VVVVVVVVVVVV', 1.323 + cursor: 12, 1.324 + current: 'toggle', 1.325 + status: 'VALID', 1.326 + predictions: [ ], 1.327 + unassigned: [ ], 1.328 + outputState: 'false:default', 1.329 + args: { 1.330 + command: { name: 'tsb' }, 1.331 + toggle: { 1.332 + value: true, 1.333 + arg: ' --toggle', 1.334 + status: 'VALID', 1.335 + message: '' 1.336 + } 1.337 + } 1.338 + }, 1.339 + exec: { 1.340 + output: 'Exec: tsb toggle=true' 1.341 + } 1.342 + } 1.343 + ]); 1.344 +}; 1.345 + 1.346 +exports.testExecNumber = function(options) { 1.347 + return helpers.audit(options, [ 1.348 + { 1.349 + setup: 'tsu 10', 1.350 + check: { 1.351 + input: 'tsu 10', 1.352 + hints: '', 1.353 + markup: 'VVVVVV', 1.354 + cursor: 6, 1.355 + current: 'num', 1.356 + status: 'VALID', 1.357 + predictions: [ ], 1.358 + unassigned: [ ], 1.359 + args: { 1.360 + command: { name: 'tsu' }, 1.361 + num: { value: 10, arg: ' 10', status: 'VALID', message: '' } 1.362 + } 1.363 + }, 1.364 + exec: { 1.365 + output: 'Exec: tsu num=10' 1.366 + } 1.367 + }, 1.368 + { 1.369 + setup: 'tsu --num 10', 1.370 + check: { 1.371 + input: 'tsu --num 10', 1.372 + hints: '', 1.373 + markup: 'VVVVVVVVVVVV', 1.374 + cursor: 12, 1.375 + current: 'num', 1.376 + status: 'VALID', 1.377 + predictions: [ ], 1.378 + unassigned: [ ], 1.379 + args: { 1.380 + command: { name: 'tsu' }, 1.381 + num: { value: 10, arg: ' --num 10', status: 'VALID', message: '' } 1.382 + } 1.383 + }, 1.384 + exec: { 1.385 + output: 'Exec: tsu num=10' 1.386 + } 1.387 + } 1.388 + ]); 1.389 +}; 1.390 + 1.391 +exports.testExecScript = function(options) { 1.392 + return helpers.audit(options, [ 1.393 + { 1.394 + // Bug 704829 - Enable GCLI Javascript parameters 1.395 + // The answer to this should be 2 1.396 + setup: 'tsj { 1 + 1 }', 1.397 + check: { 1.398 + input: 'tsj { 1 + 1 }', 1.399 + hints: '', 1.400 + markup: 'VVVVVVVVVVVVV', 1.401 + cursor: 13, 1.402 + current: 'javascript', 1.403 + status: 'VALID', 1.404 + predictions: [ ], 1.405 + unassigned: [ ], 1.406 + args: { 1.407 + command: { name: 'tsj' }, 1.408 + javascript: { 1.409 + value: '1 + 1', 1.410 + arg: ' { 1 + 1 }', 1.411 + status: 'VALID', 1.412 + message: '' 1.413 + } 1.414 + } 1.415 + }, 1.416 + exec: { 1.417 + output: 'Exec: tsj javascript=1 + 1' 1.418 + } 1.419 + } 1.420 + ]); 1.421 +}; 1.422 + 1.423 +exports.testExecNode = function(options) { 1.424 + var origDoc = nodetype.getDocument(); 1.425 + nodetype.setDocument(mockDoc); 1.426 + 1.427 + return helpers.audit(options, [ 1.428 + { 1.429 + skipIf: options.isRemote, // No DOM on server 1.430 + setup: 'tse :root', 1.431 + check: { 1.432 + input: 'tse :root', 1.433 + hints: ' [options]', 1.434 + markup: 'VVVVVVVVV', 1.435 + cursor: 9, 1.436 + current: 'node', 1.437 + status: 'VALID', 1.438 + predictions: [ ], 1.439 + unassigned: [ ], 1.440 + args: { 1.441 + command: { name: 'tse' }, 1.442 + node: { 1.443 + value: mockBody, 1.444 + arg: ' :root', 1.445 + status: 'VALID', 1.446 + message: '' 1.447 + }, 1.448 + nodes: { 1.449 + value: mockEmptyNodeList, 1.450 + arg: '', 1.451 + status: 'VALID', 1.452 + message: '' 1.453 + }, 1.454 + nodes2: { 1.455 + value: mockEmptyNodeList, 1.456 + arg: '', 1.457 + status: 'VALID', 1.458 + message: '' 1.459 + } 1.460 + } 1.461 + }, 1.462 + exec: { 1.463 + output: /^Exec: tse/ 1.464 + }, 1.465 + post: function() { 1.466 + nodetype.setDocument(origDoc); 1.467 + } 1.468 + } 1.469 + ]); 1.470 +}; 1.471 + 1.472 +exports.testExecSubCommand = function(options) { 1.473 + return helpers.audit(options, [ 1.474 + { 1.475 + setup: 'tsn dif fred', 1.476 + check: { 1.477 + input: 'tsn dif fred', 1.478 + hints: '', 1.479 + markup: 'VVVVVVVVVVVV', 1.480 + cursor: 12, 1.481 + current: 'text', 1.482 + status: 'VALID', 1.483 + predictions: [ ], 1.484 + unassigned: [ ], 1.485 + args: { 1.486 + command: { name: 'tsn dif' }, 1.487 + text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' } 1.488 + } 1.489 + }, 1.490 + exec: { 1.491 + output: 'Exec: tsnDif text=fred' 1.492 + } 1.493 + }, 1.494 + { 1.495 + setup: 'tsn exten fred', 1.496 + check: { 1.497 + input: 'tsn exten fred', 1.498 + hints: '', 1.499 + markup: 'VVVVVVVVVVVVVV', 1.500 + cursor: 14, 1.501 + current: 'text', 1.502 + status: 'VALID', 1.503 + predictions: [ ], 1.504 + unassigned: [ ], 1.505 + args: { 1.506 + command: { name: 'tsn exten' }, 1.507 + text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' }, 1.508 + } 1.509 + }, 1.510 + exec: { 1.511 + output: 'Exec: tsnExten text=fred' 1.512 + } 1.513 + }, 1.514 + { 1.515 + setup: 'tsn extend fred', 1.516 + check: { 1.517 + input: 'tsn extend fred', 1.518 + hints: '', 1.519 + markup: 'VVVVVVVVVVVVVVV', 1.520 + cursor: 15, 1.521 + current: 'text', 1.522 + status: 'VALID', 1.523 + predictions: [ ], 1.524 + unassigned: [ ], 1.525 + args: { 1.526 + command: { name: 'tsn extend' }, 1.527 + text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' }, 1.528 + } 1.529 + }, 1.530 + exec: { 1.531 + output: 'Exec: tsnExtend text=fred' 1.532 + } 1.533 + } 1.534 + ]); 1.535 +}; 1.536 + 1.537 +exports.testExecArray = function(options) { 1.538 + return helpers.audit(options, [ 1.539 + { 1.540 + setup: 'tselarr 1', 1.541 + check: { 1.542 + input: 'tselarr 1', 1.543 + hints: '', 1.544 + markup: 'VVVVVVVVV', 1.545 + cursor: 9, 1.546 + current: 'num', 1.547 + status: 'VALID', 1.548 + predictions: ['1'], 1.549 + unassigned: [ ], 1.550 + outputState: 'false:default', 1.551 + args: { 1.552 + command: { name: 'tselarr' }, 1.553 + num: { value: '1', arg: ' 1', status: 'VALID', message: '' }, 1.554 + arr: { /*value:,*/ arg: '{}', status: 'VALID', message: '' }, 1.555 + } 1.556 + }, 1.557 + exec: { 1.558 + output: 'Exec: tselarr num=1, arr=' 1.559 + } 1.560 + }, 1.561 + { 1.562 + setup: 'tselarr 1 a', 1.563 + check: { 1.564 + input: 'tselarr 1 a', 1.565 + hints: '', 1.566 + markup: 'VVVVVVVVVVV', 1.567 + cursor: 11, 1.568 + current: 'arr', 1.569 + status: 'VALID', 1.570 + predictions: [ ], 1.571 + unassigned: [ ], 1.572 + args: { 1.573 + command: { name: 'tselarr' }, 1.574 + num: { value: '1', arg: ' 1', status: 'VALID', message: '' }, 1.575 + arr: { /*value:a,*/ arg: '{ a}', status: 'VALID', message: '' }, 1.576 + } 1.577 + }, 1.578 + exec: { 1.579 + output: 'Exec: tselarr num=1, arr=a' 1.580 + } 1.581 + }, 1.582 + { 1.583 + setup: 'tselarr 1 a b', 1.584 + check: { 1.585 + input: 'tselarr 1 a b', 1.586 + hints: '', 1.587 + markup: 'VVVVVVVVVVVVV', 1.588 + cursor: 13, 1.589 + current: 'arr', 1.590 + status: 'VALID', 1.591 + predictions: [ ], 1.592 + unassigned: [ ], 1.593 + args: { 1.594 + command: { name: 'tselarr' }, 1.595 + num: { value: '1', arg: ' 1', status: 'VALID', message: '' }, 1.596 + arr: { /*value:a,b,*/ arg: '{ a, b}', status: 'VALID', message: '' }, 1.597 + } 1.598 + }, 1.599 + exec: { 1.600 + output: 'Exec: tselarr num=1, arr=a,b' 1.601 + } 1.602 + } 1.603 + ]); 1.604 +}; 1.605 + 1.606 +exports.testExecMultiple = function(options) { 1.607 + return helpers.audit(options, [ 1.608 + { 1.609 + setup: 'tsm a 10 10', 1.610 + check: { 1.611 + input: 'tsm a 10 10', 1.612 + hints: '', 1.613 + markup: 'VVVVVVVVVVV', 1.614 + cursor: 11, 1.615 + current: 'num', 1.616 + status: 'VALID', 1.617 + predictions: [ ], 1.618 + unassigned: [ ], 1.619 + args: { 1.620 + command: { name: 'tsm' }, 1.621 + abc: { value: 'a', arg: ' a', status: 'VALID', message: '' }, 1.622 + txt: { value: '10', arg: ' 10', status: 'VALID', message: '' }, 1.623 + num: { value: 10, arg: ' 10', status: 'VALID', message: '' }, 1.624 + } 1.625 + }, 1.626 + exec: { 1.627 + output: 'Exec: tsm abc=a, txt=10, num=10' 1.628 + } 1.629 + } 1.630 + ]); 1.631 +}; 1.632 + 1.633 +exports.testExecDefaults = function(options) { 1.634 + return helpers.audit(options, [ 1.635 + { 1.636 + // Bug 707009 - GCLI doesn't always fill in default parameters properly 1.637 + setup: 'tsg aaa', 1.638 + check: { 1.639 + input: 'tsg aaa', 1.640 + hints: ' [options]', 1.641 + markup: 'VVVVVVV', 1.642 + cursor: 7, 1.643 + current: 'solo', 1.644 + status: 'VALID', 1.645 + predictions: ['aaa'], 1.646 + unassigned: [ ], 1.647 + args: { 1.648 + command: { name: 'tsg' }, 1.649 + solo: { value: 'aaa', arg: ' aaa', status: 'VALID', message: '' }, 1.650 + txt1: { value: undefined, arg: '', status: 'VALID', message: '' }, 1.651 + bool: { value: false, arg: '', status: 'VALID', message: '' }, 1.652 + txt2: { value: undefined, arg: '', status: 'VALID', message: '' }, 1.653 + num: { value: undefined, arg: '', status: 'VALID', message: '' }, 1.654 + } 1.655 + }, 1.656 + exec: { 1.657 + output: 'Exec: tsg solo=aaa, txt1=null, bool=false, txt2=d, num=42' 1.658 + } 1.659 + } 1.660 + ]); 1.661 + 1.662 +};