2 <?xml-stylesheet type=
"text/css" href=
"chrome://global/skin"?>
3 <?xml-stylesheet type=
"text/css" href=
"chrome://mochikit/content/tests/SimpleTest/test.css"?>
5 https://bugzilla.mozilla.org/show_bug.cgi?id=543854
7 <window title=
"Mozilla Bug 543854"
8 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
11 <!-- test results are displayed in the html:body -->
12 <body xmlns=
"http://www.w3.org/1999/xhtml">
13 <a href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=543854"
14 target=
"_blank">Mozilla Bug
543854</a>
17 <!-- test code goes here -->
18 <script type=
"application/javascript">
21 /** Test for Bug
543854 **/
23 SimpleTest.waitForExplicitFinish();
25 const ASCIIName =
"myprofile";
26 const UnicodeName =
"\u09A0\u09BE\u0995\u09C1\u09B0"; // A Bengali name
28 var gDirService = SpecialPowers.Services.dirsvc;
29 var gIOService = SpecialPowers.Services.io;
31 var gDefaultLocalProfileParent;
33 gProfileService = Cc[
"@mozilla.org/toolkit/profile-service;1"].
34 getService(Ci.nsIToolkitProfileService);
36 gDefaultLocalProfileParent = gDirService.get(
"DefProfLRt", Ci.nsIFile);
38 createProfile(ASCIIName);
39 createProfile(UnicodeName);
43 * Read the contents of an nsIFile. Throws on error.
45 * @param file an nsIFile instance.
46 * @return string contents.
48 function readFile(file) {
49 let fstream = Cc[
"@mozilla.org/network/file-input-stream;1"].
50 createInstance(Ci.nsIFileInputStream);
51 let sstream = Cc[
"@mozilla.org/scriptableinputstream;1"].
52 createInstance(Ci.nsIScriptableInputStream);
55 const READ_OTHERS =
4;
57 fstream.init(file, RO, READ_OTHERS,
0);
58 sstream.init(fstream);
59 let out = sstream.read(sstream.available());
65 function checkBounds(lowerBound, value, upperBound) {
66 ok(lowerBound <= value,
"value " + value +
67 " is above lower bound " + lowerBound);
68 ok(upperBound
>= value,
"value " + value +
69 " is within upper bound " + upperBound);
72 function createProfile(profileName) {
73 // Filesystem precision is lower than Date precision.
74 let lowerBound = Date.now() -
1000;
76 let profile = gProfileService.createProfile(null, profileName);
78 // check that the directory was created
79 isnot(profile, null,
"Profile " + profileName +
" created");
81 let profileDir = profile.rootDir;
83 ok(profileDir.exists(),
"Profile dir created");
84 ok(profileDir.isDirectory(),
"Profile dir is a directory");
86 let profileDirPath = profileDir.path;
88 is(profileDirPath.substr(profileDirPath.length - profileName.length),
89 profileName,
"Profile dir has expected name");
91 // Ensure that our timestamp file was created.
92 let jsonFile = profileDir.clone();
93 jsonFile.append(
"times.json");
94 ok(jsonFile.path,
"Path is " + jsonFile.path);
95 ok(jsonFile.exists(),
"Times file was created");
96 ok(jsonFile.isFile(),
"Times file is a file");
97 let json = JSON.parse(readFile(jsonFile));
99 let upperBound = Date.now() +
1000;
101 let created = json.created;
102 ok(created,
"created is set");
104 // Check against real clock time.
105 checkBounds(lowerBound, created, upperBound);
107 // Clean up the profile before local profile test.
108 profile.remove(true);
109 ok(!jsonFile.exists(),
"Times file was removed");
110 ok(!profileDir.exists(),
"Profile dir was removed");
112 // Create with non-null aRootDir
113 profile = gProfileService.createProfile(profileDir, profileName);
115 let localProfileDir = profile.localDir;
116 ok(gDefaultLocalProfileParent.contains(localProfileDir, false),
117 "Local profile dir created in DefProfLRt");
119 // Clean up the profile.
120 profile.remove(true);
121 ok(!profileDir.exists(),
"Profile dir was removed");