test_library_copy_listener.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 var SB_NS = "http://songbirdnest.com/data/1.0#";
32 
33 function runTest() {
34 
35  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
36 
37  var item1URI = ios.newURI("file:///alpha.mp3", null, null);
38  var item1Properties =
39  { artistName: "A", albumName: "Alpha", trackName: "Track Alpha", trackNumber: "1", year: "2000"};
40 
41  var item2URI = ios.newURI("file:///ecto.mp3", null, null);
42  var item2Properties =
43  { artistName: "E", albumName: "Ecto", trackName: "Track Ecto", trackNumber: "2", year: "2004"};
44 
45  var item3URI = ios.newURI("file:///beta.mp3", null, null);
46  var item3Properties =
47  { artistName: "B", albumName: "Beta", trackName: "Track Beta", trackNumber: "2", year: "2001"};
48 
49  var sourceDBGUID = "test_library_copy_source";
50  var destinationDBGUID = "test_library_copy_destination";
51 
52  var sourceLibrary = createLibrary(sourceDBGUID, null, false);
53  var destinationLibrary = createLibrary(destinationDBGUID, null, false);
54 
55  var itemProperties = createPropertyArray();
56  appendPropertiesToArray(item1Properties, itemProperties);
57  var item1 = sourceLibrary.createMediaItem(item1URI,
58  itemProperties);
59 
60  itemProperties = createPropertyArray();
61  appendPropertiesToArray(item2Properties, itemProperties);
62  var item2 = sourceLibrary.createMediaItem(item2URI,
63  itemProperties);
64 
65  itemProperties = createPropertyArray();
66  appendPropertiesToArray(item3Properties, itemProperties);
67  var item3 = sourceLibrary.createMediaItem(item3URI,
68  itemProperties);
69 
70  var sourceCopyListener = {
71  current: 0,
72  items: [item1, item2, item3, item1, item2, item3],
73  onItemCopied: function _onItemCopied(aSourceItem, aDestinationItem) {
74  dump(aSourceItem + " should be equal to " + this.items[this.current] + "\n\n");
75  assertEqual(aSourceItem, this.items[this.current]);
76  assertNotEqual(aSourceItem, aDestinationItem);
77  this.current++;
78  }
79  };
80 
81  var localDatabaseLibrary =
82  sourceLibrary.QueryInterface(Ci.sbILocalDatabaseLibrary);
83  localDatabaseLibrary.addCopyListener(sourceCopyListener);
84 
85  destinationLibrary.add(item1);
86  destinationLibrary.add(item2);
87  destinationLibrary.add(item3);
88 
89  destinationLibrary.clear();
90 
91  localDatabaseLibrary.removeCopyListener(sourceCopyListener);
92 
93  var itemsArray = Cc["@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
94  .createInstance(Ci.nsIMutableArray);
95 
96  itemsArray.appendElement(item1, false);
97  itemsArray.appendElement(item2, false);
98  itemsArray.appendElement(item3, false);
99 
100  localDatabaseLibrary.addCopyListener(sourceCopyListener);
101 
102  destinationLibrary.addSome(itemsArray.enumerate());
103 
104  localDatabaseLibrary.removeCopyListener(sourceCopyListener);
105 
106  destinationLibrary.clear();
107 
108  return;
109 }
110 
112  return Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
113  .createInstance(Ci.sbIMutablePropertyArray);
114 }
115 
116 function appendPropertiesToArray(aProperties, aPropertyArray) {
117  for (var propName in aProperties) {
118  aPropertyArray.appendProperty(SB_NS + propName, aProperties[propName]);
119  }
120  return;
121 }
const Cc
function assertNotEqual(aExpected, aActual, aMessage)
function appendPropertiesToArray(aProperties, aPropertyArray)
function runTest()
Advanced DataRemote unit tests.
function assertEqual(aExpected, aActual, aMessage)
function createPropertyArray()
const char * propName
var SB_NS
Test file.
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
const Ci
var ios
Definition: head_feeds.js:5