browser/devtools/commandline/test/browser_gcli_js.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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-testJs.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 javascript = require('gcli/types/javascript');
michael@0 46
michael@0 47 var tempWindow;
michael@0 48
michael@0 49 exports.setup = function(options) {
michael@0 50 if (options.isNoDom) {
michael@0 51 return;
michael@0 52 }
michael@0 53
michael@0 54 tempWindow = javascript.getGlobalObject();
michael@0 55 Object.defineProperty(options.window, 'donteval', {
michael@0 56 get: function() {
michael@0 57 assert.ok(false, 'donteval should not be used');
michael@0 58 return { cant: '', touch: '', 'this': '' };
michael@0 59 },
michael@0 60 enumerable: true,
michael@0 61 configurable : true
michael@0 62 });
michael@0 63 javascript.setGlobalObject(options.window);
michael@0 64 };
michael@0 65
michael@0 66 exports.shutdown = function(options) {
michael@0 67 if (options.isNoDom) {
michael@0 68 return;
michael@0 69 }
michael@0 70
michael@0 71 javascript.setGlobalObject(tempWindow);
michael@0 72 tempWindow = undefined;
michael@0 73 delete options.window.donteval;
michael@0 74 };
michael@0 75
michael@0 76 function jsTestAllowed(options) {
michael@0 77 return options.isRemote || options.isNoDom ||
michael@0 78 options.requisition.canon.getCommand('{') == null;
michael@0 79 }
michael@0 80
michael@0 81 exports.testBasic = function(options) {
michael@0 82 return helpers.audit(options, [
michael@0 83 {
michael@0 84 skipRemainingIf: jsTestAllowed,
michael@0 85 setup: '{',
michael@0 86 check: {
michael@0 87 input: '{',
michael@0 88 hints: '',
michael@0 89 markup: 'V',
michael@0 90 cursor: 1,
michael@0 91 current: 'javascript',
michael@0 92 status: 'ERROR',
michael@0 93 predictions: [ ],
michael@0 94 unassigned: [ ],
michael@0 95 args: {
michael@0 96 command: { name: '{' },
michael@0 97 javascript: {
michael@0 98 value: undefined,
michael@0 99 arg: '{',
michael@0 100 status: 'INCOMPLETE'
michael@0 101 }
michael@0 102 }
michael@0 103 }
michael@0 104 },
michael@0 105 {
michael@0 106 setup: '{ ',
michael@0 107 check: {
michael@0 108 input: '{ ',
michael@0 109 hints: '',
michael@0 110 markup: 'VV',
michael@0 111 cursor: 2,
michael@0 112 current: 'javascript',
michael@0 113 status: 'ERROR',
michael@0 114 predictions: [ ],
michael@0 115 unassigned: [ ],
michael@0 116 args: {
michael@0 117 command: { name: '{' },
michael@0 118 javascript: {
michael@0 119 value: undefined,
michael@0 120 arg: '{ ',
michael@0 121 status: 'INCOMPLETE'
michael@0 122 }
michael@0 123 }
michael@0 124 }
michael@0 125 },
michael@0 126 {
michael@0 127 setup: '{ w',
michael@0 128 check: {
michael@0 129 input: '{ w',
michael@0 130 hints: 'indow',
michael@0 131 markup: 'VVI',
michael@0 132 cursor: 3,
michael@0 133 current: 'javascript',
michael@0 134 status: 'ERROR',
michael@0 135 predictionsContains: [ 'window' ],
michael@0 136 unassigned: [ ],
michael@0 137 args: {
michael@0 138 command: { name: '{' },
michael@0 139 javascript: {
michael@0 140 value: 'w',
michael@0 141 arg: '{ w',
michael@0 142 status: 'INCOMPLETE'
michael@0 143 }
michael@0 144 }
michael@0 145 }
michael@0 146 },
michael@0 147 {
michael@0 148 setup: '{ windo',
michael@0 149 check: {
michael@0 150 input: '{ windo',
michael@0 151 hints: 'w',
michael@0 152 markup: 'VVIIIII',
michael@0 153 cursor: 7,
michael@0 154 current: 'javascript',
michael@0 155 status: 'ERROR',
michael@0 156 predictions: [ 'window' ],
michael@0 157 unassigned: [ ],
michael@0 158 args: {
michael@0 159 command: { name: '{' },
michael@0 160 javascript: {
michael@0 161 value: 'windo',
michael@0 162 arg: '{ windo',
michael@0 163 status: 'INCOMPLETE'
michael@0 164 }
michael@0 165 }
michael@0 166 }
michael@0 167 },
michael@0 168 {
michael@0 169 setup: '{ window',
michael@0 170 check: {
michael@0 171 input: '{ window',
michael@0 172 hints: '',
michael@0 173 markup: 'VVVVVVVV',
michael@0 174 cursor: 8,
michael@0 175 current: 'javascript',
michael@0 176 status: 'VALID',
michael@0 177 predictions: [ ],
michael@0 178 unassigned: [ ],
michael@0 179 args: {
michael@0 180 command: { name: '{' },
michael@0 181 javascript: {
michael@0 182 value: 'window',
michael@0 183 arg: '{ window',
michael@0 184 status: 'VALID',
michael@0 185 message: ''
michael@0 186 }
michael@0 187 }
michael@0 188 }
michael@0 189 },
michael@0 190 {
michael@0 191 setup: '{ window.do',
michael@0 192 check: {
michael@0 193 input: '{ window.do',
michael@0 194 hints: 'cument',
michael@0 195 markup: 'VVIIIIIIIII',
michael@0 196 cursor: 11,
michael@0 197 current: 'javascript',
michael@0 198 status: 'ERROR',
michael@0 199 predictionsContains: [ 'window.document' ],
michael@0 200 unassigned: [ ],
michael@0 201 args: {
michael@0 202 command: { name: '{' },
michael@0 203 javascript: {
michael@0 204 value: 'window.do',
michael@0 205 arg: '{ window.do',
michael@0 206 status: 'INCOMPLETE'
michael@0 207 }
michael@0 208 }
michael@0 209 }
michael@0 210 },
michael@0 211 {
michael@0 212 setup: '{ window.document.title',
michael@0 213 check: {
michael@0 214 input: '{ window.document.title',
michael@0 215 hints: '',
michael@0 216 markup: 'VVVVVVVVVVVVVVVVVVVVVVV',
michael@0 217 cursor: 23,
michael@0 218 current: 'javascript',
michael@0 219 status: 'VALID',
michael@0 220 predictions: [ ],
michael@0 221 unassigned: [ ],
michael@0 222 args: {
michael@0 223 command: { name: '{' },
michael@0 224 javascript: {
michael@0 225 value: 'window.document.title',
michael@0 226 arg: '{ window.document.title',
michael@0 227 status: 'VALID',
michael@0 228 message: ''
michael@0 229 }
michael@0 230 }
michael@0 231 }
michael@0 232 }
michael@0 233 ]);
michael@0 234 };
michael@0 235
michael@0 236 exports.testDocument = function(options) {
michael@0 237 return helpers.audit(options, [
michael@0 238 {
michael@0 239 skipRemainingIf: jsTestAllowed,
michael@0 240 setup: '{ docu',
michael@0 241 check: {
michael@0 242 input: '{ docu',
michael@0 243 hints: 'ment',
michael@0 244 markup: 'VVIIII',
michael@0 245 cursor: 6,
michael@0 246 current: 'javascript',
michael@0 247 status: 'ERROR',
michael@0 248 predictions: [ 'document' ],
michael@0 249 unassigned: [ ],
michael@0 250 args: {
michael@0 251 command: { name: '{' },
michael@0 252 javascript: {
michael@0 253 value: 'docu',
michael@0 254 arg: '{ docu',
michael@0 255 status: 'INCOMPLETE'
michael@0 256 }
michael@0 257 }
michael@0 258 }
michael@0 259 },
michael@0 260 {
michael@0 261 setup: '{ docu<TAB>',
michael@0 262 check: {
michael@0 263 input: '{ document',
michael@0 264 hints: '',
michael@0 265 markup: 'VVVVVVVVVV',
michael@0 266 cursor: 10,
michael@0 267 current: 'javascript',
michael@0 268 status: 'VALID',
michael@0 269 predictions: [ ],
michael@0 270 unassigned: [ ],
michael@0 271 args: {
michael@0 272 command: { name: '{' },
michael@0 273 javascript: {
michael@0 274 value: 'document',
michael@0 275 arg: '{ document',
michael@0 276 status: 'VALID',
michael@0 277 message: ''
michael@0 278 }
michael@0 279 }
michael@0 280 }
michael@0 281 },
michael@0 282 {
michael@0 283 setup: '{ document.titl',
michael@0 284 check: {
michael@0 285 input: '{ document.titl',
michael@0 286 hints: 'e',
michael@0 287 markup: 'VVIIIIIIIIIIIII',
michael@0 288 cursor: 15,
michael@0 289 current: 'javascript',
michael@0 290 status: 'ERROR',
michael@0 291 predictions: [ 'document.title' ],
michael@0 292 unassigned: [ ],
michael@0 293 args: {
michael@0 294 command: { name: '{' },
michael@0 295 javascript: {
michael@0 296 value: 'document.titl',
michael@0 297 arg: '{ document.titl',
michael@0 298 status: 'INCOMPLETE'
michael@0 299 }
michael@0 300 }
michael@0 301 }
michael@0 302 },
michael@0 303 {
michael@0 304 setup: '{ document.titl<TAB>',
michael@0 305 check: {
michael@0 306 input: '{ document.title ',
michael@0 307 hints: '',
michael@0 308 markup: 'VVVVVVVVVVVVVVVVV',
michael@0 309 cursor: 17,
michael@0 310 current: 'javascript',
michael@0 311 status: 'VALID',
michael@0 312 predictions: [ ],
michael@0 313 unassigned: [ ],
michael@0 314 args: {
michael@0 315 command: { name: '{' },
michael@0 316 javascript: {
michael@0 317 value: 'document.title',
michael@0 318 arg: '{ document.title ',
michael@0 319 status: 'VALID',
michael@0 320 message: ''
michael@0 321 }
michael@0 322 }
michael@0 323 }
michael@0 324 },
michael@0 325 {
michael@0 326 setup: '{ document.title',
michael@0 327 check: {
michael@0 328 input: '{ document.title',
michael@0 329 hints: '',
michael@0 330 markup: 'VVVVVVVVVVVVVVVV',
michael@0 331 cursor: 16,
michael@0 332 current: 'javascript',
michael@0 333 status: 'VALID',
michael@0 334 predictions: [ ],
michael@0 335 unassigned: [ ],
michael@0 336 args: {
michael@0 337 command: { name: '{' },
michael@0 338 javascript: {
michael@0 339 value: 'document.title',
michael@0 340 arg: '{ document.title',
michael@0 341 status: 'VALID',
michael@0 342 message: ''
michael@0 343 }
michael@0 344 }
michael@0 345 }
michael@0 346 }
michael@0 347 ]);
michael@0 348 };
michael@0 349
michael@0 350 exports.testDonteval = function(options) {
michael@0 351 if (!options.isNoDom) {
michael@0 352 // nodom causes an eval here, maybe that's node/v8?
michael@0 353 assert.ok('donteval' in options.window, 'donteval exists');
michael@0 354 }
michael@0 355
michael@0 356 return helpers.audit(options, [
michael@0 357 {
michael@0 358 skipRemainingIf: jsTestAllowed,
michael@0 359 setup: '{ don',
michael@0 360 check: {
michael@0 361 input: '{ don',
michael@0 362 hints: 'teval',
michael@0 363 markup: 'VVIII',
michael@0 364 cursor: 5,
michael@0 365 current: 'javascript',
michael@0 366 status: 'ERROR',
michael@0 367 predictions: [ 'donteval' ],
michael@0 368 unassigned: [ ],
michael@0 369 args: {
michael@0 370 command: { name: '{' },
michael@0 371 javascript: {
michael@0 372 value: 'don',
michael@0 373 arg: '{ don',
michael@0 374 status: 'INCOMPLETE'
michael@0 375 }
michael@0 376 }
michael@0 377 }
michael@0 378 },
michael@0 379 {
michael@0 380 setup: '{ donteval',
michael@0 381 check: {
michael@0 382 input: '{ donteval',
michael@0 383 hints: '',
michael@0 384 markup: 'VVVVVVVVVV',
michael@0 385 cursor: 10,
michael@0 386 current: 'javascript',
michael@0 387 status: 'VALID',
michael@0 388 predictions: [ ],
michael@0 389 unassigned: [ ],
michael@0 390 args: {
michael@0 391 command: { name: '{' },
michael@0 392 javascript: {
michael@0 393 value: 'donteval',
michael@0 394 arg: '{ donteval',
michael@0 395 status: 'VALID',
michael@0 396 message: ''
michael@0 397 }
michael@0 398 }
michael@0 399 }
michael@0 400 },
michael@0 401 /*
michael@0 402 // This is a controversial test - technically we can tell that it's an error
michael@0 403 // because 'donteval.' is a syntax error, however donteval is unsafe so we
michael@0 404 // are playing safe by bailing out early. It's enough of a corner case that
michael@0 405 // I don't think it warrants fixing
michael@0 406 {
michael@0 407 setup: '{ donteval.',
michael@0 408 check: {
michael@0 409 input: '{ donteval.',
michael@0 410 hints: '',
michael@0 411 markup: 'VVVVVVVVVVV',
michael@0 412 cursor: 11,
michael@0 413 current: 'javascript',
michael@0 414 status: 'VALID',
michael@0 415 predictions: [ ],
michael@0 416 unassigned: [ ],
michael@0 417 args: {
michael@0 418 command: { name: '{' },
michael@0 419 javascript: {
michael@0 420 value: 'donteval.',
michael@0 421 arg: '{ donteval.',
michael@0 422 status: 'VALID',
michael@0 423 message: ''
michael@0 424 }
michael@0 425 }
michael@0 426 }
michael@0 427 },
michael@0 428 */
michael@0 429 {
michael@0 430 setup: '{ donteval.cant',
michael@0 431 check: {
michael@0 432 input: '{ donteval.cant',
michael@0 433 hints: '',
michael@0 434 markup: 'VVVVVVVVVVVVVVV',
michael@0 435 cursor: 15,
michael@0 436 current: 'javascript',
michael@0 437 status: 'VALID',
michael@0 438 predictions: [ ],
michael@0 439 unassigned: [ ],
michael@0 440 args: {
michael@0 441 command: { name: '{' },
michael@0 442 javascript: {
michael@0 443 value: 'donteval.cant',
michael@0 444 arg: '{ donteval.cant',
michael@0 445 status: 'VALID',
michael@0 446 message: ''
michael@0 447 }
michael@0 448 }
michael@0 449 }
michael@0 450 },
michael@0 451 {
michael@0 452 setup: '{ donteval.xxx',
michael@0 453 check: {
michael@0 454 input: '{ donteval.xxx',
michael@0 455 hints: '',
michael@0 456 markup: 'VVVVVVVVVVVVVV',
michael@0 457 cursor: 14,
michael@0 458 current: 'javascript',
michael@0 459 status: 'VALID',
michael@0 460 predictions: [ ],
michael@0 461 unassigned: [ ],
michael@0 462 args: {
michael@0 463 command: { name: '{' },
michael@0 464 javascript: {
michael@0 465 value: 'donteval.xxx',
michael@0 466 arg: '{ donteval.xxx',
michael@0 467 status: 'VALID',
michael@0 468 message: ''
michael@0 469 }
michael@0 470 }
michael@0 471 }
michael@0 472 }
michael@0 473 ]);
michael@0 474 };
michael@0 475
michael@0 476 exports.testExec = function(options) {
michael@0 477 return helpers.audit(options, [
michael@0 478 {
michael@0 479 skipRemainingIf: jsTestAllowed,
michael@0 480 setup: '{ 1+1',
michael@0 481 check: {
michael@0 482 input: '{ 1+1',
michael@0 483 hints: '',
michael@0 484 markup: 'VVVVV',
michael@0 485 cursor: 5,
michael@0 486 current: 'javascript',
michael@0 487 status: 'VALID',
michael@0 488 options: [ ],
michael@0 489 message: '',
michael@0 490 predictions: [ ],
michael@0 491 unassigned: [ ],
michael@0 492 args: {
michael@0 493 javascript: {
michael@0 494 value: '1+1',
michael@0 495 arg: '{ 1+1',
michael@0 496 status: 'VALID',
michael@0 497 message: ''
michael@0 498 }
michael@0 499 }
michael@0 500 },
michael@0 501 exec: {
michael@0 502 output: '2',
michael@0 503 type: 'number',
michael@0 504 error: false
michael@0 505 }
michael@0 506 },
michael@0 507 {
michael@0 508 setup: '{ 1+1 }',
michael@0 509 check: {
michael@0 510 input: '{ 1+1 }',
michael@0 511 hints: '',
michael@0 512 markup: 'VVVVVVV',
michael@0 513 cursor: 7,
michael@0 514 current: 'javascript',
michael@0 515 status: 'VALID',
michael@0 516 options: [ ],
michael@0 517 message: '',
michael@0 518 predictions: [ ],
michael@0 519 unassigned: [ ],
michael@0 520 args: {
michael@0 521 javascript: {
michael@0 522 value: '1+1',
michael@0 523 arg: '{ 1+1 }',
michael@0 524 status: 'VALID',
michael@0 525 message: ''
michael@0 526 }
michael@0 527 }
michael@0 528 },
michael@0 529 exec: {
michael@0 530 output: '2',
michael@0 531 type: 'number',
michael@0 532 error: false
michael@0 533 }
michael@0 534 },
michael@0 535 {
michael@0 536 setup: '{ "hello"',
michael@0 537 check: {
michael@0 538 input: '{ "hello"',
michael@0 539 hints: '',
michael@0 540 markup: 'VVVVVVVVV',
michael@0 541 cursor: 9,
michael@0 542 current: 'javascript',
michael@0 543 status: 'VALID',
michael@0 544 options: [ ],
michael@0 545 message: '',
michael@0 546 predictions: [ ],
michael@0 547 unassigned: [ ],
michael@0 548 args: {
michael@0 549 javascript: {
michael@0 550 value: '"hello"',
michael@0 551 arg: '{ "hello"',
michael@0 552 status: 'VALID',
michael@0 553 message: ''
michael@0 554 }
michael@0 555 }
michael@0 556 },
michael@0 557 exec: {
michael@0 558 output: 'hello',
michael@0 559 type: 'string',
michael@0 560 error: false
michael@0 561 }
michael@0 562 },
michael@0 563 {
michael@0 564 setup: '{ "hello" + 1',
michael@0 565 check: {
michael@0 566 input: '{ "hello" + 1',
michael@0 567 hints: '',
michael@0 568 markup: 'VVVVVVVVVVVVV',
michael@0 569 cursor: 13,
michael@0 570 current: 'javascript',
michael@0 571 status: 'VALID',
michael@0 572 options: [ ],
michael@0 573 message: '',
michael@0 574 predictions: [ ],
michael@0 575 unassigned: [ ],
michael@0 576 args: {
michael@0 577 javascript: {
michael@0 578 value: '"hello" + 1',
michael@0 579 arg: '{ "hello" + 1',
michael@0 580 status: 'VALID',
michael@0 581 message: ''
michael@0 582 }
michael@0 583 }
michael@0 584 },
michael@0 585 exec: {
michael@0 586 output: 'hello1',
michael@0 587 type: 'string',
michael@0 588 error: false
michael@0 589 }
michael@0 590 }
michael@0 591 ]);
michael@0 592 };

mercurial