Skip to content

Commit

Permalink
Add feature tests for block subresources and add domains
Browse files Browse the repository at this point in the history
  • Loading branch information
stoically authored and maxxcrawford committed Oct 25, 2019
1 parent 51c711b commit b0d7260
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/features/add-domain-to-fbc.test.js
Original file line number Diff line number Diff line change
@@ -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;
});
});
});

});
65 changes: 65 additions & 0 deletions test/features/block-subresources.test.js
Original file line number Diff line number Diff line change
@@ -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({});
});
});
});

0 comments on commit b0d7260

Please sign in to comment.