Source code
Revision control
Copy as Markdown
Other Tools
import {
getNotificationIdsForUrl,
isWebNotificationsEnabled,
notificationKeyForUrl,
originFromUrl,
} from "content-src/lib/web-notification-match.mjs";
describe("web-notification-match", () => {
describe("originFromUrl", () => {
it("returns the http(s) origin", () => {
assert.equal(
);
});
it("returns null for non-http(s) schemes", () => {
assert.isNull(originFromUrl("about:newtab"));
});
it("returns null for malformed input", () => {
assert.isNull(originFromUrl("not a url"));
});
});
describe("notificationKeyForUrl", () => {
it("redirects a known apex to its app origin", () => {
assert.equal(
);
assert.equal(
);
});
it("passes unknown origins through unchanged", () => {
assert.equal(
);
});
it("does not merge sibling subdomains onto one key", () => {
assert.equal(
);
});
it("returns null for non-http(s) urls", () => {
assert.isNull(notificationKeyForUrl("about:blank"));
});
});
describe("getNotificationIdsForUrl", () => {
const state = {
WebNotifications: {
},
},
};
it("resolves ids through the apex alias", () => {
"a",
"b",
]);
});
it("resolves ids for an exact origin", () => {
assert.deepEqual(
["c"]
);
});
it("returns a stable empty array for an unmatched url", () => {
assert.deepEqual(first, []);
assert.strictEqual(
first,
);
});
it("returns empty for a non-http(s) url", () => {
assert.deepEqual(getNotificationIdsForUrl(state, "about:newtab"), []);
});
});
describe("isWebNotificationsEnabled", () => {
const stateWith = values => ({ Prefs: { values } });
it("is enabled when the system and user prefs are set", () => {
assert.isTrue(
isWebNotificationsEnabled(
stateWith({
"system.showWebNotifications": true,
showWebNotifications: true,
})
)
);
});
it("is enabled via trainhop with the system pref off", () => {
assert.isTrue(
isWebNotificationsEnabled(
stateWith({
"system.showWebNotifications": false,
showWebNotifications: true,
trainhopConfig: { webNotifications: { enabled: true } },
})
)
);
});
it("is disabled when the user pref is off even if trainhop enables it", () => {
assert.isFalse(
isWebNotificationsEnabled(
stateWith({
"system.showWebNotifications": false,
showWebNotifications: false,
trainhopConfig: { webNotifications: { enabled: true } },
})
)
);
});
it("is disabled when neither the system pref nor trainhop enable it", () => {
assert.isFalse(
isWebNotificationsEnabled(
stateWith({
"system.showWebNotifications": false,
showWebNotifications: true,
})
)
);
});
});
});