Bug 1529363 - Rewrite browser_420786.js test to use add_task and BTU.withNewTab. r=paolo
authorIan Moody <moz-ian@perix.co.uk>
Wed, 06 Mar 2019 22:03:48 +0000
changeset 520712 2ae9e2afee5685f90ec9f4195bdcf77df773e51b
parent 520711 268fd30c6da4c793521a60cf5e02790062e5d89d
child 520713 00f103fd2a426139186c1951c345c7645dfb8429
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs1529363
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1529363 - Rewrite browser_420786.js test to use add_task and BTU.withNewTab. r=paolo Currently the test fails since it throws "TypeError: content is null". This hasn't been noticed since this test only runs when gsettings is absent and presumably all the test machines have it. Differential Revision: https://phabricator.services.mozilla.com/D20545
browser/components/shell/test/browser_420786.js
--- a/browser/components/shell/test/browser_420786.js
+++ b/browser/components/shell/test/browser_420786.js
@@ -1,86 +1,78 @@
 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 brandName = Services.strings.createBundle("chrome://branding/locale/brand.properties").
-                  GetStringFromName("brandShortName");
+add_task(async function() {
+  await BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: "about:logo",
+  }, (browser) => {
+    try {
+      // If GSettings is available, then the GConf tests
+      // will fail
+      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) { }
 
-  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");
+    var brandName = Services.strings.createBundle("chrome://branding/locale/brand.properties").
+                    GetStringFromName("brandShortName");
 
-  // 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");
+    var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
+                 getService(Ci.nsIDirectoryServiceProvider);
+    var homeDir = dirSvc.getFile("Home", {});
 
-  if (wpFileBackup.exists())
-    wpFileBackup.remove(false);
-
-  if (wpFile.exists())
-    wpFile.copyTo(null, wpFileBackup.leafName);
+    var wpFile = homeDir.clone();
+    wpFile.append(brandName + "_wallpaper.png");
 
-  var shell = Cc["@mozilla.org/browser/shell-service;1"].
-              getService(Ci.nsIShellService);
-  var gconf = Cc["@mozilla.org/gnome-gconf-service;1"].
-              getService(Ci.nsIGConfService);
+    // 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");
 
-  var prevImageKey = gconf.getString(DG_IMAGE_KEY);
-  var prevOptionKey = gconf.getString(DG_OPTION_KEY);
-  var prevDrawBgKey = gconf.getBool(DG_DRAW_BG_KEY);
+    if (wpFileBackup.exists())
+      wpFileBackup.remove(false);
 
-  var image = content.document.images[0];
+    if (wpFile.exists())
+      wpFile.copyTo(null, wpFileBackup.leafName);
 
-  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");
-  }
+    var shell = Cc["@mozilla.org/browser/shell-service;1"].
+                getService(Ci.nsIShellService);
+    var gconf = Cc["@mozilla.org/gnome-gconf-service;1"].
+                getService(Ci.nsIGConfService);
 
-  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");
+    var prevImageKey = gconf.getString(DG_IMAGE_KEY);
+    var prevOptionKey = gconf.getString(DG_OPTION_KEY);
+    var prevDrawBgKey = gconf.getBool(DG_DRAW_BG_KEY);
 
-  // Restore GConf and wallpaper
-
-  gconf.setString(DG_IMAGE_KEY, prevImageKey);
-  gconf.setString(DG_OPTION_KEY, prevOptionKey);
-  gconf.setBool(DG_DRAW_BG_KEY, prevDrawBgKey);
+    var image = content.document.images[0];
 
-  wpFile.remove(false);
-  if (wpFileBackup.exists())
-    wpFileBackup.moveTo(null, wpFile.leafName);
-
-  gBrowser.removeCurrentTab();
-  finish();
-}
+    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");
+    }
 
-function test() {
-  try {
-    // If GSettings is available, then the GConf tests
-    // will fail
-    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) { }
+    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
 
-  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
-  gBrowser.selectedBrowser.addEventListener("load", onPageLoad, true);
-  content.location = "about:logo";
+    gconf.setString(DG_IMAGE_KEY, prevImageKey);
+    gconf.setString(DG_OPTION_KEY, prevOptionKey);
+    gconf.setBool(DG_DRAW_BG_KEY, prevDrawBgKey);
 
-  waitForExplicitFinish();
-}
+    wpFile.remove(false);
+    if (wpFileBackup.exists())
+      wpFileBackup.moveTo(null, wpFile.leafName);
+  });
+});