diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /netwerk/test/unit/test_private_cookie_changed.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream/1%115.7.0.tar.xz thunderbird-upstream/1%115.7.0.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_private_cookie_changed.js')
-rw-r--r-- | netwerk/test/unit/test_private_cookie_changed.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_private_cookie_changed.js b/netwerk/test/unit/test_private_cookie_changed.js new file mode 100644 index 0000000000..89e9f5e75a --- /dev/null +++ b/netwerk/test/unit/test_private_cookie_changed.js @@ -0,0 +1,44 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +function makeChan(uri, isPrivate) { + var chan = NetUtil.newChannel({ + uri: uri.spec, + loadUsingSystemPrincipal: true, + }).QueryInterface(Ci.nsIHttpChannel); + + chan.QueryInterface(Ci.nsIPrivateBrowsingChannel).setPrivate(isPrivate); + return chan; +} + +function run_test() { + // We don't want to have CookieJarSettings blocking this test. + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + + // Allow all cookies. + Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); + + let publicNotifications = 0; + let privateNotifications = 0; + Services.obs.addObserver(function () { + publicNotifications++; + }, "cookie-changed"); + Services.obs.addObserver(function () { + privateNotifications++; + }, "private-cookie-changed"); + + let uri = NetUtil.newURI("http://foo.com/"); + let publicChan = makeChan(uri, false); + let svc = Services.cookies.QueryInterface(Ci.nsICookieService); + svc.setCookieStringFromHttp(uri, "oh=hai", publicChan); + let privateChan = makeChan(uri, true); + svc.setCookieStringFromHttp(uri, "oh=hai", privateChan); + Assert.equal(publicNotifications, 1); + Assert.equal(privateNotifications, 1); +} |