test_bug11624_badfilenames.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  // the name to use, per-platform (or "*" for unknown)
38  // items are arrays of <file name>, <escaped string>
39  var filenames = {
40  "WINNT": ["!@#$%^&(),_+ test\u4E2D\u6587.mp3",
41  "!@%23$%25%5e&(),_+%20test%e4%b8%ad%e6%96%87.mp3"],
42  "Darwin": ["!@#$%^&(),_+ test\u4E2D\u6587.mp3",
43  "!@%23$%25%5e&(),_+%20test%e4%b8%ad%e6%96%87.mp3"],
44  "*": ["!@#$%^&(),_+ test\u4E2D\n\u6587.mp3",
45  "!@%23$%25%5e&(),_+%20test%e4%b8%ad%0a%e6%96%87.mp3"]
46  };
47 
48  var platform = Components.classes["@mozilla.org/xre/runtime;1"]
49  .getService(Components.interfaces.nsIXULRuntime)
50  .OS;
51  if (!(platform in filenames)) {
52  platform = "*";
53  }
54 
55  var file = newAppRelativeFile("testharness/metadatamanager/files/MP3_ID3v23.mp3");
56  file = getCopyOfFile(file, filenames[platform][0]);
57  var fileURL = newFileURI(file.parent).spec + "/" + filenames[platform][1];
58  var handler = gFileMetadataService.getHandlerForMediaURL(fileURL);
59 
60  assertNotEqual(handler, null);
61 
62  // NOTE: Does not accommodate async reading
63  var itemsRead = handler.read();
64  // Make sure we got at least a couple properties
65  assertEqual(itemsRead > 5, true);
66  assertEqual(handler.completed, true);
67 
68  // Verify that initially all properties are X
69  var expectedProperties = {};
70  expectedProperties[SBProperties.artistName] = "Songbird";
71  expectedProperties[SBProperties.albumName] = "Unit Test Classics";
72  expectedProperties[SBProperties.trackName] = "Sample";
73 
74  assertObjectIsSubsetOf(expectedProperties, SBProperties.arrayToJSObject(handler.props));
75 
76 
77  // Write out new values
78  handler.props.clear();
79  var newProperties = {};
80  newProperties[SBProperties.albumName] = "New Album";
81  newProperties[SBProperties.artistName] = "New Artist";
82  newProperties[SBProperties.trackName] = "New Track";
83  newProperties[SBProperties.year] = "2008";
84  newProperties[SBProperties.trackNumber] = "13";
85  SBProperties.addToArray(newProperties, handler.props);
86 
87  // Write this to disk
88  handler.write();
89 
90  // Get a new handler just to make sure it isn't cheating somehow
91  handler.close();
92  handler = gFileMetadataService.getHandlerForMediaURL(fileURL);
93  handler.read();
94 
95  // Confirm that writing succeeded.
96  assertObjectIsSubsetOf(newProperties, SBProperties.arrayToJSObject(handler.props));
97 
98  handler.close();
99  file.remove(false);
100 }
101 
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)
var gFileMetadataService
Test reading from files with unusual file names.
GstMessage gpointer data sbGStreamerMessageHandler * handler
var file