mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 15:48:00 +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)
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,39 +389,58 @@ 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) {
|
||||||
this.setExMode();
|
|
||||||
|
|
||||||
utils.assertEqual("dactyl.assertCommandLineFocused",
|
|
||||||
this.elements.commandInput,
|
|
||||||
this.elements.focused,
|
|
||||||
"Running Ex Completion: The command line is not focused");
|
|
||||||
|
|
||||||
// dump("runExCompletion " + cmd + "\n");
|
// dump("runExCompletion " + cmd + "\n");
|
||||||
if (true) {
|
if (!longWay) {
|
||||||
let input = this.elements.commandInput;
|
var context = this.modules.CompletionContext(cmd);
|
||||||
input.value = cmd;
|
context.tabPressed = true;
|
||||||
|
context.fork("ex", 0, this.modules.completion, "ex");
|
||||||
|
|
||||||
var event = input.ownerDocument.createEvent("Events");
|
utils.assert("dactyl.runCompletions", context.wait(5000),
|
||||||
event.initEvent("change", true, false);
|
"Completion failed: " + cmd.quote());
|
||||||
input.dispatchEvent(event);
|
|
||||||
|
for (var [, ctxt] in Iterator(context.contextList))
|
||||||
|
for (var [, item] in Iterator(ctxt.items))
|
||||||
|
ctxt.createRow(item);
|
||||||
|
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.controller.type(null, cmd);
|
this.setExMode();
|
||||||
|
|
||||||
utils.assertEqual("dactyl.runExCompletion", cmd,
|
utils.assertEqual("dactyl.assertCommandLineFocused",
|
||||||
this.elements.commandInput.editor.rootElement.firstChild.textContent,
|
this.elements.commandInput,
|
||||||
"Command line does not have the expected value: " + cmd);
|
this.elements.focused,
|
||||||
|
"Running Ex Completion: The command line is not focused");
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
let input = this.elements.commandInput;
|
||||||
|
input.value = cmd;
|
||||||
|
|
||||||
|
var event = input.ownerDocument.createEvent("Events");
|
||||||
|
event.initEvent("change", true, false);
|
||||||
|
input.dispatchEvent(event);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.controller.type(null, cmd);
|
||||||
|
|
||||||
|
utils.assertEqual("dactyl.runExCompletion", cmd,
|
||||||
|
this.elements.commandInput.editor.rootElement.firstChild.textContent,
|
||||||
|
"Command line does not have the expected value: " + cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.controller.keypress(null, "VK_TAB", {});
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.controller.keypress(null, "VK_TAB", {});
|
|
||||||
|
|
||||||
// XXX
|
|
||||||
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();
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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:
|
|
||||||
@@ -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);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
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