test_1331680.html (2792B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1331680 5 --> 6 <head> 7 <title>Cookies set in content processes update immediately.</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1331680">Mozilla Bug 1331680</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 <script type="application/javascript"> 16 17 SimpleTest.waitForExplicitFinish(); 18 19 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('file_1331680.js')); 20 21 // Bug 1617611: Fix all the tests broken by "cookies SameSite=lax by default" 22 SpecialPowers.pushPrefEnv({ 23 "set": [ 24 ["network.cookie.sameSite.laxByDefault", false], 25 ] 26 }, () => { 27 gScript.addMessageListener("cookieName", confirmCookieName); 28 gScript.addMessageListener("createObserver:return", testSetCookie); 29 gScript.addMessageListener("removeObserver:return", finishTest); 30 gScript.sendAsyncMessage('createObserver'); 31 }); 32 33 var testsNum = 0; 34 35 function confirmRemoveAllCookies() { 36 is(document.cookie, "", "Removed all cookies."); 37 SpecialPowers.clearUserPref("network.cookie.sameSite.laxByDefault"); 38 SimpleTest.finish(); 39 } 40 41 // Confirm the notify which represents the cookie is updating. 42 function confirmCookieName(name) { 43 testsNum++; 44 switch(testsNum) { 45 case 1: 46 case 3: 47 is(name, "cookie0=test1", "An update for the cookie named " + name + " was observed."); 48 break; 49 case 2: 50 is(name, "cookie2=test3", "An update for the cookie named " + name + " was observed."); 51 break; 52 case 4: 53 is(name, "cookie2=test3", "An update for the cookie named " + name + " was observed."); 54 gScript.sendAsyncMessage('removeObserver'); 55 break; 56 } 57 } 58 59 function finishTest() { 60 is(document.cookie, "", "Removed all cookies from cookie-changed"); 61 SimpleTest.finish(); 62 } 63 64 /* Test document.cookie 65 * 1. Set a cookie and confirm the cookies which are processed from observer. 66 * 2. Set a cookie and get cookie. 67 */ 68 const COOKIE_NAMES = ["cookie0", "cookie1", "cookie2"]; 69 function testSetCookie() { 70 document.cookie = COOKIE_NAMES[0] + "=test1"; 71 document.cookie = COOKIE_NAMES[1] + "=test2; HttpOnly"; 72 document.cookie = COOKIE_NAMES[2] + "=test3"; 73 var confirmCookieString = COOKIE_NAMES[0] + "=test1; " + COOKIE_NAMES[2] + "=test3"; 74 is(document.cookie, confirmCookieString, "Confirm the cookies string which be get is current."); 75 for (var i = 0; i < COOKIE_NAMES.length; i++) { 76 document.cookie = COOKIE_NAMES[i] + "=; expires=Thu, 01-Jan-1970 00:00:01 GMT;"; 77 } 78 is(document.cookie, "", "Removed all cookies."); 79 } 80 81 </script> 82 83 </div> 84 <pre id="test"> 85 </pre> 86 </body> 87 </html>