summaryrefslogtreecommitdiffstats
path: root/browser/components/shell/test
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/shell/test')
-rw-r--r--browser/components/shell/test/.eslintrc.js7
-rw-r--r--browser/components/shell/test/browser.ini6
-rw-r--r--browser/components/shell/test/browser_420786.js88
-rw-r--r--browser/components/shell/test/browser_633221.js7
-rw-r--r--browser/components/shell/test/unit/.eslintrc.js7
-rw-r--r--browser/components/shell/test/unit/test_421977.js123
-rw-r--r--browser/components/shell/test/unit/xpcshell.ini7
7 files changed, 245 insertions, 0 deletions
diff --git a/browser/components/shell/test/.eslintrc.js b/browser/components/shell/test/.eslintrc.js
new file mode 100644
index 000000000..c764b133d
--- /dev/null
+++ b/browser/components/shell/test/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ "extends": [
+ "../../../../testing/mochitest/browser.eslintrc.js"
+ ]
+};
diff --git a/browser/components/shell/test/browser.ini b/browser/components/shell/test/browser.ini
new file mode 100644
index 000000000..8f18415c0
--- /dev/null
+++ b/browser/components/shell/test/browser.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+skip-if = os != "linux"
+
+[browser_420786.js]
+[browser_633221.js]
+
diff --git a/browser/components/shell/test/browser_420786.js b/browser/components/shell/test/browser_420786.js
new file mode 100644
index 000000000..ae4521890
--- /dev/null
+++ b/browser/components/shell/test/browser_420786.js
@@ -0,0 +1,88 @@
+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() {
+ 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) { }
+
+ gBrowser.selectedTab = gBrowser.addTab();
+ gBrowser.selectedBrowser.addEventListener("load", onPageLoad, true);
+ content.location = "about:logo";
+
+ waitForExplicitFinish();
+}
diff --git a/browser/components/shell/test/browser_633221.js b/browser/components/shell/test/browser_633221.js
new file mode 100644
index 000000000..7929e8098
--- /dev/null
+++ b/browser/components/shell/test/browser_633221.js
@@ -0,0 +1,7 @@
+Components.utils.import("resource:///modules/ShellService.jsm");
+
+function test() {
+ ShellService.setDefaultBrowser(true, false);
+ ok(ShellService.isDefaultBrowser(true, false), "we got here and are the default browser");
+ ok(ShellService.isDefaultBrowser(true, true), "we got here and are the default browser");
+}
diff --git a/browser/components/shell/test/unit/.eslintrc.js b/browser/components/shell/test/unit/.eslintrc.js
new file mode 100644
index 000000000..d35787cd2
--- /dev/null
+++ b/browser/components/shell/test/unit/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ "extends": [
+ "../../../../../testing/xpcshell/xpcshell.eslintrc.js"
+ ]
+};
diff --git a/browser/components/shell/test/unit/test_421977.js b/browser/components/shell/test/unit/test_421977.js
new file mode 100644
index 000000000..637db4b91
--- /dev/null
+++ b/browser/components/shell/test/unit/test_421977.js
@@ -0,0 +1,123 @@
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cr = Components.results;
+
+const GCONF_BG_COLOR_KEY = "/desktop/gnome/background/primary_color";
+
+var gShell;
+var gGConf;
+
+/**
+ * Converts from a rgb numerical color valule (r << 16 | g << 8 | b)
+ * into a hex string in #RRGGBB format.
+ */
+function colorToHex(aColor) {
+ const rMask = 4294901760;
+ const gMask = 65280;
+ const bMask = 255;
+
+ var r = (aColor & rMask) >> 16;
+ var g = (aColor & gMask) >> 8;
+ var b = (aColor & bMask);
+
+ return "#" + [r, g, b].map(aInt =>
+ aInt.toString(16).replace(/^(.)$/, "0$1"))
+ .join("").toUpperCase();
+}
+
+/**
+ * Converts a color string in #RRGGBB format to a rgb numerical color value
+ * (r << 16 | g << 8 | b).
+ */
+function hexToColor(aString) {
+ return parseInt(aString.substring(1, 3), 16) << 16 |
+ parseInt(aString.substring(3, 5), 16) << 8 |
+ parseInt(aString.substring(5, 7), 16);
+}
+
+/**
+ * Checks that setting the GConf background key to aGConfColor will
+ * result in the Shell component returning a background color equals
+ * to aExpectedShellColor in #RRGGBB format.
+ */
+function checkGConfToShellColor(aGConfColor, aExpectedShellColor) {
+
+ gGConf.setString(GCONF_BG_COLOR_KEY, aGConfColor);
+ var shellColor = colorToHex(gShell.desktopBackgroundColor);
+
+ do_check_eq(shellColor, aExpectedShellColor);
+}
+
+/**
+ * Checks that setting the background color (in #RRGGBB format) using the Shell
+ * component will result in having a GConf key for the background color set to
+ * aExpectedGConfColor.
+ */
+function checkShellToGConfColor(aShellColor, aExpectedGConfColor) {
+
+ gShell.desktopBackgroundColor = hexToColor(aShellColor);
+ var gconfColor = gGConf.getString(GCONF_BG_COLOR_KEY);
+
+ do_check_eq(gconfColor, aExpectedGConfColor);
+}
+
+function run_test() {
+
+ // This test is Linux specific for now
+ if (!("@mozilla.org/gnome-gconf-service;1" in Cc))
+ return;
+
+ 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");
+ return;
+ } catch (e) { }
+
+ gGConf = Cc["@mozilla.org/gnome-gconf-service;1"].
+ getService(Ci.nsIGConfService);
+
+ gShell = Cc["@mozilla.org/browser/shell-service;1"].
+ getService(Ci.nsIShellService);
+
+ // Save the original background color so that we can restore it
+ // after the test.
+ var origGConfColor = gGConf.getString(GCONF_BG_COLOR_KEY);
+
+ try {
+
+ checkGConfToShellColor("#000", "#000000");
+ checkGConfToShellColor("#00f", "#0000FF");
+ checkGConfToShellColor("#b2f", "#BB22FF");
+ checkGConfToShellColor("#fff", "#FFFFFF");
+
+ checkGConfToShellColor("#000000", "#000000");
+ checkGConfToShellColor("#0000ff", "#0000FF");
+ checkGConfToShellColor("#b002f0", "#B002F0");
+ checkGConfToShellColor("#ffffff", "#FFFFFF");
+
+ checkGConfToShellColor("#000000000", "#000000");
+ checkGConfToShellColor("#00f00f00f", "#000000");
+ checkGConfToShellColor("#aaabbbccc", "#AABBCC");
+ checkGConfToShellColor("#fffffffff", "#FFFFFF");
+
+ checkGConfToShellColor("#000000000000", "#000000");
+ checkGConfToShellColor("#000f000f000f", "#000000");
+ checkGConfToShellColor("#00ff00ff00ff", "#000000");
+ checkGConfToShellColor("#aaaabbbbcccc", "#AABBCC");
+ checkGConfToShellColor("#111122223333", "#112233");
+ checkGConfToShellColor("#ffffffffffff", "#FFFFFF");
+
+ checkShellToGConfColor("#000000", "#000000000000");
+ checkShellToGConfColor("#0000FF", "#00000000ffff");
+ checkShellToGConfColor("#FFFFFF", "#ffffffffffff");
+ checkShellToGConfColor("#0A0B0C", "#0a0a0b0b0c0c");
+ checkShellToGConfColor("#A0B0C0", "#a0a0b0b0c0c0");
+ checkShellToGConfColor("#AABBCC", "#aaaabbbbcccc");
+
+ } finally {
+ gGConf.setString(GCONF_BG_COLOR_KEY, origGConfColor);
+ }
+}
diff --git a/browser/components/shell/test/unit/xpcshell.ini b/browser/components/shell/test/unit/xpcshell.ini
new file mode 100644
index 000000000..be00037e0
--- /dev/null
+++ b/browser/components/shell/test/unit/xpcshell.ini
@@ -0,0 +1,7 @@
+[DEFAULT]
+head =
+tail =
+firefox-appdir = browser
+skip-if = toolkit == 'android'
+
+[test_421977.js]