|
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> |
|
11 |
|
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> |
|
17 |
|
18 <!-- test code goes here --> |
|
19 <script type="application/javascript"> |
|
20 <![CDATA[ |
|
21 |
|
22 /** Test for Bug 543854 **/ |
|
23 |
|
24 SimpleTest.waitForExplicitFinish(); |
|
25 |
|
26 const Cc = Components.classes; |
|
27 const Ci = Components.interfaces; |
|
28 |
|
29 const ASCIIName = "myprofile"; |
|
30 const UnicodeName = "\u09A0\u09BE\u0995\u09C1\u09B0"; // A Bengali name |
|
31 |
|
32 var gDirService; |
|
33 var gIOService; |
|
34 var gProfileService; |
|
35 |
|
36 var gDefaultLocalProfileParent; |
|
37 |
|
38 gDirService = Cc["@mozilla.org/file/directory_service;1"]. |
|
39 getService(Ci.nsIProperties); |
|
40 |
|
41 gIOService = Cc["@mozilla.org/network/io-service;1"]. |
|
42 getService(Ci.nsIIOService); |
|
43 |
|
44 gProfileService = Cc["@mozilla.org/toolkit/profile-service;1"]. |
|
45 getService(Ci.nsIToolkitProfileService); |
|
46 |
|
47 gDefaultLocalProfileParent = gDirService.get("DefProfLRt", Ci.nsIFile); |
|
48 |
|
49 createProfile(ASCIIName); |
|
50 createProfile(UnicodeName); |
|
51 SimpleTest.finish(); |
|
52 |
|
53 /** |
|
54 * Read the contents of an nsIFile. Throws on error. |
|
55 |
|
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); |
|
64 |
|
65 const RO = 0x01; |
|
66 const READ_OTHERS = 4; |
|
67 |
|
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 } |
|
75 |
|
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 } |
|
82 |
|
83 function createProfile(profileName) { |
|
84 // Filesystem precision is lower than Date precision. |
|
85 let lowerBound = Date.now() - 1000; |
|
86 |
|
87 let profile = gProfileService.createProfile(null, profileName); |
|
88 |
|
89 // check that the directory was created |
|
90 isnot(profile, null, "Profile " + profileName + " created"); |
|
91 |
|
92 let profileDir = profile.rootDir; |
|
93 |
|
94 ok(profileDir.exists(), "Profile dir created"); |
|
95 ok(profileDir.isDirectory(), "Profile dir is a directory"); |
|
96 |
|
97 let profileDirPath = profileDir.path; |
|
98 |
|
99 is(profileDirPath.substr(profileDirPath.length - profileName.length), |
|
100 profileName, "Profile dir has expected name"); |
|
101 |
|
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)); |
|
109 |
|
110 let upperBound = Date.now() + 1000; |
|
111 |
|
112 let created = json.created; |
|
113 ok(created, "created is set"); |
|
114 |
|
115 // Check against real clock time. |
|
116 checkBounds(lowerBound, created, upperBound); |
|
117 |
|
118 // Clean up the profile before local profile test. |
|
119 profile.remove(true); |
|
120 |
|
121 // Create with non-null aRootDir |
|
122 let profile = gProfileService.createProfile(profileDir, profileName); |
|
123 |
|
124 let localProfileDir = profile.localDir; |
|
125 ok(gDefaultLocalProfileParent.contains(localProfileDir, false), |
|
126 "Local profile dir created in DefProfLRt"); |
|
127 |
|
128 // Clean up the profile. |
|
129 profile.remove(true); |
|
130 } |
|
131 |
|
132 ]]> |
|
133 </script> |
|
134 </window> |