test_file_utils.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2009 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
32 //------------------------------------------------------------------------------
33 //------------------------------------------------------------------------------
34 //
35 // File utilities unit tests.
36 //
37 //------------------------------------------------------------------------------
38 //------------------------------------------------------------------------------
39 
44 function runTest() {
45  // Get the directory service.
46  var directoryService = Cc["@mozilla.org/file/directory_service;1"]
47  .getService(Ci.nsIDirectoryServiceProvider);
48 
49  // Test that the file utilities component is available.
50  var fileUtils;
51  try {
52  fileUtils =
53  Cc["@songbirdnest.com/Songbird/FileUtils;1"].getService(Ci.sbIFileUtils);
54  } catch (ex) {}
55  assertTrue(fileUtils,
56  "File utilities component is not available.");
57 
58  // Get the current working directory.
59  var currentDir = fileUtils.currentDir;
60  assertTrue(currentDir, "Could not get the current working directory.");
61 
62  // Validate current working directory against the directory service.
63  assertTrue(currentDir.equals(directoryService.getFile("CurWorkD", {})),
64  "Current working directory not correct.");
65 
66  // Create a test working directory.
67  var temporaryFileService =
68  Cc["@songbirdnest.com/Songbird/TemporaryFileService;1"]
69  .getService(Ci.sbITemporaryFileService);
70  var testCurrentDir =
71  temporaryFileService.createFile(Ci.nsIFile.DIRECTORY_TYPE);
72 
73  // Change to the test working directory.
74  fileUtils.currentDir = testCurrentDir;
75  assertTrue(testCurrentDir.equals(fileUtils.currentDir),
76  "Could not change working directory.");
77  assertTrue(testCurrentDir.equals(directoryService.getFile("CurWorkD", {})),
78  "Current working directory not correct.");
79 
80  // Change back to original working directory.
81  fileUtils.currentDir = currentDir;
82  assertTrue(currentDir.equals(fileUtils.currentDir),
83  "Could not change to original working directory.");
84  assertTrue(currentDir.equals(directoryService.getFile("CurWorkD", {})),
85  "Current working directory not correct.");
86 }
87 
const Cc
function assertTrue(aTest, aMessage)
function runTest()
Advanced DataRemote unit tests.
const Ci