Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / browser / components / shell / test / browser_420786.js
blob93e7aba4e8117a6460bd7a77f69e0d1722b259de
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";
9 var testPage;
11 function url(spec) {
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
33   // settings.
34   var wpFileBackup = homeDir.clone()
35   wpFileBackup.append(brandName + "_wallpaper.png.backup");
37   if (wpFileBackup.exists())
38     wpFileBackup.remove(false);
40   if (wpFile.exists())
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");
61   }
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);
74   wpFile.remove(false);
75   if (wpFileBackup.exists()) {
76    wpFileBackup.moveTo(null, wpFile.leafName);
77   }
78   testPage.close();
79   finish();
82 function test() {
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") {
88     finish();
89     return;
90   }
92   testPage = Application.activeWindow.open(url("about:blank"));
93   testPage.events.addListener("load", onPageLoad);
94   testPage.load(url("about:logo"));
95   testPage.focus();
97   waitForExplicitFinish();