browser_cookie_empty_name_value.js (2281B)
1 "use strict"; 2 3 const EMPTYNAMEVALUE_DOMAIN = "https://example.com/"; 4 const EMPTYNAMEVALUE_PATH = "browser/netwerk/cookie/test/browser/"; 5 const EMPTYNAMEVALUE_TOP_PAGE = 6 EMPTYNAMEVALUE_DOMAIN + EMPTYNAMEVALUE_PATH + "cookie_empty_name_value.sjs"; 7 8 add_setup(async function () { 9 Services.cookies.removeAll(); 10 11 registerCleanupFunction(async function () { 12 Services.cookies.removeAll(); 13 }); 14 }); 15 16 add_task(async _ => { 17 const expected = []; 18 19 const consoleListener = { 20 observe(what) { 21 if (!(what instanceof Ci.nsIConsoleMessage)) { 22 return; 23 } 24 25 info("Console Listener: " + what); 26 for (let i = expected.length - 1; i >= 0; --i) { 27 const e = expected[i]; 28 29 if (what.message.includes(e.match)) { 30 ok(true, "Message received: " + e.match); 31 expected.splice(i, 1); 32 e.resolve(); 33 } 34 } 35 }, 36 }; 37 38 Services.console.registerListener(consoleListener); 39 40 registerCleanupFunction(() => 41 Services.console.unregisterListener(consoleListener) 42 ); 43 44 const netPromises = [ 45 new Promise(resolve => { 46 expected.push({ 47 resolve, 48 match: 49 "Cookie with an empty name and an empty value has been rejected.", 50 }); 51 }), 52 ]; 53 54 // Let's open our tab. 55 const tab = await BrowserTestUtils.openNewForegroundTab( 56 gBrowser, 57 EMPTYNAMEVALUE_TOP_PAGE 58 ); 59 const browser = gBrowser.getBrowserForTab(tab); 60 61 // Let's wait for the first set of console events. 62 await Promise.all(netPromises); 63 64 await SpecialPowers.spawn(browser, [], () => { 65 Assert.strictEqual(content.document.cookie, "", "No cookies set"); 66 }); 67 68 // the DOM list of events. 69 const domPromises = [ 70 new Promise(resolve => { 71 expected.push({ 72 resolve, 73 match: 74 "Cookie with an empty name and an empty value has been rejected.", 75 }); 76 }), 77 ]; 78 79 // Let's use document.cookie 80 await SpecialPowers.spawn(browser, [], () => { 81 content.document.cookie = " ; path=/; secure"; 82 }); 83 84 // Let's wait for the dom events. 85 await Promise.all(domPromises); 86 87 await SpecialPowers.spawn(browser, [], () => { 88 Assert.strictEqual(content.document.cookie, "", "No cookies set"); 89 }); 90 91 // Let's close the tab. 92 BrowserTestUtils.removeTab(tab); 93 });