1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/shell/test/browser_420786.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +const DG_BACKGROUND = "/desktop/gnome/background" 1.5 +const DG_IMAGE_KEY = DG_BACKGROUND + "/picture_filename"; 1.6 +const DG_OPTION_KEY = DG_BACKGROUND + "/picture_options"; 1.7 +const DG_DRAW_BG_KEY = DG_BACKGROUND + "/draw_background"; 1.8 + 1.9 +function onPageLoad() { 1.10 + gBrowser.selectedBrowser.removeEventListener("load", onPageLoad, true); 1.11 + 1.12 + var bs = Cc["@mozilla.org/intl/stringbundle;1"]. 1.13 + getService(Ci.nsIStringBundleService); 1.14 + var brandName = bs.createBundle("chrome://branding/locale/brand.properties"). 1.15 + GetStringFromName("brandShortName"); 1.16 + 1.17 + var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. 1.18 + getService(Ci.nsIDirectoryServiceProvider); 1.19 + var homeDir = dirSvc.getFile("Home", {}); 1.20 + 1.21 + var wpFile = homeDir.clone(); 1.22 + wpFile.append(brandName + "_wallpaper.png"); 1.23 + 1.24 + // Backup the existing wallpaper so that this test doesn't change the user's 1.25 + // settings. 1.26 + var wpFileBackup = homeDir.clone() 1.27 + wpFileBackup.append(brandName + "_wallpaper.png.backup"); 1.28 + 1.29 + if (wpFileBackup.exists()) 1.30 + wpFileBackup.remove(false); 1.31 + 1.32 + if (wpFile.exists()) 1.33 + wpFile.copyTo(null, wpFileBackup.leafName); 1.34 + 1.35 + var shell = Cc["@mozilla.org/browser/shell-service;1"]. 1.36 + getService(Ci.nsIShellService); 1.37 + var gconf = Cc["@mozilla.org/gnome-gconf-service;1"]. 1.38 + getService(Ci.nsIGConfService); 1.39 + 1.40 + var prevImageKey = gconf.getString(DG_IMAGE_KEY); 1.41 + var prevOptionKey = gconf.getString(DG_OPTION_KEY); 1.42 + var prevDrawBgKey = gconf.getBool(DG_DRAW_BG_KEY); 1.43 + 1.44 + var image = content.document.images[0]; 1.45 + 1.46 + function checkWallpaper(position, expectedGConfPosition) { 1.47 + shell.setDesktopBackground(image, position); 1.48 + ok(wpFile.exists(), "Wallpaper was written to disk"); 1.49 + is(gconf.getString(DG_IMAGE_KEY), wpFile.path, 1.50 + "Wallpaper file GConf key is correct"); 1.51 + is(gconf.getString(DG_OPTION_KEY), expectedGConfPosition, 1.52 + "Wallpaper position GConf key is correct"); 1.53 + } 1.54 + 1.55 + checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper"); 1.56 + checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched"); 1.57 + checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered"); 1.58 + checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "zoom"); 1.59 + checkWallpaper(Ci.nsIShellService.BACKGROUND_FIT, "scaled"); 1.60 + 1.61 + // Restore GConf and wallpaper 1.62 + 1.63 + gconf.setString(DG_IMAGE_KEY, prevImageKey); 1.64 + gconf.setString(DG_OPTION_KEY, prevOptionKey); 1.65 + gconf.setBool(DG_DRAW_BG_KEY, prevDrawBgKey); 1.66 + 1.67 + wpFile.remove(false); 1.68 + if (wpFileBackup.exists()) 1.69 + wpFileBackup.moveTo(null, wpFile.leafName); 1.70 + 1.71 + gBrowser.removeCurrentTab(); 1.72 + finish(); 1.73 +} 1.74 + 1.75 +function test() { 1.76 + var osString = Cc["@mozilla.org/xre/app-info;1"]. 1.77 + getService(Ci.nsIXULRuntime).OS; 1.78 + if (osString != "Linux") { 1.79 + todo(false, "This test is Linux specific for now."); 1.80 + return; 1.81 + } 1.82 + 1.83 + try { 1.84 + // If GSettings is available, then the GConf tests 1.85 + // will fail 1.86 + var gsettings = Cc["@mozilla.org/gsettings-service;1"]. 1.87 + getService(Ci.nsIGSettingsService). 1.88 + getCollectionForSchema("org.gnome.desktop.background"); 1.89 + todo(false, "This test doesn't work when GSettings is available"); 1.90 + return; 1.91 + } catch(e) { } 1.92 + 1.93 + gBrowser.selectedTab = gBrowser.addTab(); 1.94 + gBrowser.selectedBrowser.addEventListener("load", onPageLoad, true); 1.95 + content.location = "about:logo"; 1.96 + 1.97 + waitForExplicitFinish(); 1.98 +}