31 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
32 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
38 log(
"Testing MediaPageManager Service:");
40 pageMgr =
Cc[
"@songbirdnest.com/Songbird/MediaPageManager;1"]
41 .getService(
Ci.sbIMediaPageManager);
43 "Manager service could not be retrieved!");
50 const DEFAULTPAGE1 =
"chrome://songbird/content/mediapages/filtersPage.xul"
51 const DEFAULTPAGE2 =
"chrome://songbird/content/mediapages/playlistPage.xul"
52 const EXTENSIONPAGE =
"chrome://songbird-test-media-page/content/testMediaPage.xul"
53 const EXTENSIONPAGEDOWNLOADS =
"chrome://songbird-test-media-page/content/testMediaPage.xul?downloads"
54 const EXTENSIONPAGELIBRARY =
"chrome://songbird-test-media-page/content/testMediaPage.xul?library"
55 const EXTENSIONPAGEVIDEO =
"chrome://songbird-test-media-page/content/testMediaPage.xul?video"
57 const BADURL =
"http://non/registered/url.xul";
58 const URL1 =
"http://fake/url1.xul";
59 const URL2 =
"http://fake/url2.xul";
60 const URL3 =
"http://fake/url3.xul";
67 var list1 = library1.createMediaList(
"simple");
73 var pageInfo = pageMgr.getPage(library1);
74 assertTrue(pageInfo,
"no media pages found for library");
76 "built-in page not found");
78 pageInfo = pageMgr.getPage(list1);
80 "built-in page not found");
83 list1.setProperty(SBProperties.defaultMediaPageURL, BADURL);
87 pageInfo = pageMgr.getPage(list1);
89 "setting a default page to a BADURL should give DEFAULT"
91 var defaultInfo2 = pageInfo;
95 list1.setProperty(SBProperties.defaultMediaPageURL,
DEFAULTPAGE1);
96 pageInfo = pageMgr.getPage(list1);
99 "setting playlist mediapage to filterlist should work"
101 var defaultInfo1 = pageInfo;
104 list1.setProperty(SBProperties.customType,
"download");
105 assertEqual(list1.getProperty(SBProperties.customType),
"download",
106 "customType should be set to download.");
108 var
pages = ArrayConverter.JSArray(pageMgr.getAvailablePages(list1))
110 page.QueryInterface(
Ci.sbIMediaPageInfo));
115 EXTENSIONPAGEDOWNLOADS,
116 EXTENSIONPAGEVIDEO]);
119 list1.setProperty(SBProperties.onlyCustomMediaPages,
"1");
120 pages = ArrayConverter.JSArray(pageMgr.getAvailablePages(list1))
122 page.QueryInterface(
Ci.sbIMediaPageInfo));
126 EXTENSIONPAGEDOWNLOADS,
127 EXTENSIONPAGEVIDEO]);
134 EXTENSIONPAGEDOWNLOADS,
135 EXTENSIONPAGELIBRARY,
138 pageMgr.unregisterPage({contentUrl: url});
141 var enumerator = pageMgr.getAvailablePages();
143 { toString:
function() {
148 return "after unregistering the one built-in page and the extension, " +
149 "the list should be empty: " +
151 .QueryInterface(
Ci.sbIMediaPageInfo)
161 list1 = library1.createMediaList(
"simple");
164 var page_simpletype = pageMgr.registerPage(
"MatchSimpleType",
166 function(aList) {
return (aList.type ==
"simple"); } );
170 pageInfo = pageMgr.getPage(list1);
174 var page_matchall = pageMgr.registerPage(
"MatchAll",
176 function(aList) {
return true; } );
180 pageInfo = pageMgr.getPage(list1);
184 var list2 = library1.createMediaList(
"smart");
188 pageInfo = pageMgr.getPage(list2);
192 var page_smarttype = pageMgr.registerPage(
"MatchSmartType",
194 function(aList) {
return (aList.type ==
"smart"); } );
198 pageInfo = pageMgr.getPage(list2);
202 list2.setProperty(SBProperties.defaultMediaPageURL,
URL3);
206 pageInfo = pageMgr.getPage(list2);
211 list2.setProperty(SBProperties.defaultMediaPageURL,
URL2);
215 pageInfo = pageMgr.getPage(list2);
222 list1 = library1.createMediaList(
"simple");
223 list2 = library1.createMediaList(
"smart");
226 pageMgr.setPage(list2, page_smarttype);
230 pageInfo = pageMgr.getPage(list2);
234 pageMgr.setPage(list2, page_simpletype);
238 pageInfo = pageMgr.getPage(list2);
243 enumerator = pageMgr.getAvailablePages();
263 enumerator = pageMgr.getAvailablePages(list1);
272 enumerator = pageMgr.getAvailablePages(list2);
283 pageMgr.unregisterPage(page_matchall);
285 enumerator = pageMgr.getAvailablePages();
293 pageMgr.unregisterPage(page_smarttype);
295 enumerator = pageMgr.getAvailablePages();
301 pageMgr.unregisterPage(page_simpletype);
303 enumerator = pageMgr.getAvailablePages();
315 if (databaseLocation) {
316 directory = databaseLocation.QueryInterface(
Ci.nsIFileURL).file;
319 directory =
Cc[
"@mozilla.org/file/directory_service;1"].
321 get(
"ProfD",
Ci.nsIFile);
322 directory.append(
"db");
325 var
file = directory.clone();
326 file.append(databaseGuid +
".db");
329 Cc[
"@songbirdnest.com/Songbird/Library/LocalDatabase/LibraryFactory;1"]
330 .getService(
Ci.sbILibraryFactory);
331 var hashBag =
Cc[
"@mozilla.org/hash-property-bag;1"].
333 hashBag.setPropertyAsInterface(
"databaseFile", file);
334 var library = libraryFactory.createLibrary(hashBag);
function assertTrue(aTest, aMessage)
function assertSetsEqual(s1, s2)
function assertEqual(aExpected, aActual, aMessage)
getService(Ci.sbIFaceplateManager)
function createLibrary(databaseGuid, databaseLocation)
function assertFalse(aTest, aMessage)
function runTest()
Advanced DataRemote unit tests.
function testMediaPageManager()