test_dirprovider.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
28 function runTest() {
29  var dirService = Cc["@mozilla.org/file/directory_service;1"]
30  .getService(Ci.nsIProperties);
31  var dirProvider = Cc["@songbirdnest.com/moz/directory/provider;1"]
32  .getService(Ci.nsIDirectoryServiceProvider);
33 
34  // Test that our directory service provider returns valid directories
35  // in all cases - both directly and through directory service.
36  var testDirs = ["CmDocs",
37  "CmPics",
38  "CmMusic",
39  "CmVideo",
40  "CmPics",
41  "Docs",
42  "Pics",
43  "Music",
44  "Video",
45  "DiscBurning"];
46 
47  for each (let dir in testDirs) {
48  // We cannot know whether the result is correct but test at least that
49  // it is a directory.
50  let file1 = dirService.get(dir, Ci.nsIFile);
51  assertTrue(file1, "Non-null file returned by directory service");
52  assertTrue(file1.exists(), "Existing file returned");
53  assertTrue(file1.isDirectory(), "Directory returned");
54 
55  // Make sure that directory service uses our provider to resolve the
56  // directories (or at least produces identical results)
57  let file2 = dirProvider.getFile(dir, {});
58  assertTrue(file2, "Non-null file returned by directory provider");
59  assertTrue(file2.equals(file1), "Our provider returns the same file as directory service");
60  }
61 
62  let hadException = false;
63  try {
64  dirProvider.getFile("FooBarDummy", {});
65  }
66  catch (e) {
67  hadException = true;
68  }
69  assertTrue(hadException, "Exception thrown when trying to request unknown file");
70 }
const Cc
var dirProvider
function assertTrue(aTest, aMessage)
function runTest()
test the directory service provider
const Ci