Skip to content

Commit

Permalink
Bug 1861848, update browser_gc_schedule.js to test background tabs on…
Browse files Browse the repository at this point in the history
…ly, r=pbone

Depends on D192144

Differential Revision: https://phabricator.services.mozilla.com/D192635
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Nov 20, 2023
1 parent d7148fa commit 04c7327
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions dom/ipc/tests/browser_gc_schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ function checkAllCompleted(events, expectTabsCompleted) {
}
}

async function setupTabs(num_tabs) {
async function setupTabsAndOneForForeground(num_tabs) {
++num_tabs;
var pids = [];

const parent_pid = getProcessID();
Expand Down Expand Up @@ -151,6 +152,12 @@ async function setupTabs(num_tabs) {
pids.push(tab_pid);
}

// Since calling openNewForegroundTab several times in a row doesn't update
// process priorities correctly, we need to explicitly switch tabs.
for (let tab of tabs) {
await BrowserTestUtils.switchTab(gBrowser, tab);
}

return tabs;
}

Expand All @@ -172,6 +179,11 @@ function startNextCollection(
SpecialPowers.Cu.getJSTestingFunctions().finishgc();
});

if (tab.selected) {
// One isn't expected to use the return value with foreground tab!
return {};
}

var waitBegin = SpecialPowers.spawn(browser, [], waitForGCBegin);
var waitEnd = SpecialPowers.spawn(browser, [], waitForGCEnd);
waits.push({ promise: waitBegin, tab: tab_num, state: "begin" });
Expand All @@ -189,7 +201,7 @@ add_task(async function gcOneAtATime() {
});

const num_tabs = 12;
var tabs = await setupTabs(num_tabs);
var tabs = await setupTabsAndOneForForeground(num_tabs);

info("Tabs ready, Asking for GCs");
var waits = [];
Expand Down Expand Up @@ -220,7 +232,7 @@ add_task(async function gcAbort() {
});

const num_tabs = 2;
var tabs = await setupTabs(num_tabs);
var tabs = await setupTabsAndOneForForeground(num_tabs);

info("Tabs ready, Asking for GCs");
var waits = [];
Expand Down Expand Up @@ -263,7 +275,7 @@ add_task(async function gcJSInitiatedDuring() {
});

const num_tabs = 3;
var tabs = await setupTabs(num_tabs);
var tabs = await setupTabsAndOneForForeground(num_tabs);

info("Tabs ready, Asking for GCs");
var waits = [];
Expand Down Expand Up @@ -320,7 +332,7 @@ add_task(async function gcJSInitiatedBefore() {
});

const num_tabs = 8;
var tabs = await setupTabs(num_tabs);
var tabs = await setupTabsAndOneForForeground(num_tabs);

info("Tabs ready");
var waits = [];
Expand Down

0 comments on commit 04c7327

Please sign in to comment.