tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_420786.js (3550B)


      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";
      5 
      6 const GS_BG_SCHEMA = "org.gnome.desktop.background";
      7 const GS_IMAGE_KEY = "picture-uri";
      8 const GS_OPTION_KEY = "picture-options";
      9 const GS_DRAW_BG_KEY = "draw-background";
     10 
     11 add_task(async function () {
     12  await BrowserTestUtils.withNewTab(
     13    {
     14      gBrowser,
     15      url: "about:logo",
     16    },
     17    () => {
     18      var brandName = Services.strings
     19        .createBundle("chrome://branding/locale/brand.properties")
     20        .GetStringFromName("brandShortName");
     21 
     22      var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(
     23        Ci.nsIDirectoryServiceProvider
     24      );
     25      var homeDir = dirSvc.getFile("Home", {});
     26 
     27      var wpFile = homeDir.clone();
     28      wpFile.append(brandName + "_wallpaper.png");
     29 
     30      // Backup the existing wallpaper so that this test doesn't change the user's
     31      // settings.
     32      var wpFileBackup = homeDir.clone();
     33      wpFileBackup.append(brandName + "_wallpaper.png.backup");
     34 
     35      if (wpFileBackup.exists()) {
     36        wpFileBackup.remove(false);
     37      }
     38 
     39      if (wpFile.exists()) {
     40        wpFile.copyTo(null, wpFileBackup.leafName);
     41      }
     42 
     43      var shell = Cc["@mozilla.org/browser/shell-service;1"]
     44        .getService(Ci.nsIShellService)
     45        .QueryInterface(Ci.nsIGNOMEShellService);
     46 
     47      // For simplicity, we're going to reach in and access the image on the
     48      // page directly, which means the page shouldn't be running in a remote
     49      // browser. Thankfully, about:logo runs in the parent process for now.
     50      Assert.ok(
     51        !gBrowser.selectedBrowser.isRemoteBrowser,
     52        "image can be accessed synchronously from the parent process"
     53      );
     54 
     55      var image = content.document.images[0];
     56 
     57      let checkWallpaper, restoreSettings;
     58      try {
     59        const prevImage = shell.getGSettingsString(GS_BG_SCHEMA, GS_IMAGE_KEY);
     60        const prevOption = shell.getGSettingsString(
     61          GS_BG_SCHEMA,
     62          GS_OPTION_KEY
     63        );
     64 
     65        checkWallpaper = function (position, expectedGSettingsPosition) {
     66          shell.setDesktopBackground(image, position, "");
     67          ok(wpFile.exists(), "Wallpaper was written to disk");
     68          is(
     69            shell.getGSettingsString(GS_BG_SCHEMA, GS_IMAGE_KEY),
     70            encodeURI("file://" + wpFile.path),
     71            "Wallpaper file GSettings key is correct"
     72          );
     73          is(
     74            shell.getGSettingsString(GS_BG_SCHEMA, GS_OPTION_KEY),
     75            expectedGSettingsPosition,
     76            "Wallpaper position GSettings key is correct"
     77          );
     78        };
     79 
     80        restoreSettings = function () {
     81          shell.setGSettingsString(GS_BG_SCHEMA, GS_IMAGE_KEY, prevImage);
     82          shell.setGSettingsString(GS_BG_SCHEMA, GS_OPTION_KEY, prevOption);
     83        };
     84      } catch (e) {}
     85 
     86      checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper");
     87      checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched");
     88      checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered");
     89      checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "zoom");
     90      checkWallpaper(Ci.nsIShellService.BACKGROUND_FIT, "scaled");
     91      checkWallpaper(Ci.nsIShellService.BACKGROUND_SPAN, "spanned");
     92 
     93      restoreSettings();
     94 
     95      // Restore files
     96      if (wpFileBackup.exists()) {
     97        wpFileBackup.moveTo(null, wpFile.leafName);
     98      }
     99    }
    100  );
    101 });