1 const Ci = Components.interfaces;
2 const Cc = Components.classes;
4 const DG_BACKGROUND = "/desktop/gnome/background"
5 const DG_IMAGE_KEY = DG_BACKGROUND + "/picture_filename";
6 const DG_OPTION_KEY = DG_BACKGROUND + "/picture_options";
7 const DG_DRAW_BG_KEY = DG_BACKGROUND + "/draw_background";
12 var ios = Cc["@mozilla.org/network/io-service;1"].
13 getService(Ci.nsIIOService);
14 return ios.newURI(spec, null, null);
17 function onPageLoad() {
18 testPage.events.removeListener("load", onPageLoad);
20 var bs = Cc["@mozilla.org/intl/stringbundle;1"].
21 getService(Ci.nsIStringBundleService);
22 var brandName = bs.createBundle("chrome://branding/locale/brand.properties").
23 GetStringFromName("brandShortName");
25 var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
26 getService(Ci.nsIDirectoryServiceProvider);
27 var homeDir = dirSvc.getFile("Home", {});
29 var wpFile = homeDir.clone();
30 wpFile.append(brandName + "_wallpaper.png");
32 // Backup the existing wallpaper so that this test doesn't change the user's
34 var wpFileBackup = homeDir.clone()
35 wpFileBackup.append(brandName + "_wallpaper.png.backup");
37 if (wpFileBackup.exists())
38 wpFileBackup.remove(false);
41 wpFile.copyTo(null, wpFileBackup.leafName);
43 var shell = Cc["@mozilla.org/browser/shell-service;1"].
44 getService(Ci.nsIShellService);
45 var gconf = Cc["@mozilla.org/gnome-gconf-service;1"].
46 getService(Ci.nsIGConfService);
48 var prevImageKey = gconf.getString(DG_IMAGE_KEY);
49 var prevOptionKey = gconf.getString(DG_OPTION_KEY);
50 var prevDrawBgKey = gconf.getBool(DG_DRAW_BG_KEY);
52 var image = testPage.document.getElementsByTagName("img")[0];
54 function checkWallpaper(position, expectedGConfPosition) {
55 shell.setDesktopBackground(image, position);
56 ok(wpFile.exists(), "Wallpaper was written to disk");
57 is(gconf.getString(DG_IMAGE_KEY), wpFile.path,
58 "Wallpaper file GConf key is correct");
59 is(gconf.getString(DG_OPTION_KEY), expectedGConfPosition,
60 "Wallpaper position GConf key is correct");
63 checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper");
64 checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched");
65 checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered");
66 checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "centered");
68 // Restore GConf and wallpaper
70 gconf.setString(DG_IMAGE_KEY, prevImageKey);
71 gconf.setString(DG_OPTION_KEY, prevOptionKey);
72 gconf.setBool(DG_DRAW_BG_KEY, prevDrawBgKey);
75 if (wpFileBackup.exists()) {
76 wpFileBackup.moveTo(null, wpFile.leafName);
83 var osString = Cc["@mozilla.org/xre/app-info;1"].
84 getService(Ci.nsIXULRuntime).OS;
86 // This test is Linux specific for now
87 if (osString != "Linux") {
92 testPage = Application.activeWindow.open(url("about:blank"));
93 testPage.events.addListener("load", onPageLoad);
94 testPage.load(url("about:logo"));
97 waitForExplicitFinish();