test_multilibrary.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  var one = createLibrary("multilibrary_one");
34  one.clear();
35  assertEqual(one.length, 0);
36 
37  var two = createLibrary("multilibrary_two");
38  two.clear();
39  assertEqual(two.length, 0);
40 
41  var uri = newURI("http://www.poot.com");
42 
43  var item = one.createMediaItem(uri, null, true);
44  assertEqual(one.length, 1);
45 
46  two.add(item);
47  assertEqual(two.length, 1);
48 
49  one.clear();
50  two.clear();
51  assertEqual(one.length, 0);
52  assertEqual(two.length, 0);
53 
54  var items = [];
55  for (var i = 0; i < 10; i++) {
56  items.push(one.createMediaItem(uri, null, true));
57  }
58  assertEqual(one.length, 10);
59 
60  var enumerator = new SimpleArrayEnumerator(items);
61  two.addSome(enumerator);
62  assertEqual(two.length, 10);
63 
64  two.clear();
65  assertEqual(two.length, 0);
66 
67  var list1 = two.createMediaList("simple");
68  assertEqual(list1.length, 0);
69 
70  var list2 = two.createMediaList("simple");
71  assertEqual(list2.length, 0);
72  assertEqual(two.length, 2);
73 
74  enumerator = new SimpleArrayEnumerator(items);
75  list1.addSome(enumerator);
76 
77  assertEqual(list1.length, 10);
78  assertEqual(list2.length, 0);
79  assertEqual(two.length, 12); // 10 items 2 lists
80 
81  enumerator = new SimpleArrayEnumerator(items);
82  // adding items that already exist should not give new media items in the library
83  list2.addSome(enumerator);
84  assertEqual(list1.length, 10);
85  assertEqual(list2.length, 10);
86  assertEqual(two.length, 12);
87  assertNotEqual(list1, list2);
88 
89  list2.clear();
90  assertEqual(list1.length, 10);
91  assertEqual(list2.length, 0);
92  assertEqual(two.length, 12);
93  assertEqual(one.length, 10); // unchanged from before
94 
95  enumerator = new SimpleArrayEnumerator(items);
96  list2.addSome(enumerator);
97  assertEqual(list1.length, 10);
98  assertEqual(list2.length, 10);
99  assertEqual(two.length, 12);
100 
101  var list3 = one.copyMediaList("simple", list2, false);
102  assertTrue(list3);
103  assertEqual(list2.length, list3.length);
104  assertEqual(list3.library, one);
105  assertEqual(one.length, 11); // 10 items + 1 list
106 
107  var list4 = two.copyMediaList("simple", list2, false);
108  assertTrue(list4);
109  assertEqual(list2.length, list4.length);
110  assertEqual(list4.library, two);
111  assertEqual(two.length, 13);
112 
113  var list5 = two.copyMediaList("simple", list3, false);
114  assertTrue(list5);
115  assertEqual(list3.length, list5.length);
116  assertEqual(list5.library, two);
117  assertEqual(two.length, 14);
118 
119  two.remove(list3);
120  two.remove(list4);
121  two.remove(list5);
122  assertEqual(list1.length, 10);
123  for(var i = 0; i < 10; i++) {
124  two.remove(list1.getItemByIndex(0));
125  }
126  assertEqual(list1.length, 0);
127  assertEqual(list2.length, 0);
128  assertEqual(two.length, 2);
129 
130  // test to make sure that the factory doesn't return different library
131  // instances for the same database file.
132  var libOne = createLibrary("multilibrary_libOne");
133  var libTwo = createLibrary("multilibrary_libOne");
134  assertTrue(libOne === libTwo); // same COM identity, not just equivalent
135 
136  var libOneLength = libOne.length;
137  assertEqual(libOne.length, libTwo.length);
138 
139  libOne.createMediaItem(uri);
140  assertNotEqual(libOneLength, libOne.length);
141 
142  assertEqual(libOne.length, libTwo.length);
143 
144  // Test cross-library adding of media lists
145  libTwo = createLibrary("multilibrary_libTwo");
146  var listener = new TestMediaListListener();
147  libTwo.addListener(listener);
148 
149  list1 = libOne.createMediaList("simple");
150  var list1GUID = list1.guid;
151 
152  list1.name = "Test";
153  libTwo.add(list1);
154 
155  assertTrue(listener.added[0].item instanceof Ci.sbIMediaList);
156  assertEqual(listener.added[0].item.length, 0);
157  assertEqual(listener.added[0].item.name, "Test");
158  assertNotEqual(listener.added[0].item.guid, list1GUID);
159 
160  // clean up the listener so we don't count a bogus leak
161  listener.reset();
162  libTwo.removeListener(listener);
163 
164 }
function runTest()
Test file.
function assertNotEqual(aExpected, aActual, aMessage)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
return null
Definition: FeedWriter.js:1143
function SimpleArrayEnumerator(aArray)
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
var uri
Definition: FeedWriter.js:1135
const Ci
_getSelectedPageStyle s i
function TestMediaListListener()