I've recently fought my way through a bunch of intermittent test failures in the Add-on Manager mochitest-browser suite, and there's a common anti-pattern where tests receive a Window callback, usually "unload", and proceed to do significant work inside that event handler (e.g. opening/closing/focusing other windows; see one detailed case at https://bugzilla.mozilla.org/show_bug.cgi?id=608820#c281).
The 'unload' event is signalled before the window is completely unloaded; I don't know the fine details but the stack is in a state where other window operations sometimes fail. Specifically, I found it a bit surprising that the "run_next_test()" function in the async test harness starts the next test immediately on top of the current JS stack, inside whatever callbacks are currently in progress. I just filed bug 1007906 proposing that we modify the run_next_test function in the mochitest framework to always schedule the next test for a future spin of the event loop, to allow the stack to unwind - the xpcshell test harness already does this, see http://dxr.mozilla.org/mozilla-central/source/testing/xpcshell/head.js#1443. We should also update the MDN documentation about writing mochitests to strongly advise making all DOM and Window callback listeners as small as possible; my preference is to advocate using Promises as callback listeners, because stack is always unwound before the .next handler is invoked. - irving - _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform