Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cookie parsing for the CookieChanger module
This includes parsing an empty cookie, which allows the CookieChanger users to add values even if no cookie was sent in the first place. It also enables adding a method for removing cookies in the future. Unit tests for the parsing of basic cookies are included.
- Loading branch information
Showing
2 changed files
with
38 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,28 @@ | ||
const {Cookies, modifyPrefCookie} = require("../lib/CookieChanger"); | ||
|
||
exports.testCookieParsing = (assert) => { | ||
var t = (cookieString) => { | ||
return (new Cookies(cookieString)).unparse(); | ||
}; | ||
|
||
assert.equal(t(""), ""); | ||
assert.equal(t("a=b"), "a=b"); | ||
assert.equal(t("a=1; b=2"), "a=1; b=2"); | ||
assert.equal(t("b=2; a=1"), "b=2; a=1"); | ||
|
||
assert.equal(t("a=1; b=2"), "a=1; b=2"); | ||
assert.equal(t("a=1; ; b=2"), "a=1; b=2"); | ||
assert.equal(t("a=1;; b=2"), "a=1; b=2"); | ||
assert.equal(t("a=1;;b=2"), "a=1; b=2"); | ||
assert.equal(t("a=1 ;b=2"), "a=1 ; b=2"); | ||
|
||
// Cookies uses a Map as its backend | ||
assert.equal(t("a=1; a=2"), "a=2"); | ||
|
||
assert.equal(t("abc"), ""); | ||
assert.equal(t("abc="), "abc="); | ||
assert.equal(t("=abc"), "=abc"); | ||
assert.equal(t("a=1; abc; b=2"), "a=1; b=2"); | ||
}; | ||
|
||
require('sdk/test').run(exports); |