test_guid_property.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 function runTest () {
32 
33  Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
34 
35  var library = createLibrary("test_guid_property", null, false);
36  library.clear();
37 
38  var item = library.createMediaItem(newURI("http://foo.com/"));
39 
40  assertEqual(item.guid, item.getProperty(SBProperties.GUID));
41  var properties = item.getProperties();
42  assertEqual(item.guid, properties.getPropertyValue(SBProperties.GUID));
43 
44  try {
45  item.setProperty(SBProperties.GUID, "foo");
46  fail("did not throw");
47  }
48  catch(e) {
49  assertEqual(e.result, Cr.NS_ERROR_INVALID_ARG);
50  }
51 
52  try {
53  item.setProperties(SBProperties.createArray([
54  [SBProperties.GUID, "foo"]
55  ]));
56  fail("did not throw");
57  }
58  catch(e) {
59  assertEqual(e.result, Cr.NS_ERROR_INVALID_ARG);
60  }
61 
62  // Passing in a guid as a parameter to create should not do anything bad
63  var item2 = library.createMediaItem(newURI("http://foo.com/"),
64  SBProperties.createArray([
65  [SBProperties.GUID, "foo"]
66  ]));
67  assertTrue(item2.guid != "foo");
68 
69  var listener = {
70  _item: null,
71  onEnumerationBegin: function(aMediaList) {
72  },
73  onEnumeratedItem: function(aMediaList, aMediaItem) {
74  this._item = aMediaItem;
75  },
76  onEnumerationEnd: function(aMediaList, aStatusCode) {
77  }
78  };
79 
80  library.enumerateItemsByProperty(SBProperties.GUID,
81  item.guid,
82  listener,
83  Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
84 
85  assertTrue(listener._item.equals(item));
86 }
87 
function fail(aMessage)
function runTest()
Test file.
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
const Cr
const Ci