test_m3uhandler.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  var library = createLibrary("test_playlistreader");
34 
35  var tests;
36  var platform = getPlatform();
37  if (platform == "Windows_NT") {
38  tests = [
39  {
40  originalURI: null,
41  file: "win_parse.m3u",
42  result: "win_parsem3u_result.xml"
43  },
44  {
45  originalURI: "http://www.foo.com/",
46  file: "relative_remote.m3u",
47  result: "relative_remote_result.xml"
48  },
49  {
50  originalURI: "http://www.foo.com/mp3/",
51  file: "absolute_remote.m3u",
52  result: "absolute_remote_result.xml"
53  },
54  {
55  originalURI: null,
56  file: "win_utf8.m3u",
57  result: "win_utf8_result.xml"
58  },
59  {
60  originalURI: null,
61  file: "win_utf8.m3u8",
62  result: "win_utf8_result.xml"
63  }
64  ];
65  } else {
66  tests = [
67  {
68  originalURI: null,
69  file: "maclin_parse.m3u",
70  result: "maclin_parsem3u_result.xml"
71  },
72  {
73  originalURI: "http://www.foo.com/",
74  file: "relative_remote.m3u",
75  result: "relative_remote_result.xml"
76  },
77  {
78  originalURI: "http://www.foo.com/mp3/",
79  file: "absolute_remote.m3u",
80  result: "absolute_remote_result.xml"
81  },
82  {
83  originalURI: null,
84  file: "maclin_utf8.m3u",
85  result: "maclin_utf8_result.xml"
86  },
87  {
88  originalURI: null,
89  file: "maclin_utf8.m3u8",
90  result: "maclin_utf8_result.xml"
91  },
92  {
93  enabled: platform == "Darwin",
94  originalURI: null,
95  file: "maclin_unf.m3u",
96  result: "maclin_unf_nfd_result.xml"
97  },
98  {
99  enabled: platform != "Darwin",
100  originalURI: null,
101  file: "maclin_unf.m3u",
102  result: "maclin_unf_nfc_result.xml"
103  }
104  ];
105  }
106 
107  for (var i = 0; i < tests.length; i++) {
108  var t = tests[i];
109  if (("enabled" in t) && !t.enabled)
110  continue;
111  log("testing file " + t.file);
112  library.clear();
113  var handler = Cc["@songbirdnest.com/Songbird/Playlist/Reader/M3U;1"]
114  .createInstance(Ci.sbIPlaylistReader);
115 
116  var file = getFile(t.file);
117  if (t.originalURI) {
118  handler.originalURI = newURI(t.originalURI);
119  }
120  handler.read(file, library, false);
121  assertMediaList(library, getFile(t.result));
122  }
123 
124  // test local playlists (should only import files that exist on disk)
125  library.clear();
126  var handler = Cc["@songbirdnest.com/Songbird/Playlist/Reader/M3U;1"]
127  .createInstance(Ci.sbIPlaylistReader);
128 
129  var fileName = "";
130  if (platform == "Windows_NT") {
131  fileName = "win_relative_local.m3u";
132  } else {
133  fileName = "maclin_relative_local.m3u";
134  }
135  log("testing file " + fileName);
136  var file = getFile(fileName);
137  handler.originalURI = newFileURI(file);
138  handler.read(file, library, false);
139 
140  var mp3dir = getFile("mp3");
141  var file1 = mp3dir.clone();
142  file1.append("file1.mp3");
143  var file2 = mp3dir.clone();
144  file2.append("file2.mp3");
145  var musicdir = getFile("music");
146  var file3 = musicdir.clone();
147  file3.append("file3.mp3");
148  var files = [file1, file2, file3];
149 
150  var prop = "http://songbirdnest.com/data/1.0#contentURL";
151  for (var i in files) {
152  var result = newFileURI(files[i]).spec;
153  var item = getFirstItemByProperty(library, prop, result);
154  if (!item) {
155  fail("item with property '" + prop + "' equal to '" + result + "' not found");
156  }
157  }
158  assertEqual(library.length, 3);
159 
160  // Test duplicates
161  library.clear();
162  var mediaList = library.createMediaList("simple");
163  var handler = Cc["@songbirdnest.com/Songbird/Playlist/Reader/M3U;1"]
164  .createInstance(Ci.sbIPlaylistReader);
165 
166  var file = getFile("relative_remote.m3u");
167  handler.originalURI = newURI("http://www.foo.com");
168 
169  handler.read(file, mediaList, false);
170  assertEqual(mediaList.length, 3);
171  assertEqual(mediaList.library.length, 4);
172  handler.read(file, mediaList, false);
173  assertEqual(mediaList.length, 6);
174  assertEqual(mediaList.library.length, 4);
175 
176  // Should not change the list
177  handler.read(file, mediaList, true);
178  assertEqual(mediaList.library.length, 4);
179  assertEqual(mediaList.length, 6);
180 }
181 
const Cc
function fail(aMessage)
function getFirstItemByProperty(aMediaList, aProperty, aValue)
function getPlatform()
function log(s)
function assertEqual(aExpected, aActual, aMessage)
function getFile(fileName)
var t
function newFileURI(file)
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
const Ci
function assertMediaList(aMediaList, aItemTestsFile, aPort)
_getSelectedPageStyle s i
GstMessage gpointer data sbGStreamerMessageHandler * handler
function runTest()
Test file.
var file