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