test_metadatahandler.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 
32 
33 function runTest () {
34  gFileMetadataService = Components.classes["@songbirdnest.com/Songbird/MetadataManager;1"]
35  .getService(Components.interfaces.sbIMetadataManager);
36 
37  var file = newAppRelativeFile("testharness/metadatamanager/files/MP3_ID3v23.mp3");
38  file = getCopyOfFile(file, "handler_test.mp3");
39  var fileURL = newFileURI(file).spec;
40  var handler = gFileMetadataService.getHandlerForMediaURL(fileURL);
41 
42  assertNotEqual(handler, null);
43 
44  // NOTE: Does not accommodate async reading
45  var itemsRead = handler.read();
46  // Make sure we got at least a couple properties
47  assertEqual(itemsRead > 5, true);
48  assertEqual(handler.completed, true);
49 
50  // Verify that initially all properties are X
51  var expectedProperties = {};
52  expectedProperties[SBProperties.artistName] = "Songbird";
53  expectedProperties[SBProperties.albumName] = "Unit Test Classics";
54  expectedProperties[SBProperties.trackName] = "Sample";
55 
56  assertObjectIsSubsetOf(expectedProperties, SBProperties.arrayToJSObject(handler.props));
57 
58 
59  // Write out new values
60  handler.props.clear();
61  var newProperties = {};
62  newProperties[SBProperties.albumName] = "New Album";
63  newProperties[SBProperties.artistName] = "New Artist";
64  newProperties[SBProperties.trackName] = "New Track";
65  newProperties[SBProperties.year] = "2008";
66  newProperties[SBProperties.trackNumber] = "13";
67  SBProperties.addToArray(newProperties, handler.props);
68 
69  // Write this to disk
70  handler.write();
71 
72  // Get a new handler just to make sure it isn't cheating somehow
73  handler.close();
74  handler = gFileMetadataService.getHandlerForMediaURL(fileURL);
75  handler.read();
76 
77  // Confirm that writing succeeded.
78  assertObjectIsSubsetOf(newProperties, SBProperties.arrayToJSObject(handler.props));
79 
80  handler.close();
81  file.remove(false);
82 }
83 
var gFileMetadataService
Test reading and writing with an sbIMetadataHandler.
function newAppRelativeFile(path)
function assertNotEqual(aExpected, aActual, aMessage)
function runTest()
Advanced DataRemote unit tests.
function assertEqual(aExpected, aActual, aMessage)
function getCopyOfFile(file, tempName, optionalLocation)
function newFileURI(file)
return null
Definition: FeedWriter.js:1143
function assertObjectIsSubsetOf(mapA, mapB)
GstMessage gpointer data sbGStreamerMessageHandler * handler
var file