Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | const Cc = Components.classes; |
michael@0 | 2 | const Ci = Components.interfaces; |
michael@0 | 3 | const Cr = Components.results; |
michael@0 | 4 | |
michael@0 | 5 | const GCONF_BG_COLOR_KEY = "/desktop/gnome/background/primary_color"; |
michael@0 | 6 | |
michael@0 | 7 | var gShell; |
michael@0 | 8 | var gGConf; |
michael@0 | 9 | |
michael@0 | 10 | /** |
michael@0 | 11 | * Converts from a rgb numerical color valule (r << 16 | g << 8 | b) |
michael@0 | 12 | * into a hex string in #RRGGBB format. |
michael@0 | 13 | */ |
michael@0 | 14 | function colorToHex(aColor) { |
michael@0 | 15 | const rMask = 4294901760; |
michael@0 | 16 | const gMask = 65280; |
michael@0 | 17 | const bMask = 255; |
michael@0 | 18 | |
michael@0 | 19 | var r = (aColor & rMask) >> 16; |
michael@0 | 20 | var g = (aColor & gMask) >> 8; |
michael@0 | 21 | var b = (aColor & bMask); |
michael@0 | 22 | |
michael@0 | 23 | return "#" + [r, g, b].map(function(aInt) |
michael@0 | 24 | aInt.toString(16).replace(/^(.)$/, "0$1")) |
michael@0 | 25 | .join("").toUpperCase(); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * Converts a color string in #RRGGBB format to a rgb numerical color value |
michael@0 | 30 | * (r << 16 | g << 8 | b). |
michael@0 | 31 | */ |
michael@0 | 32 | function hexToColor(aString) { |
michael@0 | 33 | return parseInt(aString.substring(1,3), 16) << 16 | |
michael@0 | 34 | parseInt(aString.substring(3,5), 16) << 8 | |
michael@0 | 35 | parseInt(aString.substring(5,7), 16); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | /** |
michael@0 | 39 | * Checks that setting the GConf background key to aGConfColor will |
michael@0 | 40 | * result in the Shell component returning a background color equals |
michael@0 | 41 | * to aExpectedShellColor in #RRGGBB format. |
michael@0 | 42 | */ |
michael@0 | 43 | function checkGConfToShellColor(aGConfColor, aExpectedShellColor) { |
michael@0 | 44 | |
michael@0 | 45 | gGConf.setString(GCONF_BG_COLOR_KEY, aGConfColor); |
michael@0 | 46 | var shellColor = colorToHex(gShell.desktopBackgroundColor); |
michael@0 | 47 | |
michael@0 | 48 | do_check_eq(shellColor, aExpectedShellColor); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | /** |
michael@0 | 52 | * Checks that setting the background color (in #RRGGBB format) using the Shell |
michael@0 | 53 | * component will result in having a GConf key for the background color set to |
michael@0 | 54 | * aExpectedGConfColor. |
michael@0 | 55 | */ |
michael@0 | 56 | function checkShellToGConfColor(aShellColor, aExpectedGConfColor) { |
michael@0 | 57 | |
michael@0 | 58 | gShell.desktopBackgroundColor = hexToColor(aShellColor); |
michael@0 | 59 | var gconfColor = gGConf.getString(GCONF_BG_COLOR_KEY); |
michael@0 | 60 | |
michael@0 | 61 | do_check_eq(gconfColor, aExpectedGConfColor); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function run_test() { |
michael@0 | 65 | |
michael@0 | 66 | // This test is Linux specific for now |
michael@0 | 67 | if (!("@mozilla.org/gnome-gconf-service;1" in Cc)) |
michael@0 | 68 | return; |
michael@0 | 69 | |
michael@0 | 70 | try { |
michael@0 | 71 | // If GSettings is available, then the GConf tests |
michael@0 | 72 | // will fail |
michael@0 | 73 | var gsettings = Cc["@mozilla.org/gsettings-service;1"]. |
michael@0 | 74 | getService(Ci.nsIGSettingsService). |
michael@0 | 75 | getCollectionForSchema("org.gnome.desktop.background"); |
michael@0 | 76 | return; |
michael@0 | 77 | } catch(e) { } |
michael@0 | 78 | |
michael@0 | 79 | gGConf = Cc["@mozilla.org/gnome-gconf-service;1"]. |
michael@0 | 80 | getService(Ci.nsIGConfService); |
michael@0 | 81 | |
michael@0 | 82 | gShell = Cc["@mozilla.org/browser/shell-service;1"]. |
michael@0 | 83 | getService(Ci.nsIShellService); |
michael@0 | 84 | |
michael@0 | 85 | // Save the original background color so that we can restore it |
michael@0 | 86 | // after the test. |
michael@0 | 87 | var origGConfColor = gGConf.getString(GCONF_BG_COLOR_KEY); |
michael@0 | 88 | |
michael@0 | 89 | try { |
michael@0 | 90 | |
michael@0 | 91 | checkGConfToShellColor("#000", "#000000"); |
michael@0 | 92 | checkGConfToShellColor("#00f", "#0000FF"); |
michael@0 | 93 | checkGConfToShellColor("#b2f", "#BB22FF"); |
michael@0 | 94 | checkGConfToShellColor("#fff", "#FFFFFF"); |
michael@0 | 95 | |
michael@0 | 96 | checkGConfToShellColor("#000000", "#000000"); |
michael@0 | 97 | checkGConfToShellColor("#0000ff", "#0000FF"); |
michael@0 | 98 | checkGConfToShellColor("#b002f0", "#B002F0"); |
michael@0 | 99 | checkGConfToShellColor("#ffffff", "#FFFFFF"); |
michael@0 | 100 | |
michael@0 | 101 | checkGConfToShellColor("#000000000", "#000000"); |
michael@0 | 102 | checkGConfToShellColor("#00f00f00f", "#000000"); |
michael@0 | 103 | checkGConfToShellColor("#aaabbbccc", "#AABBCC"); |
michael@0 | 104 | checkGConfToShellColor("#fffffffff", "#FFFFFF"); |
michael@0 | 105 | |
michael@0 | 106 | checkGConfToShellColor("#000000000000", "#000000"); |
michael@0 | 107 | checkGConfToShellColor("#000f000f000f", "#000000"); |
michael@0 | 108 | checkGConfToShellColor("#00ff00ff00ff", "#000000"); |
michael@0 | 109 | checkGConfToShellColor("#aaaabbbbcccc", "#AABBCC"); |
michael@0 | 110 | checkGConfToShellColor("#111122223333", "#112233"); |
michael@0 | 111 | checkGConfToShellColor("#ffffffffffff", "#FFFFFF"); |
michael@0 | 112 | |
michael@0 | 113 | checkShellToGConfColor("#000000", "#000000000000"); |
michael@0 | 114 | checkShellToGConfColor("#0000FF", "#00000000ffff"); |
michael@0 | 115 | checkShellToGConfColor("#FFFFFF", "#ffffffffffff"); |
michael@0 | 116 | checkShellToGConfColor("#0A0B0C", "#0a0a0b0b0c0c"); |
michael@0 | 117 | checkShellToGConfColor("#A0B0C0", "#a0a0b0b0c0c0"); |
michael@0 | 118 | checkShellToGConfColor("#AABBCC", "#aaaabbbbcccc"); |
michael@0 | 119 | |
michael@0 | 120 | } finally { |
michael@0 | 121 | gGConf.setString(GCONF_BG_COLOR_KEY, origGConfColor); |
michael@0 | 122 | } |
michael@0 | 123 | } |