diff --git a/test/spec/NativeMenu-test.js b/test/spec/NativeMenu-test.js index b653337e0b8..ec9277aff7a 100644 --- a/test/spec/NativeMenu-test.js +++ b/test/spec/NativeMenu-test.js @@ -38,15 +38,32 @@ define(function (require, exports, module) { describe("Native Menus", function () { - var TEST_MENU_TITLE = "TEST", - TEST_MENU_ID = "test", - TEST_MENU_ITEM = "Item 1", - TEST_MENU_ITEM_ID = "item1"; + var PLACEHOLDER_MENU_ID = "placeholder", + PLACEHOLDER_MENU_TITLE = "MENU", + TEST_MENU_TITLE = "TEST", + TEST_MENU_ID = "test", + TEST_MENU_ITEM = "Item 1", + TEST_MENU_ITEM_ID = "item1"; it("should have a brackets.app namespace", function () { + var complete = false, + error = 0; + expect(brackets.app).toBeTruthy(); + + // Add an empty native menu so the menu bar doesn't keep flashing + runs(function () { + brackets.app.addMenu(PLACEHOLDER_MENU_TITLE, PLACEHOLDER_MENU_ID, "", "", function (err) { + complete = true; + error = err; + }); + }); + + waitsFor(function () { return complete; }); + + expect(error).toBe(0); }); - + describe("addMenu", function () { it("should add a menu", function () { @@ -62,7 +79,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_NOT_FOUND); @@ -77,7 +94,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -93,7 +110,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -108,7 +125,7 @@ define(function (require, exports, module) { // Ignore error }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); }); it("should return an error if invalid parameters are passed", function () { @@ -122,7 +139,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS); @@ -178,7 +195,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -197,7 +214,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -213,7 +230,7 @@ define(function (require, exports, module) { error = err; }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -232,7 +249,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -246,7 +263,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -267,7 +284,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -287,7 +304,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -303,7 +320,7 @@ define(function (require, exports, module) { // Ignore error }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { complete = false; @@ -312,7 +329,7 @@ define(function (require, exports, module) { // Ignore error }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); }); it("should add new menu before reference menu", function () { @@ -327,7 +344,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -341,7 +358,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -362,7 +379,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -382,7 +399,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -398,7 +415,7 @@ define(function (require, exports, module) { // Ignore error }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { complete = false; @@ -407,7 +424,7 @@ define(function (require, exports, module) { // Ignore error }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); }); it("should add new menu at end of list when reference menu doesn't exist", function () { @@ -420,7 +437,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_NOT_FOUND); @@ -439,7 +456,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -455,7 +472,7 @@ define(function (require, exports, module) { // Ignore error }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); }); }); // describe("addMenu (with reference)") @@ -507,7 +524,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -523,7 +540,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -534,7 +551,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); }); it("should return an error if invalid parameters are passed", function () { @@ -547,7 +564,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS); @@ -586,7 +603,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -627,7 +644,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -646,7 +663,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -664,7 +681,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -690,7 +707,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -709,7 +726,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -727,7 +744,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -754,7 +771,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -773,7 +790,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -791,7 +808,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -817,7 +834,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -836,7 +853,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -854,7 +871,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -880,7 +897,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_NOT_FOUND); @@ -899,7 +916,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -917,7 +934,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -960,7 +977,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { complete = false; @@ -973,7 +990,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -990,7 +1007,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { complete = false; @@ -1003,7 +1020,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1020,7 +1037,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { complete = false; @@ -1033,7 +1050,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1050,7 +1067,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { complete = false; @@ -1063,7 +1080,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1095,7 +1112,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1109,7 +1126,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1127,7 +1144,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS); @@ -1145,7 +1162,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_NOT_FOUND); @@ -1174,7 +1191,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1196,7 +1213,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1214,7 +1231,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, "calling removeMenuItem", 1000); + waitsFor(function () { return complete; }, "calling removeMenuItem"); runs(function () { expect(error).toBe(0); @@ -1229,7 +1246,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, "calling getMenuTitle", 1000); + waitsFor(function () { return complete; }, "calling getMenuTitle"); runs(function () { expect(error).toBe(brackets.fs.ERR_NOT_FOUND); @@ -1246,7 +1263,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, "calling removeMenuItem", 1000); + waitsFor(function () { return complete; }, "calling removeMenuItem"); runs(function () { expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS); @@ -1263,7 +1280,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, "calling removeMenuItem", 1000); + waitsFor(function () { return complete; }, "calling removeMenuItem"); runs(function () { expect(error).toBe(brackets.fs.ERR_NOT_FOUND); @@ -1292,7 +1309,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1315,7 +1332,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1335,7 +1352,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1351,7 +1368,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1367,7 +1384,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1388,7 +1405,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1404,7 +1421,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1420,7 +1437,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1438,7 +1455,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS); @@ -1465,7 +1482,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1490,7 +1507,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1511,7 +1528,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1527,7 +1544,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1543,7 +1560,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1565,7 +1582,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1581,7 +1598,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1597,7 +1614,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(0); @@ -1615,7 +1632,7 @@ define(function (require, exports, module) { }); }); - waitsFor(function () { return complete; }, 1000); + waitsFor(function () { return complete; }); runs(function () { expect(error).toBe(brackets.fs.ERR_INVALID_PARAMS); @@ -1623,5 +1640,20 @@ define(function (require, exports, module) { }); }); + it("should remove placeholder menu", function () { + var complete = false, + error = 0; + + runs(function () { + brackets.app.removeMenu(PLACEHOLDER_MENU_ID, function (err) { + complete = true; + error = err; + }); + }); + + waitsFor(function () { return complete; }); + + expect(error).toBe(0); + }); }); // describe("Native Menus") });