test_device_utils.js
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
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://www.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 
33 function sbIDeviceDeviceTesterUtils_GetOrganizedPath(aUtils, aLibrary) {
34  var file = Components.classes["@mozilla.org/file/directory_service;1"]
35  .getService(Components.interfaces.nsIProperties)
36  .get("TmpD", Components.interfaces.nsIFile);
37  var oldFile = file.clone();
38  var spec = "http://0/not/a/valid/file.mp3";
39  var uri = Components.classes["@mozilla.org/network/io-service;1"]
40  .getService(Components.interfaces.nsIIOService)
41  .newURI(spec, null, null);
42  var item = aLibrary.createMediaItem(uri);
43 
44  var artist = "Some Artist *", album = "Some Album /";
45 
46  item.setProperty(SBProperties.artistName, artist);
47  item.setProperty(SBProperties.albumName, album)
48 
49  var result = aUtils.GetOrganizedPath(file, item);
50 
51  var platform = Components.classes["@mozilla.org/xre/runtime;1"]
52  .getService(Components.interfaces.nsIXULRuntime)
53  .OS;
54  var badchars;
55  if (platform == "WINNT")
56  badchars = /[\/:\*\?\\\"<>\|]/g;
57  else if (platform == "Darwin")
58  badchars = /[:\/]/g;
59  else
60  badchars = /[\/]/g;
61  artist = artist.replace(badchars, '_');
62  album = album.replace(badchars, '_');
63 
64  assertEqual(result.leafName, "file.mp3");
65  assertEqual(result.parent.leafName, album);
66  assertEqual(result.parent.parent.leafName, artist);
67  assertTrue(result.parent.parent.parent.equals(oldFile));
68 }
69 
70 function runTest () {
71  var utils = Components.classes["@songbirdnest.com/Songbird/Device/DeviceTester/Utils;1"]
72  .createInstance(Components.interfaces.sbIDeviceDeviceTesterUtils);
73 
74  var libraryFile = Components.classes["@mozilla.org/file/directory_service;1"]
75  .getService(Components.interfaces.nsIProperties)
76  .get("ProfD", Components.interfaces.nsIFile);
77  libraryFile.append("db");
78  libraryFile.append("test_devicedevice.db");
79  var libraryFactory =
80  Components.classes["@songbirdnest.com/Songbird/Library/LocalDatabase/LibraryFactory;1"]
81  .getService(Components.interfaces.sbILibraryFactory);
82  var hashBag = Components.classes["@mozilla.org/hash-property-bag;1"]
83  .createInstance(Components.interfaces.nsIWritablePropertyBag2);
84  hashBag.setPropertyAsInterface("databaseFile", libraryFile);
85  var library = libraryFactory.createLibrary(hashBag);
86  library.clear();
87 
88  sbIDeviceDeviceTesterUtils_GetOrganizedPath(utils, library);
89 }
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties artist
Definition: tuner2.js:40
function sbIDeviceDeviceTesterUtils_GetOrganizedPath(aUtils, aLibrary)
function hash(str)
Definition: sbAboutDRM.js:40
return null
Definition: FeedWriter.js:1143
var uri
Definition: FeedWriter.js:1135
Selectors Utils
var file