browser_420786.js
Go to the documentation of this file.
1 const DG_BACKGROUND = "/desktop/gnome/background"
2 const DG_IMAGE_KEY = DG_BACKGROUND + "/picture_filename";
3 const DG_OPTION_KEY = DG_BACKGROUND + "/picture_options";
4 const DG_DRAW_BG_KEY = DG_BACKGROUND + "/draw_background";
5 
6 function onPageLoad() {
7  var bs = Cc["@mozilla.org/intl/stringbundle;1"].
8  getService(Ci.nsIStringBundleService);
9  var brandName = bs.createBundle("chrome://branding/locale/brand.properties").
10  GetStringFromName("brandShortName");
11 
12  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
13  getService(Ci.nsIDirectoryServiceProvider);
14  var homeDir = dirSvc.getFile("Home", {});
15 
16  var wpFile = homeDir.clone();
17  wpFile.append(brandName + "_wallpaper.png");
18 
19  // Backup the existing wallpaper so that this test doesn't change the user's
20  // settings.
21  var wpFileBackup = homeDir.clone()
22  wpFileBackup.append(brandName + "_wallpaper.png.backup");
23 
24  if (wpFileBackup.exists())
25  wpFileBackup.remove(false);
26 
27  if (wpFile.exists())
28  wpFile.copyTo(null, wpFileBackup.leafName);
29 
30  var shell = Cc["@mozilla.org/browser/shell-service;1"].
31  getService(Ci.nsIShellService);
32  var gconf = Cc["@mozilla.org/gnome-gconf-service;1"].
33  getService(Ci.nsIGConfService);
34 
35  var prevImageKey = gconf.getString(DG_IMAGE_KEY);
36  var prevOptionKey = gconf.getString(DG_OPTION_KEY);
37  var prevDrawBgKey = gconf.getBool(DG_DRAW_BG_KEY);
38 
39  var image = content.document.images[0];
40 
41  function checkWallpaper(position, expectedGConfPosition) {
42  shell.setDesktopBackground(image, position);
43  ok(wpFile.exists(), "Wallpaper was written to disk");
44  is(gconf.getString(DG_IMAGE_KEY), wpFile.path,
45  "Wallpaper file GConf key is correct");
46  is(gconf.getString(DG_OPTION_KEY), expectedGConfPosition,
47  "Wallpaper position GConf key is correct");
48  }
49 
50  checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper");
51  checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched");
52  checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered");
53  checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "centered");
54 
55  // Restore GConf and wallpaper
56 
57  gconf.setString(DG_IMAGE_KEY, prevImageKey);
58  gconf.setString(DG_OPTION_KEY, prevOptionKey);
59  gconf.setBool(DG_DRAW_BG_KEY, prevDrawBgKey);
60 
61  wpFile.remove(false);
62  if (wpFileBackup.exists())
63  wpFileBackup.moveTo(null, wpFile.leafName);
64 
65  gBrowser.removeCurrentTab();
66  finish();
67 }
68 
69 function test() {
70  var osString = Cc["@mozilla.org/xre/app-info;1"].
71  getService(Ci.nsIXULRuntime).OS;
72 
73  // This test is Linux specific for now
74  if (osString != "Linux")
75  return;
76 
77  gBrowser.selectedTab = gBrowser.addTab();
78  gBrowser.selectedBrowser.addEventListener("load", onPageLoad, true);
79  content.location = "about:logo";
80 
82 }
const Cc
const DG_BACKGROUND
var dirSvc
const DG_DRAW_BG_KEY
getService(Ci.sbIFaceplateManager)
function test()
const DG_OPTION_KEY
waitForExplicitFinish()
return null
Definition: FeedWriter.js:1143
function onPageLoad()
const Ci