test_library_notifications.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  Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
34  Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
35 
36  var databaseGUID = "test_librarynotifications";
37  var library = createLibrary(databaseGUID, null, false);
38  library.clear();
39 
40  var databaseGUID2 = "test_simplemedialistnotifications2";
41  var library2 = createLibrary(databaseGUID2, null, false);
42  library2.clear();
43 
44  var libraryListener = new TestMediaListListener();
45  library.addListener(libraryListener, false);
46 
47  // test all the ways for onItemAdded to be called
48  var item1 = library.createMediaItem(newURI("http://foo.com/1"));
49  assertTrue(libraryListener.added[0].list.equals(library));
50  assertTrue(libraryListener.added[0].item.equals(item1));
51  assertEqual(libraryListener.added[0].index, library.length - 1);
52 
53  libraryListener.reset();
54 
55  var item2 = library.createMediaItem(newURI("http://foo.com/2"));
56  assertTrue(libraryListener.added[0].list.equals(library));
57  assertTrue(libraryListener.added[0].item.equals(item2));
58  assertEqual(libraryListener.added[0].index, library.length - 1);
59 
60  libraryListener.reset();
61 
62  var list1 = library.createMediaList("simple");
63  assertTrue(libraryListener.added[0].list.equals(library));
64  assertTrue(libraryListener.added[0].item.equals(list1));
65  assertEqual(libraryListener.added[0].index, library.length - 1);
66 
67  libraryListener.reset();
68 
69  var otheritem1 = library2.createMediaItem(newURI("http://foo.com/1"));
70  library.add(otheritem1);
71  assertTrue(libraryListener.added[0].list.equals(library));
72  assertEqual(libraryListener.added[0].index, library.length - 1);
73 
74  libraryListener.reset();
75 
76  var otheritem2 = library2.createMediaItem(newURI("http://foo.com/2"));
77  var otheritem3 = library2.createMediaItem(newURI("http://foo.com/3"));
78  var e = ArrayConverter.enumerator([otheritem2, otheritem3]);
79  library.addSome(e);
80  assertTrue(libraryListener.added[0].list.equals(library));
81  assertEqual(libraryListener.added[0].index, library.length - 2);
82  assertTrue(libraryListener.added[1].list.equals(library));
83  assertEqual(libraryListener.added[1].index, library.length - 1);
84 
85  libraryListener.reset();
86 
87  var items = library.batchCreateMediaItems(
88  ArrayConverter.nsIArray([
89  newURI("http://foo.com/4"),
90  newURI("http://foo.com/5")
91  ]));
92  assertTrue(libraryListener.added[0].list.equals(library));
93  assertTrue(libraryListener.added[0].item.equals(
94  items.queryElementAt(0, Ci.sbIMediaItem)));
95  assertEqual(libraryListener.added[0].index, library.length - 2);
96  assertTrue(libraryListener.added[1].list.equals(library));
97  assertTrue(libraryListener.added[1].item.equals(
98  items.queryElementAt(1, Ci.sbIMediaItem)));
99  assertEqual(libraryListener.added[1].index, library.length - 1);
100 
101  libraryListener.reset();
102 
103  // Test removal
104  library.remove(item2);
105  assertTrue(libraryListener.removedBefore[0].list.equals(library));
106  assertTrue(libraryListener.removedBefore[0].item.equals(item2));
107  assertEqual(libraryListener.removedBefore[0].index, 1);
108  assertTrue(libraryListener.removedAfter[0].list.equals(library));
109  assertTrue(libraryListener.removedAfter[0].item.equals(item2));
110  assertEqual(libraryListener.removedAfter[0].index, 1);
111 
112  libraryListener.reset();
113 
114  var item6 = library.createMediaItem(newURI("http://foo.com/6"));
115  var item7 = library.createMediaItem(newURI("http://foo.com/7"));
116  var item8 = library.createMediaItem(newURI("http://foo.com/8"));
117  e = ArrayConverter.enumerator([item6, item7, item8]);
118  library.removeSome(e);
119  assertTrue(libraryListener.removedBefore[0].list.equals(library));
120  assertTrue(libraryListener.removedBefore[0].item.equals(item6));
121  assertEqual(libraryListener.removedBefore[0].index, 7);
122  assertTrue(libraryListener.removedAfter[0].list.equals(library));
123  assertTrue(libraryListener.removedAfter[0].item.equals(item6));
124  assertEqual(libraryListener.removedAfter[0].index, 7);
125  assertTrue(libraryListener.removedBefore[1].list.equals(library));
126  assertTrue(libraryListener.removedBefore[1].item.equals(item7));
127  assertEqual(libraryListener.removedBefore[1].index, 7);
128  assertTrue(libraryListener.removedAfter[1].list.equals(library));
129  assertTrue(libraryListener.removedAfter[1].item.equals(item7));
130  assertEqual(libraryListener.removedAfter[1].index, 7);
131  assertTrue(libraryListener.removedBefore[2].list.equals(library));
132  assertTrue(libraryListener.removedBefore[2].item.equals(item8));
133  assertEqual(libraryListener.removedBefore[2].index, 7);
134  assertTrue(libraryListener.removedAfter[2].list.equals(library));
135  assertTrue(libraryListener.removedAfter[2].item.equals(item8));
136  assertEqual(libraryListener.removedAfter[2].index, 7);
137 
138  library.removeListener(libraryListener);
139 }
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Test file.
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
const Ci
function TestMediaListListener()