test_content_type.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 
30 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
31 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
32 
33 function runTest () {
34 try{
35  var library = createLibrary("test_content_type", null, false);
36  library.clear();
37  testItem(library, null);
38 
39  // test making a media list and make sure we don't have any funny properties
40  // set on it that we're not supposed to
41  var list = library.createMediaList("simple");
42  testItem(list, null);
43  library.clear();
44 
45  // test createMediaItem creates the property when not set
46  var item = library.createMediaItem(newURI("http://foo.example.com/"));
47  testItem(item, "audio");
48  library.clear();
49 
50  // test that we don't overwrite the property given
51  item = library.createMediaItem(newURI("http://foo.example.com/"),
52  makeProperties("audio"));
53  testItem(item, "audio");
54  library.clear();
55 
56  item = library.createMediaItem(newURI("http://foo.example.com/"),
57  makeProperties("video"));
58  testItem(item, "video");
59  library.clear();
60 
61  // test that we don't accidentally not set it via other item-creating methods
62  var retval = {}
63  library.createMediaItemIfNotExist(newURI("http://foo.example.com/"),
64  makeProperties("xyzzy"),
65  retval);
66  item = retval.value;
67  testItem(item, "xyzzy");
68  library.clear();
69 
70  var urls = ArrayConverter.nsIArray([newURI("http://foo.example.com/")]);
71  var items = library.batchCreateMediaItems(urls);
72  testItem(items.queryElementAt(0, Components.interfaces.nsISupports), "audio");
73  library.clear();
74 
75  var props = ArrayConverter.nsIArray([makeProperties("moof")]);
76  items = library.batchCreateMediaItems(urls, props);
77  testItem(items.queryElementAt(0, Components.interfaces.nsISupports), "moof");
78  library.clear();
79 
80  var listenerOne = {
81  onProgress: function(){},
82  onComplete: function(aItems, aResult) {
83  assertTrue(Components.isSuccessCode(aResult),
84  "batch create async returned failure code");
85  assertEqual(1,
86  aItems.length,
87  "missing or extra items via batch create async");
88  testItem(aItems.queryElementAt(0, Components.interfaces.nsISupports),
89  "audio");
90  testFinished();
91  }
92  };
93  library.batchCreateMediaItemsAsync(listenerOne, urls);
94  testPending();
95  library.clear();
96 
97  var listenerTwo = {
98  onProgress: function(){},
99  onComplete: function(aItems, aResult) {
100  log("Second listener complete");
101  assertTrue(Components.isSuccessCode(aResult),
102  "batch create async returned failure code");
103  assertEqual(1,
104  aItems.length,
105  "missing or extra items via batch create async");
106  testItem(aItems.queryElementAt(0, Components.interfaces.nsISupports),
107  "moof");
108  library.clear();
109  testFinished();
110  }
111  };
112  library.batchCreateMediaItemsAsync(listenerTwo, urls, props);
113  testPending();
114  library.clear();
115 
116 } catch(e) { dump(e.stack + "\n"); throw(e); }
117 }
118 
119 function testItem(aItem, aContentType) {
120  __defineGetter__("contentType",
121  function () aItem.getProperty(SBProperties.contentType));
122  if (aItem.library == aItem && null === aContentType) {
123  // the library may have the content type be empty instead of null :(
124  assertTrue(null === contentType || "" === contentType,
125  "library content type is \"" + contentType + "\" instead of null");
126  }
127  else {
128  assertEqual(aContentType, contentType, "contentType not set on created item");
129  }
130  aItem.setProperty(SBProperties.contentType, null);
131  assertEqual(null, contentType, "contentType not cleared on explicit setting");
132 }
133 
134 function makeProperties(aContentType) {
135  var props = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
136  .createInstance(Ci.sbIMutablePropertyArray);
137  props.appendProperty(SBProperties.contentType, aContentType);
138  return props;
139 }
const Cc
function onComplete(job)
Definition: test_bug7406.js:85
function log(s)
function testFinished()
function makeProperties(aContentType)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Advanced DataRemote unit tests.
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
function testItem(aItem, aContentType)
const Ci
__defineGetter__("Application", function(){delete this.Application;return this.Application=Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication);})
function testPending()