From 3f3712c729266d536b0f32129248c88187799c7d Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Sun, 22 Sep 2013 09:18:34 -0700 Subject: [PATCH 1/4] Split menu specs into HTML and Native. Add HTML and Native versions of createTestWindowAndRun. --- test/spec/Menu-test.js | 40 ++++++++++++++++++++++++++++-------- test/spec/SpecRunnerUtils.js | 22 +++++++++++++++++--- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/test/spec/Menu-test.js b/test/spec/Menu-test.js index 178fb4b94ff..780ed23dcef 100644 --- a/test/spec/Menu-test.js +++ b/test/spec/Menu-test.js @@ -36,17 +36,15 @@ define(function (require, exports, module) { KeyEvent = require("utils/KeyEvent"); - describe("Menus", function () { + describe("Menus (Native Shell)", function () { this.category = "integration"; var testWindow; beforeFirst(function () { - // Create a new window that will be shared by ALL tests in this spec. (We need the tests to - // run in a real Brackets window since HTMLCodeHints requires various core modules (it can't - // run 100% in isolation), but popping a new window per testcase is unneeded overhead). - SpecRunnerUtils.createTestWindowAndRun(this, function (w) { + // Create a new native menu window that will be shared by ALL tests in this spec. + SpecRunnerUtils.createNativeTestWindowAndRun(this, function (w) { testWindow = w; // Load module instances from brackets.test @@ -210,11 +208,37 @@ define(function (require, exports, module) { expect($menus.length).toBe(0); }); }); + }); - if (!brackets.inBrowser) { - return; - } + + describe("Menus (HTML)", function () { + + this.category = "integration"; + var testWindow; + + beforeFirst(function () { + // Create a new HTML menu window that will be shared by ALL tests in this spec. + SpecRunnerUtils.createHTMLTestWindowAndRun(this, function (w) { + testWindow = w; + + // Load module instances from brackets.test + CommandManager = testWindow.brackets.test.CommandManager; + Commands = testWindow.brackets.test.Commands; + KeyBindingManager = testWindow.brackets.test.KeyBindingManager; + Menus = testWindow.brackets.test.Menus; + }); + }); + + afterLast(function () { + testWindow = null; + CommandManager = null; + Commands = null; + KeyBindingManager = null; + Menus = null; + SpecRunnerUtils.closeTestWindow(); + }); + describe("Add Menus", function () { function getTopMenus() { diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index 8a234648627..3b2362dcba5 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -476,8 +476,7 @@ define(function (require, exports, module) { waitsForDone(promise, "dismiss dialog"); } - - function createTestWindowAndRun(spec, callback) { + function _createTestWindowAndRun(spec, hasNativeMenus, callback) { runs(function () { // Position popup windows in the lower right so they're out of the way var testWindowWid = 1000, @@ -503,6 +502,9 @@ define(function (require, exports, module) { // disable initial dialog for live development params.put("skipLiveDevelopmentInfo", true); + // determines if test window should have native or html menus + params.put("hasNativeMenus", hasNativeMenus); + _testWindow = window.open(getBracketsSourceRoot() + "/index.html?" + params.toString(), "_blank", optionsStr); _testWindow.isBracketsTestWindow = true; @@ -524,7 +526,7 @@ define(function (require, exports, module) { }); }; }); - + // FIXME (issue #249): Need an event or something a little more reliable... waitsFor( function isBracketsDoneLoading() { @@ -540,6 +542,18 @@ define(function (require, exports, module) { }); } + function createTestWindowAndRun(spec, callback) { + _createTestWindowAndRun(spec, brackets.nativeMenus, callback); + } + + function createHTMLTestWindowAndRun(spec, callback) { + _createTestWindowAndRun(spec, false, callback); + } + + function createNativeTestWindowAndRun(spec, callback) { + _createTestWindowAndRun(spec, true, callback); + } + function closeTestWindow() { // debug-only to see testWindow state before closing // waits(500); @@ -1268,6 +1282,8 @@ define(function (require, exports, module) { exports.createMockEditorForDocument = createMockEditorForDocument; exports.createMockEditor = createMockEditor; exports.createTestWindowAndRun = createTestWindowAndRun; + exports.createHTMLTestWindowAndRun = createHTMLTestWindowAndRun; + exports.createNativeTestWindowAndRun = createNativeTestWindowAndRun; exports.closeTestWindow = closeTestWindow; exports.clickDialogButton = clickDialogButton; exports.destroyMockEditor = destroyMockEditor; From 1db93ab989a6b7babf377752e016b86d42c432fd Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Sun, 22 Sep 2013 17:42:18 -0700 Subject: [PATCH 2/4] Set brackets.nativeMenus based on hasNativeMenus URL parameter. --- src/utils/Global.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/utils/Global.js b/src/utils/Global.js index 56ab38524fb..9116301d4eb 100644 --- a/src/utils/Global.js +++ b/src/utils/Global.js @@ -34,7 +34,13 @@ define(function (require, exports, module) { "use strict"; - var configJSON = require("text!config.json"); + var configJSON = require("text!config.json"), + UrlParams = require("utils/UrlParams").UrlParams; + + var params = new UrlParams(); + + // read URL params + params.parse(); // Define core brackets namespace if it isn't already defined // @@ -77,7 +83,11 @@ define(function (require, exports, module) { global.brackets.inBrowser = !global.brackets.hasOwnProperty("fs"); - global.brackets.nativeMenus = (!global.brackets.inBrowser && (global.brackets.platform !== "linux")); + if (params.get("hasNativeMenus") !== undefined) { + global.brackets.nativeMenus = (params.get("hasNativeMenus") === "true"); + } else { + global.brackets.nativeMenus = (!global.brackets.inBrowser && (global.brackets.platform !== "linux")); + } global.brackets.isLocaleDefault = function () { return !global.localStorage.getItem("locale"); From a9a8e47ed30419499df90185cbe6dda124ce1789 Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Tue, 24 Sep 2013 21:56:34 -0700 Subject: [PATCH 3/4] API changes --- test/spec/Menu-test.js | 12 ++++++++---- test/spec/SpecRunnerUtils.js | 22 +++++----------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/test/spec/Menu-test.js b/test/spec/Menu-test.js index 780ed23dcef..bbfe63932d8 100644 --- a/test/spec/Menu-test.js +++ b/test/spec/Menu-test.js @@ -43,8 +43,10 @@ define(function (require, exports, module) { var testWindow; beforeFirst(function () { + var testWindowOptions = {"hasNativeMenus" : true}; + // Create a new native menu window that will be shared by ALL tests in this spec. - SpecRunnerUtils.createNativeTestWindowAndRun(this, function (w) { + SpecRunnerUtils.createTestWindowAndRun(this, function (w) { testWindow = w; // Load module instances from brackets.test @@ -52,7 +54,7 @@ define(function (require, exports, module) { Commands = testWindow.brackets.test.Commands; KeyBindingManager = testWindow.brackets.test.KeyBindingManager; Menus = testWindow.brackets.test.Menus; - }); + }, testWindowOptions); }); afterLast(function () { @@ -218,8 +220,10 @@ define(function (require, exports, module) { var testWindow; beforeFirst(function () { + var testWindowOptions = {"hasNativeMenus" : false}; + // Create a new HTML menu window that will be shared by ALL tests in this spec. - SpecRunnerUtils.createHTMLTestWindowAndRun(this, function (w) { + SpecRunnerUtils.createTestWindowAndRun(this, function (w) { testWindow = w; // Load module instances from brackets.test @@ -227,7 +231,7 @@ define(function (require, exports, module) { Commands = testWindow.brackets.test.Commands; KeyBindingManager = testWindow.brackets.test.KeyBindingManager; Menus = testWindow.brackets.test.Menus; - }); + }, testWindowOptions); }); afterLast(function () { diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index 3b2362dcba5..1eb326703a6 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -476,7 +476,7 @@ define(function (require, exports, module) { waitsForDone(promise, "dismiss dialog"); } - function _createTestWindowAndRun(spec, hasNativeMenus, callback) { + function createTestWindowAndRun(spec, callback, options) { runs(function () { // Position popup windows in the lower right so they're out of the way var testWindowWid = 1000, @@ -502,8 +502,10 @@ define(function (require, exports, module) { // disable initial dialog for live development params.put("skipLiveDevelopmentInfo", true); - // determines if test window should have native or html menus - params.put("hasNativeMenus", hasNativeMenus); + // option to launch test window with either native or HTML menus + if (options && options.hasOwnProperty("hasNativeMenus")) { + params.put("hasNativeMenus", options.hasNativeMenus); + } _testWindow = window.open(getBracketsSourceRoot() + "/index.html?" + params.toString(), "_blank", optionsStr); @@ -542,18 +544,6 @@ define(function (require, exports, module) { }); } - function createTestWindowAndRun(spec, callback) { - _createTestWindowAndRun(spec, brackets.nativeMenus, callback); - } - - function createHTMLTestWindowAndRun(spec, callback) { - _createTestWindowAndRun(spec, false, callback); - } - - function createNativeTestWindowAndRun(spec, callback) { - _createTestWindowAndRun(spec, true, callback); - } - function closeTestWindow() { // debug-only to see testWindow state before closing // waits(500); @@ -1282,8 +1272,6 @@ define(function (require, exports, module) { exports.createMockEditorForDocument = createMockEditorForDocument; exports.createMockEditor = createMockEditor; exports.createTestWindowAndRun = createTestWindowAndRun; - exports.createHTMLTestWindowAndRun = createHTMLTestWindowAndRun; - exports.createNativeTestWindowAndRun = createNativeTestWindowAndRun; exports.closeTestWindow = closeTestWindow; exports.clickDialogButton = clickDialogButton; exports.destroyMockEditor = destroyMockEditor; From 54e3ad0e2a60a1181af92202901c4b901cd265ac Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Wed, 25 Sep 2013 20:21:56 -0700 Subject: [PATCH 4/4] hasNativeMenus param code cleanup --- src/utils/Global.js | 9 ++++++--- test/spec/SpecRunnerUtils.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/Global.js b/src/utils/Global.js index 9116301d4eb..3f5bef20bde 100644 --- a/src/utils/Global.js +++ b/src/utils/Global.js @@ -37,7 +37,8 @@ define(function (require, exports, module) { var configJSON = require("text!config.json"), UrlParams = require("utils/UrlParams").UrlParams; - var params = new UrlParams(); + var params = new UrlParams(), + hasNativeMenus = ""; // read URL params params.parse(); @@ -83,8 +84,10 @@ define(function (require, exports, module) { global.brackets.inBrowser = !global.brackets.hasOwnProperty("fs"); - if (params.get("hasNativeMenus") !== undefined) { - global.brackets.nativeMenus = (params.get("hasNativeMenus") === "true"); + hasNativeMenus = params.get("hasNativeMenus"); + + if (hasNativeMenus) { + global.brackets.nativeMenus = (hasNativeMenus === "true"); } else { global.brackets.nativeMenus = (!global.brackets.inBrowser && (global.brackets.platform !== "linux")); } diff --git a/test/spec/SpecRunnerUtils.js b/test/spec/SpecRunnerUtils.js index 1eb326703a6..88bf1d455d6 100644 --- a/test/spec/SpecRunnerUtils.js +++ b/test/spec/SpecRunnerUtils.js @@ -504,7 +504,7 @@ define(function (require, exports, module) { // option to launch test window with either native or HTML menus if (options && options.hasOwnProperty("hasNativeMenus")) { - params.put("hasNativeMenus", options.hasNativeMenus); + params.put("hasNativeMenus", (options.hasNativeMenus ? "true" : "false")); } _testWindow = window.open(getBracketsSourceRoot() + "/index.html?" + params.toString(), "_blank", optionsStr);