browser/components/shell/test/browser_420786.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

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

mercurial