test_bug643051.js (1354B)
1 const { NetUtil } = ChromeUtils.importESModule( 2 "resource://gre/modules/NetUtil.sys.mjs" 3 ); 4 const { CookieXPCShellUtils } = ChromeUtils.importESModule( 5 "resource://testing-common/CookieXPCShellUtils.sys.mjs" 6 ); 7 8 CookieXPCShellUtils.init(this); 9 CookieXPCShellUtils.createServer({ hosts: ["example.net"] }); 10 11 add_task(async () => { 12 Services.prefs.setBoolPref("dom.security.https_first", false); 13 14 // Allow all cookies. 15 Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); 16 Services.prefs.setBoolPref( 17 "network.cookieJarSettings.unblocked_for_testing", 18 true 19 ); 20 21 let uri = NetUtil.newURI("http://example.org/"); 22 let channel = NetUtil.newChannel({ 23 uri, 24 loadUsingSystemPrincipal: true, 25 contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT, 26 }); 27 28 let set = "foo=bar\nbaz=foo"; 29 let expected = "foo=bar; baz=foo"; 30 set 31 .split("\n") 32 .forEach(s => Services.cookies.setCookieStringFromHttp(uri, s, channel)); 33 34 let actual = Services.cookies.getCookieStringFromHttp(uri, channel); 35 Assert.equal(actual, expected); 36 37 await CookieXPCShellUtils.setCookieToDocument("http://example.net/", set); 38 actual = await CookieXPCShellUtils.getCookieStringFromDocument( 39 "http://example.net/" 40 ); 41 42 expected = ""; 43 Assert.equal(actual, expected); 44 Services.prefs.clearUserPref("dom.security.https_first"); 45 });