Revision control
Copy as Markdown
Other Tools
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
"use strict";
const { MockExternalProtocolService } = ChromeUtils.importESModule(
);
const { InAppNotifications } = ChromeUtils.importESModule(
);
const { NotificationManager } = ChromeUtils.importESModule(
);
const { clearInterval, clearTimeout } = ChromeUtils.importESModule(
);
const { NotificationUpdater } = ChromeUtils.importESModule(
);
const { PlacesUtils } = ChromeUtils.importESModule(
);
const SAFETY_MARGIN_MS = 100000;
function getMockNotifications() {
const now = Date.now();
const startDate = new Date(now - SAFETY_MARGIN_MS).toISOString();
const endDate = new Date(now + SAFETY_MARGIN_MS).toISOString();
return [
{
id: "foo",
title: "lorem ipsum",
start_at: startDate,
end_at: endDate,
severity: 1,
targeting: {},
type: "donation",
},
{
id: "bar",
title: "dolor sit amet",
start_at: startDate,
end_at: endDate,
severity: 5,
targeting: {},
type: "donation",
},
];
}
add_setup(async () => {
do_get_profile();
MockExternalProtocolService.init();
await InAppNotifications.init(true);
NotificationManager._PER_TIME_UNIT = 1;
registerCleanupFunction(async () => {
NotificationUpdater._clearStateForTests();
clearTimeout(InAppNotifications._showNotificationTimer);
Services.prefs.clearUserPref(
"datareporting.policy.dataSubmissionPolicyAcceptedVersion"
);
MockExternalProtocolService.reset();
await PlacesUtils.history.clear();
});
});
add_task(async function test_initializedData() {
Assert.deepEqual(
InAppNotifications.getNotifications(),
[],
"Should initialize notifications with an empty array"
);
Assert.deepEqual(
InAppNotifications._jsonFile.data.seeds,
{},
"Should initialize seeds"
);
Assert.ok(NotificationUpdater._timeout, "Should schedule an update interval");
});