1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 18:47:59 +01:00

Manually run Ex completers rather than pushing them through the

command line machinery. It's orders of magnitude faster, on the one
hand, but also runs the display machinery for all results, which may
catch more errors. Errors in the command line completion machinery
should be tested elsewhere.

Fix some sidebar test bugs.

Move dactyl.js and utils.js files out of sandboxes and into modules
so we can pass XML objects in and out of them.

--HG--
rename : common/tests/functional/dactyl.js => common/tests/functional/dactyl.jsm
rename : common/tests/functional/utils.js => common/tests/functional/utils.jsm
This commit is contained in:
Kris Maglione
2011-02-02 22:01:49 -05:00
parent 2e91c2a3cb
commit f3e510837d
10 changed files with 132 additions and 104 deletions

View File

@@ -177,7 +177,9 @@ function require(obj, name, from) {
if (arguments.length === 1) if (arguments.length === 1)
[obj, name] = [{}, obj]; [obj, name] = [{}, obj];
defineModule.loadLog.push((from || "require") + ": loading " + name + " into " + obj.NAME); if (!loaded[name])
defineModule.loadLog.push((from || "require") + ": loading " + name + (obj.NAME ? " into " + obj.NAME : ""));
JSMLoader.load(name + ".jsm", obj); JSMLoader.load(name + ".jsm", obj);
return obj; return obj;
} }

View File

