-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Gérer la suppression de permissions optionnelles.
- Loading branch information
Showing
4 changed files
with
120 additions
and
4 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
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,24 @@ | ||
/** | ||
* @module | ||
*/ | ||
|
||
/** | ||
* Actualise la configuration suite la suppression de permissions optionnelles. | ||
* | ||
* @param {Object} changes Les changements sur les permissions. | ||
* @param {string[]} changes.permissions Les permissions supprimées. | ||
*/ | ||
const handleRemove = async function ({ permissions }) { | ||
if (permissions.includes("history")) { | ||
browser.storage.local.set({ "general-history": false }); | ||
} | ||
if (permissions.includes("bookmarks")) { | ||
const config = await browser.storage.local.get(["menu-contexts"]); | ||
const contexts = config["menu-contexts"]; | ||
browser.storage.local.set({ | ||
"menu-contexts": contexts.filter((c) => "bookmark" !== c), | ||
}); | ||
} | ||
}; | ||
|
||
browser.permissions.onRemoved.addListener(handleRemove); |
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
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,59 @@ | ||
import assert from "assert"; | ||
// eslint-disable-next-line import/no-unassigned-import | ||
import "../../../src/background/permissions.js"; | ||
|
||
describe("background/permissions.js", function () { | ||
describe("handleRemove()", function () { | ||
it("should handle history", async function () { | ||
await browser.permissions.request({ | ||
permissions: ["foo", "history"], | ||
}); | ||
browser.storage.local.set({ "general-history": true }); | ||
|
||
await browser.permissions.remove({ permissions: ["foo"] }); | ||
let config = await browser.storage.local.get(["general-history"]); | ||
assert.strictEqual(config["general-history"], true); | ||
|
||
await browser.permissions.remove({ permissions: [] }); | ||
config = await browser.storage.local.get(["general-history"]); | ||
assert.strictEqual(config["general-history"], true); | ||
|
||
await browser.permissions.remove({ permissions: ["history"] }); | ||
config = await browser.storage.local.get(["general-history"]); | ||
assert.strictEqual(config["general-history"], false); | ||
|
||
await browser.permissions.remove({ permissions: ["history"] }); | ||
config = await browser.storage.local.get(["general-history"]); | ||
assert.strictEqual(config["general-history"], false); | ||
|
||
browser.storage.local.clear(); | ||
}); | ||
|
||
it("should handle bookmarks", async function () { | ||
await browser.permissions.request({ | ||
permissions: ["foo", "bookmarks"], | ||
}); | ||
browser.storage.local.set({ "menu-contexts": ["bar", "bookmark"] }); | ||
|
||
await browser.permissions.remove({ permissions: ["foo"] }); | ||
let config = await browser.storage.local.get(["menu-contexts"]); | ||
assert.deepStrictEqual(config["menu-contexts"], | ||
["bar", "bookmark"]); | ||
|
||
await browser.permissions.remove({ permissions: [] }); | ||
config = await browser.storage.local.get(["menu-contexts"]); | ||
assert.deepStrictEqual(config["menu-contexts"], | ||
["bar", "bookmark"]); | ||
|
||
await browser.permissions.remove({ permissions: ["bookmarks"] }); | ||
config = await browser.storage.local.get(["menu-contexts"]); | ||
assert.deepStrictEqual(config["menu-contexts"], ["bar"]); | ||
|
||
await browser.permissions.remove({ permissions: ["bookmarks"] }); | ||
config = await browser.storage.local.get(["menu-contexts"]); | ||
assert.deepStrictEqual(config["menu-contexts"], ["bar"]); | ||
|
||
browser.storage.local.clear(); | ||
}); | ||
}); | ||
}); |