test_library_batchcreate.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  var SB_NS = "http://songbirdnest.com/data/1.0#";
34  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
35 
36  var databaseGUID = "test_batchcreate";
37  var library = createLibrary(databaseGUID);
38 
39  var toAdd = Cc["@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(Ci.nsIMutableArray);
40  var propertyArray = Cc["@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(Ci.nsIMutableArray);
41  for (var i = 1; i < 101; i++) {
42  toAdd.appendElement(newURI("file:///foo/" + i + ".mp3"), false);
43  var props = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
44  .createInstance(Ci.sbIMutablePropertyArray);
45  props.appendProperty(SB_NS + "contentLength", i);
46  props.appendProperty(SB_NS + "trackNumber", i);
47  propertyArray.appendElement(props, false);
48  }
49 
50  var libraryListener = new TestMediaListListener();
51  library.addListener(libraryListener);
52 
53  var added = library.batchCreateMediaItems(toAdd, propertyArray);
54 
55  var e = added.enumerate();
56  while(e.hasMoreElements()) {
57  var item = e.getNext();
58 
59  var listener = {
60  _item: null,
61  onEnumerationBegin: function() {
62  },
63  onEnumeratedItem: function(list, item) {
64  this._item = item;
65  return Ci.sbIMediaListEnumerationListener.CANCEL;
66  },
67  onEnumerationEnd: function() {
68  }
69  };
70 
71  library.enumerateItemsByProperty("http://songbirdnest.com/data/1.0#contentURL",
72  item.contentSrc.spec,
73  listener,
74  Ci.sbIMediaList.ENUMERATIONTYPE_SNAPSHOT);
75 
76  assertEqual(listener._item, item);
77 
78  assertEqual(listener._item.getProperty(SB_NS + "contentLength"),
79  item.getProperty(SB_NS + "contentLength"));
80  assertEqual(listener._item.getProperty(SB_NS + "trackNumber"),
81  item.getProperty(SB_NS + "trackNumber"));
82  }
83 
84  // Check the order of the notifications
85  assertEqual(libraryListener.added.length, 100);
86  for (var i = 1; i < 101; i++) {
87  assertEqual(libraryListener.added[i - 1].item.contentSrc.spec, "file:///foo/" + i + ".mp3");
88  }
89  libraryListener.reset();
90 
91  // Do it again with duplcate URLs
92  toAdd = Cc["@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(Ci.nsIMutableArray);
93  propertyArray = Cc["@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(Ci.nsIMutableArray);
94  for (var i = 1; i < 101; i++) {
95  toAdd.appendElement(newURI("file:///foo/duplicate.mp3"), false);
96  var props = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
97  .createInstance(Ci.sbIMutablePropertyArray);
98  props.appendProperty(SB_NS + "contentLength", i);
99  props.appendProperty(SB_NS + "trackNumber", i);
100  propertyArray.appendElement(props, false);
101  }
102 
103  added = library.batchCreateMediaItems(toAdd, propertyArray, true);
104  // Check the order of the notifications
105  assertEqual(libraryListener.added.length, 100);
106  for (var i = 1; i < 101; i++) {
107  assertEqual(libraryListener.added[i - 1].item.contentSrc.spec, "file:///foo/duplicate.mp3");
108  }
109 
110  library.removeListener(libraryListener);
111 }
const Cc
function runTest()
Test file.
function assertEqual(aExpected, aActual, aMessage)
const SB_NS
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
const Ci
var ios
Definition: head_feeds.js:5
_getSelectedPageStyle s i
function TestMediaListListener()