diff options
Diffstat (limited to 'devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js')
-rw-r--r-- | devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js b/devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js new file mode 100644 index 0000000000..d2a9b3d32e --- /dev/null +++ b/devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js @@ -0,0 +1,92 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests that the Web Console doesn't leak when multiple tabs and windows are +// opened and then closed. See Bug 595350. + +"use strict"; + +const TEST_URI = + "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test for bug 595350"; + +add_task(async function () { + requestLongerTimeout(3); + // Bug 1518138: GC heuristics are broken for this test, so that the test + // ends up running out of memory. Try to work-around the problem by GCing + // before the test begins. + Cu.forceShrinkingGC(); + + const win1 = window; + + info("Add test tabs in first window"); + const tab1 = await addTab(TEST_URI, { window: win1 }); + const tab2 = await addTab(TEST_URI, { window: win1 }); + info("Test tabs added in first window"); + + info("Open a second window"); + const windowOpenedPromise = BrowserTestUtils.waitForNewWindow(); + const win2 = OpenBrowserWindow(); + await windowOpenedPromise; + + info("Add test tabs in second window"); + const tab3 = await addTab(TEST_URI, { window: win2 }); + const tab4 = await addTab(TEST_URI, { window: win2 }); + + info("Opening console in each test tab"); + const tabs = [tab1, tab2, tab3, tab4]; + for (const tab of tabs) { + // Open the console in tab${i}. + const hud = await openConsole(tab); + const browser = hud.commands.descriptorFront.localTab.linkedBrowser; + const message = "message for tab " + tabs.indexOf(tab); + + // Log a message in the newly opened console. + const onMessage = waitForMessageByType(hud, message, ".console-api"); + await SpecialPowers.spawn(browser, [message], function (msg) { + content.console.log(msg); + }); + await onMessage; + + await hud.toolbox.sourceMapURLService.waitForSourcesLoading(); + } + + const onConsolesDestroyed = waitForNEvents("web-console-destroyed", 4); + + info("Close the second window"); + win2.close(); + + info("Close the test tabs in the first window"); + win1.gBrowser.removeTab(tab1); + win1.gBrowser.removeTab(tab2); + + info("Wait for 4 web-console-destroyed events"); + await onConsolesDestroyed; + + ok(true, "Received web-console-destroyed for each console opened"); +}); + +/** + * Wait for N events helper customized to work with Services.obs.add/removeObserver. + */ +function waitForNEvents(expectedTopic, times) { + return new Promise(resolve => { + let count = 0; + + function onEvent(subject, topic) { + if (topic !== expectedTopic) { + return; + } + + count++; + info(`Received ${expectedTopic} ${count} time(s).`); + if (count == times) { + resolve(); + } + } + + registerCleanupFunction(() => { + Services.obs.removeObserver(onEvent, expectedTopic); + }); + Services.obs.addObserver(onEvent, expectedTopic); + }); +} |