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-testCanon.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 Canon = require('gcli/commands/commands').Canon; michael@0: michael@0: var startCount; michael@0: var events; michael@0: michael@0: var canonChange = function(ev) { michael@0: events++; michael@0: }; michael@0: michael@0: exports.setup = function(options) { michael@0: startCount = options.requisition.canon.getCommands().length; michael@0: events = 0; michael@0: }; michael@0: michael@0: exports.shutdown = function(options) { michael@0: startCount = undefined; michael@0: events = undefined; michael@0: }; michael@0: michael@0: exports.testAddRemove1 = function(options) { michael@0: var canon = options.requisition.canon; michael@0: michael@0: return helpers.audit(options, [ michael@0: { michael@0: name: 'testadd add', michael@0: setup: function() { michael@0: canon.onCanonChange.add(canonChange); michael@0: michael@0: canon.addCommand({ michael@0: name: 'testadd', michael@0: exec: function() { michael@0: return 1; michael@0: } michael@0: }); michael@0: michael@0: assert.is(canon.getCommands().length, michael@0: startCount + 1, michael@0: 'add command success'); michael@0: assert.is(events, 1, 'add event'); michael@0: michael@0: return helpers.setInput(options, 'testadd'); michael@0: }, michael@0: check: { michael@0: input: 'testadd', michael@0: hints: '', michael@0: markup: 'VVVVVVV', michael@0: cursor: 7, michael@0: current: '__command', michael@0: status: 'VALID', michael@0: predictions: [ ], michael@0: unassigned: [ ], michael@0: args: { } michael@0: }, michael@0: exec: { michael@0: output: /^1$/ michael@0: } michael@0: }, michael@0: { michael@0: name: 'testadd alter', michael@0: setup: function() { michael@0: canon.addCommand({ michael@0: name: 'testadd', michael@0: exec: function() { michael@0: return 2; michael@0: } michael@0: }); michael@0: michael@0: assert.is(canon.getCommands().length, michael@0: startCount + 1, michael@0: 'read command success'); michael@0: assert.is(events, 2, 'read event'); michael@0: michael@0: return helpers.setInput(options, 'testadd'); michael@0: }, michael@0: check: { michael@0: input: 'testadd', michael@0: hints: '', michael@0: markup: 'VVVVVVV', michael@0: }, michael@0: exec: { michael@0: output: '2' michael@0: } michael@0: }, michael@0: { michael@0: name: 'testadd remove', michael@0: setup: function() { michael@0: canon.removeCommand('testadd'); michael@0: michael@0: assert.is(canon.getCommands().length, michael@0: startCount, michael@0: 'remove command success'); michael@0: assert.is(events, 3, 'remove event'); michael@0: michael@0: return helpers.setInput(options, 'testadd'); michael@0: }, michael@0: check: { michael@0: typed: 'testadd', michael@0: cursor: 7, michael@0: current: '__command', michael@0: status: 'ERROR', michael@0: unassigned: [ ], michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testAddRemove2 = function(options) { michael@0: var canon = options.requisition.canon; michael@0: michael@0: canon.addCommand({ michael@0: name: 'testadd', michael@0: exec: function() { michael@0: return 3; michael@0: } michael@0: }); michael@0: michael@0: assert.is(canon.getCommands().length, michael@0: startCount + 1, michael@0: 'rereadd command success'); michael@0: assert.is(events, 4, 'rereadd event'); michael@0: michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'testadd', michael@0: exec: { michael@0: output: /^3$/ michael@0: }, michael@0: post: function() { michael@0: canon.removeCommand({ michael@0: name: 'testadd' michael@0: }); michael@0: michael@0: assert.is(canon.getCommands().length, michael@0: startCount, michael@0: 'reremove command success'); michael@0: assert.is(events, 5, 'reremove event'); michael@0: } michael@0: }, michael@0: { michael@0: setup: 'testadd', michael@0: check: { michael@0: typed: 'testadd', michael@0: status: 'ERROR' michael@0: } michael@0: } michael@0: ]); michael@0: }; michael@0: michael@0: exports.testAddRemove3 = function(options) { michael@0: var canon = options.requisition.canon; michael@0: michael@0: canon.removeCommand({ name: 'nonexistant' }); michael@0: assert.is(canon.getCommands().length, michael@0: startCount, michael@0: 'nonexistant1 command success'); michael@0: assert.is(events, 5, 'nonexistant1 event'); michael@0: michael@0: canon.removeCommand('nonexistant'); michael@0: assert.is(canon.getCommands().length, michael@0: startCount, michael@0: 'nonexistant2 command success'); michael@0: assert.is(events, 5, 'nonexistant2 event'); michael@0: michael@0: canon.onCanonChange.remove(canonChange); michael@0: }; michael@0: michael@0: exports.testAltCanon = function(options) { michael@0: var canon = options.requisition.canon; michael@0: var altCanon = new Canon(); michael@0: michael@0: var tss = { michael@0: name: 'tss', michael@0: params: [ michael@0: { name: 'str', type: 'string' }, michael@0: { name: 'num', type: 'number' }, michael@0: { name: 'opt', type: { name: 'selection', data: [ '1', '2', '3' ] } }, michael@0: ], michael@0: exec: function(args, context) { michael@0: return context.commandName + ':' + michael@0: args.str + ':' + args.num + ':' + args.opt; michael@0: } michael@0: }; michael@0: altCanon.addCommand(tss); michael@0: michael@0: var commandSpecs = altCanon.getCommandSpecs(); michael@0: assert.is(JSON.stringify(commandSpecs), michael@0: '[{"item":"command","name":"tss","params":[' + michael@0: '{"name":"str","type":"string"},' + michael@0: '{"name":"num","type":"number"},' + michael@0: '{"name":"opt","type":{"name":"selection","data":["1","2","3"]}}' + michael@0: '],"isParent":false}]', michael@0: 'JSON.stringify(commandSpecs)'); michael@0: michael@0: var remoter = function(args, context) { michael@0: assert.is(context.commandName, 'tss', 'commandName is tss'); michael@0: michael@0: var cmd = altCanon.getCommand(context.commandName); michael@0: return cmd.exec(args, context); michael@0: }; michael@0: michael@0: canon.addProxyCommands(commandSpecs, remoter, 'proxy', 'test'); michael@0: michael@0: var parent = canon.getCommand('proxy'); michael@0: assert.is(parent.name, 'proxy', 'Parent command called proxy'); michael@0: michael@0: var child = canon.getCommand('proxy tss'); michael@0: assert.is(child.name, 'proxy tss', 'child command called proxy tss'); michael@0: michael@0: return helpers.audit(options, [ michael@0: { michael@0: setup: 'proxy tss foo 6 3', michael@0: check: { michael@0: input: 'proxy tss foo 6 3', michael@0: hints: '', michael@0: markup: 'VVVVVVVVVVVVVVVVV', michael@0: cursor: 17, michael@0: status: 'VALID', michael@0: args: { michael@0: str: { value: 'foo', status: 'VALID' }, michael@0: num: { value: 6, status: 'VALID' }, michael@0: opt: { value: '3', status: 'VALID' } michael@0: } michael@0: }, michael@0: exec: { michael@0: output: 'tss:foo:6:3' michael@0: }, michael@0: post: function() { michael@0: canon.removeCommand('proxy'); michael@0: canon.removeCommand('proxy tss'); michael@0: michael@0: assert.is(canon.getCommand('proxy'), undefined, 'remove proxy'); michael@0: assert.is(canon.getCommand('proxy tss'), undefined, 'remove proxy tss'); michael@0: } michael@0: } michael@0: ]); michael@0: };