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 <?xml version="1.0"?>
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=543854
6 -->
7 <window title="Mozilla Bug 543854"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script type="application/javascript"
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
12 <!-- test results are displayed in the html:body -->
13 <body xmlns="http://www.w3.org/1999/xhtml">
14 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=543854"
15 target="_blank">Mozilla Bug 543854</a>
16 </body>
18 <!-- test code goes here -->
19 <script type="application/javascript">
20 <![CDATA[
22 /** Test for Bug 543854 **/
24 SimpleTest.waitForExplicitFinish();
26 const Cc = Components.classes;
27 const Ci = Components.interfaces;
29 const ASCIIName = "myprofile";
30 const UnicodeName = "\u09A0\u09BE\u0995\u09C1\u09B0"; // A Bengali name
32 var gDirService;
33 var gIOService;
34 var gProfileService;
36 var gDefaultLocalProfileParent;
38 gDirService = Cc["@mozilla.org/file/directory_service;1"].
39 getService(Ci.nsIProperties);
41 gIOService = Cc["@mozilla.org/network/io-service;1"].
42 getService(Ci.nsIIOService);
44 gProfileService = Cc["@mozilla.org/toolkit/profile-service;1"].
45 getService(Ci.nsIToolkitProfileService);
47 gDefaultLocalProfileParent = gDirService.get("DefProfLRt", Ci.nsIFile);
49 createProfile(ASCIIName);
50 createProfile(UnicodeName);
51 SimpleTest.finish();
53 /**
54 * Read the contents of an nsIFile. Throws on error.
56 * @param file an nsIFile instance.
57 * @return string contents.
58 */
59 function readFile(file) {
60 let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
61 createInstance(Ci.nsIFileInputStream);
62 let sstream = Cc["@mozilla.org/scriptableinputstream;1"].
63 createInstance(Components.interfaces.nsIScriptableInputStream);
65 const RO = 0x01;
66 const READ_OTHERS = 4;
68 fstream.init(file, RO, READ_OTHERS, 0);
69 sstream.init(fstream);
70 let out = sstream.read(sstream.available());
71 sstream.close();
72 fstream.close();
73 return out;
74 }
76 function checkBounds(lowerBound, value, upperBound) {
77 ok(lowerBound <= value, "value " + value +
78 " is above lower bound " + lowerBound);
79 ok(upperBound >= value, "value " + value +
80 " is within upper bound " + upperBound);
81 }
83 function createProfile(profileName) {
84 // Filesystem precision is lower than Date precision.
85 let lowerBound = Date.now() - 1000;
87 let profile = gProfileService.createProfile(null, profileName);
89 // check that the directory was created
90 isnot(profile, null, "Profile " + profileName + " created");
92 let profileDir = profile.rootDir;
94 ok(profileDir.exists(), "Profile dir created");
95 ok(profileDir.isDirectory(), "Profile dir is a directory");
97 let profileDirPath = profileDir.path;
99 is(profileDirPath.substr(profileDirPath.length - profileName.length),
100 profileName, "Profile dir has expected name");
102 // Ensure that our timestamp file was created.
103 let jsonFile = profileDir.clone();
104 jsonFile.append("times.json");
105 ok(jsonFile.path, "Path is " + jsonFile.path);
106 ok(jsonFile.exists(), "Times file was created");
107 ok(jsonFile.isFile(), "Times file is a file");
108 let json = JSON.parse(readFile(jsonFile));
110 let upperBound = Date.now() + 1000;
112 let created = json.created;
113 ok(created, "created is set");
115 // Check against real clock time.
116 checkBounds(lowerBound, created, upperBound);
118 // Clean up the profile before local profile test.
119 profile.remove(true);
121 // Create with non-null aRootDir
122 let profile = gProfileService.createProfile(profileDir, profileName);
124 let localProfileDir = profile.localDir;
125 ok(gDefaultLocalProfileParent.contains(localProfileDir, false),
126 "Local profile dir created in DefProfLRt");
128 // Clean up the profile.
129 profile.remove(true);
130 }
132 ]]>
133 </script>
134 </window>