FilterAdult.test.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {filterAdult} from "lib/FilterAdult.jsm";
  2. import {GlobalOverrider} from "test/unit/utils";
  3. describe("filterAdult", () => {
  4. let hashStub;
  5. let hashValue;
  6. let globals;
  7. beforeEach(() => {
  8. globals = new GlobalOverrider();
  9. hashStub = {
  10. finish: sinon.stub().callsFake(() => hashValue),
  11. init: sinon.stub(),
  12. update: sinon.stub(),
  13. };
  14. globals.set("Cc", {
  15. "@mozilla.org/security/hash;1": {
  16. createInstance() {
  17. return hashStub;
  18. },
  19. },
  20. });
  21. });
  22. afterEach(() => {
  23. globals.restore();
  24. });
  25. it("should default to include on unexpected urls", () => {
  26. const empty = {};
  27. const result = filterAdult([empty]);
  28. assert.equal(result.length, 1);
  29. assert.equal(result[0], empty);
  30. });
  31. it("should not filter out non-adult urls", () => {
  32. const link = {url: "https://mozilla.org/"};
  33. const result = filterAdult([link]);
  34. assert.equal(result.length, 1);
  35. assert.equal(result[0], link);
  36. });
  37. it("should filter out adult urls", () => {
  38. // Use a hash value that is in the adult set
  39. hashValue = "+/UCpAhZhz368iGioEO8aQ==";
  40. const link = {url: "https://some-adult-site/"};
  41. const result = filterAdult([link]);
  42. assert.equal(result.length, 0);
  43. });
  44. });