File: browser_420786.js

package info (click to toggle)
iceweasel 31.6.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,368,576 kB
  • sloc: cpp: 3,692,968; ansic: 1,797,194; python: 193,401; java: 180,622; asm: 133,557; xml: 89,288; sh: 71,748; perl: 22,087; makefile: 21,687; objc: 4,014; yacc: 1,995; pascal: 1,292; lex: 950; exp: 449; lisp: 228; awk: 211; php: 113; sed: 43; csh: 31; ada: 16; ruby: 3
file content (95 lines) | stat: -rw-r--r-- 3,360 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const DG_BACKGROUND = "/desktop/gnome/background"
const DG_IMAGE_KEY = DG_BACKGROUND + "/picture_filename";
const DG_OPTION_KEY = DG_BACKGROUND + "/picture_options";
const DG_DRAW_BG_KEY = DG_BACKGROUND + "/draw_background";

function onPageLoad() {
  gBrowser.selectedBrowser.removeEventListener("load", onPageLoad, true);

  var bs = Cc["@mozilla.org/intl/stringbundle;1"].
           getService(Ci.nsIStringBundleService);
  var brandName = bs.createBundle("chrome://branding/locale/brand.properties").
                  GetStringFromName("brandShortName");

  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
               getService(Ci.nsIDirectoryServiceProvider);
  var homeDir = dirSvc.getFile("Home", {});

  var wpFile = homeDir.clone();
  wpFile.append(brandName + "_wallpaper.png");

  // Backup the existing wallpaper so that this test doesn't change the user's
  // settings.
  var wpFileBackup = homeDir.clone()
  wpFileBackup.append(brandName + "_wallpaper.png.backup");

  if (wpFileBackup.exists())
    wpFileBackup.remove(false);

  if (wpFile.exists())
    wpFile.copyTo(null, wpFileBackup.leafName);

  var shell = Cc["@mozilla.org/browser/shell-service;1"].
              getService(Ci.nsIShellService);
  var gconf = Cc["@mozilla.org/gnome-gconf-service;1"].
              getService(Ci.nsIGConfService);

  var prevImageKey = gconf.getString(DG_IMAGE_KEY);
  var prevOptionKey = gconf.getString(DG_OPTION_KEY);
  var prevDrawBgKey = gconf.getBool(DG_DRAW_BG_KEY);

  var image = content.document.images[0];

  function checkWallpaper(position, expectedGConfPosition) {
    shell.setDesktopBackground(image, position);
    ok(wpFile.exists(), "Wallpaper was written to disk");
    is(gconf.getString(DG_IMAGE_KEY), wpFile.path,
       "Wallpaper file GConf key is correct");
    is(gconf.getString(DG_OPTION_KEY), expectedGConfPosition,
       "Wallpaper position GConf key is correct");
  }

  checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper");
  checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched");
  checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered");
  checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "zoom");
  checkWallpaper(Ci.nsIShellService.BACKGROUND_FIT, "scaled");

  // Restore GConf and wallpaper

  gconf.setString(DG_IMAGE_KEY, prevImageKey);
  gconf.setString(DG_OPTION_KEY, prevOptionKey);
  gconf.setBool(DG_DRAW_BG_KEY, prevDrawBgKey);

  wpFile.remove(false);
  if (wpFileBackup.exists())
    wpFileBackup.moveTo(null, wpFile.leafName);

  gBrowser.removeCurrentTab();
  finish();
}

function test() {
  var osString = Cc["@mozilla.org/xre/app-info;1"].
                 getService(Ci.nsIXULRuntime).OS;
  if (osString != "Linux") {
    todo(false, "This test is Linux specific for now.");
    return;
  }

  try {
    // If GSettings is available, then the GConf tests
    // will fail
    var gsettings = Cc["@mozilla.org/gsettings-service;1"].
                    getService(Ci.nsIGSettingsService).
                    getCollectionForSchema("org.gnome.desktop.background");
    todo(false, "This test doesn't work when GSettings is available");
    return;
  } catch(e) { }

  gBrowser.selectedTab = gBrowser.addTab();
  gBrowser.selectedBrowser.addEventListener("load", onPageLoad, true);
  content.location = "about:logo";

  waitForExplicitFinish();
}