test_itunes_xml_parser_error.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2009 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27  */
28 
34 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
35 
40 badTestXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
41 badTestXML += "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n";
42 badTestXML += "<plist version=\"1.0\">\n";
43 badTestXML += "<dict>\n";
44 badTestXML += " <key>Major Version</key><integer>1</integer>\n";
45 badTestXML += " <key>Minor Version</key><integer>1</integer>\n";
46 badTestXML += " <key>Application Version</key><string>8.1</string>\n";
47 
48 //------------------------------------------------------------------------------
49 //------------------------------------------------------------------------------
50 //
51 // iTunes importer unit tests.
52 //
53 //------------------------------------------------------------------------------
54 //------------------------------------------------------------------------------
55 
60 function stringToStream(aString) {
61  stream =
62  Cc["@mozilla.org/io/string-input-stream;1"]
63  .createInstance(Ci.nsIStringInputStream);
64  stream.setData(aString, -1);
65  return stream;
66 }
67 
68 function runTest() {
72  var listener = {
73  expectedTopLevelProperties : [ "Major Version",
74  "Minor Version",
75  "Application Version",
76  "Features",
77  "Show Content Ratings",
78  "Music Folder",
79  "Library Persistent ID" ],
80  onTopLevelProperties : function(aProperties) {
81  var length = this.expectedTopLevelProperties.length;
82  this.topLevelPropertyCount = 0;
83  for (var index =0; index < length; ++index) {
84  try {
85  if (aProperties.get(this.expectedTopLevelProperties[index]).length > 0) {
86  ++this.topLevelPropertyCount;
87  }
88  }
89  catch (e) {
90  }
91  }
92  },
93  onTrack : function(aProperties) {
94  ++this.onTrackCount;
95  },
96  onTracksComplete : function() {
97  ++this.onTracksCompleteCount;
98  },
99  onPlaylist : function(aProperties, tracks) {
100  ++this.onPlaylistCount;
101  },
102  onPlaylistsComplete : function () {
103  ++this.onPlaylistsCompleteCount;
104  fail("onPlaylistsComplete called when an error should occur");
105  },
106  onError : function(aErrorMessage) {
107  ++this.onErrorCount;
108  assertEqual(this.topLevelPropertyCount, 0, "Top level properties do not match");
109  assertEqual(this.onTrackCount, 0, "Invalid track count for error situation");
110  assertEqual(this.onTracksCompleteCount, 0, "Invalid track complete count for error situation");
111  assertEqual(this.onPlaylistCount, 0, "Invalid playlist count for error situation");
112  assertEqual(this.onPlaylistsCompleteCount, 0, "Invalid playlist complete count for error situation");
113  assertEqual(this.onErrorCount, 1, "Invalid error count for error situation");
114  parser.finalize();
115  testFinished();
116  },
117  onProgress : function() { /* nothing */ },
118  topLevelPropertyCount : 0,
119  onTrackCount : 0,
120  onTracksCompleteCount : 0,
121  onPlaylistCount : 0,
122  onPlaylistsCompleteCount : 0,
123  onErrorCount : 0,
124 
125  QueryInterface: XPCOMUtils.generateQI([Ci.sbIiTunesXMLParserListener])
126  };
127 
128  // Test error condition
129  var parser = Cc["@songbirdnest.com/Songbird/sbiTunesXMLParser;1"]
130  .getService(Ci.sbIiTunesXMLParser);
131  assertTrue(parser, "iTunes importer component is not available.");
132  parser.parse(stringToStream(badTestXML), listener);
133  testPending();
134  parser = null; // drop the reference to prevent leaks
135 }
function stringToStream(aString)
const Cc
function fail(aMessage)
function testFinished()
sbOSDControlService prototype QueryInterface
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Advanced DataRemote unit tests.
return null
Definition: FeedWriter.js:1143
const Ci
function testPending()