michael@0: const DG_BACKGROUND = "/desktop/gnome/background" michael@0: const DG_IMAGE_KEY = DG_BACKGROUND + "/picture_filename"; michael@0: const DG_OPTION_KEY = DG_BACKGROUND + "/picture_options"; michael@0: const DG_DRAW_BG_KEY = DG_BACKGROUND + "/draw_background"; michael@0: michael@0: function onPageLoad() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onPageLoad, true); michael@0: michael@0: var bs = Cc["@mozilla.org/intl/stringbundle;1"]. michael@0: getService(Ci.nsIStringBundleService); michael@0: var brandName = bs.createBundle("chrome://branding/locale/brand.properties"). michael@0: GetStringFromName("brandShortName"); michael@0: michael@0: var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. michael@0: getService(Ci.nsIDirectoryServiceProvider); michael@0: var homeDir = dirSvc.getFile("Home", {}); michael@0: michael@0: var wpFile = homeDir.clone(); michael@0: wpFile.append(brandName + "_wallpaper.png"); michael@0: michael@0: // Backup the existing wallpaper so that this test doesn't change the user's michael@0: // settings. michael@0: var wpFileBackup = homeDir.clone() michael@0: wpFileBackup.append(brandName + "_wallpaper.png.backup"); michael@0: michael@0: if (wpFileBackup.exists()) michael@0: wpFileBackup.remove(false); michael@0: michael@0: if (wpFile.exists()) michael@0: wpFile.copyTo(null, wpFileBackup.leafName); michael@0: michael@0: var shell = Cc["@mozilla.org/browser/shell-service;1"]. michael@0: getService(Ci.nsIShellService); michael@0: var gconf = Cc["@mozilla.org/gnome-gconf-service;1"]. michael@0: getService(Ci.nsIGConfService); michael@0: michael@0: var prevImageKey = gconf.getString(DG_IMAGE_KEY); michael@0: var prevOptionKey = gconf.getString(DG_OPTION_KEY); michael@0: var prevDrawBgKey = gconf.getBool(DG_DRAW_BG_KEY); michael@0: michael@0: var image = content.document.images[0]; michael@0: michael@0: function checkWallpaper(position, expectedGConfPosition) { michael@0: shell.setDesktopBackground(image, position); michael@0: ok(wpFile.exists(), "Wallpaper was written to disk"); michael@0: is(gconf.getString(DG_IMAGE_KEY), wpFile.path, michael@0: "Wallpaper file GConf key is correct"); michael@0: is(gconf.getString(DG_OPTION_KEY), expectedGConfPosition, michael@0: "Wallpaper position GConf key is correct"); michael@0: } michael@0: michael@0: checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper"); michael@0: checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched"); michael@0: checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered"); michael@0: checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "zoom"); michael@0: checkWallpaper(Ci.nsIShellService.BACKGROUND_FIT, "scaled"); michael@0: michael@0: // Restore GConf and wallpaper michael@0: michael@0: gconf.setString(DG_IMAGE_KEY, prevImageKey); michael@0: gconf.setString(DG_OPTION_KEY, prevOptionKey); michael@0: gconf.setBool(DG_DRAW_BG_KEY, prevDrawBgKey); michael@0: michael@0: wpFile.remove(false); michael@0: if (wpFileBackup.exists()) michael@0: wpFileBackup.moveTo(null, wpFile.leafName); michael@0: michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: michael@0: function test() { michael@0: var osString = Cc["@mozilla.org/xre/app-info;1"]. michael@0: getService(Ci.nsIXULRuntime).OS; michael@0: if (osString != "Linux") { michael@0: todo(false, "This test is Linux specific for now."); michael@0: return; michael@0: } michael@0: michael@0: try { michael@0: // If GSettings is available, then the GConf tests michael@0: // will fail michael@0: var gsettings = Cc["@mozilla.org/gsettings-service;1"]. michael@0: getService(Ci.nsIGSettingsService). michael@0: getCollectionForSchema("org.gnome.desktop.background"); michael@0: todo(false, "This test doesn't work when GSettings is available"); michael@0: return; michael@0: } catch(e) { } michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", onPageLoad, true); michael@0: content.location = "about:logo"; michael@0: michael@0: waitForExplicitFinish(); michael@0: }