mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 21:27:58 +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:
@@ -177,7 +177,9 @@ function require(obj, name, from) {
|
||||
if (arguments.length === 1)
|
||||
[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);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
function module(uri) {
|
||||
if (!/^[a-z-]+:/.exec(uri))
|
||||
uri = /([^ ]+\/)[^\/]+$/.exec(Components.stack.filename)[1] + uri + ".jsm";
|
||||
|
||||
var utils = require("utils");
|
||||
const { module, NS } = utils;
|
||||
let obj = {};
|
||||
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 frame = module("resource://mozmill/modules/frame.js");
|
||||
@@ -175,7 +185,7 @@ Controller.prototype = {
|
||||
errorCount = this.modules.util.errorCount;
|
||||
|
||||
try {
|
||||
func.apply(self || this, args || []);
|
||||
var returnVal = func.apply(self || this, args || []);
|
||||
}
|
||||
catch (e) {
|
||||
this.modules.util.reportError(e);
|
||||
@@ -193,9 +203,11 @@ Controller.prototype = {
|
||||
var errors = this.modules.util.errors.slice(errorCount - this.modules.util.errorCount)
|
||||
.join("\n");
|
||||
|
||||
return utils.assertEqual('dactyl.assertNoErrors',
|
||||
var res = utils.assertEqual('dactyl.assertNoErrors',
|
||||
errorCount, this.modules.util.errorCount,
|
||||
"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
|
||||
* 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();
|
||||
|
||||
utils.assertEqual("dactyl.assertCommandLineFocused",
|
||||
@@ -386,7 +417,6 @@ Controller.prototype = {
|
||||
this.elements.focused,
|
||||
"Running Ex Completion: The command line is not focused");
|
||||
|
||||
// dump("runExCompletion " + cmd + "\n");
|
||||
if (true) {
|
||||
let input = this.elements.commandInput;
|
||||
input.value = cmd;
|
||||
@@ -410,6 +440,7 @@ Controller.prototype = {
|
||||
this.modules.commandline._tabTimer.flush();
|
||||
else if (this.modules.commandline.commandSession && this.modules.commandline.commandSession.completions)
|
||||
this.modules.commandline.commandSession.completions.tabTimer.flush();
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -461,6 +492,4 @@ Controller.prototype = {
|
||||
get applicationName() this.modules.config.appName // XXX
|
||||
};
|
||||
|
||||
exports.Controller = Controller;
|
||||
|
||||
// vim: sw=4 ts=8 et:
|
||||
// vim: sw=4 ts=8 et ft=javascript:
|
||||
@@ -1,9 +1,9 @@
|
||||
// Runs a slew of generic command tests
|
||||
|
||||
var dactyllib = require("dactyl");
|
||||
var utils = require("utils");
|
||||
|
||||
const { module } = utils;
|
||||
|
||||
var dactyllib = module("dactyl");
|
||||
var jumlib = module("resource://mozmill/modules/jum.js");
|
||||
|
||||
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)));
|
||||
|
||||
function sidebarState(state)
|
||||
function () typeof state == "string" ? $("#sidebar-title").value == state
|
||||
: $("#sidebar-box").hidden == state;
|
||||
function () utils.assertEqual("testCommand.sidebarState", state,
|
||||
typeof state == "string" ? $("#sidebar-title").value
|
||||
: !$("#sidebar-box").hidden);
|
||||
|
||||
var tests = {
|
||||
"!": {
|
||||
@@ -503,7 +504,7 @@ var tests = {
|
||||
"Preferences"]
|
||||
.map(this.test))
|
||||
.concat([
|
||||
["!", sidebarState("Preferences")],
|
||||
["Preferences", sidebarState("Preferences")],
|
||||
["!", sidebarState(false)]
|
||||
]),
|
||||
completions: [
|
||||
@@ -728,17 +729,9 @@ for (var val in Iterator(tests)) (function ([command, paramsList]) {
|
||||
|
||||
dactyl.assertNoErrorMessages(function () {
|
||||
dump("COMPL: " + cmd + "\n");
|
||||
dactyl.runExCompletion(cmd);
|
||||
if (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());
|
||||
var context = dactyl.runExCompletion(cmd);
|
||||
if (context && test)
|
||||
jumlib.assert(test(context), "Completion tests failed: " + cmd.quote() + " " + test);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var dactyllib = require("dactyl");
|
||||
var dactyllib = require("utils").module("dactyl");
|
||||
|
||||
var setupModule = function (module) {
|
||||
controller = mozmill.getBrowserController();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var dactyllib = require("dactyl");
|
||||
var dactyllib = require("utils").module("dactyl");
|
||||
|
||||
const FIND_TEST_PAGE = collector.addHttpResource("./data/") + "find.html";
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var jumlib = {}; Components.utils.import("resource://mozmill/modules/jum.js", jumlib);
|
||||
var dactyllib = require("dactyl");
|
||||
const { module } = require("utils");
|
||||
var jumlib = module("resource://mozmill/modules/jum.js");
|
||||
var dactyllib = module("dactyl");
|
||||
|
||||
var setupModule = function (module) {
|
||||
controller = mozmill.getBrowserController();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var dactyllib = require("dactyl");
|
||||
var dactyllib = require("utils").module("dactyl");
|
||||
|
||||
var setupModule = function (module) {
|
||||
controller = mozmill.getBrowserController();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var dactyllib = require("dactyl");
|
||||
var dactyllib = require("utils").module("dactyl");
|
||||
|
||||
var setupModule = function (module) {
|
||||
controller = mozmill.getBrowserController();
|
||||
|
||||
@@ -1,50 +1,5 @@
|
||||
function module(uri) {
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
// Work around these horrendous Sandbox issues.
|
||||
Components.utils.import(/([^ ]+\/)[^\/]+$/.exec(Components.stack.filename)[1] + "utils.jsm", exports);
|
||||
|
||||
// vim: sw=4 ts=8 et:
|
||||
|
||||
48
common/tests/functional/utils.jsm
Normal file
48
common/tests/functional/utils.jsm
Normal 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:
|
||||
Reference in New Issue
Block a user