michael@0: /* michael@0: * Copyright 2012, Mozilla Foundation and contributors michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: 'use strict'; michael@0: // michael@0: michael@0: // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT michael@0: // DO NOT EDIT IT DIRECTLY michael@0: michael@0: var exports = {}; michael@0: michael@0: var TEST_URI = "data:text/html;charset=utf-8,

gcli-testExec.js

"; michael@0: michael@0: function test() { michael@0: return Task.spawn(function() { michael@0: let options = yield helpers.openTab(TEST_URI); michael@0: yield helpers.openToolbar(options); michael@0: gcli.addItems(mockCommands.items); michael@0: michael@0: yield helpers.runTests(options, exports); michael@0: michael@0: gcli.removeItems(mockCommands.items); michael@0: yield helpers.closeToolbar(options); michael@0: yield helpers.closeTab(options); michael@0: }).then(finish, helpers.handleError); michael@0: } michael@0: michael@0: // michael@0: michael@0: // var assert = require('../testharness/assert'); michael@0: // var helpers = require('./helpers'); michael@0: var nodetype = require('gcli/types/node'); michael@0: michael@0: var mockBody = { michael@0: style: {} michael@0: }; michael@0: michael@0: var mockEmptyNodeList = { michael@0: length: 0, michael@0: item: function() { return null; } michael@0: }; michael@0: michael@0: var mockRootNodeList = { michael@0: length: 1, michael@0: item: function(i) { return mockBody; } michael@0: }; michael@0: michael@0: var mockDoc = { michael@0: querySelectorAll: function(css) { michael@0: return (css === ':root') ? mockRootNodeList : mockEmptyNodeList; michael@0: } michael@0: }; michael@0: michael@0: exports.testParamGroup = function(options) { michael@0: var tsg = options.requisition.canon.getCommand('tsg'); michael@0: michael@0: assert.is(tsg.params[0].groupName, null, 'tsg param 0 group null'); michael@0: assert.is(tsg.params[1].groupName, 'First', 'tsg param 1 group First'); michael@0: assert.is(tsg.params[2].groupName, 'First', 'tsg param 2 group First'); michael@0: assert.is(tsg.params[3].groupName, 'Second', 'tsg param 3 group Second'); michael@0: assert.is(tsg.params[4].groupName, 'Second', 'tsg param 4 group Second'); michael@0: }; michael@0: michael@0: exports.testWithHelpers = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'tss', michael@0: check: { michael@0: input: 'tss', michael@0: hints: '', michael@0: markup: 'VVV', michael@0: cursor: 3, michael@0: current: '__command', michael@0: status: 'VALID', michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tss' }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: /^Exec: tss/, michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsv option1 10', michael@0: check: { michael@0: input: 'tsv option1 10', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVV', michael@0: cursor: 14, michael@0: current: 'optionValue', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsv' }, michael@0: optionType: { michael@0: value: 'string', michael@0: arg: ' option1', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: optionValue: { michael@0: arg: ' 10', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsv optionType=string, optionValue=10' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsv option2 10', michael@0: check: { michael@0: input: 'tsv option2 10', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVV', michael@0: cursor: 14, michael@0: current: 'optionValue', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsv' }, michael@0: optionType: { michael@0: value: 'number', michael@0: arg: ' option2', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: optionValue: { michael@0: arg: ' 10', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsv optionType=number, optionValue=10' michael@0: } michael@0: }, michael@0: // Delegated remote types can't transfer value types so we only test for michael@0: // the value of optionValue when we're local michael@0: { michael@0: skipIf: options.isRemote, michael@0: setup: 'tsv option1 10', michael@0: check: { michael@0: args: { optionValue: { value: '10' } } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsv optionType=string, optionValue=10' michael@0: } michael@0: }, michael@0: { michael@0: skipIf: options.isRemote, michael@0: setup: 'tsv option2 10', michael@0: check: { michael@0: args: { optionValue: { value: 10 } } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsv optionType=number, optionValue=10' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecText = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'tsr fred', michael@0: check: { michael@0: input: 'tsr fred', michael@0: hints: '', michael@0: markup: 'VVVVVVVV', michael@0: cursor: 8, michael@0: current: 'text', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsr' }, michael@0: text: { michael@0: value: 'fred', michael@0: arg: ' fred', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsr text=fred' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsr fred bloggs', michael@0: check: { michael@0: input: 'tsr fred bloggs', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVV', michael@0: cursor: 15, michael@0: current: 'text', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsr' }, michael@0: text: { michael@0: value: 'fred bloggs', michael@0: arg: ' fred bloggs', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsr text=fred bloggs' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsr "fred bloggs"', michael@0: check: { michael@0: input: 'tsr "fred bloggs"', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVVV', michael@0: cursor: 17, michael@0: current: 'text', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsr' }, michael@0: text: { michael@0: value: 'fred bloggs', michael@0: arg: ' "fred bloggs"', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsr text=fred bloggs' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsr "fred bloggs', michael@0: check: { michael@0: input: 'tsr "fred bloggs', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVV', michael@0: cursor: 16, michael@0: current: 'text', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsr' }, michael@0: text: { michael@0: value: 'fred bloggs', michael@0: arg: ' "fred bloggs', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsr text=fred bloggs' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecBoolean = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'tsb', michael@0: check: { michael@0: input: 'tsb', michael@0: hints: ' [toggle]', michael@0: markup: 'VVV', michael@0: cursor: 3, michael@0: current: '__command', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsb' }, michael@0: toggle: { michael@0: value: false, michael@0: arg: '', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsb toggle=false' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsb --toggle', michael@0: check: { michael@0: input: 'tsb --toggle', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVV', michael@0: cursor: 12, michael@0: current: 'toggle', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: outputState: 'false:default', michael@0: args: { michael@0: command: { name: 'tsb' }, michael@0: toggle: { michael@0: value: true, michael@0: arg: ' --toggle', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsb toggle=true' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecNumber = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'tsu 10', michael@0: check: { michael@0: input: 'tsu 10', michael@0: hints: '', michael@0: markup: 'VVVVVV', michael@0: cursor: 6, michael@0: current: 'num', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsu' }, michael@0: num: { value: 10, arg: ' 10', status: 'VALID', message: '' } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsu num=10' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsu --num 10', michael@0: check: { michael@0: input: 'tsu --num 10', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVV', michael@0: cursor: 12, michael@0: current: 'num', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsu' }, michael@0: num: { value: 10, arg: ' --num 10', status: 'VALID', message: '' } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsu num=10' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecScript = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: // Bug 704829 - Enable GCLI Javascript parameters michael@0: // The answer to this should be 2 michael@0: setup: 'tsj { 1 + 1 }', michael@0: check: { michael@0: input: 'tsj { 1 + 1 }', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVV', michael@0: cursor: 13, michael@0: current: 'javascript', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsj' }, michael@0: javascript: { michael@0: value: '1 + 1', michael@0: arg: ' { 1 + 1 }', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsj javascript=1 + 1' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecNode = function(options) { michael@0: var origDoc = nodetype.getDocument(); michael@0: nodetype.setDocument(mockDoc); michael@0: michael@0: return helpers.audit(options, [ michael@0: { michael@0: skipIf: options.isRemote, // No DOM on server michael@0: setup: 'tse :root', michael@0: check: { michael@0: input: 'tse :root', michael@0: hints: ' [options]', michael@0: markup: 'VVVVVVVVV', michael@0: cursor: 9, michael@0: current: 'node', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tse' }, michael@0: node: { michael@0: value: mockBody, michael@0: arg: ' :root', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: nodes: { michael@0: value: mockEmptyNodeList, michael@0: arg: '', michael@0: status: 'VALID', michael@0: message: '' michael@0: }, michael@0: nodes2: { michael@0: value: mockEmptyNodeList, michael@0: arg: '', michael@0: status: 'VALID', michael@0: message: '' michael@0: } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: /^Exec: tse/ michael@0: }, michael@0: post: function() { michael@0: nodetype.setDocument(origDoc); michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecSubCommand = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'tsn dif fred', michael@0: check: { michael@0: input: 'tsn dif fred', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVV', michael@0: cursor: 12, michael@0: current: 'text', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsn dif' }, michael@0: text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsnDif text=fred' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsn exten fred', michael@0: check: { michael@0: input: 'tsn exten fred', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVV', michael@0: cursor: 14, michael@0: current: 'text', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsn exten' }, michael@0: text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsnExten text=fred' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tsn extend fred', michael@0: check: { michael@0: input: 'tsn extend fred', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVV', michael@0: cursor: 15, michael@0: current: 'text', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsn extend' }, michael@0: text: { value: 'fred', arg: ' fred', status: 'VALID', message: '' }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsnExtend text=fred' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecArray = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'tselarr 1', michael@0: check: { michael@0: input: 'tselarr 1', michael@0: hints: '', michael@0: markup: 'VVVVVVVVV', michael@0: cursor: 9, michael@0: current: 'num', michael@0: status: 'VALID', michael@0: predictions: ['1'], michael@0: unassigned: [ ], michael@0: outputState: 'false:default', michael@0: args: { michael@0: command: { name: 'tselarr' }, michael@0: num: { value: '1', arg: ' 1', status: 'VALID', message: '' }, michael@0: arr: { /*value:,*/ arg: '{}', status: 'VALID', message: '' }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tselarr num=1, arr=' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tselarr 1 a', michael@0: check: { michael@0: input: 'tselarr 1 a', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVV', michael@0: cursor: 11, michael@0: current: 'arr', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tselarr' }, michael@0: num: { value: '1', arg: ' 1', status: 'VALID', message: '' }, michael@0: arr: { /*value:a,*/ arg: '{ a}', status: 'VALID', message: '' }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tselarr num=1, arr=a' michael@0: } michael@0: }, michael@0: { michael@0: setup: 'tselarr 1 a b', michael@0: check: { michael@0: input: 'tselarr 1 a b', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVV', michael@0: cursor: 13, michael@0: current: 'arr', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tselarr' }, michael@0: num: { value: '1', arg: ' 1', status: 'VALID', message: '' }, michael@0: arr: { /*value:a,b,*/ arg: '{ a, b}', status: 'VALID', message: '' }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tselarr num=1, arr=a,b' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecMultiple = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'tsm a 10 10', michael@0: check: { michael@0: input: 'tsm a 10 10', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVV', michael@0: cursor: 11, michael@0: current: 'num', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsm' }, michael@0: abc: { value: 'a', arg: ' a', status: 'VALID', message: '' }, michael@0: txt: { value: '10', arg: ' 10', status: 'VALID', message: '' }, michael@0: num: { value: 10, arg: ' 10', status: 'VALID', message: '' }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsm abc=a, txt=10, num=10' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testExecDefaults = function(options) { michael@0: return helpers.audit(options, [ michael@0: { michael@0: // Bug 707009 - GCLI doesn't always fill in default parameters properly michael@0: setup: 'tsg aaa', michael@0: check: { michael@0: input: 'tsg aaa', michael@0: hints: ' [options]', michael@0: markup: 'VVVVVVV', michael@0: cursor: 7, michael@0: current: 'solo', michael@0: status: 'VALID', michael@0: predictions: ['aaa'], michael@0: unassigned: [ ], michael@0: args: { michael@0: command: { name: 'tsg' }, michael@0: solo: { value: 'aaa', arg: ' aaa', status: 'VALID', message: '' }, michael@0: txt1: { value: undefined, arg: '', status: 'VALID', message: '' }, michael@0: bool: { value: false, arg: '', status: 'VALID', message: '' }, michael@0: txt2: { value: undefined, arg: '', status: 'VALID', message: '' }, michael@0: num: { value: undefined, arg: '', status: 'VALID', message: '' }, michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'Exec: tsg solo=aaa, txt1=null, bool=false, txt2=d, num=42' michael@0: } michael@0: } michael@0: ]); michael@0: michael@0: };