Bug 1932019 - Use URL formatting for in app notifications update URL. r=arschmitz

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin Giger 2024-11-25 16:49:06 +00:00
Родитель afeb48721e
Коммит 937d3c3a74
2 изменённых файлов: 37 добавлений и 4 удалений

Просмотреть файл

@ -98,11 +98,10 @@ export const NotificationUpdater = {
);
return false;
}
const refreshUrl = Services.prefs.getStringPref(
"mail.inappnotifications.url",
""
const refreshUrl = Services.urlFormatter.formatURLPref(
"mail.inappnotifications.url"
);
if (!refreshUrl) {
if (refreshUrl === "about:blank") {
return false;
}
try {

Просмотреть файл

@ -38,6 +38,11 @@ add_setup(async () => {
server.registerPathHandler("/error.json", (request, response) => {
response.setStatusLine(request.httpVersion, 404, "Not Found");
});
server.registerPrefixHandler("/formatted/", (request, response) => {
response.setStatusLine(request.httpVersion, 200, "OK");
response.setHeader("Content-Type", "application/json");
response.write(JSON.stringify({ formatTest: request.path }));
});
server.start(-1);
const serverUrl = `http://localhost:${server.identity.primaryPort}/notifications.json`;
@ -273,3 +278,32 @@ add_task(async function test_init_withRecentUpdate() {
updateSpy.resetHistory();
});
add_task(async function test_fetch_formattedURL() {
const url = Services.prefs.getStringPref("mail.inappnotifications.url", "");
Services.prefs.setStringPref(
"mail.inappnotifications.url",
url.replace("notifications.json", "formatted/%LOCALE%/notifications.json")
);
const expectedURL = Services.urlFormatter.formatURLPref(
"mail.inappnotifications.url"
);
// Cut off http://host:port
const expectedPath = `/${expectedURL.split("/").slice(3).join("/")}`;
Assert.stringContains(expectedURL, "formatted", "Should have updated URL");
Assert.ok(
!expectedURL.includes("%LOCALE%"),
"Placeholder should be formatted"
);
const formattedFetch = await NotificationUpdater._fetch();
Assert.ok(formattedFetch, "Should report fetch");
Assert.ok(
updateSpy.calledWith({ formatTest: expectedPath }),
"Should call update with expected payload"
);
Services.prefs.setStringPref("mail.inappnotifications.url", url);
updateSpy.resetHistory();
});