test_dblocation.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 function runTest () {
32 
33  const PERMISSIONS_FILE = 0644;
34  const PERMISSIONS_DIRECTORY = 0755;
35 
36  const dbGUID = "9c1ecf14-667b-47ce-b533-2dfd242f3ede";
37 
38  var directory = Cc["@mozilla.org/file/directory_service;1"].
39  getService(Ci.nsIProperties).
40  get("ProfD", Ci.nsIFile);
41  directory.append("db_tests");
42 
43  if (!directory.exists()) {
44  directory.create(Ci.nsIFile.DIRECTORY_TYPE, PERMISSIONS_DIRECTORY);
45  }
46 
47  var file = directory.clone();
48  file.append(dbGUID + ".db");
49 
50  if (file.exists()) {
51  file.remove(false);
52  }
53 
54  var libraryFactory =
55  Cc["@songbirdnest.com/Songbird/Library/LocalDatabase/LibraryFactory;1"].
56  getService(Ci.sbILibraryFactory);
57 
58  var hashBag = Cc["@mozilla.org/hash-property-bag;1"].
59  createInstance(Ci.nsIWritablePropertyBag2);
60  hashBag.setPropertyAsInterface("databaseFile", file);
61 
62  var library = libraryFactory.createLibrary(hashBag);
63 
64  var location = newFileURI(directory);
65  loadData(dbGUID, location);
66 
67  var testURI = newURI("file:///testitem");
68  var item1 = library.createMediaItem(testURI, null, true);
69  var item2 = library.createMediaItem(testURI, null, true);
70  assertNotEqual(item1.guid, item2.guid);
71 
72  // Test that they items were added to the library
73  assertEqual(library.getItemByGuid(item1.guid).guid, item1.guid);
74  assertEqual(library.getItemByGuid(item2.guid).guid, item2.guid);
75 }
function loadData(databaseGuid, databaseLocation)
const Cc
function assertNotEqual(aExpected, aActual, aMessage)
#define PERMISSIONS_FILE
sidebarFactory createInstance
Definition: nsSidebar.js:351
function assertEqual(aExpected, aActual, aMessage)
getService(Ci.sbIFaceplateManager)
function runTest()
Test file.
function newFileURI(file)
return null
Definition: FeedWriter.js:1143
function newURI(aURLString)
#define PERMISSIONS_DIRECTORY
const Ci
var file