diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:55:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:55:34 +0000 |
commit | 75417f5e3d32645859d94cec82255dc130ec4a2e (patch) | |
tree | 5fd46925c6b4a881c9208772ed8e5cc0588bc164 /src/tests/tests/options.js | |
parent | Initial commit. (diff) | |
download | privacybadger-6b49d00bf3190484bc85a5a56537b517a7c7801a.tar.xz privacybadger-6b49d00bf3190484bc85a5a56537b517a7c7801a.zip |
Adding upstream version 2020.10.7.upstream/2020.10.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tests/tests/options.js')
-rw-r--r-- | src/tests/tests/options.js | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/tests/tests/options.js b/src/tests/tests/options.js new file mode 100644 index 0000000..2abeba8 --- /dev/null +++ b/src/tests/tests/options.js @@ -0,0 +1,105 @@ +(function () { + +QUnit.module("Options page utils"); + +let { getOriginsArray } = require("optionslib"); + +QUnit.test("getOriginsArray", (assert) => { + const origins = { + "allowed.com": "allow", + "blocked.org": "block", + "alsoblocked.org": "block", + "cookieblocked.biz": "cookieblock", + "UserAllowed.net": "user_allow", + "uuuserblocked.nyc": "user_block", + "dntDomain.co.uk": "dnt", + "another.allowed.domain.example": "allow", + }; + const originsSansAllowed = _.reduce( + origins, (memo, val, key) => { + if (val != "allow") { + memo[key] = val; + } + return memo; + }, {} + ); + + const tests = [ + { + msg: "Empty, no filters", + args: [{},], + expected: [] + }, + { + msg: "No filters (allowed domains are filtered out)", + args: [origins,], + expected: Object.keys(originsSansAllowed) + }, + { + msg: "Not-yet-blocked domains are shown", + args: [origins, null, null, null, true], + expected: Object.keys(origins) + }, + { + msg: "Type filter", + args: [origins, "", "user"], + expected: ["UserAllowed.net", "uuuserblocked.nyc"] + }, + { + msg: "Status filter", + args: [origins, "", "", "allow"], + expected: ["UserAllowed.net", "dntDomain.co.uk"] + }, + { + msg: "Text filter", + args: [origins, ".org"], + expected: ["blocked.org", "alsoblocked.org"] + }, + { + msg: "Text filter and domain case insensitivity", + args: [origins, "uSER"], + expected: ["UserAllowed.net", "uuuserblocked.nyc"] + }, + { + msg: "Text filter with extra space", + args: [origins, " .org"], + expected: ["blocked.org", "alsoblocked.org"] + }, + { + msg: "Negative text filter", + args: [origins, "-.org"], + expected: [ + "cookieblocked.biz", + "UserAllowed.net", + "uuuserblocked.nyc", + "dntDomain.co.uk", + ] + }, + { + msg: "Multiple negative text filter", + args: [origins, "-.net -cookie -.co.uk"], + expected: ["blocked.org", "alsoblocked.org", "uuuserblocked.nyc"] + }, + { + msg: "Multiple text filters", + args: [origins, " -also .biz .org "], + expected: ["blocked.org", "cookieblocked.biz"] + }, + { + msg: "All filters together", + args: [origins, ".net", "user", "allow", true], + expected: ["UserAllowed.net"] + }, + ]; + + tests.forEach((test) => { + assert.deepEqual( + getOriginsArray.apply(window, test.args), + test.expected, + test.msg + ); + }); + +}); + +}()); |