diff --git a/common/bootstrap.js b/common/bootstrap.js index cbd001a6..4ab93a0f 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -85,9 +85,7 @@ function startup(data, reason) { addonData = data; addon = data; - dump("dactyl: bootstrap: pre-getAddonByID\n"); AddonManager.getAddonByID(addon.id, function (a) { - dump("dactyl: bootstrap: getAddonByID: " + a + "\n"); addon = a; updateVersion(); }); diff --git a/common/tests/functional/dactyl.jsm b/common/tests/functional/dactyl.jsm index fe23a514..69b352c6 100644 --- a/common/tests/functional/dactyl.jsm +++ b/common/tests/functional/dactyl.jsm @@ -23,12 +23,16 @@ function wrapAssertNoErrors(func, message) { function assertMessage(funcName, want, got, message) { if (typeof want === "string") return utils.assertEqual(funcName, want, got, message); - else if (typeof want === "function") - return utils.test(want(got), { + else if (typeof want === "function") { + var res = want(got); + if (res === undefined) + return true; + return utils.test(res, { function: funcName, want: want, got: got, comment: message }); + } else return utils.test(want.test(got), { function: funcName, diff --git a/common/tests/functional/testCommands.js b/common/tests/functional/testCommands.js index 48fb4d76..4a4f0a98 100644 --- a/common/tests/functional/testCommands.js +++ b/common/tests/functional/testCommands.js @@ -14,14 +14,19 @@ var setupModule = function (module) { dactyl.modules.options["wildmode"] = ["list"]; dactyl.modules.prefs.set("browser.tabs.closeWindowWithLastTab", false); + dactyl.elements.multilineContainer.setAttribute("moz-collapsed", "true"); }; var teardownModule = function (module) { + dactyl.elements.multilineContainer.removeAttribute("moz-collapsed"); dactyl.teardown(); } function $(selector) controller.window.document.querySelector(selector); -function hasNItems(nItems) function (context) utils.assertEqual("testCommand.hasNItems", nItems, context.allItems.items.length); +function hasNItems(nItems) + function hasNItems(context) { + utils.assertEqual("testCommand.hasNItems", nItems, context.allItems.items.length); + }; function hasItems(context) context.allItems.items.length; @@ -29,9 +34,15 @@ function hasntNullItems(context) hasItems(context) && !context.allItems.items.some(function ({ text, description }) [text, description].some(function (text) /^\[object/.test(text))); function sidebarState(state) - function () utils.assertEqual("testCommand.sidebarState", state, - typeof state == "string" ? $("#sidebar-title").value - : !$("#sidebar-box").hidden); + function sidebarState() { + utils.assertEqual("testCommand.sidebarState", state, + typeof state == "string" ? $("#sidebar-title").value + : !$("#sidebar-box").hidden); + }; +function toolbarState(selector, state) + function toolbarState() { + utils.assertEqual("testCommand.toolbarState", state, !$(selector).collapsed) + }; var tests = { "!": { @@ -128,7 +139,7 @@ var tests = { }, delbmarks: { anyOutput: ["", "about:pentadactyl"] }, delcommand: { - noOutput: ["foo"] + noOutput: ["foo"] // TODO: Why is this failing? "Unexpected command output: delcommand foo" }, delmacros: { error: [""], @@ -600,9 +611,36 @@ var tests = { tabprevious: {}, tabrewind: {}, time: {}, - toolbarhide: {}, - toolbarshow: {}, - toolbartoggle: {}, + toolbarhide: { + init: [ + ["tbs Navigation Toolbar", toolbarState("#nav-bar", true)], + ["tbs Bookmarks Toolbar", toolbarState("#PersonalToolbar", true)] + ], + completions: [["", hasItems]], + noOutput: [ + ["Navigation Toolbar", toolbarState("#nav-bar", false)], + ["Bookmarks Toolbar", toolbarState("#PersonalToolbar", false)] + ], + error: ["", "foo"] + }, + toolbarshow: { + completions: [["", hasItems]], + noOutput: [ + ["Navigation Toolbar", toolbarState("#nav-bar", true)], + ["Bookmarks Toolbar", toolbarState("#PersonalToolbar", true)] + ], + error: ["", "foo"] + }, + toolbartoggle: { + completions: [["", hasItems]], + noOutput: [ + ["Navigation Toolbar", toolbarState("#nav-bar", false)], + ["Bookmarks Toolbar", toolbarState("#PersonalToolbar", false)], + ["Navigation Toolbar", toolbarState("#nav-bar", true)], + ["Bookmarks Toolbar", toolbarState("#PersonalToolbar", true)] + ], + error: ["", "foo"] + }, tunmap: {}, unabbreviate: {}, undo: {}, @@ -610,14 +648,34 @@ var tests = { unlet: {}, unmap: {}, verbose: {}, - version: {}, + version: { + multiOutput: [ + ["", function (msg) { + var res = /(\w+dactyl) (\S+) \(([\^)]+)\) running on:\nMozilla/; + return res && res[2] != "null" && res[3] != "null"; + }] + ] + }, viewsource: {}, winclose: {}, window: {}, winonly: {}, winopen: {}, wqall: {}, - yank: {}, + yank: { + multiOutput: [ + ["foo".quote(), /foo/], + [":echo " + "bar".quote(), /bar/], + [":addons", /Pentadactyl/] + ], + error: [ + ":echoerr " + "foo".quote() + ], + completions: [ + ["", hasItems], + [":", hasItems] + ] + }, zoom: {} }; @@ -655,12 +713,19 @@ function _runCommands(cmdName, testName, commands) { dump("CMD: " + testName + " " + cmdName + " " + cmd + "\n"); var res = dactyl.runExCommand(cmd); controller.waitForPageLoad(controller.tabs.activeTab); - if (test) - jumlib.assert(test(), "Initializing for " + cmdName + " tests failed: " + cmd.quote() + " " + test); + runTest("Initializing for " + cmdName + " tests failed: " + cmd.quote() + " " + test, + test); }); }); } +function runTest(message, test) { + if (test) + var res = test.apply(null, Array.slice(arguments, runTest.length)); + if (res !== undefined) + jumlib.assert(res, message); +} + for (var val in Iterator(tests)) (function ([command, paramsList]) { Array.concat(paramsList).forEach(function (params, i) { if (params.init) @@ -696,14 +761,14 @@ for (var val in Iterator(tests)) (function ([command, paramsList]) { var res = dactyl.assertMessageLine(/./, "Expected command output: " + cmd); if (res && test != null) dactyl.assertMessageLine(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource()); - }, true && !params.errorsOk); + }, !params.errorsOk); break; case "multiOutput": runCommands(command, testName, commands, function (cmd, test) { var res = dactyl.assertMessageWindowOpen(true, "Expected command output: " + cmd); if (res && test != null) dactyl.assertMessageWindow(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource()); - }, true && !params.errorsOk); + }, !params.errorsOk); break; case "error": addTest(command, testName, function () { @@ -717,7 +782,7 @@ for (var val in Iterator(tests)) (function ([command, paramsList]) { }, null, [], cmd); if (res && test != null) - dactyl.runExCommand(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource()); + dactyl.assertMessage(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource()); }); }); break; @@ -730,8 +795,9 @@ for (var val in Iterator(tests)) (function ([command, paramsList]) { dactyl.assertNoErrorMessages(function () { dump("COMPL: " + cmd + "\n"); var context = dactyl.runExCompletion(cmd); - if (context && test) - jumlib.assert(test(context), "Completion tests failed: " + cmd.quote() + " " + test); + if (context) + runTest("Completion tests failed: " + cmd.quote() + " " + test, + test, context); }); }); });