@@ -1,6 +1,16 @@
function module(uri) {
if (!/^[a-z-]+:/.exec(uri))
uri = /([^ ]+\/)[^\/]+$/.exec(Components.stack.filename)[1] + uri + ".jsm";
var utils = require("utils"); let obj = {};
const { module, NS } = utils; Components.utils.import(uri, obj);
return obj;
}
var EXPORTED_SYMBOLS = ["Controller"];
var utils = module("utils");
const { NS } = utils;
var elementslib = module("resource://mozmill/modules/elementslib.js"); var elementslib = module("resource://mozmill/modules/elementslib.js");
var frame = module("resource://mozmill/modules/frame.js"); var frame = module("resource://mozmill/modules/frame.js");
@@ -175,7 +185,7 @@ Controller.prototype = {
errorCount = this.modules.util.errorCount; errorCount = this.modules.util.errorCount;
try { try {
func.apply(self || this, args || []); var returnVal = func.apply(self || this, args || []);
} }
catch (e) { catch (e) {
this.modules.util.reportError(e); this.modules.util.reportError(e);
@@ -193,9 +203,11 @@ Controller.prototype = {
var errors = this.modules.util.errors.slice(errorCount - this.modules.util.errorCount) var errors = this.modules.util.errors.slice(errorCount - this.modules.util.errorCount)
.join("\n"); .join("\n");
return utils.assertEqual('dactyl.assertNoErrors', var res = utils.assertEqual('dactyl.assertNoErrors',
errorCount, this.modules.util.errorCount, errorCount, this.modules.util.errorCount,
"Errors were reported during the execution of this test" + msg + "\n" + errors); "Errors were reported during the execution of this test" + msg + "\n" + errors);
return returnVal === undefined ? res : returnVal;
}, },
/** /**
@@ -377,8 +389,27 @@ Controller.prototype = {
* *
* @param {string} cmd The Ex command string as entered on the command * @param {string} cmd The Ex command string as entered on the command
* line. * line.
* @param {boolean} longWay Whether to test the completion by
* entering it into the command line and dispatching a <Tab> key
* press.
*/ */
runExCompletion: wrapAssertNoErrors(function (cmd) { runExCompletion: wrapAssertNoErrors(function (cmd, longWay) {
// dump("runExCompletion " + cmd + "\n");
if (!longWay) {
var context = this.modules.CompletionContext(cmd);
context.tabPressed = true;
context.fork("ex", 0, this.modules.completion, "ex");
utils.assert("dactyl.runCompletions", context.wait(5000),
"Completion failed: " + cmd.quote());
for (var [, ctxt] in Iterator(context.contextList))
for (var [, item] in Iterator(ctxt.items))
ctxt.createRow(item);
return context;
}
else {
this.setExMode(); this.setExMode();
utils.assertEqual("dactyl.assertCommandLineFocused", utils.assertEqual("dactyl.assertCommandLineFocused",
@@ -386,7 +417,6 @@ Controller.prototype = {
this.elements.focused, this.elements.focused,
"Running Ex Completion: The command line is not focused"); "Running Ex Completion: The command line is not focused");
// dump("runExCompletion " + cmd + "\n");
if (true) { if (true) {
let input = this.elements.commandInput; let input = this.elements.commandInput;
input.value = cmd; input.value = cmd;
@@ -410,6 +440,7 @@ Controller.prototype = {
this.modules.commandline._tabTimer.flush(); this.modules.commandline._tabTimer.flush();
else if (this.modules.commandline.commandSession && this.modules.commandline.commandSession.completions) else if (this.modules.commandline.commandSession && this.modules.commandline.commandSession.completions)
this.modules.commandline.commandSession.completions.tabTimer.flush(); this.modules.commandline.commandSession.completions.tabTimer.flush();
}
}), }),
/** /**
@@ -461,6 +492,4 @@ Controller.prototype = {
get applicationName() this.modules.config.appName // XXX get applicationName() this.modules.config.appName // XXX
}; };
exports.Controller = Controller; // vim: sw=4 ts=8 et ft=javascript:
// vim: sw=4 ts=8 et:

View File

@@ -1,9 +1,9 @@
// Runs a slew of generic command tests // Runs a slew of generic command tests
var dactyllib = require("dactyl");
var utils = require("utils"); var utils = require("utils");
const { module } = utils; const { module } = utils;
var dactyllib = module("dactyl");
var jumlib = module("resource://mozmill/modules/jum.js"); var jumlib = module("resource://mozmill/modules/jum.js");
var setupModule = function (module) { var setupModule = function (module) {
@@ -29,8 +29,9 @@ 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 () typeof state == "string" ? $("#sidebar-title").value == state function () utils.assertEqual("testCommand.sidebarState", state,
: $("#sidebar-box").hidden == state; typeof state == "string" ? $("#sidebar-title").value
: !$("#sidebar-box").hidden);
var tests = { var tests = {
"!": { "!": {
@@ -503,7 +504,7 @@ var tests = {
"Preferences"] "Preferences"]
.map(this.test)) .map(this.test))
.concat([ .concat([
["!", sidebarState("Preferences")], ["Preferences", sidebarState("Preferences")],
["!", sidebarState(false)] ["!", sidebarState(false)]
]), ]),
completions: [ completions: [
@@ -728,17 +729,9 @@ for (var val in Iterator(tests)) (function ([command, paramsList]) {
dactyl.assertNoErrorMessages(function () { dactyl.assertNoErrorMessages(function () {
dump("COMPL: " + cmd + "\n"); dump("COMPL: " + cmd + "\n");
dactyl.runExCompletion(cmd); var context = dactyl.runExCompletion(cmd);
if (test) { if (context && test)
/* Freezes. :(
var context = dactyl.modules.commandline.commandSession.completions.context;
*/
var context = dactyl.modules.CompletionContext(cmd);
context.tabPressed = true;
context.fork("ex", 0, dactyl.modules.completion, "ex");
jumlib.assert(context.wait(5000), "Completion failed: " + cmd.quote());
jumlib.assert(test(context), "Completion tests failed: " + cmd.quote() + " " + test); jumlib.assert(test(context), "Completion tests failed: " + cmd.quote() + " " + test);
}
}); });
}); });
}); });

View File

