From dab394de78443070c6b31ffd2352c5ab6ccf2350 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 1 Feb 2011 00:29:21 -0500 Subject: [PATCH] Bang on tests a bit more. --- common/modules/base.jsm | 6 +- common/tests/functional/dactyl.js | 64 +++---- common/tests/functional/testCommands.js | 239 +++++++++++++++--------- common/tests/functional/utils.js | 5 +- 4 files changed, 187 insertions(+), 127 deletions(-) diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 8e0c6cc8..593b6379 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -1001,9 +1001,9 @@ var Timer = Class("Timer", { this.latest = 0; }, - notify: function (timer) { + notify: function (timer, force) { try { - if (util.rehashing || typeof util === "undefined") + if (util.rehashing || typeof util === "undefined" || !force && this.doneAt == 0) return; this._timer.cancel(); @@ -1051,7 +1051,7 @@ var Timer = Class("Timer", { flush: function (force) { if (this.doneAt == -1 || force) - this.notify(); + this.notify(null, true); } }); diff --git a/common/tests/functional/dactyl.js b/common/tests/functional/dactyl.js index f6f9fed2..0ece4c54 100644 --- a/common/tests/functional/dactyl.js +++ b/common/tests/functional/dactyl.js @@ -41,7 +41,7 @@ function Controller(controller) { * @property {object} The dactyl modules namespace, to be used * sparingly in tests. */ - this.dactyl = controller.window.dactyl.modules; + this.modules = controller.window.dactyl.modules; this.errorCount = 0; @@ -53,9 +53,9 @@ function Controller(controller) { if (/\bErrorMsg\b/.test(highlight)) self.errors.push(String(message)); } - this.dactyl.dactyl.registerObserver("beep", this._countBeep); - this.dactyl.dactyl.registerObserver("echoLine", this._countError); - this.dactyl.dactyl.registerObserver("echoMultiline", this._countError); + this.modules.dactyl.registerObserver("beep", this._countBeep); + this.modules.dactyl.registerObserver("echoLine", this._countError); + this.modules.dactyl.registerObserver("echoMultiline", this._countError); this.resetErrorCount(); } @@ -63,9 +63,9 @@ function Controller(controller) { Controller.prototype = { teardown: function () { - this.dactyl.dactyl.unregisterObserver("beep", this._countBeep); - this.dactyl.dactyl.unregisterObserver("echoLine", this._countError); - this.dactyl.dactyl.unregisterObserver("echoMultiline", this._countError); + this.modules.dactyl.unregisterObserver("beep", this._countBeep); + this.modules.dactyl.unregisterObserver("echoLine", this._countError); + this.modules.dactyl.unregisterObserver("echoMultiline", this._countError); }, beepCount: 0, @@ -172,29 +172,29 @@ Controller.prototype = { let beepCount = this.beepCount; let errorCount = this.errorCount; if (func) { - errorCount = this.dactyl.util.errorCount; + errorCount = this.modules.util.errorCount; try { func.apply(self || this, args || []); } catch (e) { - this.dactyl.util.reportError(e); + this.modules.util.reportError(e); } } if (this.beepCount > beepCount) - this.frame.log({ + frame.log({ function: "dactyl.beepMonitor", want: beepCount, got: this.beepCount, comment: "Got " + (this.beepCount - beepCount) + " beeps during execution" + msg }); - if (errorCount != this.dactyl.util.errorCount) - var errors = this.dactyl.util.errors.slice(errorCount - this.dactyl.util.errorCount) + if (errorCount != this.modules.util.errorCount) + var errors = this.modules.util.errors.slice(errorCount - this.modules.util.errorCount) .join("\n"); return utils.assertEqual('dactyl.assertNoErrors', - errorCount, this.dactyl.util.errorCount, + errorCount, this.modules.util.errorCount, "Errors were reported during the execution of this test" + msg + "\n" + errors); }, @@ -219,7 +219,7 @@ Controller.prototype = { func.apply(self || this, args || []); } catch (e) { - this.dactyl.util.reportError(e); + this.modules.util.reportError(e); } return utils.assertEqual('dactyl.assertNoErrorMessages', count, this.errors.length, @@ -232,7 +232,7 @@ Controller.prototype = { * reported during the execution of a test. */ resetErrorCount: function () { - this.errorCount = this.dactyl.util.errorCount; + this.errorCount = this.modules.util.errorCount; }, /** @@ -263,7 +263,7 @@ Controller.prototype = { * @property {string} The name of dactyl's current key handling * mode. */ - get currentMode() this.dactyl.modes.main.name, + get currentMode() this.modules.modes.main.name, /** * @property {object} A map of dactyl widgets to be used sparingly @@ -273,7 +273,7 @@ Controller.prototype = { /** * @property {HTMLInputElement} The command line's command input box */ - get commandInput() self.dactyl.commandline.widgets.active.command.inputField, + get commandInput() self.modules.commandline.widgets.active.command.inputField, /** * @property {Node|null} The currently focused node. */ @@ -281,15 +281,15 @@ Controller.prototype = { /** * @property {HTMLInputElement} The message bar's command input box */ - get message() self.dactyl.commandline.widgets.active.message, + get message() self.modules.commandline.widgets.active.message, /** * @property {Node} The multi-line output window. */ - get multiline() self.dactyl.commandline.widgets.multilineOutput, + get multiline() self.modules.commandline.widgets.multilineOutput, /** * @property {Node} The multi-line output container. */ - get multilineContainer() self.dactyl.commandline.widgets.mowContainer, + get multilineContainer() self.modules.commandline.widgets.mowContainer, }), /** @@ -297,12 +297,12 @@ Controller.prototype = { */ setNormalMode: wrapAssertNoErrors(function () { // XXX: Normal mode test - for (let i = 0; i < 15 && this.dactyl.modes.stack.length > 1; i++) + for (let i = 0; i < 15 && this.modules.modes.stack.length > 1; i++) this.controller.keypress(null, "VK_ESCAPE", {}); this.controller.keypress(null, "l", { ctrlKey: true }); - utils.assert("dactyl.setNormalMode", this.dactyl.modes.stack.length == 1, + utils.assert("dactyl.setNormalMode", this.modules.modes.stack.length == 1, "Failed to return to Normal mode"); this.assertMessageWindowOpen(false, "Returning to normal mode: Multi-line output not closed"); @@ -352,11 +352,11 @@ Controller.prototype = { try { // Force async commands to wait for their output to be ready // before returning. - this.dactyl.commandline.savingOutput = true; + this.modules.commandline.savingOutput = true; if (args) - this.dactyl.ex[cmd](args); + this.modules.ex[cmd](args); else if (true) - this.dactyl.commands.execute(cmd, null, false, null, + this.modules.commands.execute(cmd, null, false, null, { file: "[Command Line]", line: 1 }); else { var doc = this.controller.window.document; @@ -367,7 +367,7 @@ Controller.prototype = { } } finally { - this.dactyl.commandline.savingOutput = false; + this.modules.commandline.savingOutput = false; } }), @@ -406,10 +406,10 @@ Controller.prototype = { this.controller.keypress(null, "VK_TAB", {}); // XXX - if (this.dactyl.commandline._tabTimer) - this.dactyl.commandline._tabTimer.flush(); - else if (this.dactyl.commandline.commandSession && this.dactyl.commandline.commandSession.completions) - this.dactyl.commandline.commandSession.completions.tabTimer.flush(); + if (this.modules.commandline._tabTimer) + this.modules.commandline._tabTimer.flush(); + else if (this.modules.commandline.commandSession && this.modules.commandline.commandSession.completions) + this.modules.commandline.commandSession.completions.tabTimer.flush(); }), /** @@ -436,7 +436,7 @@ Controller.prototype = { * Opens the output message window by echoing a single newline character. */ openMessageWindow: wrapAssertNoErrors(function () { - this.dactyl.dactyl.echo("\n"); + this.modules.dactyl.echo("\n"); }, "Opening message window"), /** @@ -458,7 +458,7 @@ Controller.prototype = { /** * @property {string} The specific Dactyl application. Eg. Pentadactyl */ - get applicationName() this.dactyl.config.appName // XXX + get applicationName() this.modules.config.appName // XXX }; exports.Controller = Controller; diff --git a/common/tests/functional/testCommands.js b/common/tests/functional/testCommands.js index 356dfaf3..44e98a89 100644 --- a/common/tests/functional/testCommands.js +++ b/common/tests/functional/testCommands.js @@ -1,15 +1,19 @@ // Runs a slew of generic command tests var dactyllib = require("dactyl"); +var utils = require("utils"); + +const { module } = utils; +var jumlib = module("resource://mozmill/modules/jum.js"); var setupModule = function (module) { controller = mozmill.getBrowserController(); dactyl = new dactyllib.Controller(controller); - dactyl.dactyl.options["autocomplete"] = []; - dactyl.dactyl.options["wildmode"] = ["list"]; + dactyl.modules.options["autocomplete"] = []; + dactyl.modules.options["wildmode"] = ["list"]; - dactyl.dactyl.prefs.set("browser.tabs.closeWindowWithLastTab", false); + dactyl.modules.prefs.set("browser.tabs.closeWindowWithLastTab", false); }; var teardownModule = function (module) { dactyl.teardown(); @@ -118,8 +122,13 @@ var tests = { multiOutput: ["", "dactyl", "dactyl"] }, echo: { - singleOutput: ["' - '"], - multiOutput: ["'\\n'", "window"], + singleOutput: [ + ["' - '", " - "] + ], + multiOutput: [ + ["'\\n'", /\n/], + ["window", /\[object\sChromeWindow\]/] + ], completions: [ "", "window", @@ -145,16 +154,22 @@ var tests = { noOutput: ["", "'js " + "".quote() + "'"], someOutput: ["'ls'"] }, - extadd: { error: [""] }, - extdelete: { error: [""] }, - extdisable: { error: [""] }, - extenable: { error: [""] }, - extoptions: { error: [""] }, - extrehash: { error: [""] }, - exttoggle: { error: [""] }, - extupdate: { error: [""] }, + extadd: { + completions: [""], + error: [""] + }, + extdelete: { + completions: [""], + error: [""] + }, + get extdisable() this.extdelete, + get extenable() this.extdelete, + get extoptions() this.extdelete, + get extrehash() this.extdelete, + get exttoggle() this.extdelete, + get extupdate() this.extdelete, feedkeys: { - noOutput: [""], + noOutput: [""], error: [""] }, finish: { noOutput: [""] }, @@ -223,7 +238,7 @@ var tests = { loadplugins: {}, macros: { multiOutput: [""], - complete: [""] + completeions: [""] }, map: { multiOutput: ["", "i"], @@ -240,7 +255,7 @@ var tests = { "-mode=some-nonexistent-mode ", "-gtroup=some-nonexistent-group " ], - complete: [ + completeions: [ "", "-", "-mode=ex ", @@ -253,7 +268,7 @@ var tests = { }, mapclear: { noOutput: [""], - complete: [""] + completeions: [""] }, mapgroup: { multiOutput: [""], @@ -267,7 +282,7 @@ var tests = { "some-nonexistent-group", "foo -d='foo group' -nopersist 'bar.com,http://bar/*,http://bar,^http:'" ], - complete: [ + completeions: [ "", "foo " ], @@ -276,13 +291,13 @@ var tests = { mark: { error: ["", "#", "xy"], noOutput: ["y"], - complete: [""] + completeions: [""] }, marks: { init: ["delmarks q"], multiOutput: ["", "y"], error: ["q", "#"], - complete: [""] + completeions: [""] }, messages: { anyOutput: ["messages"] @@ -297,7 +312,7 @@ var tests = { "! some-nonexistent-rc.penta" ], error: ["some-nonexistent-rc.penta"], - complete: [""], + completeions: [""], cleanup: ["silent !rm some-nonexistent-rc.penta"] }, mksyntax: { @@ -311,7 +326,7 @@ var tests = { "some-nonexistent-pentadactyl-dir/", "some-nonexistent-pentadactyl-dir/foo.vim" ], - complete: [""], + completeions: [""], cleanup: ["silent !rm -r some-nonexistent-pentadactyl-dir/"] }, normal: { @@ -321,7 +336,7 @@ var tests = { }, open: { noOutput: ["about:blank | about:home"], - complete: [ + completions: [ "", "./", "./ | ", @@ -335,11 +350,11 @@ var tests = { }, pageinfo: { multiOutput: ["", "fgm"], - complete: [""], + completions: [""], error: ["abcdefghijklmnopqrstuvwxyz", "f g m"] }, pagestyle: { - complete: [""] + completions: [""] }, preferences: {}, // Skip for now pwd: { @@ -351,15 +366,19 @@ var tests = { "m foo bar" ], error: ["", "#"], - complete: ["", "m "] - }, - qmarks: { - // init: ["delqmarks a-zA-Z0-9"], - // error: ["", "x"], - init: ["qmark x"], - multiOutput: ["", "m", "x"], - complete: [""] + completions: ["", "m "] }, + qmarks: [ + { + init: ["delqmarks a-zA-Z0-9"], + error: ["", "x"], + }, + { + init: ["qmark x"], + multiOutput: ["", "m", "x"], + completions: [""] + } + ], quit: {}, // Skip for now quitall: {}, // Skip for now redraw: { @@ -392,13 +411,21 @@ var tests = { "some-nonexistent/bad.penta" ], singleOutput: ["some-nonexistent-file.js"], - complete: [ + completions: [ "", "plugins/", "info/" ] }, - sanitize: {}, + sanitize: { + // Skip details for now. + completions: [ + "", + "-", + "-host=", + "-timespan=" + ] + }, saveas: {}, sbclose: { noOutput: [""] @@ -478,8 +505,10 @@ function addTest(cmdName, testName, func) { function runCommands(cmdName, testName, commands, test, forbidErrors) { addTest(cmdName, testName, function () { - commands.forEach(function (cmd) { - // dump("CMD: " + cmdName + " " + cmd + "\n"); + commands.forEach(function (val) { + var [cmd, testVal] = Array.concat(val); + + // dump("CMD: " + testName + " " + cmdName + " " + cmd + "\n"); dactyl.clearMessage(); dactyl.closeMessageWindow(); @@ -491,74 +520,104 @@ function runCommands(cmdName, testName, commands, test, forbidErrors) { dactyl.runExCommand(cmd); controller.waitForPageLoad(controller.tabs.activeTab); - test(cmd); + test(cmd, testVal); }); }); } function _runCommands(cmdName, testName, commands) { addTest(cmdName, testName, function () { - commands.forEach(function (cmd) { - dactyl.runExCommand(cmd); + commands.forEach(function (value) { + var [cmd, test] = Array.concat(value); + + // 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); }); }); } -for (var val in Iterator(tests)) (function ([command, params]) { - if (params.init) - _runCommands(command, "init", params.init, function () {}); +for (var val in Iterator(tests)) (function ([command, paramsList]) { + Array.concat(paramsList).forEach(function (params, i) { + if (params.init) + _runCommands(command, "init" + (i || ""), params.init); - // Goddamn stupid fucking MozMill and its stupid fucking sandboxes with their ancient fucking JS versions. - for (var val in Iterator(params)) (function ([testName, commands]) { - switch (testName) { - case "noOutput": - runCommands(command, testName, commands, function (cmd) { - dactyl.assertMessage(function (msg) !msg, "Unexpected command output: " + cmd); - }); - break; - case "anyOutput": - runCommands(command, testName, commands, function (cmd) {}); - break; - case "someOutput": - runCommands(command, testName, commands, function (cmd) { - dactyl.assertMessage(/./, "Expected command output: " + cmd); - }); - break; - case "singleOutput": - runCommands(command, testName, commands, function (cmd) { - dactyl.assertMessageLine(/./, "Expected command output: " + cmd); - }, true && !params.errorsOk); - break; - case "multiOutput": - runCommands(command, testName, commands, function (cmd) { - dactyl.assertMessageWindowOpen(true, "Expected command output: " + cmd); - }, true && !params.errorsOk); - break; - case "error": - addTest(command, testName, function () { - commands.forEach(function (cmd) { - cmd = command + cmd.replace(/^(!?) ?/, "$1 "); - dactyl.assertMessageError(function () { - dactyl.runExCommand(cmd); - controller.waitForPageLoad(controller.tabs.activeTab); - }, null, [], cmd); + // Goddamn stupid fucking MozMill and its stupid fucking sandboxes with their ancient fucking JS versions. + for (var val in Iterator(params)) (function ([test, commands]) { + var testName = test + (i || ""); + + switch (test) { + case "noOutput": + runCommands(command, testName, commands, function (cmd, test) { + var res = dactyl.assertMessage(function (msg) !msg, "Unexpected command output: " + cmd); + if (res && test) + jumlib.assert(test(), "Initializing for " + cmdName + " tests failed: " + cmd.quote() + " " + test); }); - }); - break; - case "completions": - addTest(command, testName, function () { - commands.forEach(function (cmd) { - dactyl.assertNoErrorMessages(function () { - dactyl.runExCompletion(command + cmd.replace(/^(!?) ?/, "$1 ")); + break; + case "anyOutput": + runCommands(command, testName, commands, function (cmd, test) { + if (test) + jumlib.assert(test(), "Initializing for " + cmdName + " tests failed: " + cmd.quote() + " " + test); + }); + break; + case "someOutput": + runCommands(command, testName, commands, function (cmd, test) { + var res = dactyl.assertMessage(/./, "Expected command output: " + cmd); + if (res && res && test != null) + dactyl.assertMessage(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource()); + }); + break; + case "singleOutput": + runCommands(command, testName, commands, function (cmd, test) { + 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); + 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); + break; + case "error": + addTest(command, testName, function () { + commands.forEach(function (val) { + var [cmd, test] = Array.concat(val); + cmd = command + cmd.replace(/^(!?) ?/, "$1 "); + + var res = dactyl.assertMessageError(function () { + dactyl.runExCommand(cmd); + controller.waitForPageLoad(controller.tabs.activeTab); + }, null, [], cmd); + + if (res && test != null) + dactyl.runExCommand(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource()); }); }); - }); - break; - } - })(val); + break; + case "completions": + addTest(command, testName, function () { + commands.forEach(function (val) { + var [cmd, test] = Array.concat(val); - if (params.cleanup) - _runCommands(command, "cleanup", params.cleanup, function () {}); + dactyl.assertNoErrorMessages(function () { + dactyl.runExCompletion(command + cmd.replace(/^(!?) ?/, "$1 ")); + if (test) + jumlib.assert(test(dactyl.modules.commandline.commandSession.completions.context), + "Initializing for " + cmdName + " tests failed: " + cmd.quote() + " " + test); + }); + }); + }); + break; + } + })(val); + + if (params.cleanup) + _runCommands(command, "cleanup" + (i || ""), params.cleanup); + }); })(val); // vim: sw=4 ts=8 et: diff --git a/common/tests/functional/utils.js b/common/tests/functional/utils.js index b5fa59f0..2de22ac9 100644 --- a/common/tests/functional/utils.js +++ b/common/tests/functional/utils.js @@ -11,8 +11,9 @@ var jumlib = module("resource://mozmill/modules/jum.js"); function toJSON(val) { if (typeof val == "function") return val.toSource(); - else - return val; + if (val instanceof Ci.nsIDOMNode || val instanceof Ci.nsIDOMWindow) + return { DOMNode: String(val) }; + return val; } function test(val, params) {