Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: services/sync/tests/unit/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
const { Service } = ChromeUtils.importESModule(
);
add_task(async function test_findCluster() {
syncTestLogging();
_("Test Service._findCluster()");
try {
let whenReadyToAuthenticate = Promise.withResolvers();
Service.identity.whenReadyToAuthenticate = whenReadyToAuthenticate;
whenReadyToAuthenticate.resolve(true);
Service.identity._ensureValidToken = () =>
Promise.reject(new Error("Connection refused"));
_("_findCluster() throws on network errors (e.g. connection refused).");
await Assert.rejects(Service.identity._findCluster(), /Connection refused/);
Service.identity._ensureValidToken = () =>
_("_findCluster() returns the user's cluster node");
let cluster = await Service.identity._findCluster();
} finally {
for (const pref of Svc.PrefBranch.getChildList("")) {
Svc.PrefBranch.clearUserPref(pref);
}
}
});
add_task(async function test_setCluster() {
syncTestLogging();
_("Test Service._setCluster()");
try {
_("Check initial state.");
Assert.equal(Service.clusterURL, "");
_("Set the cluster URL.");
Assert.ok(await Service.identity.setCluster());
_("Setting it again won't make a difference if it's the same one.");
Assert.ok(!(await Service.identity.setCluster()));
_("A 'null' response won't make a difference either.");
Service.identity._findCluster = () => null;
Assert.ok(!(await Service.identity.setCluster()));
} finally {
for (const pref of Svc.PrefBranch.getChildList("")) {
Svc.PrefBranch.clearUserPref(pref);
}
}
});