head_playlistreader.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 
30 function getFile(fileName) {
31  var file = Cc["@mozilla.org/file/directory_service;1"]
32  .getService(Ci.nsIProperties)
33  .get("resource:app", Ci.nsIFile);
34  file = file.clone();
35  file.append("testharness");
36  file.append("playlistreader");
37  file.append(fileName);
38  return file;
39 }
40 
41 function assertMediaList(aMediaList, aItemTestsFile, aPort) {
42 
43  var xmlReader = Cc["@mozilla.org/saxparser/xmlreader;1"]
44  .createInstance(Ci.nsISAXXMLReader);
45 
46  var failMessage = null;
47 
48  xmlReader.contentHandler = {
49  _item: null,
50  startDocument: function() {
51  },
52 
53  endDocument: function() {
54  },
55 
56  startElement: function(uri, localName, qName, /*nsISAXAttributes*/ attributes) {
57  if (failMessage)
58  return;
59 
60  if (localName == "item-test") {
61  var prop = attributes.getValueFromName("", "property");
62  if (prop.indexOf("#") == 0) {
63  prop = "http://songbirdnest.com/data/1.0" + prop;
64  }
65 
66  var value = attributes.getValueFromName("", "value");
67  value = value.replace("%PORT%", aPort);
68 
69  this._item = getFirstItemByProperty(aMediaList, prop, value);
70  if (!this._item) {
71  failMessage = "item with property '" + prop + "' equal to '" + value + "' not found";
72  }
73  }
74 
75  if (localName == "assert-property-value" && this._item) {
76  var prop = attributes.getValueFromName("", "name");
77  if (prop.indexOf("#") == 0) {
78  prop = "http://songbirdnest.com/data/1.0" + prop;
79  }
80 
81  var value = attributes.getValueFromName("", "value");
82  value = value.replace("%PORT%", aPort);
83 
84  var itemValue = this._item.getProperty(prop);
85 
86  if (itemValue != value) {
87  failMessage = "item with url '" + this._item.contentSrc.spec +
88  "' does not match result at property '" + prop +
89  "', '" + itemValue + "' != '" + value + "'";
90  }
91  }
92  },
93 
94  endElement: function(uri, localName, qName) {
95  },
96 
97  characters: function(value) {
98  },
99 
100  processingInstruction: function(target, data) {
101  },
102 
103  ignorableWhitespace: function(whitespace) {
104  },
105 
106  startPrefixMapping: function(prefix, uri) {
107  },
108 
109  endPrefixMapping: function(prefix) {
110  },
111 
112  // nsISupports
113  QueryInterface: function(iid) {
114  if(!iid.equals(Ci.nsISupports) &&
115  !iid.equals(Ci.nsISAXContentHandler))
116  throw Cr.NS_ERROR_NO_INTERFACE;
117  return this;
118  }
119  };
120 
121  var istream = Cc["@mozilla.org/network/file-input-stream;1"]
122  .createInstance(Ci.nsIFileInputStream);
123  istream.init(aItemTestsFile, 0x01, 0444, 0);
124  xmlReader.parseFromStream(istream, null, "text/xml");
125 
126  // Need this to prevent the closure from leaking
127  xmlReader.contentHandler = null;
128 
129  if (failMessage) {
130  fail(failMessage);
131  }
132 }
133 
134 function getFirstItemByProperty(aMediaList, aProperty, aValue) {
135 
136  var listener = {
137  item: null,
138  onEnumerationBegin: function() {
139  },
140  onEnumeratedItem: function(list, item) {
141  this.item = item;
142  return Components.interfaces.sbIMediaListEnumerationListener.CANCEL;
143  },
144  onEnumerationEnd: function() {
145  }
146  };
147 
148  aMediaList.enumerateItemsByProperty(aProperty,
149  aValue,
150  listener,
151  Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
152 
153  return listener.item;
154 }
const Cc
function fail(aMessage)
var istream
tabData attributes[name]
onPageChanged aValue
Definition: FeedWriter.js:1395
sbOSDControlService prototype QueryInterface
function assertMediaList(aMediaList, aItemTestsFile, aPort)
function getFirstItemByProperty(aMediaList, aProperty, aValue)
return null
Definition: FeedWriter.js:1143
var uri
Definition: FeedWriter.js:1135
countRef value
Definition: FeedWriter.js:1423
const Cr
const Ci
function getFile(fileName)
Some globally useful stuff for the playlistreader tests.
observe data
Definition: FeedWriter.js:1329
var file