test_librarymanager.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 countEnumeratedItems(enumerator) {
32  var count = 0;
33 
34  while(enumerator.hasMoreElements()) {
35  var item = enumerator.getNext();
36  count++;
37  }
38 
39  return count;
40 }
41 
42 function runTest () {
43  var libraryManager = Cc["@songbirdnest.com/Songbird/library/Manager;1"].
44  getService(Ci.sbILibraryManager);
45  var enumerator = libraryManager.getLibraries();
46 
47  var baseLibraryCount = countEnumeratedItems(enumerator);
48 
49  var library1 = createLibrary("test_library-base1");
50 
51  libraryManager.registerLibrary(library1, false);
52  enumerator = libraryManager.getLibraries();
53  assertEqual(countEnumeratedItems(enumerator), baseLibraryCount + 1);
54 
55  libraryManager.unregisterLibrary(library1);
56  enumerator = libraryManager.getLibraries();
57  assertEqual(countEnumeratedItems(enumerator), baseLibraryCount);
58 
59  libraryManager.registerLibrary(library1, false);
60  libraryManager.registerLibrary(library1, false);
61  enumerator = libraryManager.getLibraries();
62  assertEqual(countEnumeratedItems(enumerator), baseLibraryCount + 1);
63 
64  libraryManager.unregisterLibrary(library1);
65  libraryManager.unregisterLibrary(library1);
66  enumerator = libraryManager.getLibraries();
67  assertEqual(countEnumeratedItems(enumerator), baseLibraryCount);
68 
69  var library2 = createLibrary("test_library-base2");
70 
71  libraryManager.registerLibrary(library1, false);
72  libraryManager.registerLibrary(library2, false);
73  enumerator = libraryManager.getLibraries();
74  assertEqual(countEnumeratedItems(enumerator), baseLibraryCount + 2);
75 
76  var getLibraryException;
77  try {
78  var testLibrary = libraryManager.getLibrary("whippersnapper");
79  } catch (e) {
80  getLibraryException = e;
81  }
82  assertEqual(getLibraryException.result, Cr.NS_ERROR_NOT_AVAILABLE);
83 
84  var testLibrary = libraryManager.getLibrary(library1.guid);
85  assertEqual(testLibrary, library1);
86 
87  var mainLibrary = libraryManager.mainLibrary;
88  assertTrue(mainLibrary);
89 
90  enumerator = libraryManager.getStartupLibraries();
91  var baseStartupLibraryCount = countEnumeratedItems(enumerator);
92  assertTrue(baseStartupLibraryCount >= 2);
93 
94  var library3 = createLibrary("test_library-base3");
95  libraryManager.registerLibrary(library3, true);
96  enumerator = libraryManager.getStartupLibraries();
97  assertEqual(countEnumeratedItems(enumerator), baseStartupLibraryCount + 1);
98 
99  libraryManager.setLibraryLoadsAtStartup(library3, false);
100  enumerator = libraryManager.getStartupLibraries();
101  assertEqual(countEnumeratedItems(enumerator), baseStartupLibraryCount);
102 
103  libraryManager.setLibraryLoadsAtStartup(library2, true);
104  assertTrue(libraryManager.getLibraryLoadsAtStartup(library2));
105 
106  enumerator = libraryManager.getStartupLibraries();
107  assertEqual(countEnumeratedItems(enumerator), baseStartupLibraryCount + 1);
108 
109  libraryManager.setLibraryLoadsAtStartup(library2, false);
110  assertFalse(libraryManager.getLibraryLoadsAtStartup(library2));
111 
112  enumerator = libraryManager.getStartupLibraries();
113  assertEqual(countEnumeratedItems(enumerator), baseStartupLibraryCount);
114 }
const Cc
function countEnumeratedItems(enumerator)
Test file.
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
getService(Ci.sbIFaceplateManager)
var count
Definition: test_bug7406.js:32
function runTest()
Advanced DataRemote unit tests.
var libraryManager
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function assertFalse(aTest, aMessage)
const Cr
const Ci