fune/browser/base/content/test/tabs/browser_removeTabs_order.js
Gijs Kruitbosch b76ad616d1 Bug 1753696 - go back to using add_task in files that have no other tasks at all, r=Standard8
Otherwise the framework complains that there are no tests/tasks.

Differential Revision: https://phabricator.services.mozilla.com/D142441
2022-03-30 16:16:43 +00:00

38 lines
1.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
add_task(async function() {
let tab1 = await addTab();
let tab2 = await addTab();
let tab3 = await addTab();
let tabs = [tab1, tab2, tab3];
// Add a beforeunload event listener in one of the tabs; it should be called
// before closing any of the tabs.
await ContentTask.spawn(tab2.linkedBrowser, null, async function() {
content.window.addEventListener("beforeunload", function(event) {}, true);
});
let permitUnloadSpy = sinon.spy(tab2.linkedBrowser, "asyncPermitUnload");
let removeTabSpy = sinon.spy(gBrowser, "removeTab");
gBrowser.removeTabs(tabs);
Assert.ok(permitUnloadSpy.calledOnce, "permitUnload was called only once");
Assert.equal(
removeTabSpy.callCount,
tabs.length,
"removeTab was called for every tab"
);
Assert.ok(
permitUnloadSpy.lastCall.calledBefore(removeTabSpy.firstCall),
"permitUnload was called before for first removeTab call"
);
removeTabSpy.restore();
permitUnloadSpy.restore();
});