tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 15684d6c231c73d8d6874965e6be120f4b65f404
parent b155d5523cd205b7e87fb21ed856710d9101120a
Author: Stephen Thompson <sthompson@mozilla.com>
Date:   Tue, 23 Dec 2025 17:00:42 +0000

Bug 2003696 - retain tab notes properties on tabs when adopting r=jswinarton,tabbrowser-reviewers

When an existing tab with a tab note moves to another window, its tab note metadata needs to be retained so that it still appears to have a tab note in its new window.

Differential Revision: https://phabricator.services.mozilla.com/D277396

Diffstat:
Mbrowser/components/tabbrowser/content/tabbrowser.js | 4++++
Mbrowser/components/tabnotes/test/browser/browser.toml | 2++
Abrowser/components/tabnotes/test/browser/browser_tab_notes_adopt.js | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js @@ -6026,6 +6026,10 @@ aOtherTab.dispatchEvent(event); } + // Copy tab note-related properties of the tab. + aOurTab.hasTabNote = aOtherTab.hasTabNote; + aOurTab.canonicalUrl = aOtherTab.canonicalUrl; + if (otherBrowser.isDistinctProductPageVisit) { ourBrowser.isDistinctProductPageVisit = true; } diff --git a/browser/components/tabnotes/test/browser/browser.toml b/browser/components/tabnotes/test/browser/browser.toml @@ -6,4 +6,6 @@ support-files = [ "head.js", ] +["browser_tab_notes_adopt.js"] + ["browser_tab_notes_menu.js"] diff --git a/browser/components/tabnotes/test/browser/browser_tab_notes_adopt.js b/browser/components/tabnotes/test/browser/browser_tab_notes_adopt.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +registerCleanupFunction(async () => { + await TabNotes.reset(); +}); + +add_task(async function test_tab_notes_data_preserved_on_adoption() { + const url = "https://example.com/"; + const noteText = "test note text"; + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + + let notatedTab = BrowserTestUtils.addTab(gBrowser, url); + await BrowserTestUtils.browserLoaded(notatedTab.linkedBrowser); + await Promise.all([ + TabNotes.set(notatedTab, noteText), + BrowserTestUtils.waitForEvent(notatedTab, "TabNote:Created"), + ]); + + Assert.equal( + notatedTab.canonicalUrl, + url, + "notated tab should have correct canonical URL" + ); + Assert.ok( + notatedTab.hasTabNote, + "notated tab should indicate it has a tab note" + ); + + // Adopt the tab into the new window + let adoptedTab = newWin.gBrowser.adoptTab(notatedTab); + + Assert.ok(adoptedTab, "adoptTab should succeed"); + Assert.equal( + adoptedTab.canonicalUrl, + url, + "adopted tab should preserve the same canonical URL" + ); + Assert.ok( + adoptedTab.hasTabNote, + "adopted tab should also indicate it has a tab note" + ); + + // Verify the original tab is gone (should be closed by adoptTab) + ok( + notatedTab.closing || !notatedTab.parentNode, + "Original tab should be closed or removed" + ); + + // Clean up + await BrowserTestUtils.closeWindow(newWin); +});