test_non-ascii-cookie.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 type="application/javascript" 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. </div>
  17. <pre id="test">
  18. <script type="application/javascript">
  19. /** Test for non-ASCII cookie values **/
  20. SimpleTest.waitForExplicitFinish();
  21. var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("file_cookiemanager.js"));
  22. function getCookieFromManager() {
  23. return new Promise(resolve => {
  24. gScript.addMessageListener("getCookieFromManager:return", function gcfm({ cookie }) {
  25. gScript.removeMessageListener("getCookieFromManager:return", gcfm);
  26. resolve(cookie);
  27. });
  28. gScript.sendAsyncMessage("getCookieFromManager", { host: location.hostname, path: location.pathname });
  29. });
  30. }
  31. var c = document.cookie;
  32. is(document.cookie, 'abc=012©ABC\ufffdDEF', "document.cookie should be decoded as UTF-8");
  33. var newCookie;
  34. getCookieFromManager().then((cookie) => {
  35. is(cookie, document.cookie, "nsICookieManager should be consistent with document.cookie");
  36. newCookie = 'def=∼≩≭≧∯≳≲≣∽≸≸∺≸∠≯≮≥≲≲≯≲∽≡≬≥≲≴∨∱∩∾';
  37. document.cookie = newCookie;
  38. is(document.cookie, c + '; ' + newCookie, "document.cookie should be encoded as UTF-8");
  39. return getCookieFromManager();
  40. }).then((cookie) => {
  41. is(cookie, document.cookie, "nsICookieManager should be consistent with document.cookie");
  42. var date1 = new Date();
  43. date1.setTime(0);
  44. document.cookie = newCookie + 'def=;expires=' + date1.toGMTString();
  45. gScript.destroy();
  46. SimpleTest.finish();
  47. });
  48. </script>
  49. </pre>
  50. </body>
  51. </html>