content/html/document/test/test_non-ascii-cookie.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/html/document/test/test_non-ascii-cookie.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=784367
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for non-ASCII cookie values</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=784367">Mozilla Bug 784367</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +  
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<script type="application/javascript">
    1.23 +
    1.24 +/** Test for non-ASCII cookie values **/
    1.25 +
    1.26 +var [Cc, Ci] = [SpecialPowers.Cc, SpecialPowers.Ci];
    1.27 +
    1.28 +var cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
    1.29 +function getCookieFromManager() {
    1.30 +  var values = [];
    1.31 +  var host = location.hostname;
    1.32 +  var path = location.pathname;
    1.33 +  path = path.substring(0, path.lastIndexOf("/") + 1);
    1.34 +  var e = cm.enumerator;
    1.35 +  while (e.hasMoreElements()) {
    1.36 +    var cookie = e.getNext().QueryInterface(Ci.nsICookie);
    1.37 +    if (!cookie) {
    1.38 +      break;
    1.39 +    }
    1.40 +    if (host != cookie.host || path != cookie.path) {
    1.41 +      continue;
    1.42 +    }
    1.43 +    values.push(cookie.name + "=" + cookie.value);
    1.44 +  }
    1.45 +  return values.join("; ");
    1.46 +}
    1.47 +
    1.48 +var c = document.cookie;
    1.49 +is(document.cookie, 'abc=012©ABC\ufffdDEF', "document.cookie should be decoded as UTF-8");
    1.50 +is(getCookieFromManager(), document.cookie, "nsICookieManager should be consistent with document.cookie");
    1.51 +var newCookie = 'def=∼≩≭≧∯≳≲≣∽≸≸∺≸∠≯≮≥≲≲≯≲∽≡≬≥≲≴∨∱∩∾';
    1.52 +document.cookie = newCookie;
    1.53 +is(document.cookie, c + '; ' + newCookie, "document.cookie should be encoded as UTF-8");
    1.54 +is(getCookieFromManager(), document.cookie, "nsICookieManager should be consistent with document.cookie");
    1.55 +var date1 = new Date();
    1.56 +date1.setTime(0);
    1.57 +document.cookie = newCookie + 'def=;expires=' + date1.toGMTString();
    1.58 +</script>
    1.59 +</pre>
    1.60 +</body>
    1.61 +</html>

mercurial