test_manager.js
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
29 function runTest () {
30 
31  var library = createLibrary("test_playlistwritermanager");
32 
33  var manager = Cc["@songbirdnest.com/Songbird/PlaylistWriterManager;1"]
34  .getService(Ci.sbIPlaylistWriterManager);
35  var platform = getPlatform();
36 
37  // Test mime types
38  var mimeTypesCount = {};
39  var mimeTypes = manager.supportedMIMETypes(mimeTypesCount);
40  var expected = ["audio/mpegurl", "audio/x-mpegurl"];
41 
42  for (var i in expected) {
43  assertTrue(
44  mimeTypes.some( function(a) { return a == expected[i]}),
45  "Could not find support for mimetype " + expected[i]);
46  }
47 
48  for (var i in mimeTypes) {
49  assertTrue(
50  expected.some( function(a) { return a == mimeTypes[i]}),
51  "Found unexpected support for mimetype " + mimeTypes[i]);
52  }
53 
54  // Test extensions
55  var extCount = {};
56  var exts = manager.supportedFileExtensions(extCount);
57  expected = ["m3u", "m3u8"];
58 
59  for (var i in expected) {
60  assertTrue(
61  exts.some( function(a) { return a == expected[i]}),
62  "Could not find support for mimetype " + expected[i]);
63  }
64 
65  for (var i in exts) {
66  assertTrue(
67  expected.some( function(a) { return a == exts[i]}),
68  "Found unexpected support for extension " + exts[i]);
69  }
70 
71 
72  var ioService = Cc["@mozilla.org/network/io-service;1"]
73  .getService(Ci.nsIIOService);
74  var temporaryFileService =
75  Cc["@songbirdnest.com/Songbird/TemporaryFileService;1"]
76  .getService(Ci.sbITemporaryFileService);
77  var testDir = temporaryFileService.createFile(Ci.nsIFile.DIRECTORY_TYPE);
78 
79  var testMediaList = library.createMediaList("simple");
80 
81  var item1File = testDir.clone();
82  item1File.append("item1.mp3");
83  var item1 = library.createMediaItem(ioService.newFileURI(item1File));
84  testMediaList.add(item1);
85 
86  var item2File = testDir.clone();
87  item2File.append("item2Dir");
88  item2File.append("item2.mp3");
89  var item2 = library.createMediaItem(ioService.newFileURI(item2File));
90  testMediaList.add(item2);
91 
92  // Test write with extension
93  var playlistFile1 = testDir.clone();
94  playlistFile1.append("playlist1.m3u");
95  manager.write(playlistFile1, testMediaList, null);
96  assertFilesEqual(playlistFile1, getFile("test.m3u"));
97 
98  // Test write with content type
99  var playlistFile2 = testDir.clone();
100  playlistFile2.append("playlist2");
101  manager.write(playlistFile2, testMediaList, "audio/mpegurl");
102  assertFilesEqual(playlistFile2, getFile("test.m3u"));
103 }
104 
105 function getFileUri(aFile) {
106  var ioService = Cc["@mozilla.org/network/io-service;1"].
107  getService(Ci.nsIIOService);
108  return ioService.newFileURI(aFile);
109 }
110 
function getFileUri(aFile)
const Cc
function runTest()
Test file.
Definition: test_manager.js:29
function getPlatform()
function assertTrue(aTest, aMessage)
var ioService
getService(Ci.sbIFaceplateManager)
function getFile(fileName)
function assertFilesEqual(aFile1, aFile2, aMessage)
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
var expected
const Ci
_getSelectedPageStyle s i