Closed Bug 1759299 Opened 2 years ago Closed 2 years ago

replaceTabsWithWindow should take into account that adoptTab can abort

Categories

(Firefox :: Tabbed Browser, defect)

defect

Tracking

()

RESOLVED FIXED
100 Branch
Tracking Status
firefox100 --- fixed

People

(Reporter: Oriol, Assigned: Oriol)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

var triggeringPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
var tab0 = gBrowser.addTab("data:text/plain,0", {triggeringPrincipal});
var tab1 = gBrowser.addTab("data:text/plain,1", {triggeringPrincipal});
var tab2 = gBrowser.addTab("data:text/plain,2", {triggeringPrincipal});
gBrowser.selectedTab = tab2;
gBrowser.addToMultiSelectedTabs(tab0);
gBrowser.addToMultiSelectedTabs(tab1);
gBrowser.replaceTabsWithWindow(tab2);
tab0.linkedBrowser.setAttribute("remote", !tab0.linkedBrowser.isRemoteBrowser);

This code creates 3 tabs: tab0, tab1, tab2. And moved them into a new window, with the same order.

Just with a catch: the adoption of tab0 will fail because we have tampered with the remote attribute. But a failure can happen naturally due to bugs like bug 1758307.

Then the new window ends up with 2 tabs: tab2 and tab1. The order has been reversed!

That's because replaceTabsWithWindow assumes that tab adoption will always succeed, so:

  1. It creates a new window, it has a single tab, that will adopt the selected tab, tab2.
  2. Then it makes the new window adopt tab0 at index 0, but this fails.
  3. Then it makes the new window adopt tab1 at index 1, assuming that it will appear between the tab that adopted tab0 and the tab that will adopt tab2. But since tab0 was not adopted, the new window has a single tab (the one that will adopt tab2), so tab1 is adopted after it.

replaceTabsWithWindow should take into account that adoptTab can fail, and preserve the order of the tabs that can be adopted successfully.

Pushed by archaeopteryx@coole-files.de:
https://hg.mozilla.org/integration/autoland/rev/3438a6dc3bb4
Make replaceTabsWithWindow handle adoptTab failures. r=Gijs
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: