Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
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">
17 </div>
18 <pre id="test">
19 <script type="application/javascript">
21 /** Test for non-ASCII cookie values **/
23 var [Cc, Ci] = [SpecialPowers.Cc, SpecialPowers.Ci];
25 var cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
26 function getCookieFromManager() {
27 var values = [];
28 var host = location.hostname;
29 var path = location.pathname;
30 path = path.substring(0, path.lastIndexOf("/") + 1);
31 var e = cm.enumerator;
32 while (e.hasMoreElements()) {
33 var cookie = e.getNext().QueryInterface(Ci.nsICookie);
34 if (!cookie) {
35 break;
36 }
37 if (host != cookie.host || path != cookie.path) {
38 continue;
39 }
40 values.push(cookie.name + "=" + cookie.value);
41 }
42 return values.join("; ");
43 }
45 var c = document.cookie;
46 is(document.cookie, 'abc=012©ABC\ufffdDEF', "document.cookie should be decoded as UTF-8");
47 is(getCookieFromManager(), document.cookie, "nsICookieManager should be consistent with document.cookie");
48 var newCookie = 'def=∼≩≭≧∯≳≲≣∽≸≸∺≸∠≯≮≥≲≲≯≲∽≡≬≥≲≴∨∱∩∾';
49 document.cookie = newCookie;
50 is(document.cookie, c + '; ' + newCookie, "document.cookie should be encoded as UTF-8");
51 is(getCookieFromManager(), document.cookie, "nsICookieManager should be consistent with document.cookie");
52 var date1 = new Date();
53 date1.setTime(0);
54 document.cookie = newCookie + 'def=;expires=' + date1.toGMTString();
55 </script>
56 </pre>
57 </body>
58 </html>