25 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
29 var
ios =
Cc[
"@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService);
31 var testItemURL = ios.newURI(
"file:///alpha.mp3",
null,
null);
32 var testItemProperties =
33 SBProperties.createArray({ artistName:
"A",
35 trackName:
"Track Alpha",
39 var
history =
Cc[
"@songbirdnest.com/Songbird/PlaybackHistoryService;1"]
40 .getService(
Ci.sbIPlaybackHistoryService);
44 var
entry =
Cc[
"@songbirdnest.com/Songbird/PlaybackHistoryEntry;1"]
45 .createInstance(
Ci.sbIPlaybackHistoryEntry);
50 .getService(
Ci.sbILibraryManager);
51 libraryManager.registerLibrary(library,
false);
53 var item = library.createMediaItem(testItemURL, testItemProperties);
55 var itemPlayedAt =
new Date();
56 var itemPlayDuration = 1000 * 1000 * 1000;
58 entry.init(item, itemPlayedAt, itemPlayDuration,
null);
61 assertEqual(entry.timestamp, itemPlayedAt.getTime());
64 history.addEntry(entry);
66 var itemPlayedAt2 =
new Date().getTime() + 10000;
67 var itemPlayDuration2 = 1000 * 1000 * 999;
69 var annotations =
Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
70 .createInstance(
Ci.sbIPropertyArray);
71 annotations.appendProperty(
"http://songbirdnest.com/data/1.0#scrobbled",
74 var entry2 = history.createEntry(item,
78 history.addEntry(entry2);
80 entry2.setAnnotation(
"http://songbirdnest.com/data/1.0#iheartthis",
"true");
82 var getByAnnotationArray = history.getEntriesByAnnotation(
"http://songbirdnest.com/data/1.0#iheartthis",
"true");
84 var getByAnnotationEntry = getByAnnotationArray.queryElementAt(0,
Ci.sbIPlaybackHistoryEntry);
85 assertEqual(getByAnnotationEntry.getAnnotation(
"http://songbirdnest.com/data/1.0#iheartthis"),
88 entry2.setAnnotation(
"http://songbirdnest.com/data/1.0#ashamedDoNotScrobble",
"true");
90 var annotations2 =
Cc[
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
91 .createInstance(
Ci.sbIPropertyArray);
92 annotations2.appendProperty(
"http://songbirdnest.com/data/1.0#iheartthis",
94 annotations2.appendProperty(
"http://songbirdnest.com/data/1.0#ashamedDoNotScrobble",
97 var getByAnnotationsArray = history.getEntriesByAnnotations(annotations2, 1);
99 var getByAnnotationsEntry = getByAnnotationsArray.queryElementAt(0,
Ci.sbIPlaybackHistoryEntry);
100 assertEqual(getByAnnotationsEntry.getAnnotation(
"http://songbirdnest.com/data/1.0#iheartthis"),
102 assertEqual(getByAnnotationsEntry.getAnnotation(
"http://songbirdnest.com/data/1.0#ashamedDoNotScrobble"),
105 entry2.removeAnnotation(
"http://songbirdnest.com/data/1.0#iheartthis");
107 log(
"The playback history service has " + history.entryCount +
" entries.");
110 var entriesArray = [entry2,
entry];
111 var enumEntries = history.entries;
116 while(enumEntries.hasMoreElements()) {
117 let entry = enumEntries.getNext()
118 .QueryInterface(
Ci.sbIPlaybackHistoryEntry);
120 assertEqual(entry.timestamp, entriesArray[i].timestamp);
121 assertEqual(entry.duration, entriesArray[i].duration);
128 let entries = history.getEntriesByTimestamp(itemPlayedAt, itemPlayedAt + 1);
131 let entry = entries.queryElementAt(0,
Ci.sbIPlaybackHistoryEntry);
133 assertEqual(entry.timestamp, itemPlayedAt.getTime());
137 var entry_fromGetEntry = history.getEntryByIndex(0);
139 assertEqual(entry_fromGetEntry.timestamp, itemPlayedAt2);
140 assertEqual(entry_fromGetEntry.duration, itemPlayDuration2);
142 var entries = history.getEntriesByIndex(0, 2);
145 history.removeEntry(entry);
146 log(
"After removing one entry, the history service has " + history.entryCount +
" entry");
149 var remainingEntry = entries.queryElementAt(0,
Ci.sbIPlaybackHistoryEntry);
151 assertEqual(remainingEntry.timestamp, itemPlayedAt2);
152 assertEqual(remainingEntry.duration, itemPlayDuration2);
function assertEqual(aExpected, aActual, aMessage)
function createLibrary(databaseGuid, databaseLocation)
_getSelectedPageStyle s i
function runTest()
Advanced DataRemote unit tests.