test_bulkproperties.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 SB_NS = "http://songbirdnest.com/data/1.0#";
36 
37  var databaseGUID = "test_bulkproperties";
38  var library = createLibrary(databaseGUID, null, true);
39 
40  var listener = new TestMediaListListener();
41  library.addListener(listener, false);
42 
43  var uri = "http://floo.com/";
44  var item = library.createMediaItem(newURI(uri));
45  // Set the track name so that the identity hash gets set; otherwise changes
46  // later will make it come into existence and thus get our number of added
47  // properties wrong.
48  item.setProperty(SB_NS + "trackName", "Test item");
49 
50  var props = item.getProperties(null);
51 
52  var originalPropCount = props.length;
53  assertTrue(props.length > 1);
54  assertEqual(props.getPropertyValue(SB_NS + "contentURL"), uri);
55 
56  props = item.getProperties(SBProperties.createArray([
57  [SBProperties.contentURL, uri],
58  [SBProperties.hidden, "0"]
59  ]));
60 
61  assertEqual(props.length, 2);
62  assertEqual(props.getPropertyValue(SB_NS + "contentURL"), uri);
63  assertEqual(props.getPropertyValue(SB_NS + "hidden"), "0");
64 
65  var a = SBProperties.createArray([
66  [SBProperties.albumName, "album name"],
67  [SBProperties.artistName, "artist name"]
68  ]);
69 
70  listener.reset();
71  item.setProperties(a);
72 
73  props = item.getProperties(null);
74  assertEqual(props.length, originalPropCount + 2);
75  assertEqual(props.getPropertyValue(SB_NS + "contentURL"), uri);
76  assertEqual(props.getPropertyValue(SB_NS + "albumName"), "album name");
77  assertEqual(props.getPropertyValue(SB_NS + "artistName"), "artist name");
78 
79  var changedProps = listener.updatedProperties;
80  assertEqual(changedProps.length, 2);
81  assertEqual(changedProps.getPropertyValue(SB_NS + "albumName"), null);
82  assertEqual(changedProps.getPropertyValue(SB_NS + "artistName"), null);
83 
84  a = SBProperties.createArray([
85  [SBProperties.albumName, "album name2"],
86  [SBProperties.artistName, "artist name2"]
87  ]);
88 
89  listener.reset();
90  item.setProperties(a);
91 
92  props = item.getProperties(null);
93  assertEqual(props.length, originalPropCount + 2);
94  assertEqual(props.getPropertyValue(SB_NS + "contentURL"), uri);
95  assertEqual(props.getPropertyValue(SB_NS + "albumName"), "album name2");
96  assertEqual(props.getPropertyValue(SB_NS + "artistName"), "artist name2");
97 
98  changedProps = listener.updatedProperties;
99  assertEqual(changedProps.length, 2);
100  assertEqual(changedProps.getPropertyValue(SB_NS + "albumName"), "album name");
101  assertEqual(changedProps.getPropertyValue(SB_NS + "artistName"), "artist name");
102 
103  // TODO: Add a test for setting a property to null
104 
105  // Try an invalid value
106  a = SBProperties.createArray([
107  [SBProperties.trackNumber, "invalid"]
108  ], false);
109  try {
110  item.setProperties(a);
111  fail("Exception not thrown");
112  }
113  catch (e) {
114  assertEqual(e.result, Cr.NS_ERROR_INVALID_ARG);
115  }
116 
117  library.removeListener(listener);
118 }
function fail(aMessage)
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Test file.
const SB_NS
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
var uri
Definition: FeedWriter.js:1135
const Cr
function TestMediaListListener()