browser_webconsole_warning_group_cookies.js (6969B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Load a page that generates cookie warning/info messages. See bug 1622306. 5 6 "use strict"; 7 requestLongerTimeout(2); 8 9 const TEST_FILE = 10 "browser/devtools/client/webconsole/test/browser/test-warning-groups.html"; 11 const COOKIE_GROUP = "Cookie warnings"; 12 13 pushPref("devtools.webconsole.groupSimilarMessages", true); 14 pushPref("network.cookie.sameSite.laxByDefaultWarningsForBeta", true); 15 16 async function cleanUp() { 17 await new Promise(resolve => { 18 Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, () => 19 resolve() 20 ); 21 }); 22 } 23 24 add_task(cleanUp); 25 26 add_task(async function testSameSiteCookieMessage() { 27 const tests = [ 28 { 29 pref: true, 30 message1: 31 "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.", 32 typeMessage1: ".info", 33 message2: 34 "Cookie “b” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.", 35 }, 36 { 37 pref: false, 38 message1: 39 "Cookie “a” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value", 40 typeMessage1: ".warn", 41 message2: 42 "Cookie “b” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value", 43 }, 44 ]; 45 46 for (const test of tests) { 47 info("LaxByDefault: " + test.pref); 48 await pushPref("network.cookie.sameSite.laxByDefault", test.pref); 49 50 const { hud, tab, win } = await openNewWindowAndConsole( 51 "http://example.org/" + TEST_FILE 52 ); 53 54 info("Test cookie messages"); 55 const onLaxMissingWarningMessage = waitForMessageByType( 56 hud, 57 test.message1, 58 test.typeMessage1 59 ); 60 61 SpecialPowers.spawn(tab.linkedBrowser, [], () => { 62 content.wrappedJSObject.createCookie("a=1"); 63 }); 64 65 await onLaxMissingWarningMessage; 66 67 ok(true, "The first message was displayed"); 68 69 info("Emit a new cookie message to check that it causes a grouping"); 70 71 const onCookieSameSiteWarningGroupMessage = waitForMessageByType( 72 hud, 73 COOKIE_GROUP, 74 ".warn" 75 ); 76 77 SpecialPowers.spawn(tab.linkedBrowser, [], () => { 78 content.wrappedJSObject.createCookie("b=1"); 79 }); 80 81 const { node } = await onCookieSameSiteWarningGroupMessage; 82 is( 83 node.querySelector(".warning-group-badge").textContent, 84 "2", 85 "The badge has the expected text" 86 ); 87 88 await checkConsoleOutputForWarningGroup(hud, [`▶︎⚠ ${COOKIE_GROUP} 2`]); 89 90 info("Open the group"); 91 node.querySelector(".arrow").click(); 92 await waitFor(() => findWarningMessage(hud, "Cookie")); 93 94 await checkConsoleOutputForWarningGroup(hud, [ 95 `▼︎⚠ ${COOKIE_GROUP} 2`, 96 `| ${test.message1}`, 97 `| ${test.message2}`, 98 ]); 99 100 await win.close(); 101 } 102 }); 103 104 add_task(cleanUp); 105 106 add_task(async function testInvalidSameSiteMessage() { 107 await pushPref("network.cookie.sameSite.laxByDefault", true); 108 109 const message1 = 110 "Invalid “SameSite“ value for cookie “a”. The supported values are: “Lax“, “Strict“, “None“."; 111 const message2 = 112 "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."; 113 114 const { hud, tab, win } = await openNewWindowAndConsole( 115 "http://example.org/" + TEST_FILE 116 ); 117 118 info("Test cookie messages"); 119 120 SpecialPowers.spawn(tab.linkedBrowser, [], () => { 121 content.wrappedJSObject.createCookie("a=1; sameSite=batman"); 122 }); 123 124 const { node } = await waitForMessageByType(hud, COOKIE_GROUP, ".warn"); 125 is( 126 node.querySelector(".warning-group-badge").textContent, 127 "2", 128 "The badge has the expected text" 129 ); 130 131 await checkConsoleOutputForWarningGroup(hud, [`▶︎⚠ ${COOKIE_GROUP} 2`]); 132 133 info("Open the group"); 134 node.querySelector(".arrow").click(); 135 await waitFor(() => findWarningMessage(hud, "Cookie")); 136 137 await checkConsoleOutputForWarningGroup(hud, [ 138 `▼︎⚠ ${COOKIE_GROUP} 2`, 139 `| ${message2}`, 140 `| ${message1}`, 141 ]); 142 143 // Source map are being resolved in background and we might have 144 // pending request related to this service if we close the window 145 // immeditely. So just wait for these request to finish before proceeding. 146 await hud.toolbox.sourceMapURLService.waitForSourcesLoading(); 147 148 await win.close(); 149 }); 150 151 add_task(cleanUp); 152 153 add_task(async function testInvalidMaxAgeMessage() { 154 const message1 = 155 "Invalid “max-age“ value for cookie “a”. The attribute is ignored."; 156 const message2 = 157 "Invalid “max-age“ value for cookie “b”. The attribute is ignored."; 158 159 const { hud, tab, win } = await openNewWindowAndConsole( 160 "http://example.org/" + TEST_FILE 161 ); 162 163 info("Test cookie messages"); 164 165 SpecialPowers.spawn(tab.linkedBrowser, [], () => { 166 content.wrappedJSObject.createCookie("a=1; max-age=abc; samesite=lax"); 167 content.wrappedJSObject.createCookie("b=1; max-age=1,2; samesite=lax"); 168 }); 169 170 const { node } = await waitForMessageByType(hud, COOKIE_GROUP, ".warn"); 171 is( 172 node.querySelector(".warning-group-badge").textContent, 173 "2", 174 "The badge has the expected text" 175 ); 176 177 await checkConsoleOutputForWarningGroup(hud, [`▶︎⚠ ${COOKIE_GROUP} 2`]); 178 179 info("Open the group"); 180 node.querySelector(".arrow").click(); 181 await waitFor(() => findWarningMessage(hud, "Cookie")); 182 183 await checkConsoleOutputForWarningGroup(hud, [ 184 `▼︎⚠ ${COOKIE_GROUP} 2`, 185 `| ${message1}`, 186 `| ${message2}`, 187 ]); 188 189 // Source map are being resolved in background and we might have 190 // pending request related to this service if we close the window 191 // immeditely. So just wait for these request to finish before proceeding. 192 await hud.toolbox.sourceMapURLService.waitForSourcesLoading(); 193 194 await win.close(); 195 }); 196 197 add_task(cleanUp);