diff --git a/common/content/events.js b/common/content/events.js index 87f7df53..c422eaba 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -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 == "" || key == "" || key == ""); }, + 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 // diff --git a/common/content/liberator.js b/common/content/liberator.js index b905c372..8881b789 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -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)); } }, diff --git a/common/content/ui.js b/common/content/ui.js index a39b0e6f..136ba90a 100644 --- a/common/content/ui.js +++ b/common/content/ui.js @@ -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 diff --git a/vimperator/regressions.js b/vimperator/regressions.js index 0c89171c..fd866396 100644 --- a/vimperator/regressions.js +++ b/vimperator/regressions.js @@ -51,9 +51,9 @@ let tests = [ // verify: function () getOutput() == "testerr" }, { cmds: ["gg", ""], // NOTE: does not work when there is no page to scroll, we should load a large page before doing these tests verify: function () this._initialPos.y != getBufferPosition().y, - init: function () this._initialPos = getBufferPosition() } + init: function () this._initialPos = getBufferPosition() } - // testing tab behavior + // testing tab behavior ]; // these functions highly depend on the liberator API, so use ex command tests whenever possible @@ -69,10 +69,10 @@ let functions = [ function resetEnvironment() { - multilineOutput.contentDocument.body.innerHTML = ""; - singlelineOutput.value = ""; - commandline.close(); - modes.reset(); + multilineOutput.contentDocument.body.innerHTML = ""; + singlelineOutput.value = ""; + commandline.close(); + modes.reset(); } function getOutput() multilineOutput.contentDocument.body.textContent || singlelineOutput.value; @@ -84,15 +84,33 @@ function getTabCount() getBrowser().mTabs.length; function getBufferPosition() { - let win = window.content; - return { x: win.scrollMaxX ? win.pageXOffset / win.scrollMaxX : 0, - y: win.scrollMaxY ? win.pageYOffset / win.scrollMaxY : 0 } + let win = window.content; + return { x: win.scrollMaxX ? win.pageXOffset / win.scrollMaxX : 0, + y: win.scrollMaxY ? win.pageYOffset / win.scrollMaxY : 0 } }; // 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( +
{str}
, + doc)); +} +function echoMulti(str, group) +{ + if (!doc) + return; + doc.body.appendChild(util.xmlToDom(
{template.maybeXML(str)}
, + doc)); +} commands.addUserCommand(["regr[essions]"], "Run regression tests", @@ -104,17 +122,44 @@ 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(); let totalTests = tests.length + functions.length; let successfulTests = 0; - let skippedTests = 0; + let skippedTests = 0; let currentTest = 0; + init(); + // TODO: might want to unify 'tests' and 'functions' handling // 1.) run commands and mappings tests - outer: + outer: for (let [, test] in Iterator(tests)) { currentTest++; @@ -122,15 +167,15 @@ commands.addUserCommand(["regr[essions]"], continue; let testDescription = util.clip(test.cmds.join(" -> "), 80); - for (let [,cmd] in Iterator(test.cmds)) - { - if (skipTests.indexOf(cmd) != -1) - { - skippedTests++; - liberator.echomsg("Skipping test " + currentTest + " of " + totalTests + ": " + testDescription, 0); - continue outer; - } - }; + for (let [,cmd] in Iterator(test.cmds)) + { + if (skipTests.indexOf(cmd) != -1) + { + skippedTests++; + liberator.echomsg("Skipping test " + currentTest + " of " + totalTests + ": " + testDescription, 0); + continue outer; + } + }; liberator.echomsg("Running test " + currentTest + " of " + totalTests + ": " + testDescription, 0); resetEnvironment(); @@ -141,13 +186,13 @@ commands.addUserCommand(["regr[essions]"], if (cmd[0] == ":") liberator.execute(cmd); else - events.feedkeys(cmd); + events.feedkeys(cmd); }); if (!test.verify()) liberator.echoerr("Test " + currentTest + " failed: " + testDescription); else - successfulTests++; + successfulTests++; } // 2.) Run function tests @@ -166,29 +211,32 @@ commands.addUserCommand(["regr[essions]"], successfulTests++; } - let runTests = (args.count >= 1 ? 1 : totalTests) - skippedTests; - XML.ignoreWhitespace = false; - liberator.echomsg(<>{successfulTests} of {runTests} - tests successfully completed ({skippedTests} tests skipped) in - {((Date.now() - now) / 1000.0)} msec); + cleanup(); + + let runTests = (args.count >= 1 ? 1 : totalTests) - skippedTests; + XML.ignoreWhitespace = false; + liberator.echomsg(<>{successfulTests} of {runTests} + tests successfully completed ({skippedTests} tests skipped) in + {((Date.now() - now) / 1000.0)} msec); liberator.execute(":messages"); } if (!args.bang) - { - liberator.echo(<> - Running tests should always be done in a new profile.
+ { + liberator.echo(<> + Running tests should always be done in a new profile.
- 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.

+ 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.

+ - Use :regressions! to skip this prompt. - ); - commandline.input("Type 'yes' to run the tests:", function (res) { if (res == "yes") run(); } ); - return; - } - run(); + Use :regressions! to skip this prompt. + ); + commandline.input("Type 'yes' to run the tests: ", function (res) { if (res == "yes") run(); } ); + return; + } + run(); }, { bang: true, @@ -196,4 +244,4 @@ commands.addUserCommand(["regr[essions]"], count: true }); -// vimperator: set et ts=4 sw=4 : +// vimperator: set et sts=4 sw=4 :