tor-browser

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

commit 4c6c6735429ea9ed3acdb8acb217a7a4a13a7f3d
parent 3f0a2a6e8d3e1c4ec735510da543739e63498615
Author: Meg Viar <lmegviar@gmail.com>
Date:   Fri,  3 Oct 2025 14:07:29 +0000

Bug 1992156 - Trigger loading detected backup details in restore component when EmbeddedBackupRestore loads r=omc-reviewers,jprickett

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

Diffstat:
Mbrowser/components/aboutwelcome/actors/AboutWelcomeChild.sys.mjs | 10++++++++++
Mbrowser/components/aboutwelcome/actors/AboutWelcomeParent.sys.mjs | 11+++++++++++
Mbrowser/components/aboutwelcome/content-src/components/EmbeddedBackupRestore.jsx | 8+++++++-
Mbrowser/components/aboutwelcome/content/aboutwelcome.bundle.js | 4++++
Mbrowser/components/aboutwelcome/tests/unit/ContentTiles.test.jsx | 8++++++++
Mbrowser/components/aboutwelcome/tests/unit/EmbeddedBackupRestore.test.jsx | 20++++++++++++++++++++
6 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/browser/components/aboutwelcome/actors/AboutWelcomeChild.sys.mjs b/browser/components/aboutwelcome/actors/AboutWelcomeChild.sys.mjs @@ -140,6 +140,11 @@ export class AboutWelcomeChild extends JSWindowActorChild { Cu.exportFunction(this.AWGetUnhandledCampaignAction.bind(this), window, { defineAs: "AWGetUnhandledCampaignAction", }); + Cu.exportFunction( + this.AWFindBackupsInWellKnownLocations.bind(this), + window, + { defineAs: "AWFindBackupsInWellKnownLocations" } + ); } /** @@ -190,6 +195,11 @@ export class AboutWelcomeChild extends JSWindowActorChild { ); } + AWFindBackupsInWellKnownLocations() { + // This return value will be used in https://bugzilla.mozilla.org/show_bug.cgi?id=1992157 + return this.sendQueryAndCloneForContent("AWPage:BACKUP_FIND_WELL_KNOWN"); + } + /** * Send initial data to page including experiment information */ diff --git a/browser/components/aboutwelcome/actors/AboutWelcomeParent.sys.mjs b/browser/components/aboutwelcome/actors/AboutWelcomeParent.sys.mjs @@ -11,6 +11,7 @@ ChromeUtils.defineESModuleGetters(lazy, { "resource:///modules/aboutwelcome/AboutWelcomeTelemetry.sys.mjs", AddonManager: "resource://gre/modules/AddonManager.sys.mjs", AWScreenUtils: "resource:///modules/aboutwelcome/AWScreenUtils.sys.mjs", + BackupService: "resource:///modules/backup/BackupService.sys.mjs", BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs", BuiltInThemes: "resource:///modules/BuiltInThemes.sys.mjs", FxAccounts: "resource://gre/modules/FxAccounts.sys.mjs", @@ -289,6 +290,16 @@ export class AboutWelcomeParent extends JSWindowActorParent { } break; } + case "AWPage:BACKUP_FIND_WELL_KNOWN": { + // Ask the BackupService to probe default locations. + let bs; + try { + bs = lazy.BackupService.get(); + } catch { + bs = lazy.BackupService.init(); + } + return bs.findBackupsInWellKnownLocations(); + } default: lazy.log.debug(`Unexpected event ${type} was not handled.`); } diff --git a/browser/components/aboutwelcome/content-src/components/EmbeddedBackupRestore.jsx b/browser/components/aboutwelcome/content-src/components/EmbeddedBackupRestore.jsx @@ -11,11 +11,17 @@ export const EmbeddedBackupRestore = ({ handleAction, skipButton }) => { const ref = useRef(null); useEffect(() => { + const loadRestore = async () => { + await window.AWFindBackupsInWellKnownLocations?.(); + }; + loadRestore(); // Clear the pref used to target the restore screen so that users will not // automatically see it again the next time they visit about:welcome. AboutWelcomeUtils.handleUserAction({ type: "SET_PREF", - data: { pref: { name: "showRestoreFromBackup", value: false } }, + data: { + pref: { name: "showRestoreFromBackup", value: false }, + }, }); }, []); diff --git a/browser/components/aboutwelcome/content/aboutwelcome.bundle.js b/browser/components/aboutwelcome/content/aboutwelcome.bundle.js @@ -3468,6 +3468,10 @@ const EmbeddedBackupRestore = ({ const [recoveryInProgress, setRecoveryInProgress] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false); const ref = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null); (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => { + const loadRestore = async () => { + await window.AWFindBackupsInWellKnownLocations?.(); + }; + loadRestore(); // Clear the pref used to target the restore screen so that users will not // automatically see it again the next time they visit about:welcome. _lib_aboutwelcome_utils_mjs__WEBPACK_IMPORTED_MODULE_1__.AboutWelcomeUtils.handleUserAction({ diff --git a/browser/components/aboutwelcome/tests/unit/ContentTiles.test.jsx b/browser/components/aboutwelcome/tests/unit/ContentTiles.test.jsx @@ -91,6 +91,14 @@ describe("ContentTiles component", () => { AWSendToDeviceEmailsSupported: () => Promise.resolve(), }); globals.set({ AWSendToParent: sandbox.stub() }); + globals.set({ + AWSendToParent: sandbox.stub(), + AWFindBackupsInWellKnownLocations: sandbox.stub().resolves({ + found: false, + multipleBackupsFound: false, + backupFileToRestore: null, + }), + }); wrapper = shallow( <ContentTiles content={TEST_CONTENT} diff --git a/browser/components/aboutwelcome/tests/unit/EmbeddedBackupRestore.test.jsx b/browser/components/aboutwelcome/tests/unit/EmbeddedBackupRestore.test.jsx @@ -12,6 +12,14 @@ describe("EmbeddedBackupRestore component", () => { sandbox = sinon.createSandbox(); globals = new GlobalOverrider(); globals.set({ AWSendToParent: sandbox.stub() }); + globals.set({ + AWSendToParent: sandbox.stub(), + AWFindBackupsInWellKnownLocations: sandbox.stub().resolves({ + found: false, + multipleBackupsFound: false, + backupFileToRestore: null, + }), + }); }); afterEach(() => { @@ -43,4 +51,16 @@ describe("EmbeddedBackupRestore component", () => { "labelFontWeight should be set to '600'" ); }); + + it("calls AWFindBackupsInWellKnownLocations on mount", async () => { + wrapper = mount(<EmbeddedBackupRestore />); + + // Ensure the effect runs before we assert. + await new Promise(resolve => setTimeout(resolve, 0)); + + assert.isTrue( + window.AWFindBackupsInWellKnownLocations.calledOnce, + "should call AWFindBackupsInWellKnownLocations exactly once on mount" + ); + }); });