27 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
33 var fsWatcher =
Cc[
"@songbirdnest.com/filesystem/watcher;1"]
34 .createInstance(
Ci.sbIFileSystemWatcher);
35 if (!fsWatcher.isSupported) {
43 var watchDir =
Cc[
"@mozilla.org/file/directory_service;1"]
44 .getService(
Ci.nsIProperties)
45 .get(
"ProfD",
Ci.nsIFile);
48 watchDir.append(
"watch_dir");
49 if (!watchDir.exists() || !watchDir.isDirectory()) {
50 watchDir.create(
Ci.nsIFile.DIRECTORY_TYPE, 0777);
67 this._watchDir = aWatchDir;
68 this._fsWatcher = aFSWatcher;
78 _receivedAddedEvent:
false,
79 _receivedChangedEvent:
false,
80 _receivedRemovedEvent:
false,
87 this.
_log(
"Starting 'filesystemevents' test");
89 this._addedFile = this._watchDir.clone();
90 this._addedFile.append(
"added.file");
91 if (this._addedFile.exists()) {
92 this._addedFile.remove(
false);
95 this._changeFile = this._watchDir.clone();
96 this._changeFile.append(
"changed.file");
97 if (!this._changeFile.exists()) {
98 this._changeFile.create(
Ci.nsIFile.NORMAL_FILE_TYPE, 0777);
101 this._removeFile = this._watchDir.clone();
102 this._removeFile.append(
"removed.file");
103 if (!this._removeFile.exists()) {
104 this._removeFile.create(
Ci.nsIFile.NORMAL_FILE_TYPE, 0777);
107 this._fsWatcher.init(
this, this._watchDir.path,
true);
108 this._fsWatcher.startWatching();
111 _log:
function(aMessage)
113 dump(
"----------------------------------------------------------\n");
114 dump(
" " + aMessage +
"\n");
115 dump(
"----------------------------------------------------------\n");
119 onWatcherStarted:
function()
121 this.
_log(
" ... file system watcher started");
124 this._eventTimer =
Cc[
"@mozilla.org/timer;1"].createInstance(
Ci.nsITimer);
125 this._eventTimer.initWithCallback(
this,
127 Ci.nsITimerCallback.TYPE_ONE_SHOT);
130 onWatcherStopped:
function()
132 this.
_log(
"... file system watcher has stopped");
135 this._addedFile.remove(
false);
136 this._addedFile =
null;
138 this._removeFile =
null;
140 this._changeFile.remove(
false);
141 this._changeFile =
null;
146 this._watchDir.remove(
true);
147 this._watchDir =
null;
155 this.
_log(
"... ensuring events were received");
162 this._fsWatcher =
null;
166 onWatcherError:
function(aErrorType, aDescription)
169 this.
_log(
"ERROR: [" + aErrorType +
"] = " + aDescription +
" !!!!!!!");
172 onFileSystemChanged:
function(aFilePath)
174 this.
_log(
"CHANGED: " + aFilePath);
175 this._receivedChangedEvent =
true;
178 onFileSystemRemoved:
function(aFilePath)
180 this.
_log(
"REMOVED: " + aFilePath);
181 this._receivedRemovedEvent =
true;
184 onFileSystemAdded:
function(aFilePath)
186 this.
_log(
"ADDED: " + aFilePath);
187 this._receivedAddedEvent =
true;
193 if (aTimer == this._eventTimer) {
197 this._addedFile.create(
Ci.nsIFile.NORMAL_FILE_TYPE, 0755);
200 this._removeFile.remove(
false);
203 var foStream =
Cc[
"@mozilla.org/network/file-output-stream;1"]
204 .createInstance(
Ci.nsIFileOutputStream);
205 foStream.init(this._changeFile, -1, -1, 0);
206 var junk =
"garbage garbage garbage";
207 foStream.write(junk, junk.length);
211 this._shutdownTimer =
Cc[
"@mozilla.org/timer;1"]
212 .createInstance(
Ci.nsITimer);
213 this._shutdownTimer.initWithCallback(
this,
215 Ci.nsITimerCallback.TYPE_ONE_SHOT);
221 this._fsWatcher.stopWatching(
false);
226 XPCOMUtils.generateQI( [
Ci.sbIFileSystemListener,
Ci.nsITimerCallback] )
function sleep(ms, suppressOutput)
function sbFSListener(aWatchDir, aFSWatcher)
sbOSDControlService prototype QueryInterface
function assertTrue(aTest, aMessage)
TimerLoop prototype notify
function runTest()
Advanced DataRemote unit tests.
function _log(aMsg, aMenuID)