@@ -1,4 +1,4 @@
var dactyllib = require("dactyl"); var dactyllib = require("utils").module("dactyl");
var setupModule = function (module) { var setupModule = function (module) {
controller = mozmill.getBrowserController(); controller = mozmill.getBrowserController();

View File

@@ -1,4 +1,4 @@
var dactyllib = require("dactyl"); var dactyllib = require("utils").module("dactyl");
const FIND_TEST_PAGE = collector.addHttpResource("./data/") + "find.html"; const FIND_TEST_PAGE = collector.addHttpResource("./data/") + "find.html";

View File

@@ -1,5 +1,6 @@
var jumlib = {}; Components.utils.import("resource://mozmill/modules/jum.js", jumlib); const { module } = require("utils");
var dactyllib = require("dactyl"); var jumlib = module("resource://mozmill/modules/jum.js");
var dactyllib = module("dactyl");
var setupModule = function (module) { var setupModule = function (module) {
controller = mozmill.getBrowserController(); controller = mozmill.getBrowserController();

View File

@@ -1,4 +1,4 @@
var dactyllib = require("dactyl"); var dactyllib = require("utils").module("dactyl");
var setupModule = function (module) { var setupModule = function (module) {
controller = mozmill.getBrowserController(); controller = mozmill.getBrowserController();

View File

@@ -1,4 +1,4 @@
var dactyllib = require("dactyl"); var dactyllib = require("utils").module("dactyl");
var setupModule = function (module) { var setupModule = function (module) {
controller = mozmill.getBrowserController(); controller = mozmill.getBrowserController();

View File

@@ -1,50 +1,5 @@
function module(uri) {
let obj = {};
Components.utils.import(uri, obj);
return obj;
}
var elementslib = module("resource://mozmill/modules/elementslib.js"); // Work around these horrendous Sandbox issues.
var frame = module("resource://mozmill/modules/frame.js"); Components.utils.import(/([^ ]+\/)[^\/]+$/.exec(Components.stack.filename)[1] + "utils.jsm", exports);
var jumlib = module("resource://mozmill/modules/jum.js");
function toJSON(val) {
if (typeof val == "function")
return val.toSource();
if (val instanceof Ci.nsIDOMNode || val instanceof Ci.nsIDOMWindow)
return { DOMNode: String(val) };
return val;
}
function test(val, params) {
frame.events[val ? "pass" : "fail"](params);
return val;
}
for (var [k, v] in Iterator({
NS: Namespace("dactyl", "http://vimperator.org/namespaces/liberator"),
module: module,
toJSON: toJSON,
test: test,
assert: function (funcName, value, comment)
test(value, {
function: funcName,
value: toJSON(value),
comment: toJSON(comment)
}),
assertEqual: function (funcName, want, got, comment)
test(want == got, {
function: funcName,
want: toJSON(want), got: toJSON(got),
comment: toJSON(comment)
})
}))
exports[k] = v;
// vim: sw=4 ts=8 et: // vim: sw=4 ts=8 et:

View File

@@ -0,0 +1,48 @@
var EXPORTED_SYMBOLS = ["NS", "assert", "assertEqual", "module", "test", "toJSON"];
const Ci = Components.interfaces;
function module(uri) {
if (!/^[a-z-]+:/.exec(uri))
uri = /([^ ]+\/)[^\/]+$/.exec(Components.stack.filename)[1] + uri + ".jsm";
let obj = {};
Components.utils.import(uri, obj);
return obj;
}
var elementslib = module("resource://mozmill/modules/elementslib.js");
var frame = module("resource://mozmill/modules/frame.js");
var jumlib = module("resource://mozmill/modules/jum.js");
function toJSON(val) {
if (typeof val == "function")
return val.toSource();
if (val instanceof Ci.nsIDOMNode || val instanceof Ci.nsIDOMWindow)
return { DOMNode: String(val) };
return val;
}
function test(val, params) {
frame.events[val ? "pass" : "fail"](params);
return val;
}
var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator");
function assert(funcName, value, comment)
test(value, {
function: funcName,
value: toJSON(value),
comment: toJSON(comment)
});
function assertEqual(funcName, want, got, comment)
test(want == got, {
function: funcName,
want: toJSON(want), got: toJSON(got),
comment: toJSON(comment)
});
// vim: sw=4 ts=8 et ft=javascript: