test_non-ascii-cookie.html (2256B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=784367 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for non-ASCII cookie values</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=784367">Mozilla Bug 784367</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for non-ASCII cookie values */ 22 23 SimpleTest.waitForExplicitFinish(); 24 25 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("file_cookiemanager.js")); 26 27 function getCookieFromManager() { 28 return new Promise(resolve => { 29 gScript.addMessageListener("getCookieFromManager:return", function gcfm({ cookie }) { 30 gScript.removeMessageListener("getCookieFromManager:return", gcfm); 31 resolve(cookie); 32 }); 33 gScript.sendAsyncMessage("getCookieFromManager", { host: location.hostname, path: location.pathname }); 34 }); 35 } 36 37 SpecialPowers.pushPrefEnv({ 38 "set": [ 39 // Bug 1617611: Fix all the tests broken by "cookies SameSite=lax by default" 40 ["network.cookie.sameSite.laxByDefault", false], 41 ] 42 }, () => { 43 var c = document.cookie; 44 is(document.cookie, 'abc=012©ABC\ufffdDEF', "document.cookie should be decoded as UTF-8"); 45 46 var newCookie; 47 48 getCookieFromManager().then((cookie) => { 49 is(cookie, document.cookie, "nsICookieManager should be consistent with document.cookie"); 50 newCookie = 'def=∼≩≭≧∯≳≲≣∽≸≸∺≸∠≯≮≥≲≲≯≲∽≡≬≥≲≴∨∱∩∾'; 51 document.cookie = newCookie; 52 is(document.cookie, c + '; ' + newCookie, "document.cookie should be encoded as UTF-8"); 53 54 return getCookieFromManager(); 55 }).then((cookie) => { 56 is(cookie, document.cookie, "nsICookieManager should be consistent with document.cookie"); 57 var date1 = new Date(); 58 date1.setTime(0); 59 document.cookie = newCookie + 'def=;expires=' + date1.toGMTString(); 60 gScript.destroy(); 61 SpecialPowers.clearUserPref("network.cookie.sameSite.laxByDefault"); 62 SimpleTest.finish(); 63 }); 64 }); 65 66 </script> 67 </pre> 68 </body> 69 </html>