head_clipboardhelper.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 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
32 
33 function getPlatform() {
34  var platform;
35  try {
36  var sysInfo =
37  Components.classes["@mozilla.org/system-info;1"]
38  .getService(Components.interfaces.nsIPropertyBag2);
39  platform = sysInfo.getProperty("name");
40  }
41  catch (e) {
42  dump("System-info not available, trying the user agent string.\n");
43  var user_agent = navigator.userAgent;
44  if (user_agent.indexOf("Windows") != -1)
45  platform = "Windows_NT";
46  else if (user_agent.indexOf("Mac OS X") != -1)
47  platform = "Darwin";
48  else if (user_agent.indexOf("Linux") != -1)
49  platform = "Linux";
50  else if (user_agent.indexOf("SunOS") != -1)
51  platform = "SunOS";
52  }
53  return platform;
54 }
55 
60 function getCopyOfFolder(folder, tempName) {
61  assertNotEqual(folder, null);
62  var tempFolder = getTempFolder();
63  folder.copyTo(tempFolder, tempName);
64  folder = tempFolder.clone();
65  folder.append(tempName);
66  assertEqual(folder.exists(), true);
67  return folder;
68 }
69 
70 
75 function getCopyOfFile(file, tempName, optionalLocation) {
77  var folder = optionalLocation ? optionalLocation : getTempFolder();
78  file.copyTo(folder, tempName);
79  file = folder.clone();
80  file.append(tempName);
81  assertEqual(file.exists(), true);
82  return file;
83 }
84 
90 function getTempFolder() {
91  if (gTempFolder) {
92  return gTempFolder;
93  }
94  gTempFolder = Components.classes["@mozilla.org/file/directory_service;1"]
95  .getService(Components.interfaces.nsIProperties)
96  .get("TmpD", Components.interfaces.nsIFile);
97  gTempFolder.append("songbird_clipboardhelper_tests.tmp");
98  gTempFolder.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
99  return gTempFolder;
100 }
101 
102 
107 function removeTempFolder() {
108  if (gTempFolder && gTempFolder.exists()) {
109  gTempFolder.remove(true);
110  } else {
111  log("\n\n\nClipboard Helper Test may not have performed cleanup. Temp files may exist.\n\n\n");
112  }
113 }
function getCopyOfFile(file, tempName, optionalLocation)
function assertNotEqual(aExpected, aActual, aMessage)
function log(s)
function getCopyOfFolder(folder, tempName)
var gTempFolder
function assertEqual(aExpected, aActual, aMessage)
function getPlatform()
return null
Definition: FeedWriter.js:1143
function getTempFolder()
function removeTempFolder()
var file