Skip to content

Commit 60afa56

Browse files
committed
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 UltraBlame original commit: 988d08ce7423f749256382637c0f6c03655a0fce
1 parent 219aab5 commit 60afa56

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

browser/components/aboutwelcome/actors/AboutWelcomeChild.sys.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ export class AboutWelcomeChild extends JSWindowActorChild {
140140
Cu.exportFunction(this.AWGetUnhandledCampaignAction.bind(this), window, {
141141
defineAs: "AWGetUnhandledCampaignAction",
142142
});
143+
Cu.exportFunction(
144+
this.AWFindBackupsInWellKnownLocations.bind(this),
145+
window,
146+
{ defineAs: "AWFindBackupsInWellKnownLocations" }
147+
);
143148
}
144149

145150
/**
@@ -190,6 +195,11 @@ export class AboutWelcomeChild extends JSWindowActorChild {
190195
);
191196
}
192197

198+
AWFindBackupsInWellKnownLocations() {
199+
// This return value will be used in https://bugzilla.mozilla.org/show_bug.cgi?id=1992157
200+
return this.sendQueryAndCloneForContent("AWPage:BACKUP_FIND_WELL_KNOWN");
201+
}
202+
193203
/**
194204
* Send initial data to page including experiment information
195205
*/

browser/components/aboutwelcome/actors/AboutWelcomeParent.sys.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
1111
"resource:///modules/aboutwelcome/AboutWelcomeTelemetry.sys.mjs",
1212
AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
1313
AWScreenUtils: "resource:///modules/aboutwelcome/AWScreenUtils.sys.mjs",
14+
BackupService: "resource:///modules/backup/BackupService.sys.mjs",
1415
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
1516
BuiltInThemes: "resource:///modules/BuiltInThemes.sys.mjs",
1617
FxAccounts: "resource://gre/modules/FxAccounts.sys.mjs",
@@ -289,6 +290,16 @@ export class AboutWelcomeParent extends JSWindowActorParent {
289290
}
290291
break;
291292
}
293+
case "AWPage:BACKUP_FIND_WELL_KNOWN": {
294+
// Ask the BackupService to probe default locations.
295+
let bs;
296+
try {
297+
bs = lazy.BackupService.get();
298+
} catch {
299+
bs = lazy.BackupService.init();
300+
}
301+
return bs.findBackupsInWellKnownLocations();
302+
}
292303
default:
293304
lazy.log.debug(`Unexpected event ${type} was not handled.`);
294305
}

browser/components/aboutwelcome/content-src/components/EmbeddedBackupRestore.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ export const EmbeddedBackupRestore = ({ handleAction, skipButton }) => {
1111
const ref = useRef(null);
1212

1313
useEffect(() => {
14+
const loadRestore = async () => {
15+
await window.AWFindBackupsInWellKnownLocations?.();
16+
};
17+
loadRestore();
1418
// Clear the pref used to target the restore screen so that users will not
1519
// automatically see it again the next time they visit about:welcome.
1620
AboutWelcomeUtils.handleUserAction({
1721
type: "SET_PREF",
18-
data: { pref: { name: "showRestoreFromBackup", value: false } },
22+
data: {
23+
pref: { name: "showRestoreFromBackup", value: false },
24+
},
1925
});
2026
}, []);
2127

browser/components/aboutwelcome/content/aboutwelcome.bundle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,6 +3468,10 @@ const EmbeddedBackupRestore = ({
34683468
const [recoveryInProgress, setRecoveryInProgress] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
34693469
const ref = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
34703470
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
3471+
const loadRestore = async () => {
3472+
await window.AWFindBackupsInWellKnownLocations?.();
3473+
};
3474+
loadRestore();
34713475

34723476

34733477
_lib_aboutwelcome_utils_mjs__WEBPACK_IMPORTED_MODULE_1__.AboutWelcomeUtils.handleUserAction({

browser/components/aboutwelcome/tests/unit/ContentTiles.test.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ describe("ContentTiles component", () => {
9191
AWSendToDeviceEmailsSupported: () => Promise.resolve(),
9292
});
9393
globals.set({ AWSendToParent: sandbox.stub() });
94+
globals.set({
95+
AWSendToParent: sandbox.stub(),
96+
AWFindBackupsInWellKnownLocations: sandbox.stub().resolves({
97+
found: false,
98+
multipleBackupsFound: false,
99+
backupFileToRestore: null,
100+
}),
101+
});
94102
wrapper = shallow(
95103
<ContentTiles
96104
content={TEST_CONTENT}

browser/components/aboutwelcome/tests/unit/EmbeddedBackupRestore.test.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ describe("EmbeddedBackupRestore component", () => {
1212
sandbox = sinon.createSandbox();
1313
globals = new GlobalOverrider();
1414
globals.set({ AWSendToParent: sandbox.stub() });
15+
globals.set({
16+
AWSendToParent: sandbox.stub(),
17+
AWFindBackupsInWellKnownLocations: sandbox.stub().resolves({
18+
found: false,
19+
multipleBackupsFound: false,
20+
backupFileToRestore: null,
21+
}),
22+
});
1523
});
1624

1725
afterEach(() => {
@@ -43,4 +51,16 @@ describe("EmbeddedBackupRestore component", () => {
4351
"labelFontWeight should be set to '600'"
4452
);
4553
});
54+
55+
it("calls AWFindBackupsInWellKnownLocations on mount", async () => {
56+
wrapper = mount(<EmbeddedBackupRestore />);
57+
58+
// Ensure the effect runs before we assert.
59+
await new Promise(resolve => setTimeout(resolve, 0));
60+
61+
assert.isTrue(
62+
window.AWFindBackupsInWellKnownLocations.calledOnce,
63+
"should call AWFindBackupsInWellKnownLocations exactly once on mount"
64+
);
65+
});
4666
});

0 commit comments

Comments
 (0)