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