diff options
Diffstat (limited to 'netwerk/test/unit/test_cookie_ipv6.js')
-rw-r--r-- | netwerk/test/unit/test_cookie_ipv6.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_cookie_ipv6.js b/netwerk/test/unit/test_cookie_ipv6.js new file mode 100644 index 0000000000..70bb360e0f --- /dev/null +++ b/netwerk/test/unit/test_cookie_ipv6.js @@ -0,0 +1,52 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Test that channels with different LoadInfo + * are stored in separate namespaces ("cookie jars") + */ + +"use strict"; + +let ip = "[::1]"; +XPCOMUtils.defineLazyGetter(this, "URL", function() { + return `http://${ip}:${httpserver.identity.primaryPort}/`; +}); + +const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js"); + +let httpserver = new HttpServer(); + +function cookieSetHandler(metadata, response) { + response.setStatusLine(metadata.httpVersion, 200, "Ok"); + response.setHeader( + "Set-Cookie", + `Set-Cookie: T1=T2; path=/; SameSite=Lax; domain=${ip}; httponly`, + false + ); + response.setHeader("Content-Type", "text/html"); + response.setHeader("Content-Length", "2"); + response.bodyOutputStream.write("Ok", "Ok".length); +} + +add_task(async function test_cookie_ipv6() { + Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); + Services.prefs.setBoolPref( + "network.cookieJarSettings.unblocked_for_testing", + true + ); + + httpserver.registerPathHandler("/", cookieSetHandler); + httpserver._start(-1, ip); + + var chan = NetUtil.newChannel({ + uri: URL, + loadUsingSystemPrincipal: true, + }); + await new Promise(resolve => { + chan.asyncOpen(new ChannelListener(resolve)); + }); + var cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager); + equal(cm.cookies.length, 1); +}); |