Bug 1437295 - Ensure cleanup functions registered in a subtest are invoked when unloading the subtest. r=botond

If we are registering a cleanup function inside a subtest (as we will do
in the next patch) then we need to make sure it gets cleaned up before
the subtest is unloaded. Otherwise the cleanup will be attempted when
the top-level test page is unloaded, at which point the subtest is long
gone, and that results in an error.

MozReview-Commit-ID: 828XddkOUlP

--HG--
extra : rebase_source : a4b64d41c0dfcc27941abbff7ffbde2c69513b58
This commit is contained in:
Kartikaya Gupta 2018-03-10 23:26:27 -05:00
Родитель 3191dbda01
Коммит e29fdef19c
2 изменённых файлов: 31 добавлений и 2 удалений

Просмотреть файл

@ -197,6 +197,10 @@ function runSubtestsSeriallyInFreshWindows(aSubtests) {
function advanceSubtestExecution() {
var test = aSubtests[testIndex];
if (w) {
// Run any cleanup functions registered in the subtest
if (w.ApzCleanup) { // guard against the subtest not loading apz_test_utils.js
w.ApzCleanup.execute();
}
if (typeof test.dp_suppression != 'undefined') {
// We modified the suppression when starting the test, so now undo that.
SpecialPowers.getDOMWindowUtils(window).respectDisplayPortSuppression(!test.dp_suppression);
@ -234,6 +238,7 @@ function runSubtestsSeriallyInFreshWindows(aSubtests) {
function spawnTest(aFile) {
w = window.open('', "_blank");
w.subtestDone = advanceSubtestExecution;
w.isApzSubtest = true;
w.SimpleTest = SimpleTest;
w.is = function(a, b, msg) { return is(a, b, aFile + " | " + msg); };
w.ok = function(cond, name, diag) { return ok(cond, aFile + " | " + name, diag); };
@ -369,7 +374,7 @@ function getSnapshot(rect) {
if (typeof getSnapshot.chromeHelper == 'undefined') {
// This is the first time getSnapshot is being called; do initialization
getSnapshot.chromeHelper = SpecialPowers.loadChromeScript(parentProcessSnapshot);
SimpleTest.registerCleanupFunction(function() { getSnapshot.chromeHelper.destroy() });
ApzCleanup.register(function() { getSnapshot.chromeHelper.destroy() });
}
return getSnapshot.chromeHelper.sendSyncMessage('snapshot', JSON.stringify(rect)).toString();
@ -556,3 +561,27 @@ function hitTestScrollbar(params) {
scrollframeMsg + " - horizontal scrollbar scrollid");
}
}
var ApzCleanup = {
_cleanups: [],
register: function(func) {
if (this._cleanups.length == 0) {
if (!window.isApzSubtest) {
SimpleTest.registerCleanupFunction(this.execute.bind(this));
} // else ApzCleanup.execute is called from runSubtestsSeriallyInFreshWindows
}
this._cleanups.push(func);
},
execute: function() {
while (this._cleanups.length > 0) {
var func = this._cleanups.pop();
try {
func();
} catch (ex) {
SimpleTest.ok(false, "Subtest cleanup function [" + func.toString() + "] threw exception [" + ex + "] on page [" + location.href + "]");
}
}
}
};

Просмотреть файл

@ -76,7 +76,7 @@ function chromeTouchEventCounter(operation) {
if (typeof chromeTouchEventCounter.chromeHelper == 'undefined') {
// This is the first time chromeTouchEventCounter is being called; do initialization
chromeTouchEventCounter.chromeHelper = SpecialPowers.loadChromeScript(chromeProcessCounter);
SimpleTest.registerCleanupFunction(function() { chromeTouchEventCounter.chromeHelper.destroy() });
ApzCleanup.register(function() { chromeTouchEventCounter.chromeHelper.destroy() });
}
return chromeTouchEventCounter.chromeHelper.sendSyncMessage(operation, "");