diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/cascade_bloom_filter/test | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/cascade_bloom_filter/test')
-rw-r--r-- | toolkit/components/cascade_bloom_filter/test/xpcshell/test_cascade_bindings.js | 51 | ||||
-rw-r--r-- | toolkit/components/cascade_bloom_filter/test/xpcshell/xpcshell.toml | 3 |
2 files changed, 54 insertions, 0 deletions
diff --git a/toolkit/components/cascade_bloom_filter/test/xpcshell/test_cascade_bindings.js b/toolkit/components/cascade_bloom_filter/test/xpcshell/test_cascade_bindings.js new file mode 100644 index 0000000000..c326df2018 --- /dev/null +++ b/toolkit/components/cascade_bloom_filter/test/xpcshell/test_cascade_bindings.js @@ -0,0 +1,51 @@ +"use strict"; + +const CASCADE_CID = "@mozilla.org/cascade-filter;1"; +const CASCADE_IID = Ci.nsICascadeFilter; +const CascadeFilter = Components.Constructor(CASCADE_CID, CASCADE_IID); + +add_task(function CascadeFilter_uninitialized() { + let filter = new CascadeFilter(); + Assert.throws( + () => filter.has(""), + e => e.result === Cr.NS_ERROR_NOT_INITIALIZED, + "Cannot use has() if the filter is not initialized" + ); +}); + +add_task(function CascadeFilter_with_setFilterData() { + let filter = new CascadeFilter(); + Assert.throws( + () => filter.setFilterData(), + e => e.result === Cr.NS_ERROR_XPC_NOT_ENOUGH_ARGS, + "setFilterData without parameters should throw" + ); + Assert.throws( + () => filter.setFilterData(null), + e => e.result === Cr.NS_ERROR_XPC_CANT_CONVERT_PRIMITIVE_TO_ARRAY, + "setFilterData with null parameter is invalid" + ); + Assert.throws( + () => filter.setFilterData(new Uint8Array()), + e => e.result === Cr.NS_ERROR_INVALID_ARG, + "setFilterData with empty array is invalid" + ); + + // Test data based on rust_cascade's unit tests (bloom_v1_test_from_bytes), + // with two bytes in front to have a valid format. + const TEST_DATA = [1, 0, 1, 9, 0, 0, 0, 1, 0, 0, 0, 1, 0x41, 0]; + Assert.throws( + () => filter.setFilterData(new Uint8Array(TEST_DATA.slice(1))), + e => e.result === Cr.NS_ERROR_INVALID_ARG, + "setFilterData with invalid data (missing head) is invalid" + ); + Assert.throws( + () => filter.setFilterData(new Uint8Array(TEST_DATA.slice(0, -1))), + e => e.result === Cr.NS_ERROR_INVALID_ARG, + "setFilterData with invalid data (missing tail) is invalid" + ); + filter.setFilterData(new Uint8Array(TEST_DATA)); + Assert.equal(filter.has("this"), true, "has(this) should be true"); + Assert.equal(filter.has("that"), true, "has(that) should be true"); + Assert.equal(filter.has("other"), false, "has(other) should be false"); +}); diff --git a/toolkit/components/cascade_bloom_filter/test/xpcshell/xpcshell.toml b/toolkit/components/cascade_bloom_filter/test/xpcshell/xpcshell.toml new file mode 100644 index 0000000000..5c102ce23f --- /dev/null +++ b/toolkit/components/cascade_bloom_filter/test/xpcshell/xpcshell.toml @@ -0,0 +1,3 @@ +[DEFAULT] + +["test_cascade_bindings.js"] |