browser_sameSiteConsole.js (3867B)
1 "use strict"; 2 3 const SAMESITE_DOMAIN = "http://example.com/"; 4 const SAMESITE_PATH = "browser/netwerk/cookie/test/browser/"; 5 const SAMESITE_TOP_PAGE = SAMESITE_DOMAIN + SAMESITE_PATH + "sameSite.sjs"; 6 7 add_task(async _ => { 8 Services.cookies.removeAll(); 9 10 await SpecialPowers.pushPrefEnv({ 11 set: [ 12 ["network.cookie.sameSite.laxByDefault", true], 13 ["network.cookie.sameSite.noneRequiresSecure", true], 14 ], 15 }); 16 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 “a” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.", 50 }); 51 }), 52 53 new Promise(resolve => { 54 expected.push({ 55 resolve, 56 match: 57 "Cookie “b” rejected because it has the “SameSite=None” attribute but is missing the “secure” attribute.", 58 }); 59 }), 60 61 new Promise(resolve => { 62 expected.push({ 63 resolve, 64 match: 65 "Invalid “SameSite“ value for cookie “c”. The supported values are: “Lax“, “Strict“, “None“.", 66 }); 67 }), 68 69 new Promise(resolve => { 70 expected.push({ 71 resolve, 72 match: 73 "Cookie “c” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.", 74 }); 75 }), 76 ]; 77 78 // Let's open our tab. 79 const tab = BrowserTestUtils.addTab(gBrowser, SAMESITE_TOP_PAGE); 80 gBrowser.selectedTab = tab; 81 82 const browser = gBrowser.getBrowserForTab(tab); 83 await BrowserTestUtils.browserLoaded(browser); 84 85 // Let's wait for the first set of console events. 86 await Promise.all(netPromises); 87 88 // the DOM list of events. 89 const domPromises = [ 90 new Promise(resolve => { 91 expected.push({ 92 resolve, 93 match: 94 "Cookie “d” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.", 95 }); 96 }), 97 98 new Promise(resolve => { 99 expected.push({ 100 resolve, 101 match: 102 "Cookie “e” rejected because it has the “SameSite=None” attribute but is missing the “secure” attribute.", 103 }); 104 }), 105 106 new Promise(resolve => { 107 expected.push({ 108 resolve, 109 match: 110 "Invalid “SameSite“ value for cookie “f”. The supported values are: “Lax“, “Strict“, “None“.", 111 }); 112 }), 113 114 new Promise(resolve => { 115 expected.push({ 116 resolve, 117 match: 118 "Cookie “f” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.", 119 }); 120 }), 121 ]; 122 123 // Let's use document.cookie 124 SpecialPowers.spawn(browser, [], () => { 125 content.document.cookie = "d=4"; 126 content.document.cookie = "e=5; sameSite=none"; 127 content.document.cookie = "f=6; sameSite=batmat"; 128 }); 129 130 // Let's wait for the dom events. 131 await Promise.all(domPromises); 132 133 // Let's close the tab. 134 BrowserTestUtils.removeTab(tab); 135 });