diff --git a/browser/components/shell/Makefile.in b/browser/components/shell/Makefile.in index d0c719f6b93..ae69168d65e 100644 --- a/browser/components/shell/Makefile.in +++ b/browser/components/shell/Makefile.in @@ -44,4 +44,8 @@ include $(DEPTH)/config/autoconf.mk DIRS = public src +ifdef MOZ_MOCHITEST +DIRS += test +endif + include $(topsrcdir)/config/rules.mk diff --git a/browser/components/shell/src/nsGNOMEShellService.cpp b/browser/components/shell/src/nsGNOMEShellService.cpp index 88bfd7fb4d5..0ff75cf8485 100644 --- a/browser/components/shell/src/nsGNOMEShellService.cpp +++ b/browser/components/shell/src/nsGNOMEShellService.cpp @@ -365,7 +365,6 @@ WriteImage(const nsCString& aPath, gfxIImageFrame* aImage) gboolean res = gdk_pixbuf_save(pixbuf, aPath.get(), "png", NULL, NULL); - aImage->UnlockImageData(); g_object_unref(pixbuf); return res ? NS_OK : NS_ERROR_FAILURE; #endif diff --git a/browser/components/shell/test/Makefile.in b/browser/components/shell/test/Makefile.in new file mode 100644 index 00000000000..4724e935411 --- /dev/null +++ b/browser/components/shell/test/Makefile.in @@ -0,0 +1,51 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is +# Sylvain Pasche. +# Portions created by the Initial Developer are Copyright (C) 2008 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either of the GNU General Public License Version 2 or later (the "GPL"), +# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ +relativesrcdir = browser/components/shell/test + +include $(DEPTH)/config/autoconf.mk + +include $(topsrcdir)/config/rules.mk + +_BROWSER_TEST_FILES = browser_420786.js \ + $(NULL) + +libs:: $(_BROWSER_TEST_FILES) + $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir) diff --git a/browser/components/shell/test/browser_420786.js b/browser/components/shell/test/browser_420786.js new file mode 100644 index 00000000000..93e7aba4e81 --- /dev/null +++ b/browser/components/shell/test/browser_420786.js @@ -0,0 +1,98 @@ +const Ci = Components.interfaces; +const Cc = Components.classes; + +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"; + +var testPage; + +function url(spec) { + var ios = Cc["@mozilla.org/network/io-service;1"]. + getService(Ci.nsIIOService); + return ios.newURI(spec, null, null); +} + +function onPageLoad() { + testPage.events.removeListener("load", onPageLoad); + + 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 = testPage.document.getElementsByTagName("img")[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, "centered"); + + // 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); + } + testPage.close(); + finish(); +} + +function test() { + var osString = Cc["@mozilla.org/xre/app-info;1"]. + getService(Ci.nsIXULRuntime).OS; + + // This test is Linux specific for now + if (osString != "Linux") { + finish(); + return; + } + + testPage = Application.activeWindow.open(url("about:blank")); + testPage.events.addListener("load", onPageLoad); + testPage.load(url("about:logo")); + testPage.focus(); + + waitForExplicitFinish(); +}