test_mediafilemanager.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 
31 // This is the root of our test folder (temporary items)
33  "_temp_mediafilemanager_files");
34 
38 function onComplete(job) {
39  try {
40  if (job.status == Components.interfaces.sbIJobProgress.STATUS_RUNNING) {
41  return;
42  }
43  job.removeJobProgressListener(onComplete);
44 
45  // Manage the files
46  var properties = getMediaManagerProperties();
47 
48  var fileManager = Cc[SB_MEDIAFILEMANAGER]
49  .createInstance(Ci.sbIMediaFileManager);
50  fileManager.init(properties);
51  // COPY/MOVE/RENAME
52  for (var i = 0; i < gTestMediaItems.length; i++) {
53  var isManaged = false;
54  var item = gTestMediaItems.queryElementAt(i, Ci.sbIMediaItem);
55  try {
56  isManaged = fileManager.organizeItem(item,
57  Ci.sbIMediaFileManager.MANAGE_RENAME |
58  Ci.sbIMediaFileManager.MANAGE_COPY |
59  Ci.sbIMediaFileManager.MANAGE_MOVE);
60  } catch (err) {
61  doFail("ERROR: Unable to manage item: " + err);
62  }
63  assertTrue(isManaged, "Unable to manage item " + i);
64  assertTrue(checkItem(item, i, true),
65  "Item " + i + " was not relocated properly");
66  }
67 
68  // DELETE
69  for (var i = 0; i < gTestMediaItems.length; i++) {
70  var isManaged = false;
71  var item = gTestMediaItems.queryElementAt(i, Ci.sbIMediaItem);
72  try {
73  isManaged = fileManager.organizeItem(item,
74  Ci.sbIMediaFileManager.MANAGE_DELETE);
75  } catch (err) {
76  doFail("Unable to delete item: " + err);
77  }
78  assertTrue(isManaged, "Unable to delete item " + i);
79  assertTrue(checkDeletedItem(item), "Item " + i + " was not deleted");
80  }
81 
82  testFinished();
83  } catch (err) {
84  doFail("ERROR: " + err);
85  }
86 
87 }
88 
89 function runTest () {
90  var libraryManager = Cc["@songbirdnest.com/Songbird/library/Manager;1"]
91  .getService(Ci.sbILibraryManager);
92 
93  // Create the test library, do not init with items
94  gTestLibrary = createLibrary("test_mediafilemanager", null, false);
96  libraryManager.registerLibrary(gTestLibrary, false);
97  assertEqual(gTestLibrary.length, 0);
98 
99  var listListener = new TestMediaListListener();
100  gTestLibrary.addListener(listListener, false);
101 
102  // Add test items to the library
103  addItemsToLibrary(gTestLibrary);
104  gTestMediaItems = listListener.added;
105  assertEqual(gTestLibrary.length, gResultInformation.length);
106  assertEqual(gTestMediaItems.length, gResultInformation.length);
107 
108  gTestLibrary.removeListener(listListener);
109 
110  // Read the metadata for these items
111  var fileMetadataService = Cc["@songbirdnest.com/Songbird/FileMetadataService;1"]
112  .getService(Ci.sbIFileMetadataService);
113  var job = fileMetadataService.read(gTestMediaItems);
114 
115  // Set an observer to know when we complete
116  job.addJobProgressListener(onComplete);
117  testPending();
118 }
const Cc
function newAppRelativeFile(path)
function testFinished()
function runTest()
Advanced DataRemote unit tests.
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
var gFileLocation
Test reading and writing artwork from various media formats.
function onComplete(job)
var libraryManager
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
var testFolder
Test COPY/MOVE/RENAME/DELETE operations of the Media File Manager.
const Ci
function doFail(text)
function getCopyOfFolder(folder, tempName)
Copy the given folder to tempName, returning an nsIFile for the new location.
var gTestMediaItems
_getSelectedPageStyle s i
function TestMediaListListener()
var gTestLibrary
function testPending()