test_filesystemerrors.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2009 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
28 
29 
30 function runTest()
31 {
32  var fsWatcher = Cc["@songbirdnest.com/filesystem/watcher;1"]
33  .createInstance(Ci.sbIFileSystemWatcher);
34  if (!fsWatcher.isSupported) {
35  return;
36  }
37 
38  // This test simply tries to bootstrap the file-system watcher at an
39  // invalid path.
40 
41  var watchDir = Cc["@mozilla.org/file/directory_service;1"]
42  .getService(Ci.nsIProperties)
43  .get("ProfD", Ci.nsIFile);
44 
45  watchDir.normalize();
46  watchDir.append("invalid_watch_dir");
47  if (watchDir.exists()) {
48  // Ensure that the folder does not exist for this test.
49  watchDir.remove(true);
50  }
51 
52  // Callback for the fs watcher error, the only method that should be
53  // implemented here is |onWatcherError()| since it should be the only
54  // method called when the watcher is started with our fake path below.
55  var listener = {
56  onWatcherError: function(aErrorType, aDescription)
57  {
58  var isCorrectErrorCode = false; // ensure |ROOT_PATH_MISSING|
59 
60  var message = "WATCHER ERROR RECIEVED: ";
61  switch (aErrorType) {
62  case Ci.sbIFileSystemListener.ROOT_PATH_MISSING:
63  isCorrectErrorCode = true;
64  message += "ROOT_PATH_MISSING ";
65  break;
66 
67  case Ci.sbIFileSystemListener.INVALID_DIRECTORY:
68  message += "INVALID_DIRECTORY ";
69  break;
70 
71  case Ci.sbIFileSystemListener.SESSION_LOAD_ERROR:
72  message += "SESSION_LOAD_ERROR ";
73  break;
74 
75  default:
76  message += "INVALID ERROR TYPE!!!! ";
77  }
78 
79  LOG(message += aDescription);
80  assertTrue(isCorrectErrorCode);
81 
82  fsWatcher = null;
83  watchDir = null;
84  testFinished();
85  },
86  };
87 
88  LOG("ROOT PATH TEST");
89 
90  // Start the fsWatcher at the invalid path.
91  fsWatcher.init(listener, watchDir.path, true);
92  fsWatcher.startWatching();
93  testPending();
94 }
95 
96 
97 // \brief Console logging helper method.
98 function LOG(aMessage)
99 {
100  dump("----------------------------------------------------------\n");
101  dump(" " + aMessage + "\n");
102  dump("----------------------------------------------------------\n");
103 }
104 
const Cc
function testFinished()
function assertTrue(aTest, aMessage)
GstMessage * message
return null
Definition: FeedWriter.js:1143
const Ci
function LOG(aMessage)
function runTest()
Advanced DataRemote unit tests.
function testPending()