1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-16 03:33:32 +01:00

More testing stuff.

This commit is contained in:
Kris Maglione
2011-02-03 05:17:02 -05:00
parent b10e4e4b3a
commit 11a6a7a31b
3 changed files with 89 additions and 21 deletions

2
common/bootstrap.js vendored
View File

@@ -85,9 +85,7 @@ function startup(data, reason) {
addonData = data; addonData = data;
addon = data; addon = data;
dump("dactyl: bootstrap: pre-getAddonByID\n");
AddonManager.getAddonByID(addon.id, function (a) { AddonManager.getAddonByID(addon.id, function (a) {
dump("dactyl: bootstrap: getAddonByID: " + a + "\n");
addon = a; addon = a;
updateVersion(); updateVersion();
}); });

View File

@@ -23,12 +23,16 @@ function wrapAssertNoErrors(func, message) {
function assertMessage(funcName, want, got, message) { function assertMessage(funcName, want, got, message) {
if (typeof want === "string") if (typeof want === "string")
return utils.assertEqual(funcName, want, got, message); return utils.assertEqual(funcName, want, got, message);
else if (typeof want === "function") else if (typeof want === "function") {
return utils.test(want(got), { var res = want(got);
if (res === undefined)
return true;
return utils.test(res, {
function: funcName, function: funcName,
want: want, got: got, want: want, got: got,
comment: message comment: message
}); });
}
else else
return utils.test(want.test(got), { return utils.test(want.test(got), {
function: funcName, function: funcName,

View File

@@ -14,14 +14,19 @@ var setupModule = function (module) {
dactyl.modules.options["wildmode"] = ["list"]; dactyl.modules.options["wildmode"] = ["list"];
dactyl.modules.prefs.set("browser.tabs.closeWindowWithLastTab", false); dactyl.modules.prefs.set("browser.tabs.closeWindowWithLastTab", false);
dactyl.elements.multilineContainer.setAttribute("moz-collapsed", "true");
}; };
var teardownModule = function (module) { var teardownModule = function (module) {
dactyl.elements.multilineContainer.removeAttribute("moz-collapsed");
dactyl.teardown(); dactyl.teardown();
} }
function $(selector) controller.window.document.querySelector(selector); 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; 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))); !context.allItems.items.some(function ({ text, description }) [text, description].some(function (text) /^\[object/.test(text)));
function sidebarState(state) function sidebarState(state)
function () utils.assertEqual("testCommand.sidebarState", state, function sidebarState() {
typeof state == "string" ? $("#sidebar-title").value utils.assertEqual("testCommand.sidebarState", state,
: !$("#sidebar-box").hidden); typeof state == "string" ? $("#sidebar-title").value
: !$("#sidebar-box").hidden);
};
function toolbarState(selector, state)
function toolbarState() {
utils.assertEqual("testCommand.toolbarState", state, !$(selector).collapsed)
};
var tests = { var tests = {
"!": { "!": {
@@ -128,7 +139,7 @@ var tests = {
}, },
delbmarks: { anyOutput: ["", "about:pentadactyl"] }, delbmarks: { anyOutput: ["", "about:pentadactyl"] },
delcommand: { delcommand: {
noOutput: ["foo"] noOutput: ["foo"] // TODO: Why is this failing? "Unexpected command output: delcommand foo"
}, },
delmacros: { delmacros: {
error: [""], error: [""],
@@ -600,9 +611,36 @@ var tests = {
tabprevious: {}, tabprevious: {},
tabrewind: {}, tabrewind: {},
time: {}, time: {},
toolbarhide: {}, toolbarhide: {
toolbarshow: {}, init: [
toolbartoggle: {}, ["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: {}, tunmap: {},
unabbreviate: {}, unabbreviate: {},
undo: {}, undo: {},
@@ -610,14 +648,34 @@ var tests = {
unlet: {}, unlet: {},
unmap: {}, unmap: {},
verbose: {}, verbose: {},
version: {}, version: {
multiOutput: [
["", function (msg) {
var res = /(\w+dactyl) (\S+) \(([\^)]+)\) running on:\nMozilla/;
return res && res[2] != "null" && res[3] != "null";
}]
]
},
viewsource: {}, viewsource: {},
winclose: {}, winclose: {},
window: {}, window: {},
winonly: {}, winonly: {},
winopen: {}, winopen: {},
wqall: {}, wqall: {},
yank: {}, yank: {
multiOutput: [
["foo".quote(), /foo/],
[":echo " + "bar".quote(), /bar/],
[":addons", /Pentadactyl/]
],
error: [
":echoerr " + "foo".quote()
],
completions: [
["", hasItems],
[":", hasItems]
]
},
zoom: {} zoom: {}
}; };
@@ -655,12 +713,19 @@ function _runCommands(cmdName, testName, commands) {
dump("CMD: " + testName + " " + cmdName + " " + cmd + "\n"); dump("CMD: " + testName + " " + cmdName + " " + cmd + "\n");
var res = dactyl.runExCommand(cmd); var res = dactyl.runExCommand(cmd);
controller.waitForPageLoad(controller.tabs.activeTab); controller.waitForPageLoad(controller.tabs.activeTab);
if (test) runTest("Initializing for " + cmdName + " tests failed: " + cmd.quote() + " " + test,
jumlib.assert(test(), "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]) { for (var val in Iterator(tests)) (function ([command, paramsList]) {
Array.concat(paramsList).forEach(function (params, i) { Array.concat(paramsList).forEach(function (params, i) {
if (params.init) if (params.init)
@@ -696,14 +761,14 @@ for (var val in Iterator(tests)) (function ([command, paramsList]) {
var res = dactyl.assertMessageLine(/./, "Expected command output: " + cmd); var res = dactyl.assertMessageLine(/./, "Expected command output: " + cmd);
if (res && test != null) if (res && test != null)
dactyl.assertMessageLine(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource()); dactyl.assertMessageLine(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource());
}, true && !params.errorsOk); }, !params.errorsOk);
break; break;
case "multiOutput": case "multiOutput":
runCommands(command, testName, commands, function (cmd, test) { runCommands(command, testName, commands, function (cmd, test) {
var res = dactyl.assertMessageWindowOpen(true, "Expected command output: " + cmd); var res = dactyl.assertMessageWindowOpen(true, "Expected command output: " + cmd);
if (res && test != null) if (res && test != null)
dactyl.assertMessageWindow(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource()); dactyl.assertMessageWindow(test, "Running " + testName + " tests failed: " + cmd.quote() + " " + test.toSource());
}, true && !params.errorsOk); }, !params.errorsOk);
break; break;
case "error": case "error":
addTest(command, testName, function () { addTest(command, testName, function () {
@@ -717,7 +782,7 @@ for (var val in Iterator(tests)) (function ([command, paramsList]) {
}, null, [], cmd); }, null, [], cmd);
if (res && test != null) 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; break;
@@ -730,8 +795,9 @@ for (var val in Iterator(tests)) (function ([command, paramsList]) {
dactyl.assertNoErrorMessages(function () { dactyl.assertNoErrorMessages(function () {
dump("COMPL: " + cmd + "\n"); dump("COMPL: " + cmd + "\n");
var context = dactyl.runExCompletion(cmd); var context = dactyl.runExCompletion(cmd);
if (context && test) if (context)
jumlib.assert(test(context), "Completion tests failed: " + cmd.quote() + " " + test); runTest("Completion tests failed: " + cmd.quote() + " " + test,
test, context);
}); });
}); });
}); });