head_metadatamanager.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-2008 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 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
32 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
33 
34 var gFilesToClose = [];
35 var gTailCallback = [];
36 
37 function createNewLibrary(databaseGuid, databaseLocation) {
38 
39  var directory;
40  if (databaseLocation) {
41  directory = databaseLocation.QueryInterface(Ci.nsIFileURL).file;
42  }
43  else {
44  directory = Cc["@mozilla.org/file/directory_service;1"].
45  getService(Ci.nsIProperties).
46  get("ProfD", Ci.nsIFile);
47  directory.append("db");
48  }
49 
50  var file = directory.clone();
51  file.append(databaseGuid + ".db");
52 
53  var libraryFactory =
54  Cc["@songbirdnest.com/Songbird/Library/LocalDatabase/LibraryFactory;1"]
55  .getService(Ci.sbILibraryFactory);
56  var hashBag = Cc["@mozilla.org/hash-property-bag;1"].
57  createInstance(Ci.nsIWritablePropertyBag2);
58  hashBag.setPropertyAsInterface("databaseFile", file);
59  var library = libraryFactory.createLibrary(hashBag);
60  try {
61  library.clear();
62  }
63  catch(e) {
64  }
65 
66  if (library) {
67  var libraryManager = Cc["@songbirdnest.com/Songbird/library/Manager;1"].
68  getService(Ci.sbILibraryManager);
69  libraryManager.registerLibrary(library, false);
70  }
71  return library;
72 }
73 
74 function getPlatform() {
75  var platform;
76  try {
77  var sysInfo =
78  Components.classes["@mozilla.org/system-info;1"]
79  .getService(Components.interfaces.nsIPropertyBag2);
80  platform = sysInfo.getProperty("name");
81  }
82  catch (e) {
83  dump("System-info not available, trying the user agent string.\n");
84  var user_agent = navigator.userAgent;
85  if (user_agent.indexOf("Windows") != -1)
86  platform = "Windows_NT";
87  else if (user_agent.indexOf("Mac OS X") != -1)
88  platform = "Darwin";
89  else if (user_agent.indexOf("Linux") != -1)
90  platform = "Linux";
91  else if (user_agent.indexOf("SunOS") != -1)
92  platform = "SunOS";
93  }
94  return platform;
95 }
96 
100 function assertObjectIsSubsetOf(mapA, mapB) {
101  for (var id in mapA) {
102  assertEqual(mapA[id], mapB[id]);
103  }
104 }
105 
106 
111 function reportJobProgress(job, jobName) {
112  log("\n\n\nMetadata - " + jobName + " job progress - " +
113  job.progress + "/" + job.total + ", " + job.errorCount + " failed. " +
114  "Status " + job.statusText + " (" + job.status + "), Title: " + job.titleText);
115  var errorEnumerator = job.getErrorMessages();
116  while (errorEnumerator.hasMore()) {
117  log("MetadataJob " + jobName + " - failed url: " + errorEnumerator.getNext());
118  }
119  log("\n\n");
120 }
121 
122 
127 function getCopyOfFolder(folder, tempName) {
128  assertNotEqual(folder, null);
129  var tempFolder = getTempFolder();
130  folder.copyTo(tempFolder, tempName);
131  folder = tempFolder.clone();
132  folder.append(tempName);
133  assertEqual(folder.exists(), true);
134  return folder;
135 }
136 
137 
142 function getCopyOfFile(file, tempName, optionalLocation) {
144  var folder = optionalLocation ? optionalLocation : getTempFolder();
145  file.copyTo(folder, tempName);
146  file = folder.clone();
147  file.append(tempName);
148  assertEqual(file.exists(), true);
149  return file;
150 }
151 
157 function getTempFolder() {
158  if (gTempFolder) {
159  return gTempFolder;
160  }
161  gTempFolder = Components.classes["@mozilla.org/file/directory_service;1"]
162  .getService(Components.interfaces.nsIProperties)
163  .get("TmpD", Components.interfaces.nsIFile);
164  gTempFolder.append("songbird_metadata_tests.tmp");
165  gTempFolder.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
166  return gTempFolder;
167 }
168 
169 
174 function removeTempFolder() {
175  if (gTempFolder && gTempFolder.exists()) {
176  gTempFolder.remove(true);
177  } else {
178  log("\n\n\nMetadata Manager Test may not have performed cleanup. Temp files may exist.\n\n\n");
179  }
180 }
const Cc
var gTailCallback
function getPlatform()
function assertNotEqual(aExpected, aActual, aMessage)
function getCopyOfFolder(folder, tempName)
function log(s)
function createNewLibrary(databaseGuid, databaseLocation)
sidebarFactory createInstance
Definition: nsSidebar.js:351
function removeTempFolder()
function assertEqual(aExpected, aActual, aMessage)
getService(Ci.sbIFaceplateManager)
function reportJobProgress(job, jobName)
function getTempFolder()
function getCopyOfFile(file, tempName, optionalLocation)
var libraryManager
return null
Definition: FeedWriter.js:1143
function assertObjectIsSubsetOf(mapA, mapB)
const Ci
var gFilesToClose
var gTempFolder
var file