From b0d7260bce13e5cf459d1d7bb3048ca2e3d08994 Mon Sep 17 00:00:00 2001 From: stoically Date: Sat, 20 Jul 2019 12:13:34 +0200 Subject: [PATCH] Add feature tests for block subresources and add domains --- test/features/add-domain-to-fbc.test.js | 38 ++++++++++++++ test/features/block-subresources.test.js | 65 ++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 test/features/add-domain-to-fbc.test.js create mode 100644 test/features/block-subresources.test.js diff --git a/test/features/add-domain-to-fbc.test.js b/test/features/add-domain-to-fbc.test.js new file mode 100644 index 00000000..b7317b33 --- /dev/null +++ b/test/features/add-domain-to-fbc.test.js @@ -0,0 +1,38 @@ +describe("Add domain to Facebook Container", () => { + let webExtension, background; + + beforeEach(async () => { + webExtension = await loadWebExtension(); + background = webExtension.background; + }); + + describe("runtime message add-to-facebook-container", () => { + beforeEach(async () => { + await background.browser.runtime.onMessage.addListener.yield("add-to-facebook-container", { + url: "https://example.com" + }); + }); + + describe("runtime message what-sites-are-added", () => { + it("should return the added sites", async () => { + const [promise] = await background.browser.runtime.onMessage.addListener.yield("what-sites-are-added", {}); + const sites = await promise; + expect(sites.includes("example.com")).to.be.true; + }); + }); + + + describe("runtime message removeDomain", () => { + it("should have removed the domain", async () => { + await background.browser.runtime.onMessage.addListener.yield({ + removeDomain: "example.com" + }, {}); + + const [promise] = await background.browser.runtime.onMessage.addListener.yield("what-sites-are-added", {}); + const sites = await promise; + expect(sites.includes("example.com")).to.be.false; + }); + }); + }); + +}); \ No newline at end of file diff --git a/test/features/block-subresources.test.js b/test/features/block-subresources.test.js new file mode 100644 index 00000000..0827e1fb --- /dev/null +++ b/test/features/block-subresources.test.js @@ -0,0 +1,65 @@ +describe("Block SubResources", () => { + let webExtension, background; + + beforeEach(async () => { + webExtension = await loadWebExtension(); + background = webExtension.background; + }); + + describe("origin url is not facebook", () => { + it("should block subresources", async () => { + const promise = background.browser.webRequest.onBeforeRequest.addListener.secondCall.yield({ + url: "https://fbcdn.net", + originUrl: "https://example.com" + }); + + expect(await promise).to.deep.equal({cancel: true}); + }); + + it("should not block subresources if origin url is added to facebook container", async () => { + background.browser.storage.local.set({ + domainsAddedToFacebookContainer: ["example.com"] + }); + + const promise = background.browser.webRequest.onBeforeRequest.addListener.secondCall.yield({ + url: "https://fbcdn.net", + originUrl: "https://example.com" + }); + + expect(await promise).to.deep.equal({}); + }); + }); + + describe("origin url is facebook", () => { + it("should not block subresources", async () => { + const promise = background.browser.webRequest.onBeforeRequest.addListener.secondCall.yield({ + url: "https://fbcdn.net", + originUrl: "https://www.facebook.com" + }); + + expect(await promise).to.deep.equal({}); + }); + }); + + describe("origin url undefined", () => { + it("should not block subresources", async () => { + const promise = background.browser.webRequest.onBeforeRequest.addListener.secondCall.yield({ + url: "https://fbcdn.net", + originUrl: undefined + }); + + expect(await promise).to.deep.equal({}); + }); + }); + + describe("request url is not facebook", () => { + it("should not block subresources", async () => { + const promise = background.browser.webRequest.onBeforeRequest.addListener.secondCall.yield({ + url: "https://www.example.com", + originUrl: "https://www.example.com" + }); + + expect(await promise).to.deep.equal({}); + }); + }); +}); \ No newline at end of file