test_usereditable.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  Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
33 
34  // Create a library and confirm that it is editable
35  var library = createLibrary("usereditable");
36  library.clear();
37  library.setProperty(SBProperties.isReadOnly, null);
38  assertTrue(library.userEditable);
39 
40  // Create a media list within the library and confirm
41  // that it is also editable by default
42  var list = library.createMediaList("simple");
43  assertTrue(list.userEditable);
44 
45  // Set the list read-only and confirm that it is no longer editable
46  list.setProperty(SBProperties.isReadOnly, "1");
47  assertTrue(!list.userEditable);
48  list.setProperty(SBProperties.isReadOnly, null);
49  assertTrue(list.userEditable);
50 
51  // Create a local item in the library and confirm that it is editable
52  var file = newTempFile("user-editable-test.mp3");
53  var item = library.createMediaItem(newFileURI(file), null, true);
54  assertTrue(item.userEditable);
55 
56  // Set the item read-only and confirm that it is no longer editable
57  item.setProperty(SBProperties.isReadOnly, "1");
58  assertTrue(!item.userEditable);
59  item.setProperty(SBProperties.isReadOnly, null);
60  assertTrue(item.userEditable);
61 
62  // Set the library read-only and confirm that the list, item and library are not editable
63  library.setProperty(SBProperties.isReadOnly, "1");
64  assertTrue(!library.userEditable);
65  assertTrue(!list.userEditable);
66  assertTrue(!item.userEditable);
67  library.setProperty(SBProperties.isReadOnly, null);
68  assertTrue(library.userEditable);
69 
70  // Set the file for the item to be read only
71  // and confirm that it isn't user editable
72  assertTrue(item.userEditable);
73  file.permissions = 0400;
74  assertTrue(!item.userEditable);
75  file.permissions = 0664;
76  assertTrue(item.userEditable);
77 
78  // Set the file for the item to be a path that doesn't exist
79  // and confirm that it isn't user editable
80  file = file.parent;
81  file.append("file-that-doesnt-exist.mp3");
82  item.contentSrc = newFileURI(file);
83  assertTrue(!item.userEditable, "Non-existent files are read-only.");
84 
85  // Set the item to a remote file and confirm that isn't user editable
86  item.contentSrc = newURI("http://example.com/foo.mp3");
87  assertTrue(item.userEditable, "Remote files are user editable.");
88 }
89 
90 
91 function newTempFile( name ) {
92  var file = Components.classes["@mozilla.org/file/directory_service;1"]
93  .getService(Components.interfaces.nsIProperties)
94  .get("TmpD", Components.interfaces.nsIFile);
95  file.append(name);
96  file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0664);
97  var registerFileForDelete = Cc["@mozilla.org/uriloader/external-helper-app-service;1"]
98  .getService(Ci.nsPIExternalAppLauncher);
99  registerFileForDelete.deleteTemporaryFileOnExit(file);
100  return file;
101 }
102 
const Cc
function assertTrue(aTest, aMessage)
function runTest()
Confirm that sbILibraryResource.userEditable works as expected.
function newFileURI(file)
return null
Definition: FeedWriter.js:1143
function createLibrary(databaseGuid, databaseLocation)
Definition: test_load.js:151
function newURI(aURLString)
const Ci
function newTempFile(name)
var file