PageRenderTime 30ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/test/spec/NativeMenu-test.js

https://bitbucket.org/stephenabritton/brackets
JavaScript | 1627 lines | 1270 code | 277 blank | 80 comment | 9 complexity | 2cbdb94b819a92dbe725616f78916da8 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. *
  22. */
  23. /*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
  24. /*global define: false, describe: false, it: false, expect: false, beforeEach: false, afterEach: false, waitsFor: false, waitsForDone: false, runs: false, brackets: false */
  25. define(function (require, exports, module) {
  26. 'use strict';
  27. // Don't run tests when running in browser
  28. if (brackets.inBrowser) {
  29. return;
  30. }
  31. // These are tests for the low-level file io routines in brackets-app. Make sure
  32. // you have the latest brackets-app before running.
  33. describe("Native Menus", function () {
  34. var TEST_MENU_TITLE = "TEST",
  35. TEST_MENU_ID = "test",
  36. TEST_MENU_ITEM = "Item 1",
  37. TEST_MENU_ITEM_ID = "item1";
  38. it("should have a brackets.app namespace", function () {
  39. expect(brackets.app).toBeTruthy();
  40. });
  41. describe("addMenu", function () {
  42. it("should add a menu", function () {
  43. var complete = false,
  44. error = 0,
  45. title;
  46. // Make sure menu isn't present
  47. runs(function () {
  48. brackets.app.getMenuTitle(TEST_MENU_ID, function (err) {
  49. complete = true;
  50. error = err;
  51. });
  52. });
  53. waitsFor(function () { return complete; }, 1000);
  54. runs(function () {
  55. expect(error).toBe(brackets.fs.ERR_NOT_FOUND);
  56. });
  57. // Add menu
  58. runs(function () {
  59. complete = false;
  60. brackets.app.addMenu(TEST_MENU_TITLE, TEST_MENU_ID, "", "", function (err) {
  61. complete = true;
  62. error = err;
  63. });
  64. });
  65. waitsFor(function () { return complete; }, 1000);
  66. runs(function () {
  67. expect(error).toBe(0);
  68. });
  69. // Verify menu is found
  70. runs(function () {
  71. complete = false;
  72. brackets.app.getMenuTitle(TEST_MENU_ID, function (err, titleStr) {
  73. complete = true;
  74. error = err;
  75. title = titleStr;
  76. });
  77. });
  78. waitsFor(function () { return complete; }, 1000);
  79. runs(function () {
  80. expect(error).toBe(0);
  81. expect(title).toBe(TEST_MENU_TITLE);
  82. });
  83. // Remove menu
  84. runs(function () {
  85. complete = false;
  86. brackets.app.removeMenu(TEST_MENU_ID, function (err) {
  87. complete = true;
  88. // Ignore error
  89. });
  90. });
  91. waitsFor(function () { return complete; }, 1000);
  92. });
  93. it("should return an error if invalid parameters are passed", function () {
  94. var complete = false,
  95. error = 0;
  96. runs(function () {
  97. brackets.app.addMenu(TEST_MENU_TITLE, TEST_MENU_ID, 42, "", function (err) {
  98. complete = true;
  99. error = err;
  100. });
  101. });
  102. waitsFor(function () { return complete; }, 1000);
  103. runs(function () {
  104. expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS);
  105. });
  106. });
  107. }); // describe("addMenu")
  108. describe("addMenu (with reference)", function () {
  109. var complete = false,
  110. error = 0,
  111. parentId,
  112. position = -1;
  113. beforeEach(function () {
  114. runs(function () {
  115. complete = false;
  116. brackets.app.addMenu(TEST_MENU_TITLE, TEST_MENU_ID, "", "", function (err) {
  117. complete = true;
  118. error = err;
  119. });
  120. });
  121. waitsFor(function () { return complete; });
  122. runs(function () {
  123. expect(error).toBe(0);
  124. });
  125. });
  126. afterEach(function () {
  127. runs(function () {
  128. complete = false;
  129. brackets.app.removeMenu(TEST_MENU_ID, function (err) {
  130. complete = true;
  131. error = err;
  132. });
  133. });
  134. waitsFor(function () { return complete; });
  135. runs(function () {
  136. expect(error).toBe(0);
  137. });
  138. });
  139. it("should add new menu in last position of list", function () {
  140. error = 0;
  141. runs(function () {
  142. complete = false;
  143. brackets.app.addMenu("Custom1", "menu-unittest1", "", "", function (err) {
  144. complete = true;
  145. error = err;
  146. });
  147. });
  148. waitsFor(function () { return complete; }, 1000);
  149. runs(function () {
  150. expect(error).toBe(0);
  151. });
  152. // Verify menu is found
  153. runs(function () {
  154. complete = false;
  155. parentId = null;
  156. position = -1;
  157. brackets.app.getMenuPosition("menu-unittest1", function (err, parent, index) {
  158. complete = true;
  159. error = err;
  160. parentId = parent;
  161. position = index;
  162. });
  163. });
  164. waitsFor(function () { return complete; }, 1000);
  165. runs(function () {
  166. expect(error).toBe(0);
  167. expect(parentId).toBe("");
  168. expect(position).toBeGreaterThan(0);
  169. });
  170. // Remove menu
  171. runs(function () {
  172. complete = false;
  173. brackets.app.removeMenu("menu-unittest1", function (err) {
  174. complete = true;
  175. error = err;
  176. });
  177. });
  178. waitsFor(function () { return complete; }, 1000);
  179. runs(function () {
  180. expect(error).toBe(0);
  181. });
  182. });
  183. it("should add new menu after reference menu", function () {
  184. var targetPos = -1;
  185. error = 0;
  186. runs(function () {
  187. complete = false;
  188. brackets.app.addMenu("CustomFirst", "menu-unittest-first", "first", "", function (err) {
  189. complete = true;
  190. error = err;
  191. });
  192. });
  193. waitsFor(function () { return complete; }, 1000);
  194. runs(function () {
  195. expect(error).toBe(0);
  196. });
  197. runs(function () {
  198. complete = false;
  199. brackets.app.addMenu("CustomAfter", "menu-unittest-after", "after", "menu-unittest-first", function (err) {
  200. complete = true;
  201. error = err;
  202. });
  203. });
  204. waitsFor(function () { return complete; }, 1000);
  205. runs(function () {
  206. expect(error).toBe(0);
  207. });
  208. // Verify menu is found
  209. runs(function () {
  210. complete = false;
  211. parentId = null;
  212. position = -1;
  213. targetPos = -1;
  214. brackets.app.getMenuPosition("menu-unittest-first", function (err, parent, index) {
  215. complete = true;
  216. error = err;
  217. parentId = parent;
  218. position = index;
  219. targetPos = position + 1;
  220. });
  221. });
  222. waitsFor(function () { return complete; }, 1000);
  223. runs(function () {
  224. expect(error).toBe(0);
  225. expect(parentId).toBe("");
  226. });
  227. // Verify menu is found
  228. runs(function () {
  229. complete = false;
  230. parentId = null;
  231. position = -1;
  232. brackets.app.getMenuPosition("menu-unittest-after", function (err, parent, index) {
  233. complete = true;
  234. error = err;
  235. parentId = parent;
  236. position = index;
  237. });
  238. });
  239. waitsFor(function () { return complete; }, 1000);
  240. runs(function () {
  241. expect(error).toBe(0);
  242. expect(parentId).toBe("");
  243. expect(position).toBe(targetPos);
  244. });
  245. // Remove menu
  246. runs(function () {
  247. complete = false;
  248. brackets.app.removeMenu("menu-unittest-first", function (err) {
  249. complete = true;
  250. // Ignore error
  251. });
  252. });
  253. waitsFor(function () { return complete; }, 1000);
  254. runs(function () {
  255. complete = false;
  256. brackets.app.removeMenu("menu-unittest-after", function (err) {
  257. complete = true;
  258. // Ignore error
  259. });
  260. });
  261. waitsFor(function () { return complete; }, 1000);
  262. });
  263. it("should add new menu before reference menu", function () {
  264. var targetPos = -1;
  265. error = 0;
  266. runs(function () {
  267. complete = false;
  268. brackets.app.addMenu("CustomLast", "menu-unittest-last", "last", "", function (err) {
  269. complete = true;
  270. error = err;
  271. });
  272. });
  273. waitsFor(function () { return complete; }, 1000);
  274. runs(function () {
  275. expect(error).toBe(0);
  276. });
  277. runs(function () {
  278. complete = false;
  279. brackets.app.addMenu("CustomBefore", "menu-unittest-before", "before", "menu-unittest-last", function (err) {
  280. complete = true;
  281. error = err;
  282. });
  283. });
  284. waitsFor(function () { return complete; }, 1000);
  285. runs(function () {
  286. expect(error).toBe(0);
  287. });
  288. // Verify menu is found
  289. runs(function () {
  290. complete = false;
  291. parentId = null;
  292. position = -1;
  293. targetPos = -1;
  294. brackets.app.getMenuPosition("menu-unittest-last", function (err, parent, index) {
  295. complete = true;
  296. error = err;
  297. parentId = parent;
  298. position = index;
  299. targetPos = position - 1;
  300. });
  301. });
  302. waitsFor(function () { return complete; }, 1000);
  303. runs(function () {
  304. expect(error).toBe(0);
  305. expect(parentId).toBe("");
  306. });
  307. // Verify menu is found
  308. runs(function () {
  309. complete = false;
  310. parentId = null;
  311. position = -1;
  312. brackets.app.getMenuPosition("menu-unittest-before", function (err, parent, index) {
  313. complete = true;
  314. error = err;
  315. parentId = parent;
  316. position = index;
  317. });
  318. });
  319. waitsFor(function () { return complete; }, 1000);
  320. runs(function () {
  321. expect(error).toBe(0);
  322. expect(parentId).toBe("");
  323. expect(position).toBe(targetPos);
  324. });
  325. // Remove menu
  326. runs(function () {
  327. complete = false;
  328. brackets.app.removeMenu("menu-unittest-last", function (err) {
  329. complete = true;
  330. // Ignore error
  331. });
  332. });
  333. waitsFor(function () { return complete; }, 1000);
  334. runs(function () {
  335. complete = false;
  336. brackets.app.removeMenu("menu-unittest-before", function (err) {
  337. complete = true;
  338. // Ignore error
  339. });
  340. });
  341. waitsFor(function () { return complete; }, 1000);
  342. });
  343. it("should add new menu at end of list when reference menu doesn't exist", function () {
  344. error = 0;
  345. runs(function () {
  346. complete = false;
  347. brackets.app.addMenu("Custom4", "menu-unittest4", "after", "NONEXISTANT", function (err) {
  348. complete = true;
  349. error = err;
  350. });
  351. });
  352. waitsFor(function () { return complete; }, 1000);
  353. runs(function () {
  354. expect(error).toBe(brackets.fs.ERR_NOT_FOUND);
  355. });
  356. // Verify menu is found
  357. runs(function () {
  358. complete = false;
  359. parentId = null;
  360. position = -1;
  361. brackets.app.getMenuPosition("menu-unittest4", function (err, parent, index) {
  362. complete = true;
  363. error = err;
  364. parentId = parent;
  365. position = index;
  366. });
  367. });
  368. waitsFor(function () { return complete; }, 1000);
  369. runs(function () {
  370. expect(error).toBe(0);
  371. expect(parentId).toBe("");
  372. expect(position).toBeGreaterThan(0);
  373. });
  374. // Remove menu
  375. runs(function () {
  376. complete = false;
  377. brackets.app.removeMenu("menu-unittest4", function (err) {
  378. complete = true;
  379. // Ignore error
  380. });
  381. });
  382. waitsFor(function () { return complete; }, 1000);
  383. });
  384. }); // describe("addMenu (with reference)")
  385. describe("addMenuItem", function () {
  386. var complete = false,
  387. error = 0,
  388. title;
  389. beforeEach(function () {
  390. runs(function () {
  391. complete = false;
  392. brackets.app.addMenu(TEST_MENU_TITLE, TEST_MENU_ID, "", "", function (err) {
  393. complete = true;
  394. error = err;
  395. });
  396. });
  397. waitsFor(function () { return complete; });
  398. runs(function () {
  399. expect(error).toBe(0);
  400. });
  401. });
  402. afterEach(function () {
  403. runs(function () {
  404. complete = false;
  405. brackets.app.removeMenu(TEST_MENU_ID, function (err) {
  406. complete = true;
  407. error = err;
  408. });
  409. });
  410. waitsFor(function () { return complete; });
  411. runs(function () {
  412. expect(error).toBe(0);
  413. });
  414. });
  415. it("should add a menu item", function () {
  416. error = 0;
  417. runs(function () {
  418. complete = false;
  419. brackets.app.addMenuItem(TEST_MENU_ID, TEST_MENU_ITEM, TEST_MENU_ITEM_ID, "", "", "", "", function (err) {
  420. complete = true;
  421. error = err;
  422. });
  423. });
  424. waitsFor(function () { return complete; }, 1000);
  425. runs(function () {
  426. expect(error).toBe(0);
  427. });
  428. // Verify item
  429. runs(function () {
  430. complete = false;
  431. brackets.app.getMenuTitle(TEST_MENU_ITEM_ID, function (err, titleStr) {
  432. complete = true;
  433. error = err;
  434. title = titleStr;
  435. });
  436. });
  437. waitsFor(function () { return complete; }, 1000);
  438. runs(function () {
  439. expect(error).toBe(0);
  440. expect(title).toBe(TEST_MENU_ITEM);
  441. complete = false;
  442. brackets.app.removeMenuItem(TEST_MENU_ITEM_ID, function (err) {
  443. complete = true;
  444. });
  445. });
  446. waitsFor(function () { return complete; }, 1000);
  447. });
  448. it("should return an error if invalid parameters are passed", function () {
  449. runs(function () {
  450. error = 0;
  451. complete = false;
  452. brackets.app.addMenuItem(TEST_MENU_ID, TEST_MENU_ITEM, TEST_MENU_ITEM_ID, "", 42, "", "", function (err) {
  453. complete = true;
  454. error = err;
  455. });
  456. });
  457. waitsFor(function () { return complete; }, 1000);
  458. runs(function () {
  459. expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS);
  460. });
  461. });
  462. }); // describe("addMenuItem")
  463. describe("addMenuItem (with reference)", function () {
  464. var complete = false,
  465. error = 0,
  466. title,
  467. parentId = null,
  468. position = -1;
  469. beforeEach(function () {
  470. runs(function () {
  471. complete = false;
  472. brackets.app.addMenu(TEST_MENU_TITLE, TEST_MENU_ID, "", "", function (err) {
  473. complete = true;
  474. error = err;
  475. });
  476. });
  477. waitsFor(function () { return complete; });
  478. runs(function () {
  479. expect(error).toBe(0);
  480. });
  481. // Add a menu item into the empty menu
  482. runs(function () {
  483. complete = false;
  484. brackets.app.addMenuItem(TEST_MENU_ID, TEST_MENU_ITEM, TEST_MENU_ITEM_ID, "", "", "", "", function (err) {
  485. complete = true;
  486. error = err;
  487. });
  488. });
  489. waitsFor(function () { return complete; }, 1000);
  490. runs(function () {
  491. expect(error).toBe(0);
  492. });
  493. });
  494. afterEach(function () {
  495. runs(function () {
  496. complete = false;
  497. brackets.app.removeMenuItem(TEST_MENU_ITEM_ID, function (err) {
  498. complete = true;
  499. });
  500. });
  501. waitsFor(function () { return complete; });
  502. runs(function () {
  503. complete = false;
  504. brackets.app.removeMenu(TEST_MENU_ID, function (err) {
  505. complete = true;
  506. error = err;
  507. });
  508. });
  509. waitsFor(function () { return complete; });
  510. runs(function () {
  511. expect(error).toBe(0);
  512. });
  513. });
  514. it("should add a menu item in first position of menu", function () {
  515. error = 0;
  516. runs(function () {
  517. complete = false;
  518. brackets.app.addMenuItem(TEST_MENU_ID, "Brackets Test Command Custom 1", "Menu-test.command01", "", "", "first", "", function (err) {
  519. complete = true;
  520. error = err;
  521. });
  522. });
  523. waitsFor(function () { return complete; }, 1000);
  524. runs(function () {
  525. expect(error).toBe(0);
  526. });
  527. // Verify item is found in the right position
  528. runs(function () {
  529. complete = false;
  530. parentId = null;
  531. position = -1;
  532. brackets.app.getMenuPosition("Menu-test.command01", function (err, parent, index) {
  533. complete = true;
  534. error = err;
  535. parentId = parent;
  536. position = index;
  537. });
  538. });
  539. waitsFor(function () { return complete; }, 1000);
  540. runs(function () {
  541. expect(error).toBe(0);
  542. expect(parentId).toBe(TEST_MENU_ID);
  543. expect(position).toBe(0);
  544. });
  545. // Verify item
  546. runs(function () {
  547. complete = false;
  548. brackets.app.getMenuTitle("Menu-test.command01", function (err, titleStr) {
  549. complete = true;
  550. error = err;
  551. title = titleStr;
  552. });
  553. });
  554. waitsFor(function () { return complete; }, 1000);
  555. runs(function () {
  556. expect(error).toBe(0);
  557. expect(title).toBe("Brackets Test Command Custom 1");
  558. });
  559. runs(function () {
  560. complete = false;
  561. brackets.app.removeMenuItem("Menu-test.command01", function (err) {
  562. complete = true;
  563. });
  564. });
  565. waitsFor(function () { return complete; });
  566. });
  567. it("should add a menu item in last position of menu", function () {
  568. error = 0;
  569. runs(function () {
  570. complete = false;
  571. brackets.app.addMenuItem(TEST_MENU_ID, "Brackets Test Command Custom 2", "Menu-test.command02", "", "", "last", "", function (err) {
  572. complete = true;
  573. error = err;
  574. });
  575. });
  576. waitsFor(function () { return complete; }, 1000);
  577. runs(function () {
  578. expect(error).toBe(0);
  579. });
  580. // Verify item is found in the right position
  581. runs(function () {
  582. complete = false;
  583. parentId = null;
  584. position = -1;
  585. brackets.app.getMenuPosition("Menu-test.command02", function (err, parent, index) {
  586. complete = true;
  587. error = err;
  588. parentId = parent;
  589. position = index;
  590. });
  591. });
  592. waitsFor(function () { return complete; }, 1000);
  593. runs(function () {
  594. expect(error).toBe(0);
  595. expect(parentId).toBe(TEST_MENU_ID);
  596. expect(position).toBe(1);
  597. });
  598. // Verify item
  599. runs(function () {
  600. complete = false;
  601. brackets.app.getMenuTitle("Menu-test.command02", function (err, titleStr) {
  602. complete = true;
  603. error = err;
  604. title = titleStr;
  605. });
  606. });
  607. waitsFor(function () { return complete; }, 1000);
  608. runs(function () {
  609. expect(error).toBe(0);
  610. expect(title).toBe("Brackets Test Command Custom 2");
  611. });
  612. runs(function () {
  613. complete = false;
  614. brackets.app.removeMenuItem("Menu-test.command02", function (err) {
  615. complete = true;
  616. });
  617. });
  618. waitsFor(function () { return complete; });
  619. });
  620. it("should add a menu item after the referenced menu item", function () {
  621. error = 0;
  622. runs(function () {
  623. complete = false;
  624. brackets.app.addMenuItem(TEST_MENU_ID, "Brackets Test Command Custom 3", "Menu-test.command03", "", "", "after", TEST_MENU_ITEM_ID, function (err) {
  625. complete = true;
  626. error = err;
  627. });
  628. });
  629. waitsFor(function () { return complete; }, 1000);
  630. runs(function () {
  631. expect(error).toBe(0);
  632. });
  633. // Verify item is found in the right position
  634. runs(function () {
  635. complete = false;
  636. parentId = null;
  637. position = -1;
  638. brackets.app.getMenuPosition("Menu-test.command03", function (err, parent, index) {
  639. complete = true;
  640. error = err;
  641. parentId = parent;
  642. position = index;
  643. });
  644. });
  645. waitsFor(function () { return complete; }, 1000);
  646. runs(function () {
  647. expect(error).toBe(0);
  648. expect(parentId).toBe(TEST_MENU_ID);
  649. expect(position).toBe(1);
  650. });
  651. // Verify item
  652. runs(function () {
  653. complete = false;
  654. brackets.app.getMenuTitle("Menu-test.command03", function (err, titleStr) {
  655. complete = true;
  656. error = err;
  657. title = titleStr;
  658. });
  659. });
  660. waitsFor(function () { return complete; }, 1000);
  661. runs(function () {
  662. expect(error).toBe(0);
  663. expect(title).toBe("Brackets Test Command Custom 3");
  664. });
  665. runs(function () {
  666. complete = false;
  667. brackets.app.removeMenuItem("Menu-test.command03", function (err) {
  668. complete = true;
  669. });
  670. });
  671. waitsFor(function () { return complete; });
  672. });
  673. it("should add a menu item before the referenced menu item", function () {
  674. error = 0;
  675. runs(function () {
  676. complete = false;
  677. brackets.app.addMenuItem(TEST_MENU_ID, "Brackets Test Command Custom 4", "Menu-test.command04", "", "", "before", TEST_MENU_ITEM_ID, function (err) {
  678. complete = true;
  679. error = err;
  680. });
  681. });
  682. waitsFor(function () { return complete; }, 1000);
  683. runs(function () {
  684. expect(error).toBe(0);
  685. });
  686. // Verify item is found in the right position
  687. runs(function () {
  688. complete = false;
  689. parentId = null;
  690. position = -1;
  691. brackets.app.getMenuPosition("Menu-test.command04", function (err, parent, index) {
  692. complete = true;
  693. error = err;
  694. parentId = parent;
  695. position = index;
  696. });
  697. });
  698. waitsFor(function () { return complete; }, 1000);
  699. runs(function () {
  700. expect(error).toBe(0);
  701. expect(parentId).toBe(TEST_MENU_ID);
  702. expect(position).toBe(0);
  703. });
  704. // Verify item
  705. runs(function () {
  706. complete = false;
  707. brackets.app.getMenuTitle("Menu-test.command04", function (err, titleStr) {
  708. complete = true;
  709. error = err;
  710. title = titleStr;
  711. });
  712. });
  713. waitsFor(function () { return complete; }, 1000);
  714. runs(function () {
  715. expect(error).toBe(0);
  716. expect(title).toBe("Brackets Test Command Custom 4");
  717. });
  718. runs(function () {
  719. complete = false;
  720. brackets.app.removeMenuItem("Menu-test.command04", function (err) {
  721. complete = true;
  722. });
  723. });
  724. waitsFor(function () { return complete; });
  725. });
  726. it("should add a menu item at the end when reference menu item doesn't exist", function () {
  727. error = 0;
  728. runs(function () {
  729. complete = false;
  730. brackets.app.addMenuItem(TEST_MENU_ID, "Brackets Test Command Custom 5", "Menu-test.command05", "", "", "before", "NONEXISTANT", function (err) {
  731. complete = true;
  732. error = err;
  733. });
  734. });
  735. waitsFor(function () { return complete; }, 1000);
  736. runs(function () {
  737. expect(error).toBe(brackets.fs.ERR_NOT_FOUND);
  738. });
  739. // Verify item is found in the right position
  740. runs(function () {
  741. complete = false;
  742. parentId = null;
  743. position = -1;
  744. brackets.app.getMenuPosition("Menu-test.command05", function (err, parent, index) {
  745. complete = true;
  746. error = err;
  747. parentId = parent;
  748. position = index;
  749. });
  750. });
  751. waitsFor(function () { return complete; }, 1000);
  752. runs(function () {
  753. expect(error).toBe(0);
  754. expect(parentId).toBe(TEST_MENU_ID);
  755. expect(position).toBe(1);
  756. });
  757. // Verify item
  758. runs(function () {
  759. complete = false;
  760. brackets.app.getMenuTitle("Menu-test.command05", function (err, titleStr) {
  761. complete = true;
  762. error = err;
  763. title = titleStr;
  764. });
  765. });
  766. waitsFor(function () { return complete; }, 1000);
  767. runs(function () {
  768. expect(error).toBe(0);
  769. expect(title).toBe("Brackets Test Command Custom 5");
  770. });
  771. runs(function () {
  772. complete = false;
  773. brackets.app.removeMenuItem("Menu-test.command05", function (err) {
  774. complete = true;
  775. });
  776. });
  777. waitsFor(function () { return complete; });
  778. });
  779. it("should add menu items to beginning and end of menu section", function () {
  780. var complete,
  781. error,
  782. index,
  783. parent;
  784. // set up test menu and menu items
  785. var SECTION_MENU = "menuitem-sectiontest";
  786. runs(function () {
  787. brackets.app.addMenu("Section Test", "menuitem-sectiontest", "", "", function (err) {});
  788. brackets.app.addMenuItem(SECTION_MENU, "Command 10", "Menu-test.command10", "", "", "", "", function (err) {});
  789. brackets.app.addMenuItem(SECTION_MENU, "Command 11", "Menu-test.command11", "", "", "", "", function (err) {});
  790. brackets.app.addMenuItem(SECTION_MENU, "---", String(Date.now()), "", "", "", "", function (err) {});
  791. brackets.app.addMenuItem(SECTION_MENU, "Command 12", "Menu-test.command12", "", "", "", "", function (err) {});
  792. brackets.app.addMenuItem(SECTION_MENU, "Command 13", "Menu-test.command13", "", "", "", "", function (err) {});
  793. });
  794. // Add new menu to END of menuSectionCmd10
  795. runs(function () {
  796. complete = false;
  797. error = 0;
  798. brackets.app.addMenuItem(SECTION_MENU, "Command 14", "Menu-test.command14", "", "", "lastInSection", "Menu-test.command10", function (err) {
  799. complete = true;
  800. error = err;
  801. });
  802. });
  803. waitsFor(function () { return complete; }, 1000);
  804. runs(function () {
  805. complete = false;
  806. error = 0;
  807. brackets.app.getMenuPosition("Menu-test.command14", function (err, par, idx) {
  808. complete = true;
  809. error = err;
  810. parent = par;
  811. index = idx;
  812. });
  813. });
  814. waitsFor(function () { return complete; }, 1000);
  815. runs(function () {
  816. expect(error).toBe(0);
  817. expect(index).toBe(2);
  818. });
  819. // Add new menu to END of menuSectionCmd2
  820. runs(function () {
  821. complete = false;
  822. error = 0;
  823. brackets.app.addMenuItem(SECTION_MENU, "Command 15", "Menu-test.command15", "", "", "lastInSection", "Menu-test.command13", function (err) {
  824. complete = true;
  825. error = err;
  826. });
  827. });
  828. waitsFor(function () { return complete; }, 1000);
  829. runs(function () {
  830. complete = false;
  831. error = 0;
  832. brackets.app.getMenuPosition("Menu-test.command15", function (err, par, idx) {
  833. complete = true;
  834. error = err;
  835. parent = par;
  836. index = idx;
  837. });
  838. });
  839. waitsFor(function () { return complete; }, 1000);
  840. runs(function () {
  841. expect(error).toBe(0);
  842. expect(index).toBe(6);
  843. });
  844. // Add new menu to BEGINNING of menuSectionCmd0
  845. runs(function () {
  846. complete = false;
  847. error = 0;
  848. brackets.app.addMenuItem(SECTION_MENU, "Command 16", "Menu-test.command16", "", "", "firstInSection", "Menu-test.command11", function (err) {
  849. complete = true;
  850. error = err;
  851. });
  852. });
  853. waitsFor(function () { return complete; }, 1000);
  854. runs(function () {
  855. complete = false;
  856. error = 0;
  857. brackets.app.getMenuPosition("Menu-test.command16", function (err, par, idx) {
  858. complete = true;
  859. error = err;
  860. parent = par;
  861. index = idx;
  862. });
  863. });
  864. waitsFor(function () { return complete; }, 1000);
  865. runs(function () {
  866. expect(error).toBe(0);
  867. expect(index).toBe(0);
  868. });
  869. // Add new menu to BEGINNING of menuSectionCmd2
  870. runs(function () {
  871. complete = false;
  872. error = 0;
  873. brackets.app.addMenuItem(SECTION_MENU, "Command 17", "Menu-test.command17", "", "", "firstInSection", "Menu-test.command12", function (err) {
  874. complete = true;
  875. error = err;
  876. });
  877. });
  878. waitsFor(function () { return complete; }, 1000);
  879. runs(function () {
  880. complete = false;
  881. error = 0;
  882. brackets.app.getMenuPosition("Menu-test.command17", function (err, par, idx) {
  883. complete = true;
  884. error = err;
  885. parent = par;
  886. index = idx;
  887. });
  888. });
  889. waitsFor(function () { return complete; }, 1000);
  890. runs(function () {
  891. expect(error).toBe(0);
  892. expect(index).toBe(5);
  893. });
  894. runs(function () {
  895. brackets.app.removeMenuItem("Menu-test.command10", function (err) {});
  896. brackets.app.removeMenuItem("Menu-test.command11", function (err) {});
  897. brackets.app.removeMenuItem("Menu-test.command12", function (err) {});
  898. brackets.app.removeMenuItem("Menu-test.command13", function (err) {});
  899. brackets.app.removeMenuItem("Menu-test.command14", function (err) {});
  900. brackets.app.removeMenuItem("Menu-test.command15", function (err) {});
  901. brackets.app.removeMenuItem("Menu-test.command16", function (err) {});
  902. brackets.app.removeMenuItem("Menu-test.command17", function (err) {});
  903. brackets.app.removeMenu(SECTION_MENU, function (err) {});
  904. });
  905. });
  906. }); // describe("addMenuItem (with reference)")
  907. describe("removeMenu", function () {
  908. var complete = false,
  909. error = 0;
  910. it("should remove a menu", function () {
  911. runs(function () {
  912. brackets.app.addMenu(TEST_MENU_TITLE, TEST_MENU_ID, "", "", function (err) {
  913. complete = true;
  914. error = err;
  915. });
  916. });
  917. waitsFor(function () { return complete; }, 1000);
  918. runs(function () {
  919. expect(error).toBe(0);
  920. });
  921. runs(function () {
  922. complete = false;
  923. brackets.app.removeMenu(TEST_MENU_ID, function (err) {
  924. complete = true;
  925. error = err;
  926. });
  927. });
  928. waitsFor(function () { return complete; }, 1000);
  929. runs(function () {
  930. expect(error).toBe(0);
  931. });
  932. });
  933. it("should return an error if invalid parameters are passed", function () {
  934. complete = false;
  935. error = 0;
  936. runs(function () {
  937. brackets.app.removeMenu(42, function (err) {
  938. complete = true;
  939. error = err;
  940. });
  941. });
  942. waitsFor(function () { return complete; }, 1000);
  943. runs(function () {
  944. expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS);
  945. });
  946. });
  947. it("should return an error if the menu can't be found", function () {
  948. complete = false;
  949. error = 0;
  950. runs(function () {
  951. brackets.app.removeMenu(TEST_MENU_ID, function (err) {
  952. complete = true;
  953. error = err;
  954. });
  955. });
  956. waitsFor(function () { return complete; }, 1000);
  957. runs(function () {
  958. expect(error).toBe(brackets.fs.ERR_NOT_FOUND);
  959. });
  960. });
  961. });
  962. describe("removeMenuItem", function () {
  963. var ITEM_ID = TEST_MENU_ITEM_ID + "1";
  964. beforeEach(function () {
  965. var complete = false,
  966. error = 0;
  967. runs(function () {
  968. brackets.app.addMenu(TEST_MENU_TITLE, TEST_MENU_ID, "", "", function (err) {
  969. if (err) {
  970. complete = true;
  971. error = err;
  972. } else {
  973. brackets.app.addMenuItem(TEST_MENU_ID, TEST_MENU_ITEM, ITEM_ID, "", "", "", "", function (err) {
  974. complete = true;
  975. error = err;
  976. });
  977. }
  978. });
  979. });
  980. waitsFor(function () { return complete; }, 1000);
  981. runs(function () {
  982. expect(error).toBe(0);
  983. });
  984. });
  985. afterEach(function () {
  986. var complete = false,
  987. error = 0;
  988. runs(function () {
  989. brackets.app.removeMenuItem(ITEM_ID, function (err) {
  990. // Ignore the error from removeMenuItem(). The item may have
  991. // already been removed by the test.
  992. brackets.app.removeMenu(TEST_MENU_ID, function (err) {
  993. complete = true;
  994. error = err;
  995. });
  996. });
  997. });
  998. waitsFor(function () { return complete; }, 1000);
  999. runs(function () {
  1000. expect(error).toBe(0);
  1001. });
  1002. });
  1003. it("should remove a menu item", function () {
  1004. var complete = false,
  1005. error = 0;
  1006. runs(function () {
  1007. brackets.app.removeMenuItem(ITEM_ID, function (err) {
  1008. complete = true;
  1009. error = err;
  1010. });
  1011. });
  1012. waitsFor(function () { return complete; }, "calling removeMenuItem", 1000);
  1013. runs(function () {
  1014. expect(error).toBe(0);
  1015. });
  1016. // Make sure it's gone
  1017. runs(function () {
  1018. complete = false;
  1019. brackets.app.getMenuTitle(ITEM_ID, function (err, titleStr) {
  1020. complete = true;
  1021. error = err;
  1022. });
  1023. });
  1024. waitsFor(function () { return complete; }, "calling getMenuTitle", 1000);
  1025. runs(function () {
  1026. expect(error).toBe(brackets.fs.ERR_NOT_FOUND);
  1027. });
  1028. });
  1029. it("should return an error if invalid parameters are passed", function () {
  1030. var complete = false,
  1031. error = 0;
  1032. runs(function () {
  1033. brackets.app.removeMenuItem(42, function (err) {
  1034. complete = true;
  1035. error = err;
  1036. });
  1037. });
  1038. waitsFor(function () { return complete; }, "calling removeMenuItem", 1000);
  1039. runs(function () {
  1040. expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS);
  1041. });
  1042. });
  1043. it("should return an error if the menu item can't be found", function () {
  1044. var complete = false,
  1045. error = 0;
  1046. runs(function () {
  1047. brackets.app.removeMenuItem(ITEM_ID + "foo", function (err) {
  1048. complete = true;
  1049. error = err;
  1050. });
  1051. });
  1052. waitsFor(function () { return complete; }, "calling removeMenuItem", 1000);
  1053. runs(function () {
  1054. expect(error).toBe(brackets.fs.ERR_NOT_FOUND);
  1055. });
  1056. });
  1057. });
  1058. describe("getMenuItemState setMenuItemState", function () {
  1059. var ITEM_ID = TEST_MENU_ITEM_ID + "2";
  1060. beforeEach(function () {
  1061. var complete = false,
  1062. error = 0;
  1063. runs(function () {
  1064. brackets.app.addMenu(TEST_MENU_TITLE, TEST_MENU_ID, "", "", function (err) {
  1065. if (err) {
  1066. complete = true;
  1067. error = err;
  1068. } else {
  1069. brackets.app.addMenuItem(TEST_MENU_ID, TEST_MENU_ITEM, ITEM_ID, "", "", "", "", function (err) {
  1070. complete = true;
  1071. error = err;
  1072. });
  1073. }
  1074. });
  1075. });

Large files files are truncated, but you can click here to view the full file