Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012, Mozilla Foundation and contributors |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | 'use strict'; |
michael@0 | 18 | // <INJECTED SOURCE:START> |
michael@0 | 19 | |
michael@0 | 20 | // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT |
michael@0 | 21 | // DO NOT EDIT IT DIRECTLY |
michael@0 | 22 | |
michael@0 | 23 | var exports = {}; |
michael@0 | 24 | |
michael@0 | 25 | var TEST_URI = "data:text/html;charset=utf-8,<p id='gcli-input'>gcli-testCanon.js</p>"; |
michael@0 | 26 | |
michael@0 | 27 | function test() { |
michael@0 | 28 | return Task.spawn(function() { |
michael@0 | 29 | let options = yield helpers.openTab(TEST_URI); |
michael@0 | 30 | yield helpers.openToolbar(options); |
michael@0 | 31 | gcli.addItems(mockCommands.items); |
michael@0 | 32 | |
michael@0 | 33 | yield helpers.runTests(options, exports); |
michael@0 | 34 | |
michael@0 | 35 | gcli.removeItems(mockCommands.items); |
michael@0 | 36 | yield helpers.closeToolbar(options); |
michael@0 | 37 | yield helpers.closeTab(options); |
michael@0 | 38 | }).then(finish, helpers.handleError); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | // <INJECTED SOURCE:END> |
michael@0 | 42 | |
michael@0 | 43 | // var assert = require('../testharness/assert'); |
michael@0 | 44 | // var helpers = require('./helpers'); |
michael@0 | 45 | var Canon = require('gcli/commands/commands').Canon; |
michael@0 | 46 | |
michael@0 | 47 | var startCount; |
michael@0 | 48 | var events; |
michael@0 | 49 | |
michael@0 | 50 | var canonChange = function(ev) { |
michael@0 | 51 | events++; |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | exports.setup = function(options) { |
michael@0 | 55 | startCount = options.requisition.canon.getCommands().length; |
michael@0 | 56 | events = 0; |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | exports.shutdown = function(options) { |
michael@0 | 60 | startCount = undefined; |
michael@0 | 61 | events = undefined; |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | exports.testAddRemove1 = function(options) { |
michael@0 | 65 | var canon = options.requisition.canon; |
michael@0 | 66 | |
michael@0 | 67 | return helpers.audit(options, [ |
michael@0 | 68 | { |
michael@0 | 69 | name: 'testadd add', |
michael@0 | 70 | setup: function() { |
michael@0 | 71 | canon.onCanonChange.add(canonChange); |
michael@0 | 72 | |
michael@0 | 73 | canon.addCommand({ |
michael@0 | 74 | name: 'testadd', |
michael@0 | 75 | exec: function() { |
michael@0 | 76 | return 1; |
michael@0 | 77 | } |
michael@0 | 78 | }); |
michael@0 | 79 | |
michael@0 | 80 | assert.is(canon.getCommands().length, |
michael@0 | 81 | startCount + 1, |
michael@0 | 82 | 'add command success'); |
michael@0 | 83 | assert.is(events, 1, 'add event'); |
michael@0 | 84 | |
michael@0 | 85 | return helpers.setInput(options, 'testadd'); |
michael@0 | 86 | }, |
michael@0 | 87 | check: { |
michael@0 | 88 | input: 'testadd', |
michael@0 | 89 | hints: '', |
michael@0 | 90 | markup: 'VVVVVVV', |
michael@0 | 91 | cursor: 7, |
michael@0 | 92 | current: '__command', |
michael@0 | 93 | status: 'VALID', |
michael@0 | 94 | predictions: [ ], |
michael@0 | 95 | unassigned: [ ], |
michael@0 | 96 | args: { } |
michael@0 | 97 | }, |
michael@0 | 98 | exec: { |
michael@0 | 99 | output: /^1$/ |
michael@0 | 100 | } |
michael@0 | 101 | }, |
michael@0 | 102 | { |
michael@0 | 103 | name: 'testadd alter', |
michael@0 | 104 | setup: function() { |
michael@0 | 105 | canon.addCommand({ |
michael@0 | 106 | name: 'testadd', |
michael@0 | 107 | exec: function() { |
michael@0 | 108 | return 2; |
michael@0 | 109 | } |
michael@0 | 110 | }); |
michael@0 | 111 | |
michael@0 | 112 | assert.is(canon.getCommands().length, |
michael@0 | 113 | startCount + 1, |
michael@0 | 114 | 'read command success'); |
michael@0 | 115 | assert.is(events, 2, 'read event'); |
michael@0 | 116 | |
michael@0 | 117 | return helpers.setInput(options, 'testadd'); |
michael@0 | 118 | }, |
michael@0 | 119 | check: { |
michael@0 | 120 | input: 'testadd', |
michael@0 | 121 | hints: '', |
michael@0 | 122 | markup: 'VVVVVVV', |
michael@0 | 123 | }, |
michael@0 | 124 | exec: { |
michael@0 | 125 | output: '2' |
michael@0 | 126 | } |
michael@0 | 127 | }, |
michael@0 | 128 | { |
michael@0 | 129 | name: 'testadd remove', |
michael@0 | 130 | setup: function() { |
michael@0 | 131 | canon.removeCommand('testadd'); |
michael@0 | 132 | |
michael@0 | 133 | assert.is(canon.getCommands().length, |
michael@0 | 134 | startCount, |
michael@0 | 135 | 'remove command success'); |
michael@0 | 136 | assert.is(events, 3, 'remove event'); |
michael@0 | 137 | |
michael@0 | 138 | return helpers.setInput(options, 'testadd'); |
michael@0 | 139 | }, |
michael@0 | 140 | check: { |
michael@0 | 141 | typed: 'testadd', |
michael@0 | 142 | cursor: 7, |
michael@0 | 143 | current: '__command', |
michael@0 | 144 | status: 'ERROR', |
michael@0 | 145 | unassigned: [ ], |
michael@0 | 146 | } |
michael@0 | 147 | } |
michael@0 | 148 | ]); |
michael@0 | 149 | }; |
michael@0 | 150 | |
michael@0 | 151 | exports.testAddRemove2 = function(options) { |
michael@0 | 152 | var canon = options.requisition.canon; |
michael@0 | 153 | |
michael@0 | 154 | canon.addCommand({ |
michael@0 | 155 | name: 'testadd', |
michael@0 | 156 | exec: function() { |
michael@0 | 157 | return 3; |
michael@0 | 158 | } |
michael@0 | 159 | }); |
michael@0 | 160 | |
michael@0 | 161 | assert.is(canon.getCommands().length, |
michael@0 | 162 | startCount + 1, |
michael@0 | 163 | 'rereadd command success'); |
michael@0 | 164 | assert.is(events, 4, 'rereadd event'); |
michael@0 | 165 | |
michael@0 | 166 | return helpers.audit(options, [ |
michael@0 | 167 | { |
michael@0 | 168 | setup: 'testadd', |
michael@0 | 169 | exec: { |
michael@0 | 170 | output: /^3$/ |
michael@0 | 171 | }, |
michael@0 | 172 | post: function() { |
michael@0 | 173 | canon.removeCommand({ |
michael@0 | 174 | name: 'testadd' |
michael@0 | 175 | }); |
michael@0 | 176 | |
michael@0 | 177 | assert.is(canon.getCommands().length, |
michael@0 | 178 | startCount, |
michael@0 | 179 | 'reremove command success'); |
michael@0 | 180 | assert.is(events, 5, 'reremove event'); |
michael@0 | 181 | } |
michael@0 | 182 | }, |
michael@0 | 183 | { |
michael@0 | 184 | setup: 'testadd', |
michael@0 | 185 | check: { |
michael@0 | 186 | typed: 'testadd', |
michael@0 | 187 | status: 'ERROR' |
michael@0 | 188 | } |
michael@0 | 189 | } |
michael@0 | 190 | ]); |
michael@0 | 191 | }; |
michael@0 | 192 | |
michael@0 | 193 | exports.testAddRemove3 = function(options) { |
michael@0 | 194 | var canon = options.requisition.canon; |
michael@0 | 195 | |
michael@0 | 196 | canon.removeCommand({ name: 'nonexistant' }); |
michael@0 | 197 | assert.is(canon.getCommands().length, |
michael@0 | 198 | startCount, |
michael@0 | 199 | 'nonexistant1 command success'); |
michael@0 | 200 | assert.is(events, 5, 'nonexistant1 event'); |
michael@0 | 201 | |
michael@0 | 202 | canon.removeCommand('nonexistant'); |
michael@0 | 203 | assert.is(canon.getCommands().length, |
michael@0 | 204 | startCount, |
michael@0 | 205 | 'nonexistant2 command success'); |
michael@0 | 206 | assert.is(events, 5, 'nonexistant2 event'); |
michael@0 | 207 | |
michael@0 | 208 | canon.onCanonChange.remove(canonChange); |
michael@0 | 209 | }; |
michael@0 | 210 | |
michael@0 | 211 | exports.testAltCanon = function(options) { |
michael@0 | 212 | var canon = options.requisition.canon; |
michael@0 | 213 | var altCanon = new Canon(); |
michael@0 | 214 | |
michael@0 | 215 | var tss = { |
michael@0 | 216 | name: 'tss', |
michael@0 | 217 | params: [ |
michael@0 | 218 | { name: 'str', type: 'string' }, |
michael@0 | 219 | { name: 'num', type: 'number' }, |
michael@0 | 220 | { name: 'opt', type: { name: 'selection', data: [ '1', '2', '3' ] } }, |
michael@0 | 221 | ], |
michael@0 | 222 | exec: function(args, context) { |
michael@0 | 223 | return context.commandName + ':' + |
michael@0 | 224 | args.str + ':' + args.num + ':' + args.opt; |
michael@0 | 225 | } |
michael@0 | 226 | }; |
michael@0 | 227 | altCanon.addCommand(tss); |
michael@0 | 228 | |
michael@0 | 229 | var commandSpecs = altCanon.getCommandSpecs(); |
michael@0 | 230 | assert.is(JSON.stringify(commandSpecs), |
michael@0 | 231 | '[{"item":"command","name":"tss","params":[' + |
michael@0 | 232 | '{"name":"str","type":"string"},' + |
michael@0 | 233 | '{"name":"num","type":"number"},' + |
michael@0 | 234 | '{"name":"opt","type":{"name":"selection","data":["1","2","3"]}}' + |
michael@0 | 235 | '],"isParent":false}]', |
michael@0 | 236 | 'JSON.stringify(commandSpecs)'); |
michael@0 | 237 | |
michael@0 | 238 | var remoter = function(args, context) { |
michael@0 | 239 | assert.is(context.commandName, 'tss', 'commandName is tss'); |
michael@0 | 240 | |
michael@0 | 241 | var cmd = altCanon.getCommand(context.commandName); |
michael@0 | 242 | return cmd.exec(args, context); |
michael@0 | 243 | }; |
michael@0 | 244 | |
michael@0 | 245 | canon.addProxyCommands(commandSpecs, remoter, 'proxy', 'test'); |
michael@0 | 246 | |
michael@0 | 247 | var parent = canon.getCommand('proxy'); |
michael@0 | 248 | assert.is(parent.name, 'proxy', 'Parent command called proxy'); |
michael@0 | 249 | |
michael@0 | 250 | var child = canon.getCommand('proxy tss'); |
michael@0 | 251 | assert.is(child.name, 'proxy tss', 'child command called proxy tss'); |
michael@0 | 252 | |
michael@0 | 253 | return helpers.audit(options, [ |
michael@0 | 254 | { |
michael@0 | 255 | setup: 'proxy tss foo 6 3', |
michael@0 | 256 | check: { |
michael@0 | 257 | input: 'proxy tss foo 6 3', |
michael@0 | 258 | hints: '', |
michael@0 | 259 | markup: 'VVVVVVVVVVVVVVVVV', |
michael@0 | 260 | cursor: 17, |
michael@0 | 261 | status: 'VALID', |
michael@0 | 262 | args: { |
michael@0 | 263 | str: { value: 'foo', status: 'VALID' }, |
michael@0 | 264 | num: { value: 6, status: 'VALID' }, |
michael@0 | 265 | opt: { value: '3', status: 'VALID' } |
michael@0 | 266 | } |
michael@0 | 267 | }, |
michael@0 | 268 | exec: { |
michael@0 | 269 | output: 'tss:foo:6:3' |
michael@0 | 270 | }, |
michael@0 | 271 | post: function() { |
michael@0 | 272 | canon.removeCommand('proxy'); |
michael@0 | 273 | canon.removeCommand('proxy tss'); |
michael@0 | 274 | |
michael@0 | 275 | assert.is(canon.getCommand('proxy'), undefined, 'remove proxy'); |
michael@0 | 276 | assert.is(canon.getCommand('proxy tss'), undefined, 'remove proxy tss'); |
michael@0 | 277 | } |
michael@0 | 278 | } |
michael@0 | 279 | ]); |
michael@0 | 280 | }; |