Skip to content

Commit

Permalink
#85 - removing cookie toggles whitelist state instead of removing it
Browse files Browse the repository at this point in the history
  • Loading branch information
Manvel committed Mar 6, 2020
1 parent acfefc7 commit 660033e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/js/ui/tabs/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async function setWhitelistDomain(domain, value)
await browser.storage.local.set({cookieWhitelist});
}

async function setWhitelistCookie(domain, cookie)
async function toggleWhitelistCookie(domain, cookie)
{
const {cookieWhitelist} = await browser.storage.local.get("cookieWhitelist");
if (!(domain in cookieWhitelist))
Expand All @@ -189,6 +189,16 @@ async function setWhitelistCookie(domain, cookie)
await browser.storage.local.set({cookieWhitelist});
}

async function removeWhitelistCookie(domain, cookie)
{
if (!await isCookieWhitelisted(domain, cookie))
return;

const {cookieWhitelist} = await browser.storage.local.get("cookieWhitelist");
cookieWhitelist[domain].cookies = cookieWhitelist[domain].cookies.filter(el => el !== cookie);
await browser.storage.local.set({cookieWhitelist});
}

async function onCookiesAction(action, item, parentItem)
{
pmTable = document.querySelector("pm-table");
Expand Down Expand Up @@ -234,7 +244,7 @@ async function onCookiesAction(action, item, parentItem)
{
const cookie = item.texts.name;
const domain = parentItem.texts.domain;
await setWhitelistCookie(domain, cookie);
await toggleWhitelistCookie(domain, cookie);
break;
}
case "delete-domain":
Expand Down Expand Up @@ -526,7 +536,7 @@ browser.cookies.onChanged.addListener(async({cookie, removed}) =>
else
{
pmTable.removeItem(cookie.name, domain);
setWhitelistCookie(domain, cookie.name, false);
removeWhitelistCookie(domain, cookie.name);
const domainItem = pmTable.getItem(domain);
domainItem.texts.cookienum = setCookiesNum(domainCounts[domain]);
pmTable.updateItem(domainItem, domain);
Expand Down
7 changes: 7 additions & 0 deletions test/puppeteer/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ describe("Testing Cookies tab", () =>
await page.waitFor(30);
equal(await isWhitelisted("name2", "domain5.com"), "false");
equal(await isWhitelisted("domain5.com"), "false");

// see https://github.com/Privacy-Managers/Privacy-Manager/issues/85
equal(await isWhitelisted("name2", "domain5.com"), "false");
await (await deleteButtonHandle("name1", "domain5.com")).click();
await addCookie("https://domain5.com", "name1", "value1");
await page.waitFor(30);
equal(await isWhitelisted("name1", "domain5.com"), "false");
});
it("Cookie is added using 'add cookies' dialog", async() =>
{
Expand Down

0 comments on commit 660033e

Please sign in to comment.