test_addonMetadata.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 // TODO:
32 // - Test caching functionality
33 // - Test enabled/disabled extension functionality
34 
35 const RDFURI_ADDON_ROOT = "urn:songbird:addon:root"
36 const PREFIX_ADDON_URI = "urn:songbird:addon:";
37 const PREFIX_NS_EM = "http://www.mozilla.org/2004/em-rdf#";
38 const PREFIX_NS_SONGBIRD = "http://www.songbirdnest.com/2007/addon-metadata-rdf#";
39 
40 function SONGBIRD_NS(property) {
41  return PREFIX_NS_SONGBIRD + property;
42 }
43 
44 function EM_NS(property) {
45  return PREFIX_NS_EM + property;
46 }
47 
48 function ADDON_NS(id) {
49  return PREFIX_ADDON_URI + id;
50 }
51 
52 
53 
57 function dumpDS(prefix, ds) {
58  var outputStream = {
59  data: "",
60  close : function(){},
61  flush : function(){},
62  write : function (buffer,count){
63  this.data += buffer;
64  return count;
65  },
66  writeFrom : function (stream,count){},
67  isNonBlocking: false
68  }
69 
70  var serializer = Components.classes["@mozilla.org/rdf/xml-serializer;1"]
71  .createInstance(Components.interfaces.nsIRDFXMLSerializer);
72  serializer.init(ds);
73 
74  serializer.QueryInterface(Components.interfaces.nsIRDFXMLSource);
75  serializer.Serialize(outputStream);
76 
77  outputStream.data.split('\n').forEach( function(line) {
78  dump(prefix + line + "\n");
79  });
80 }
81 
82 
83 
88 function runTest () {
89 
90  var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
91  .getService(Components.interfaces.nsIRDFService);
92  var datasource = rdfService.GetDataSourceBlocking("rdf:addon-metadata");
93 
94  // dumpDS("AddonMetadataTest DataSource: ", datasource);
95 
96  // Find coppery in the item container
97  var coppery = null;
98  var itemRoot = rdfService.GetResource(RDFURI_ADDON_ROOT);
99  var cu = Components.classes["@mozilla.org/rdf/container-utils;1"]
100  .getService(Components.interfaces.nsIRDFContainerUtils);
101  var container = cu.MakeSeq(datasource, itemRoot);
102  var addons = container.GetElements();
103 
104  while (addons.hasMoreElements()) {
105  var addon = addons.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
106  if (addon.Value == ADDON_NS("bluemonday@getnightingale.com")) {
107  coppery = addon;
108  break;
109  }
110  }
111 
112  // Did we find coppery in the list?
113  assertEqual(coppery != null, true);
114 
115  // Does it have a description?
116  assertEqual(datasource.hasArcOut(coppery,
117  rdfService.GetResource(EM_NS("description"))), true);
118 
119 
120  // Good enough for now
121  return Components.results.NS_OK;
122 }
123 
124 
menuItem id
Definition: FeedWriter.js:971
const PREFIX_NS_EM
function assertEqual(aExpected, aActual, aMessage)
function dumpDS(prefix, ds)
const RDFURI_ADDON_ROOT
AddonMetadata test file.
const PREFIX_NS_SONGBIRD
var count
Definition: test_bug7406.js:32
function ADDON_NS(id)
return null
Definition: FeedWriter.js:1143
function SONGBIRD_NS(property)
observe data
Definition: FeedWriter.js:1329
function runTest()
function EM_NS(property)