Bug 1285373 P3 Test that sdk/event/chrome observer channels can be GC'd. r=gabor

This commit is contained in:
Ben Kelly 2016-07-20 06:47:23 -07:00
Родитель ac08e4b7de
Коммит 40b908d4b7
3 изменённых файлов: 43 добавлений и 0 удалений

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

@ -4,3 +4,4 @@ support-files =
[test-leak-window-events.js]
[test-leak-event-dom-closed-window.js]
[test-leak-event-chrome.js]

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

@ -31,6 +31,7 @@ function gc() {
Cu.schedulePreciseGC(genGCCallback());
});
}
exports.gc = gc;
// Execute the given test function and verify that we did not leak windows
// in the process. The test function must return a promise or be a generator.

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

@ -0,0 +1,41 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';
const { gc } = require("./leak-utils");
const { Loader } = require("sdk/test/loader");
const { Cu } = require("chrome");
const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
exports["test sdk/event/chrome does not leak when not referenced"] = function*(assert) {
let loader = Loader(module);
let { observe } = loader.require("sdk/event/chrome");
let { on } = loader.require("sdk/event/core");
let gotFooEvent = false;
on(observe("test-foo"), "data", function(evt) {
gotFooEvent = true;
});
let bar = observe("test-bar");
let barPromise = new Promise(resolve => {
on(bar, "data", function(evt) {
assert.ok(!gotFooEvent, "should not have gotten test-foo event");
resolve();
});
});
// This should clear the test-foo observer channel because we are not
// holding a reference to it above.
yield gc();
Services.obs.notifyObservers(null, "test-foo", null);
Services.obs.notifyObservers(null, "test-bar", null);
yield barPromise;
loader.unload();
}
require("sdk/test").run(exports);