mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 04:41:11 +00:00
Bug 1927609 - correctly set process priority when rapidly switching tabs r=tabbrowser-reviewers,dao
Differential Revision: https://phabricator.services.mozilla.com/D229696
This commit is contained in:
parent
7a0af5447b
commit
6c0172f049
@ -928,8 +928,8 @@ export class AsyncTabSwitcher {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the browser should be deactivated. If the browser is a print preivew or
|
||||
* PiP browser then we won't deactive it.
|
||||
* Check if the browser should be deactivated. If the browser is a print preview or
|
||||
* PiP browser then we won't deactivate it.
|
||||
* @param browser The browser to check if it should be deactivated
|
||||
* @returns false if a print preview or PiP browser else true
|
||||
*/
|
||||
@ -1061,6 +1061,15 @@ export class AsyncTabSwitcher {
|
||||
this.requestedTab = tab;
|
||||
if (tabState == this.STATE_LOADED) {
|
||||
this.maybeVisibleTabs.clear();
|
||||
// We're switching to a tab that is still loaded.
|
||||
// Make sure its priority is correct as it may
|
||||
// have been deprioritized when it was switched
|
||||
// away from (bug 1927609)
|
||||
let browser = tab.linkedBrowser;
|
||||
let remoteTab = browser.frameLoader?.remoteTab;
|
||||
if (remoteTab) {
|
||||
remoteTab.priorityHint = true;
|
||||
}
|
||||
}
|
||||
|
||||
tab.linkedBrowser.setAttribute("primary", "true");
|
||||
|
@ -993,3 +993,42 @@ add_task(async function test_tab_moved_to_new_window() {
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test that if a tab is quickly switched away from and back to, it ends up at
|
||||
* PROCESS_PRIORITY_FOREGROUND.
|
||||
* See bug 1927609.
|
||||
*/
|
||||
add_task(async function test_tab_quickly_switched() {
|
||||
let originalTab = gBrowser.selectedTab;
|
||||
let origtabID = browsingContextChildID(
|
||||
originalTab.linkedBrowser.browsingContext
|
||||
);
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
"https://example.com/browser/dom/ipc/tests/file_dummy.html",
|
||||
async browser => {
|
||||
let tab = gBrowser.getTabForBrowser(browser);
|
||||
let tabID = browsingContextChildID(tab.linkedBrowser.browsingContext);
|
||||
|
||||
// Don't use BrowserTestUtils.switchTab() because things have settled
|
||||
// by the time it's done, which doesn't expose this bug.
|
||||
gBrowser.selectedTab = originalTab;
|
||||
gBrowser.selectedTab = tab;
|
||||
await new Promise(resolve =>
|
||||
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
||||
setTimeout(resolve, WAIT_FOR_CHANGE_TIME_MS)
|
||||
);
|
||||
Assert.equal(
|
||||
gTabPriorityWatcher.currentPriority(tabID),
|
||||
PROCESS_PRIORITY_FOREGROUND,
|
||||
"Active tab should be foreground priority"
|
||||
);
|
||||
Assert.equal(
|
||||
gTabPriorityWatcher.currentPriority(origtabID),
|
||||
PROCESS_PRIORITY_BACKGROUND,
|
||||
"Inactive tab should be background priority"
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user