mockCommands.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. /*
  2. * Copyright 2012, Mozilla Foundation and contributors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. "use strict";
  17. // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
  18. // PLEASE TALK TO SOMEONE IN DEVELOPER TOOLS BEFORE EDITING IT
  19. var mockCommands;
  20. if (typeof exports !== "undefined") {
  21. // If we're being loaded via require();
  22. mockCommands = exports;
  23. }
  24. else {
  25. // If we're being loaded via loadScript in mochitest
  26. mockCommands = {};
  27. }
  28. // We use an alias for exports here because this module is used in Firefox
  29. // mochitests where we don't have define/require
  30. /**
  31. * Registration and de-registration.
  32. */
  33. mockCommands.setup = function (requisition) {
  34. requisition.system.addItems(mockCommands.items);
  35. };
  36. mockCommands.shutdown = function (requisition) {
  37. requisition.system.removeItems(mockCommands.items);
  38. };
  39. function createExec(name) {
  40. return function (args, context) {
  41. var promises = [];
  42. Object.keys(args).map(function (argName) {
  43. var value = args[argName];
  44. var type = this.getParameterByName(argName).type;
  45. var promise = Promise.resolve(type.stringify(value, context));
  46. promises.push(promise.then(function (str) {
  47. return { name: argName, value: str };
  48. }.bind(this)));
  49. }.bind(this));
  50. return Promise.all(promises).then(function (data) {
  51. var argValues = {};
  52. data.forEach(function (entry) { argValues[entry.name] = entry.value; });
  53. return context.typedData("testCommandOutput", {
  54. name: name,
  55. args: argValues
  56. });
  57. }.bind(this));
  58. };
  59. }
  60. mockCommands.items = [
  61. {
  62. item: "converter",
  63. from: "testCommandOutput",
  64. to: "dom",
  65. exec: function (testCommandOutput, context) {
  66. var view = context.createView({
  67. data: testCommandOutput,
  68. html: "" +
  69. "<table>" +
  70. "<thead>" +
  71. "<tr>" +
  72. '<th colspan="3">Exec: ${name}</th>' +
  73. "</tr>" +
  74. "</thead>" +
  75. "<tbody>" +
  76. '<tr foreach="key in ${args}">' +
  77. "<td> ${key}</td>" +
  78. "<td>=</td>" +
  79. "<td>${args[key]}</td>" +
  80. "</tr>" +
  81. "</tbody>" +
  82. "</table>",
  83. options: {
  84. allowEval: true
  85. }
  86. });
  87. return view.toDom(context.document);
  88. }
  89. },
  90. {
  91. item: "converter",
  92. from: "testCommandOutput",
  93. to: "string",
  94. exec: function (testCommandOutput, context) {
  95. var argsOut = Object.keys(testCommandOutput.args).map(function (key) {
  96. return key + "=" + testCommandOutput.args[key];
  97. }).join(" ");
  98. return "Exec: " + testCommandOutput.name + " " + argsOut;
  99. }
  100. },
  101. {
  102. item: "type",
  103. name: "optionType",
  104. parent: "selection",
  105. lookup: [
  106. {
  107. name: "option1",
  108. value: "string"
  109. },
  110. {
  111. name: "option2",
  112. value: "number"
  113. },
  114. {
  115. name: "option3",
  116. value: {
  117. name: "selection",
  118. lookup: [
  119. { name: "one", value: 1 },
  120. { name: "two", value: 2 },
  121. { name: "three", value: 3 }
  122. ]
  123. }
  124. }
  125. ]
  126. },
  127. {
  128. item: "type",
  129. name: "optionValue",
  130. parent: "delegate",
  131. delegateType: function (executionContext) {
  132. if (executionContext != null) {
  133. var option = executionContext.getArgsObject().optionType;
  134. if (option != null) {
  135. return option;
  136. }
  137. }
  138. return "blank";
  139. }
  140. },
  141. {
  142. item: "command",
  143. name: "tsv",
  144. params: [
  145. { name: "optionType", type: "optionType" },
  146. { name: "optionValue", type: "optionValue" }
  147. ],
  148. exec: createExec("tsv")
  149. },
  150. {
  151. item: "command",
  152. name: "tsr",
  153. params: [ { name: "text", type: "string" } ],
  154. exec: createExec("tsr")
  155. },
  156. {
  157. item: "command",
  158. name: "tsrsrsr",
  159. params: [
  160. { name: "p1", type: "string" },
  161. { name: "p2", type: "string" },
  162. { name: "p3", type: { name: "string", allowBlank: true} },
  163. ],
  164. exec: createExec("tsrsrsr")
  165. },
  166. {
  167. item: "command",
  168. name: "tso",
  169. params: [ { name: "text", type: "string", defaultValue: null } ],
  170. exec: createExec("tso")
  171. },
  172. {
  173. item: "command",
  174. name: "tse",
  175. params: [
  176. { name: "node", type: "node" },
  177. {
  178. group: "options",
  179. params: [
  180. { name: "nodes", type: { name: "nodelist" } },
  181. { name: "nodes2", type: { name: "nodelist", allowEmpty: true } }
  182. ]
  183. }
  184. ],
  185. exec: createExec("tse")
  186. },
  187. {
  188. item: "command",
  189. name: "tsj",
  190. params: [ { name: "javascript", type: "javascript" } ],
  191. exec: createExec("tsj")
  192. },
  193. {
  194. item: "command",
  195. name: "tsb",
  196. params: [ { name: "toggle", type: "boolean" } ],
  197. exec: createExec("tsb")
  198. },
  199. {
  200. item: "command",
  201. name: "tss",
  202. exec: createExec("tss")
  203. },
  204. {
  205. item: "command",
  206. name: "tsu",
  207. params: [
  208. {
  209. name: "num",
  210. type: {
  211. name: "number",
  212. max: 10,
  213. min: -5,
  214. step: 3
  215. }
  216. }
  217. ],
  218. exec: createExec("tsu")
  219. },
  220. {
  221. item: "command",
  222. name: "tsf",
  223. params: [
  224. {
  225. name: "num",
  226. type: {
  227. name: "number",
  228. allowFloat: true,
  229. max: 11.5,
  230. min: -6.5,
  231. step: 1.5
  232. }
  233. }
  234. ],
  235. exec: createExec("tsf")
  236. },
  237. {
  238. item: "command",
  239. name: "tsn"
  240. },
  241. {
  242. item: "command",
  243. name: "tsn dif",
  244. params: [ { name: "text", type: "string", description: "tsn dif text" } ],
  245. exec: createExec("tsnDif")
  246. },
  247. {
  248. item: "command",
  249. name: "tsn hidden",
  250. hidden: true,
  251. exec: createExec("tsnHidden")
  252. },
  253. {
  254. item: "command",
  255. name: "tsn ext",
  256. params: [ { name: "text", type: "string" } ],
  257. exec: createExec("tsnExt")
  258. },
  259. {
  260. item: "command",
  261. name: "tsn exte",
  262. params: [ { name: "text", type: "string" } ],
  263. exec: createExec("tsnExte")
  264. },
  265. {
  266. item: "command",
  267. name: "tsn exten",
  268. params: [ { name: "text", type: "string" } ],
  269. exec: createExec("tsnExten")
  270. },
  271. {
  272. item: "command",
  273. name: "tsn extend",
  274. params: [ { name: "text", type: "string" } ],
  275. exec: createExec("tsnExtend")
  276. },
  277. {
  278. item: "command",
  279. name: "tsn deep"
  280. },
  281. {
  282. item: "command",
  283. name: "tsn deep down"
  284. },
  285. {
  286. item: "command",
  287. name: "tsn deep down nested"
  288. },
  289. {
  290. item: "command",
  291. name: "tsn deep down nested cmd",
  292. exec: createExec("tsnDeepDownNestedCmd")
  293. },
  294. {
  295. item: "command",
  296. name: "tshidden",
  297. hidden: true,
  298. params: [
  299. {
  300. group: "Options",
  301. params: [
  302. {
  303. name: "visible",
  304. type: "string",
  305. short: "v",
  306. defaultValue: null,
  307. description: "visible"
  308. },
  309. {
  310. name: "invisiblestring",
  311. type: "string",
  312. short: "i",
  313. description: "invisiblestring",
  314. defaultValue: null,
  315. hidden: true
  316. },
  317. {
  318. name: "invisibleboolean",
  319. short: "b",
  320. type: "boolean",
  321. description: "invisibleboolean",
  322. hidden: true
  323. }
  324. ]
  325. }
  326. ],
  327. exec: createExec("tshidden")
  328. },
  329. {
  330. item: "command",
  331. name: "tselarr",
  332. params: [
  333. { name: "num", type: { name: "selection", data: [ "1", "2", "3" ] } },
  334. { name: "arr", type: { name: "array", subtype: "string" } }
  335. ],
  336. exec: createExec("tselarr")
  337. },
  338. {
  339. item: "command",
  340. name: "tsm",
  341. description: "a 3-param test selection|string|number",
  342. params: [
  343. { name: "abc", type: { name: "selection", data: [ "a", "b", "c" ] } },
  344. { name: "txt", type: "string" },
  345. { name: "num", type: { name: "number", max: 42, min: 0 } }
  346. ],
  347. exec: createExec("tsm")
  348. },
  349. {
  350. item: "command",
  351. name: "tsg",
  352. description: "a param group test",
  353. params: [
  354. {
  355. name: "solo",
  356. type: { name: "selection", data: [ "aaa", "bbb", "ccc" ] },
  357. description: "solo param"
  358. },
  359. {
  360. group: "First",
  361. params: [
  362. {
  363. name: "txt1",
  364. type: "string",
  365. defaultValue: null,
  366. description: "txt1 param"
  367. },
  368. {
  369. name: "bool",
  370. type: "boolean",
  371. description: "bool param"
  372. }
  373. ]
  374. },
  375. {
  376. name: "txt2",
  377. type: "string",
  378. defaultValue: "d",
  379. description: "txt2 param",
  380. option: "Second"
  381. },
  382. {
  383. name: "num",
  384. type: { name: "number", min: 40 },
  385. defaultValue: 42,
  386. description: "num param",
  387. option: "Second"
  388. }
  389. ],
  390. exec: createExec("tsg")
  391. },
  392. {
  393. item: "command",
  394. name: "tscook",
  395. description: "param group test to catch problems with cookie command",
  396. params: [
  397. {
  398. name: "key",
  399. type: "string",
  400. description: "tscookKeyDesc"
  401. },
  402. {
  403. name: "value",
  404. type: "string",
  405. description: "tscookValueDesc"
  406. },
  407. {
  408. group: "tscookOptionsDesc",
  409. params: [
  410. {
  411. name: "path",
  412. type: "string",
  413. defaultValue: "/",
  414. description: "tscookPathDesc"
  415. },
  416. {
  417. name: "domain",
  418. type: "string",
  419. defaultValue: null,
  420. description: "tscookDomainDesc"
  421. },
  422. {
  423. name: "secure",
  424. type: "boolean",
  425. description: "tscookSecureDesc"
  426. }
  427. ]
  428. }
  429. ],
  430. exec: createExec("tscook")
  431. },
  432. {
  433. item: "command",
  434. name: "tslong",
  435. description: "long param tests to catch problems with the jsb command",
  436. params: [
  437. {
  438. name: "msg",
  439. type: "string",
  440. description: "msg Desc"
  441. },
  442. {
  443. group: "Options Desc",
  444. params: [
  445. {
  446. name: "num",
  447. short: "n",
  448. type: "number",
  449. description: "num Desc",
  450. defaultValue: 2
  451. },
  452. {
  453. name: "sel",
  454. short: "s",
  455. type: {
  456. name: "selection",
  457. lookup: [
  458. { name: "space", value: " " },
  459. { name: "tab", value: "\t" }
  460. ]
  461. },
  462. description: "sel Desc",
  463. defaultValue: " "
  464. },
  465. {
  466. name: "bool",
  467. short: "b",
  468. type: "boolean",
  469. description: "bool Desc"
  470. },
  471. {
  472. name: "num2",
  473. short: "m",
  474. type: "number",
  475. description: "num2 Desc",
  476. defaultValue: -1
  477. },
  478. {
  479. name: "bool2",
  480. short: "c",
  481. type: "boolean",
  482. description: "bool2 Desc"
  483. },
  484. {
  485. name: "sel2",
  486. short: "t",
  487. type: {
  488. name: "selection",
  489. data: [ "collapse", "basic", "with space", "with two spaces" ]
  490. },
  491. description: "sel2 Desc",
  492. defaultValue: "collapse"
  493. }
  494. ]
  495. }
  496. ],
  497. exec: createExec("tslong")
  498. },
  499. {
  500. item: "command",
  501. name: "tsdate",
  502. description: "long param tests to catch problems with the jsb command",
  503. params: [
  504. {
  505. name: "d1",
  506. type: "date",
  507. },
  508. {
  509. name: "d2",
  510. type: {
  511. name: "date",
  512. min: "1 jan 2000",
  513. max: "28 feb 2000",
  514. step: 2
  515. }
  516. },
  517. ],
  518. exec: createExec("tsdate")
  519. },
  520. {
  521. item: "command",
  522. name: "tsfail",
  523. description: "test errors",
  524. params: [
  525. {
  526. name: "method",
  527. type: {
  528. name: "selection",
  529. data: [
  530. "reject", "rejecttyped",
  531. "throwerror", "throwstring", "throwinpromise",
  532. "noerror"
  533. ]
  534. }
  535. }
  536. ],
  537. exec: function (args, context) {
  538. if (args.method === "reject") {
  539. return new Promise(function (resolve, reject) {
  540. context.environment.window.setTimeout(function () {
  541. reject("rejected promise");
  542. }, 10);
  543. });
  544. }
  545. if (args.method === "rejecttyped") {
  546. return new Promise(function (resolve, reject) {
  547. context.environment.window.setTimeout(function () {
  548. reject(context.typedData("number", 54));
  549. }, 10);
  550. });
  551. }
  552. if (args.method === "throwinpromise") {
  553. return new Promise(function (resolve, reject) {
  554. context.environment.window.setTimeout(function () {
  555. resolve("should be lost");
  556. }, 10);
  557. }).then(function () {
  558. var t = null;
  559. return t.foo;
  560. });
  561. }
  562. if (args.method === "throwerror") {
  563. throw new Error("thrown error");
  564. }
  565. if (args.method === "throwstring") {
  566. throw "thrown string";
  567. }
  568. return "no error";
  569. }
  570. },
  571. {
  572. item: "command",
  573. name: "tsfile",
  574. description: "test file params",
  575. },
  576. {
  577. item: "command",
  578. name: "tsfile open",
  579. description: "a file param in open mode",
  580. params: [
  581. {
  582. name: "p1",
  583. type: {
  584. name: "file",
  585. filetype: "file",
  586. existing: "yes"
  587. }
  588. }
  589. ],
  590. exec: createExec("tsfile open")
  591. },
  592. {
  593. item: "command",
  594. name: "tsfile saveas",
  595. description: "a file param in saveas mode",
  596. params: [
  597. {
  598. name: "p1",
  599. type: {
  600. name: "file",
  601. filetype: "file",
  602. existing: "no"
  603. }
  604. }
  605. ],
  606. exec: createExec("tsfile saveas")
  607. },
  608. {
  609. item: "command",
  610. name: "tsfile save",
  611. description: "a file param in save mode",
  612. params: [
  613. {
  614. name: "p1",
  615. type: {
  616. name: "file",
  617. filetype: "file",
  618. existing: "maybe"
  619. }
  620. }
  621. ],
  622. exec: createExec("tsfile save")
  623. },
  624. {
  625. item: "command",
  626. name: "tsfile cd",
  627. description: "a file param in cd mode",
  628. params: [
  629. {
  630. name: "p1",
  631. type: {
  632. name: "file",
  633. filetype: "directory",
  634. existing: "yes"
  635. }
  636. }
  637. ],
  638. exec: createExec("tsfile cd")
  639. },
  640. {
  641. item: "command",
  642. name: "tsfile mkdir",
  643. description: "a file param in mkdir mode",
  644. params: [
  645. {
  646. name: "p1",
  647. type: {
  648. name: "file",
  649. filetype: "directory",
  650. existing: "no"
  651. }
  652. }
  653. ],
  654. exec: createExec("tsfile mkdir")
  655. },
  656. {
  657. item: "command",
  658. name: "tsfile rm",
  659. description: "a file param in rm mode",
  660. params: [
  661. {
  662. name: "p1",
  663. type: {
  664. name: "file",
  665. filetype: "any",
  666. existing: "yes"
  667. }
  668. }
  669. ],
  670. exec: createExec("tsfile rm")
  671. },
  672. {
  673. item: "command",
  674. name: "tsslow",
  675. params: [
  676. {
  677. name: "hello",
  678. type: {
  679. name: "selection",
  680. data: function (context) {
  681. return new Promise(function (resolve, reject) {
  682. context.environment.window.setTimeout(function () {
  683. resolve([
  684. "Shalom", "Namasté", "Hallo", "Dydd-da",
  685. "Chào", "Hej", "Saluton", "Sawubona"
  686. ]);
  687. }, 10);
  688. });
  689. }
  690. }
  691. }
  692. ],
  693. exec: function (args, context) {
  694. return "Test completed";
  695. }
  696. },
  697. {
  698. item: "command",
  699. name: "urlc",
  700. params: [
  701. {
  702. name: "url",
  703. type: "url"
  704. }
  705. ],
  706. returnType: "json",
  707. exec: function (args, context) {
  708. return args;
  709. }
  710. },
  711. {
  712. item: "command",
  713. name: "unionc1",
  714. params: [
  715. {
  716. name: "first",
  717. type: {
  718. name: "union",
  719. alternatives: [
  720. {
  721. name: "selection",
  722. lookup: [
  723. { name: "one", value: 1 },
  724. { name: "two", value: 2 },
  725. ]
  726. },
  727. "number",
  728. { name: "string" }
  729. ]
  730. }
  731. }
  732. ],
  733. returnType: "json",
  734. exec: function (args, context) {
  735. return args;
  736. }
  737. },
  738. {
  739. item: "command",
  740. name: "unionc2",
  741. params: [
  742. {
  743. name: "first",
  744. type: {
  745. name: "union",
  746. alternatives: [
  747. {
  748. name: "selection",
  749. lookup: [
  750. { name: "one", value: 1 },
  751. { name: "two", value: 2 },
  752. ]
  753. },
  754. {
  755. name: "url"
  756. }
  757. ]
  758. }
  759. }
  760. ],
  761. returnType: "json",
  762. exec: function (args, context) {
  763. return args;
  764. }
  765. },
  766. {
  767. item: "command",
  768. name: "tsres",
  769. params: [
  770. {
  771. name: "resource",
  772. type: "resource"
  773. }
  774. ],
  775. exec: createExec("tsres"),
  776. }
  777. ];