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.

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

mercurial