-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature tests for block subresources and add domains
- Loading branch information
1 parent
51c711b
commit b0d7260
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}); | ||
}); | ||
}); | ||
}); |