mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 21:37:57 +01:00
Fuck with :regressions a bit.
This commit is contained in:
@@ -559,48 +559,7 @@ function Events() //{{{
|
||||
}
|
||||
|
||||
// return true when load successful, or false otherwise
|
||||
function waitForPageLoaded()
|
||||
{
|
||||
liberator.dump("start waiting in loaded state: " + buffer.loaded);
|
||||
liberator.threadYield(true); // clear queue
|
||||
|
||||
if (buffer.loaded == 1)
|
||||
return true;
|
||||
|
||||
let start = Date.now();
|
||||
let end = start + 25000; // maximum time to wait - TODO: add option
|
||||
let now;
|
||||
while (now = Date.now(), now < end)
|
||||
{
|
||||
liberator.threadYield();
|
||||
if ((now - start) % 1000 < 10)
|
||||
liberator.dump("waited: " + (now - start) + " ms");
|
||||
|
||||
if (!events.feedingKeys)
|
||||
return false;
|
||||
|
||||
if (buffer.loaded > 0)
|
||||
{
|
||||
liberator.sleep(250);
|
||||
break;
|
||||
}
|
||||
else
|
||||
liberator.echo("Waiting for page to load...");
|
||||
}
|
||||
modes.show();
|
||||
|
||||
// TODO: allow macros to be continued when page does not fully load with an option
|
||||
var ret = (buffer.loaded == 1);
|
||||
if (!ret)
|
||||
liberator.echoerr("Page did not load completely in " + ms + " milliseconds. Macro stopped.");
|
||||
liberator.dump("done waiting: " + ret);
|
||||
|
||||
// sometimes the input widget had focus when replaying a macro
|
||||
// maybe this call should be moved somewhere else?
|
||||
// liberator.focusContent(true);
|
||||
|
||||
return ret;
|
||||
}
|
||||
function waitForPageLoaded() events.waitForPageLoaded();
|
||||
|
||||
// load all macros inside ~/.vimperator/macros/
|
||||
// setTimeout needed since io. is loaded after events.
|
||||
@@ -1051,6 +1010,49 @@ function Events() //{{{
|
||||
return (key == "<Esc>" || key == "<C-[>" || key == "<C-c>");
|
||||
},
|
||||
|
||||
waitForPageLoad: function ()
|
||||
{
|
||||
liberator.dump("start waiting in loaded state: " + buffer.loaded);
|
||||
liberator.threadYield(true); // clear queue
|
||||
|
||||
if (buffer.loaded == 1)
|
||||
return true;
|
||||
|
||||
let start = Date.now();
|
||||
let end = start + 25000; // maximum time to wait - TODO: add option
|
||||
let now;
|
||||
while (now = Date.now(), now < end)
|
||||
{
|
||||
liberator.threadYield();
|
||||
if ((now - start) % 1000 < 10)
|
||||
liberator.dump("waited: " + (now - start) + " ms");
|
||||
|
||||
if (!events.feedingKeys)
|
||||
return false;
|
||||
|
||||
if (buffer.loaded > 0)
|
||||
{
|
||||
liberator.sleep(250);
|
||||
break;
|
||||
}
|
||||
else
|
||||
liberator.echo("Waiting for page to load...");
|
||||
}
|
||||
modes.show();
|
||||
|
||||
// TODO: allow macros to be continued when page does not fully load with an option
|
||||
var ret = (buffer.loaded == 1);
|
||||
if (!ret)
|
||||
liberator.echoerr("Page did not load completely in " + ms + " milliseconds. Macro stopped.");
|
||||
liberator.dump("done waiting: " + ret);
|
||||
|
||||
// sometimes the input widget had focus when replaying a macro
|
||||
// maybe this call should be moved somewhere else?
|
||||
// liberator.focusContent(true);
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
// argument "event" is delibarately not used, as i don't seem to have
|
||||
// access to the real focus target
|
||||
//
|
||||
|
||||
@@ -635,12 +635,17 @@ const liberator = (function () //{{{
|
||||
|
||||
registerObserver: registerObserver,
|
||||
|
||||
triggerObserver: function (type, data)
|
||||
unregisterObserver: function (type, callback)
|
||||
{
|
||||
observers = observers.filter(function ([t, c]) t != type || c != callback);
|
||||
},
|
||||
|
||||
triggerObserver: function (type)
|
||||
{
|
||||
for (let [,[thistype, callback]] in Iterator(observers))
|
||||
{
|
||||
if (thistype == type)
|
||||
callback(data);
|
||||
callback.apply(null, Array.slice(arguments, 1));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -547,6 +547,8 @@ function CommandLine() //{{{
|
||||
setHighlightGroup(highlightGroup);
|
||||
messageBox.value = str;
|
||||
|
||||
liberator.triggerObserver("echoLine", str, highlightGroup, forceSingle);
|
||||
|
||||
if (!commandShown())
|
||||
commandline.hide();
|
||||
|
||||
@@ -562,6 +564,8 @@ function CommandLine() //{{{
|
||||
let doc = multilineOutputWidget.contentDocument;
|
||||
let win = multilineOutputWidget.contentWindow;
|
||||
|
||||
liberator.triggerObserver("echoMultiline", str, highlightGroup);
|
||||
|
||||
/* If it's already XML, assume it knows what it's doing.
|
||||
* Otherwise, white space is significant.
|
||||
* The problem elsewhere is that E4X tends to insert new lines
|
||||
|
||||
@@ -92,7 +92,25 @@ function getBufferPosition()
|
||||
// TODO: need to find a way to wait for page load
|
||||
function getLocation() window.content.document.location.href;
|
||||
|
||||
var doc;
|
||||
|
||||
function echoLine(str, group)
|
||||
{
|
||||
if (!doc)
|
||||
return;
|
||||
doc.body.appendChild(util.xmlToDom(
|
||||
<div highlight={group} style="border: 1px solid gray; white-space: pre">{str}</div>,
|
||||
doc));
|
||||
}
|
||||
function echoMulti(str, group)
|
||||
{
|
||||
if (!doc)
|
||||
return;
|
||||
doc.body.appendChild(util.xmlToDom(<div class="ex-command-output"
|
||||
style="white-space: nowrap; border: 1px solid black"
|
||||
highlight={group}>{template.maybeXML(str)}</div>,
|
||||
doc));
|
||||
}
|
||||
|
||||
commands.addUserCommand(["regr[essions]"],
|
||||
"Run regression tests",
|
||||
@@ -104,6 +122,31 @@ commands.addUserCommand(["regr[essions]"],
|
||||
// should only be done in a clean profile or b) run functions and not
|
||||
// just ex command tests; Yet to be decided
|
||||
|
||||
let updateOutputHeight = null;
|
||||
function init()
|
||||
{
|
||||
liberator.registerObserver("echoLine", echoLine);
|
||||
liberator.registerObserver("echoMulti", echoMulti);
|
||||
liberator.open("chrome://liberator/content/buffer.xhtml", liberator.NEW_TAB);
|
||||
events.waitForPageLoad();
|
||||
doc = content.document;
|
||||
|
||||
updateOutputHeight = commandline.updateOutputHeight;
|
||||
commandline.updateOutputHeight = function (open)
|
||||
{
|
||||
let elem = document.getElementById("liberator-multiline-output");
|
||||
if (open)
|
||||
elem.collapsed = false;
|
||||
elem.height = 0;
|
||||
};
|
||||
}
|
||||
function cleanup()
|
||||
{
|
||||
liberator.unregisterObserver("echoLine", echoLine);
|
||||
liberator.unregisterObserver("echoMulti", echoMulti);
|
||||
commandline.updateOutputHeight = updateOutputHeight;
|
||||
}
|
||||
|
||||
function run ()
|
||||
{
|
||||
let now = Date.now();
|
||||
@@ -112,6 +155,8 @@ commands.addUserCommand(["regr[essions]"],
|
||||
let skippedTests = 0;
|
||||
let currentTest = 0;
|
||||
|
||||
init();
|
||||
|
||||
// TODO: might want to unify 'tests' and 'functions' handling
|
||||
// 1.) run commands and mappings tests
|
||||
outer:
|
||||
@@ -166,6 +211,8 @@ commands.addUserCommand(["regr[essions]"],
|
||||
successfulTests++;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
let runTests = (args.count >= 1 ? 1 : totalTests) - skippedTests;
|
||||
XML.ignoreWhitespace = false;
|
||||
liberator.echomsg(<><span style="font-weight: bold">{successfulTests}</span> of <span style="font-weight: bold">{runTests}</span>
|
||||
@@ -182,6 +229,7 @@ commands.addUserCommand(["regr[essions]"],
|
||||
It should not do any harm to your profile, but your current settings like options,
|
||||
abbreviations or mappings might not be in the same state as before running the tests.
|
||||
Just make sure, you don't :mkvimperatorrc, after running the tests.<br/><br/>
|
||||
<!--' vim. -->
|
||||
|
||||
Use :regressions! to skip this prompt.
|
||||
</>);
|
||||
@@ -196,4 +244,4 @@ commands.addUserCommand(["regr[essions]"],
|
||||
count: true
|
||||
});
|
||||
|
||||
// vimperator: set et ts=4 sw=4 :
|
||||
// vimperator: set et sts=4 sw=4 :
|
||||
|
||||
Reference in New Issue
Block a user