summaryrefslogtreecommitdiffstats
path: root/services/settings/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
commit086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch)
treea4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /services/settings/test
parentAdding debian version 124.0.1-1. (diff)
downloadfirefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz
firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/settings/test')
-rw-r--r--services/settings/test/unit/test_attachments_downloader.js82
-rw-r--r--services/settings/test/unit/test_remote_settings.js20
-rw-r--r--services/settings/test/unit/test_remote_settings_dump_lastmodified.js8
-rw-r--r--services/settings/test/unit/test_remote_settings_offline.js12
-rw-r--r--services/settings/test/unit/test_remote_settings_poll.js12
-rw-r--r--services/settings/test/unit/test_remote_settings_signatures.js6
-rw-r--r--services/settings/test/unit/test_remote_settings_worker.js4
-rw-r--r--services/settings/test/unit/test_shutdown_handling.js4
8 files changed, 116 insertions, 32 deletions
diff --git a/services/settings/test/unit/test_attachments_downloader.js b/services/settings/test/unit/test_attachments_downloader.js
index 86dd52b729..284294cfde 100644
--- a/services/settings/test/unit/test_attachments_downloader.js
+++ b/services/settings/test/unit/test_attachments_downloader.js
@@ -47,7 +47,7 @@ function pathFromURL(url) {
const PROFILE_URL = PathUtils.toFileURI(PathUtils.localProfileDir);
-function run_test() {
+add_setup(() => {
server = new HttpServer();
server.start(-1);
registerCleanupFunction(() => server.stop(() => {}));
@@ -56,9 +56,7 @@ function run_test() {
"/cdn/main-workspace/some-collection/",
do_get_file("test_attachments_downloader")
);
-
- run_next_test();
-}
+});
async function clear_state() {
Services.prefs.setStringPref(
@@ -68,9 +66,9 @@ async function clear_state() {
downloader = new Downloader("main", "some-collection");
const dummyCacheImpl = {
- get: async attachmentId => {},
- set: async (attachmentId, attachment) => {},
- delete: async attachmentId => {},
+ get: async () => {},
+ set: async () => {},
+ delete: async () => {},
};
// The download() method requires a cacheImpl, but the Downloader
// class does not have one. Define a dummy no-op one.
@@ -388,7 +386,7 @@ async function doTestDownloadCacheImpl({ simulateCorruption }) {
throw new Error("Simulation of corrupted cache (write)");
}
},
- async delete(attachmentId) {},
+ async delete() {},
};
Object.defineProperty(downloader, "cacheImpl", { value: cacheImpl });
@@ -621,6 +619,74 @@ add_task(async function test_download_from_dump() {
// but added for consistency with other tests tasks around here.
add_task(clear_state);
+add_task(async function test_attachment_get() {
+ // Since get() is largely a wrapper around the same code as download(),
+ // we only test a couple of parts to check it functions as expected, and
+ // rely on the download() testing for the rest.
+
+ await Assert.rejects(
+ downloader.get(RECORD),
+ /NotFoundError: Could not find /,
+ "get() fails when there is no local cache nor dump"
+ );
+
+ const client = RemoteSettings("dump-collection", {
+ bucketName: "dump-bucket",
+ });
+
+ // Temporarily replace the resource:-URL with another resource:-URL.
+ const orig_RESOURCE_BASE_URL = Downloader._RESOURCE_BASE_URL;
+ Downloader._RESOURCE_BASE_URL = "resource://rs-downloader-test";
+ const resProto = Services.io
+ .getProtocolHandler("resource")
+ .QueryInterface(Ci.nsIResProtocolHandler);
+ resProto.setSubstitution(
+ "rs-downloader-test",
+ Services.io.newFileURI(do_get_file("test_attachments_downloader"))
+ );
+
+ function checkInfo(result, expectedSource, expectedRecord = RECORD_OF_DUMP) {
+ Assert.equal(
+ new TextDecoder().decode(new Uint8Array(result.buffer)),
+ "This would be a RS dump.\n",
+ "expected content from dump"
+ );
+ Assert.deepEqual(result.record, expectedRecord, "expected record for dump");
+ Assert.equal(result._source, expectedSource, "expected source of dump");
+ }
+
+ // When a record is given, use whichever that has the matching last_modified.
+ const dump = await client.attachments.get(RECORD_OF_DUMP);
+ checkInfo(dump, "dump_match");
+
+ await client.attachments.deleteDownloaded(RECORD_OF_DUMP);
+
+ await Assert.rejects(
+ client.attachments.get(null, {
+ attachmentId: "filename-without-meta.txt",
+ fallbackToDump: true,
+ }),
+ /NotFoundError: Could not find filename-without-meta.txt in cache or dump/,
+ "Cannot download dump that lacks a .meta.json file"
+ );
+
+ await Assert.rejects(
+ client.attachments.get(null, {
+ attachmentId: "filename-without-content.txt",
+ fallbackToDump: true,
+ }),
+ /Could not download resource:\/\/rs-downloader-test\/settings\/dump-bucket\/dump-collection\/filename-without-content\.txt(?!\.meta\.json)/,
+ "Cannot download dump that is missing, despite the existing .meta.json"
+ );
+
+ // Restore, just in case.
+ Downloader._RESOURCE_BASE_URL = orig_RESOURCE_BASE_URL;
+ resProto.setSubstitution("rs-downloader-test", null);
+});
+// Not really needed because the last test doesn't modify the main collection,
+// but added for consistency with other tests tasks around here.
+add_task(clear_state);
+
add_task(async function test_obsolete_attachments_are_pruned() {
const RECORD2 = {
...RECORD,
diff --git a/services/settings/test/unit/test_remote_settings.js b/services/settings/test/unit/test_remote_settings.js
index 0937acb519..382d1aa983 100644
--- a/services/settings/test/unit/test_remote_settings.js
+++ b/services/settings/test/unit/test_remote_settings.js
@@ -133,7 +133,11 @@ add_task(
await clientWithDump.maybeSync(timestamp);
const list = await clientWithDump.get();
- ok(list.length > 20, `The dump was loaded (${list.length} records)`);
+ Assert.greater(
+ list.length,
+ 20,
+ `The dump was loaded (${list.length} records)`
+ );
equal(received.created[0].id, "xx", "Record from the sync come first.");
const createdById = received.created.reduce((acc, r) => {
@@ -328,8 +332,9 @@ add_task(async function test_get_sorts_results_if_specified() {
);
const records = await client.get({ order: "field" });
- ok(
- records[0].field < records[records.length - 1].field,
+ Assert.less(
+ records[0].field,
+ records[records.length - 1].field,
"records are sorted"
);
});
@@ -350,6 +355,7 @@ add_task(async function test_get_falls_back_sorts_results() {
order: "-id",
});
+ // eslint-disable-next-line mozilla/no-comparison-or-assignment-inside-ok
ok(records[0].id > records[records.length - 1].id, "records are sorted");
clientWithDump.db.getLastModified = backup;
@@ -539,7 +545,7 @@ add_task(async function test_get_does_not_verify_signature_if_load_dump() {
let called;
clientWithDump._verifier = {
- async asyncVerifyContentSignature(serialized, signature) {
+ async asyncVerifyContentSignature() {
called = true;
return true;
},
@@ -577,7 +583,7 @@ add_task(
const backup = clientWithDump._verifier;
let callCount = 0;
clientWithDump._verifier = {
- async asyncVerifyContentSignature(serialized, signature) {
+ async asyncVerifyContentSignature() {
callCount++;
return true;
},
@@ -634,7 +640,7 @@ add_task(
let called;
clientWithDump._verifier = {
- async asyncVerifyContentSignature(serialized, signature) {
+ async asyncVerifyContentSignature() {
called = true;
return true;
},
@@ -1168,7 +1174,7 @@ add_task(clear_state);
add_task(async function test_sync_event_is_not_sent_from_get_when_no_dump() {
let called = false;
- client.on("sync", e => {
+ client.on("sync", () => {
called = true;
});
diff --git a/services/settings/test/unit/test_remote_settings_dump_lastmodified.js b/services/settings/test/unit/test_remote_settings_dump_lastmodified.js
index 1cce089ff7..25de34c1be 100644
--- a/services/settings/test/unit/test_remote_settings_dump_lastmodified.js
+++ b/services/settings/test/unit/test_remote_settings_dump_lastmodified.js
@@ -14,7 +14,11 @@ async function getLocalDumpLastModified(bucket, collection) {
return -1;
}
const { timestamp } = await res.json();
- ok(timestamp >= 0, `${bucket}/${collection} dump has timestamp`);
+ Assert.greaterOrEqual(
+ timestamp,
+ 0,
+ `${bucket}/${collection} dump has timestamp`
+ );
return timestamp;
}
@@ -51,5 +55,5 @@ add_task(async function lastModified_summary_is_correct() {
equal(lastModified, actual, `last_modified should match collection`);
checked++;
}
- ok(checked > 0, "At least one dump was packaged and checked.");
+ Assert.greater(checked, 0, "At least one dump was packaged and checked.");
});
diff --git a/services/settings/test/unit/test_remote_settings_offline.js b/services/settings/test/unit/test_remote_settings_offline.js
index ffb810829d..0a250c3e0a 100644
--- a/services/settings/test/unit/test_remote_settings_offline.js
+++ b/services/settings/test/unit/test_remote_settings_offline.js
@@ -107,7 +107,11 @@ add_task(clear_state);
add_task(async function test_load_dump_after_non_empty_import() {
// Dump is updated regularly, verify that the dump matches our expectations
// before running the test.
- ok(DUMP_LAST_MODIFIED > 1234, "Assuming dump to be newer than dummy 1234");
+ Assert.greater(
+ DUMP_LAST_MODIFIED,
+ 1234,
+ "Assuming dump to be newer than dummy 1234"
+ );
await importData([{ last_modified: 1234, id: "dummy" }]);
@@ -120,7 +124,11 @@ add_task(clear_state);
add_task(async function test_load_dump_after_import_from_broken_distro() {
// Dump is updated regularly, verify that the dump matches our expectations
// before running the test.
- ok(DUMP_LAST_MODIFIED > 1234, "Assuming dump to be newer than dummy 1234");
+ Assert.greater(
+ DUMP_LAST_MODIFIED,
+ 1234,
+ "Assuming dump to be newer than dummy 1234"
+ );
// No last_modified time.
await importData([{ id: "dummy" }]);
diff --git a/services/settings/test/unit/test_remote_settings_poll.js b/services/settings/test/unit/test_remote_settings_poll.js
index 3bf389ea34..c8025f4b7b 100644
--- a/services/settings/test/unit/test_remote_settings_poll.js
+++ b/services/settings/test/unit/test_remote_settings_poll.js
@@ -188,7 +188,7 @@ add_task(async function test_check_success() {
// Ensure that the remote-settings:changes-poll-end notification works
let notificationObserved = false;
const observer = {
- observe(aSubject, aTopic, aData) {
+ observe() {
Services.obs.removeObserver(this, "remote-settings:changes-poll-end");
notificationObserved = true;
},
@@ -258,7 +258,7 @@ add_task(async function test_update_timer_interface() {
await new Promise(resolve => {
const e = "remote-settings:changes-poll-end";
const changesPolledObserver = {
- observe(aSubject, aTopic, aData) {
+ observe() {
Services.obs.removeObserver(this, e);
resolve();
},
@@ -288,7 +288,7 @@ add_task(async function test_check_up_to_date() {
// Ensure that the remote-settings:changes-poll-end notification is sent.
let notificationObserved = false;
const observer = {
- observe(aSubject, aTopic, aData) {
+ observe() {
Services.obs.removeObserver(this, "remote-settings:changes-poll-end");
notificationObserved = true;
},
@@ -686,7 +686,7 @@ add_task(async function test_server_error() {
let notificationObserved = false;
const observer = {
- observe(aSubject, aTopic, aData) {
+ observe() {
Services.obs.removeObserver(this, "remote-settings:changes-poll-end");
notificationObserved = true;
},
@@ -807,7 +807,7 @@ add_task(async function test_client_error() {
let notificationsObserved = [];
const observer = {
- observe(aSubject, aTopic, aData) {
+ observe(aSubject, aTopic) {
Services.obs.removeObserver(this, aTopic);
notificationsObserved.push([aTopic, aSubject.wrappedJSObject]);
},
@@ -935,7 +935,7 @@ add_task(
// Wait for the "sync-broken-error" notification.
let notificationObserved = false;
const observer = {
- observe(aSubject, aTopic, aData) {
+ observe() {
notificationObserved = true;
},
};
diff --git a/services/settings/test/unit/test_remote_settings_signatures.js b/services/settings/test/unit/test_remote_settings_signatures.js
index 840cc24dd8..a730ba185e 100644
--- a/services/settings/test/unit/test_remote_settings_signatures.js
+++ b/services/settings/test/unit/test_remote_settings_signatures.js
@@ -487,7 +487,7 @@ add_task(async function test_check_synchronization_with_signatures() {
);
let syncEventSent = false;
- client.on("sync", ({ data }) => {
+ client.on("sync", () => {
syncEventSent = true;
});
@@ -542,7 +542,7 @@ add_task(async function test_check_synchronization_with_signatures() {
registerHandlers(badSigGoodOldResponses);
syncEventSent = false;
- client.on("sync", ({ data }) => {
+ client.on("sync", () => {
syncEventSent = true;
});
@@ -783,7 +783,7 @@ add_task(async function test_check_synchronization_with_signatures() {
const sigCalls = [];
let i = 0;
client._verifier = {
- async asyncVerifyContentSignature(serialized, signature) {
+ async asyncVerifyContentSignature(serialized) {
sigCalls.push(serialized);
console.log(`verify call ${i}`);
return [
diff --git a/services/settings/test/unit/test_remote_settings_worker.js b/services/settings/test/unit/test_remote_settings_worker.js
index 42b85bb92c..e2dcdb0063 100644
--- a/services/settings/test/unit/test_remote_settings_worker.js
+++ b/services/settings/test/unit/test_remote_settings_worker.js
@@ -82,8 +82,8 @@ add_task(async function test_throws_error_if_worker_fails_async() {
// should be reported to the caller.
await new Promise((resolve, reject) => {
const request = indexedDB.deleteDatabase("remote-settings");
- request.onsuccess = event => resolve();
- request.onblocked = event => reject(new Error("Cannot delete DB"));
+ request.onsuccess = () => resolve();
+ request.onblocked = () => reject(new Error("Cannot delete DB"));
request.onerror = event => reject(event.target.error);
});
let error;
diff --git a/services/settings/test/unit/test_shutdown_handling.js b/services/settings/test/unit/test_shutdown_handling.js
index a35ab6080a..2c98f0ab9b 100644
--- a/services/settings/test/unit/test_shutdown_handling.js
+++ b/services/settings/test/unit/test_shutdown_handling.js
@@ -41,7 +41,7 @@ add_task(async function test_shutdown_abort_after_start() {
const request = store
.index("cid")
.openCursor(IDBKeyRange.only("foopydoo/foo"));
- request.onsuccess = event => {
+ request.onsuccess = () => {
makeRequest();
};
}
@@ -74,7 +74,7 @@ add_task(async function test_shutdown_immediate_abort() {
let request = store
.index("cid")
.openCursor(IDBKeyRange.only("foopydoo/foo"));
- request.onsuccess = event => {
+ request.onsuccess = () => {
// Abort immediately.
Database._shutdownHandler();
request = store