40 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
41 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
46 .getService(
Ci.sbILibraryManager);
47 libraryManager.registerLibrary(library,
false);
54 onItemRemoved:
function(aMediaItem) {
55 this.itemRemovedCount++;
57 onItemUpdated:
function(aMediaItem) {
58 log(aMediaItem.contentSrc.spec);
59 this.itemUpdatedCount++;
63 this.itemRemovedCount = 0;
64 this.itemUpdatedCount = 0;
76 library.addListener(batchListener,
78 Ci.sbIMediaList.LISTENER_FLAGS_BATCHBEGIN |
79 Ci.sbIMediaList.LISTENER_FLAGS_BATCHEND);
80 while (batchListener.depth > 0) {
85 mediaItem1 = library.createMediaItem(
newURI(
"http://test.com/test1"));
87 mediaItem2 = library.createMediaItem(
newURI(
"http://test.com/test2"));
91 mediaItemWatcher =
Cc[
"@songbirdnest.com/Songbird/Library/MediaItemWatcher;1"]
92 .createInstance(
Ci.sbIMediaItemWatcher);
94 mediaItemWatcher.watch(mediaItem1, listener);
95 while (batchListener.depth > 0) {
100 batchListener.waitForCompletion(
function()
101 mediaItem1.setProperty(SBProperties.trackName,
"test1"));
102 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
103 assertEqual(listener.itemUpdatedCount, 1,
"incorrect number of updated items");
104 batchListener.waitForCompletion(
function()
105 mediaItem1.setProperty(SBProperties.albumName,
"test1"));
106 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
107 assertEqual(listener.itemUpdatedCount, 2,
"incorrect number of updated items");
108 batchListener.waitForCompletion(
function()
109 mediaItem2.setProperty(SBProperties.trackName,
"test2"));
110 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
111 assertEqual(listener.itemUpdatedCount, 2,
"incorrect number of updated items");
115 batchListener.waitForCompletion(
function() {
116 library.remove(mediaItem1);
117 library.remove(mediaItem2);
119 assertEqual(listener.itemRemovedCount, 1,
"incorrect number of removed items");
120 assertEqual(listener.itemUpdatedCount, 0,
"incorrect number of updated items");
123 mediaItemWatcher.cancel();
124 library.remove(mediaItem1);
125 library.remove(mediaItem2);
137 mediaItem1 = library.createMediaItem(
newURI(
"http://test.com/test1"));
141 mediaItemWatcher =
Cc[
"@songbirdnest.com/Songbird/Library/MediaItemWatcher;1"]
142 .createInstance(
Ci.sbIMediaItemWatcher);
144 mediaItemWatcher.watch(mediaItem1, listener);
147 batchListener.waitForCompletion(
function()
148 mediaItem1.setProperty(SBProperties.trackName,
"test1"));
149 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
150 assertEqual(listener.itemUpdatedCount, 1,
"incorrect number of updated items");
151 mediaItemWatcher.cancel();
152 batchListener.waitForCompletion(
function()
153 mediaItem1.setProperty(SBProperties.trackName,
"test2"));
154 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
155 assertEqual(listener.itemUpdatedCount, 1,
"incorrect number of updated items");
158 mediaItemWatcher.cancel();
159 library.remove(mediaItem1);
171 mediaItem1 = library.createMediaItem(
newURI(
"http://test.com/test"));
175 mediaItemWatcher =
Cc[
"@songbirdnest.com/Songbird/Library/MediaItemWatcher;1"]
176 .createInstance(
Ci.sbIMediaItemWatcher);
178 filter = SBProperties.createArray([ [ SBProperties.trackName,
null ] ]);
179 mediaItemWatcher.watch(mediaItem1, listener, filter);
182 batchListener.waitForCompletion(
function()
183 mediaItem1.setProperty(SBProperties.trackName,
"test"));
184 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
185 assertEqual(listener.itemUpdatedCount, 1,
"incorrect number of updated items");
186 batchListener.waitForCompletion(
function()
187 mediaItem1.setProperty(SBProperties.albumName,
"test"));
188 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
189 assertEqual(listener.itemUpdatedCount, 1,
"incorrect number of updated items");
192 mediaItemWatcher.cancel();
193 library.remove(mediaItem1);
205 mediaItem1 = library.createMediaItem(
newURI(
"http://test.com/test"));
207 mediaItem2 = library.createMediaItem(
newURI(
"http://test.com/test"));
211 mediaItemWatcher =
Cc[
"@songbirdnest.com/Songbird/Library/MediaItemWatcher;1"]
212 .createInstance(
Ci.sbIMediaItemWatcher);
214 mediaItemWatcher.watch(mediaItem1, listener);
218 mediaItem1.setProperty(SBProperties.trackName,
"test");
219 mediaItem2.setProperty(SBProperties.trackName,
"test");
220 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
221 assertEqual(listener.itemUpdatedCount, 0,
"incorrect number of updated items");
223 library.runInBatchMode(func);
224 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
225 assertEqual(listener.itemUpdatedCount, 1,
"incorrect number of updated items");
228 mediaItemWatcher.cancel();
229 library.remove(mediaItem1);
230 library.remove(mediaItem2);
242 mediaItem1 = library.createMediaItem(
newURI(
"http://test.com/test"));
244 mediaItem2 = library.createMediaItem(
newURI(
"http://test.com/test"));
248 mediaItemWatcher =
Cc[
"@songbirdnest.com/Songbird/Library/MediaItemWatcher;1"]
249 .createInstance(
Ci.sbIMediaItemWatcher);
251 mediaItemWatcher.watch(mediaItem1, listener);
255 library.remove(mediaItem1);
256 library.remove(mediaItem2);
257 assertEqual(listener.itemRemovedCount, 0,
"incorrect number of removed items");
258 assertEqual(listener.itemUpdatedCount, 0,
"incorrect number of updated items");
260 library.runInBatchMode(func);
261 assertEqual(listener.itemRemovedCount, 1,
"incorrect number of removed items");
262 assertEqual(listener.itemUpdatedCount, 0,
"incorrect number of updated items");
265 mediaItemWatcher.cancel();
266 library.remove(mediaItem1);
267 library.remove(mediaItem2);
268 while (batchListener.depth > 0) {
271 library.removeListener(batchListener);
274 libraryManager.unregisterLibrary(library);
function sleep(ms, suppressOutput)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function BatchEndListener()
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)
Array filter(tab.attributes, function(aAttr){return(_this.xulAttributes.indexOf(aAttr.name) >-1);}).forEach(tab.removeAttribute