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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | function run_test() { |
michael@0 | 5 | var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"]. |
michael@0 | 6 | getService(Ci.nsIURLFormatter); |
michael@0 | 7 | var locale = Cc["@mozilla.org/chrome/chrome-registry;1"]. |
michael@0 | 8 | getService(Ci.nsIXULChromeRegistry). |
michael@0 | 9 | getSelectedLocale('global'); |
michael@0 | 10 | var prefs = Cc['@mozilla.org/preferences-service;1']. |
michael@0 | 11 | getService(Ci.nsIPrefBranch); |
michael@0 | 12 | var sysInfo = Cc["@mozilla.org/system-info;1"]. |
michael@0 | 13 | getService(Ci.nsIPropertyBag2); |
michael@0 | 14 | var OSVersion = sysInfo.getProperty("name") + " " + |
michael@0 | 15 | sysInfo.getProperty("version"); |
michael@0 | 16 | try { |
michael@0 | 17 | OSVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")"; |
michael@0 | 18 | } catch (e) {} |
michael@0 | 19 | OSVersion = encodeURIComponent(OSVersion); |
michael@0 | 20 | var macutils = null; |
michael@0 | 21 | try { |
michael@0 | 22 | macutils = Cc["@mozilla.org/xpcom/mac-utils;1"]. |
michael@0 | 23 | getService(Ci.nsIMacUtils); |
michael@0 | 24 | } catch (e) {} |
michael@0 | 25 | var appInfo = Cc["@mozilla.org/xre/app-info;1"]. |
michael@0 | 26 | getService(Ci.nsIXULAppInfo). |
michael@0 | 27 | QueryInterface(Ci.nsIXULRuntime); |
michael@0 | 28 | var abi = macutils && macutils.isUniversalBinary ? "Universal-gcc3" : appInfo.XPCOMABI; |
michael@0 | 29 | |
michael@0 | 30 | let channel = "default"; |
michael@0 | 31 | let defaults = prefs.QueryInterface(Ci.nsIPrefService).getDefaultBranch(null); |
michael@0 | 32 | try { |
michael@0 | 33 | channel = defaults.getCharPref("app.update.channel"); |
michael@0 | 34 | } catch (e) {} |
michael@0 | 35 | // Set distribution values. |
michael@0 | 36 | defaults.setCharPref("distribution.id", "bacon"); |
michael@0 | 37 | defaults.setCharPref("distribution.version", "1.0"); |
michael@0 | 38 | |
michael@0 | 39 | var upperUrlRaw = "http://%LOCALE%.%VENDOR%.foo/?name=%NAME%&id=%ID%&version=%VERSION%&platversion=%PLATFORMVERSION%&abid=%APPBUILDID%&pbid=%PLATFORMBUILDID%&app=%APP%&os=%OS%&abi=%XPCOMABI%"; |
michael@0 | 40 | var lowerUrlRaw = "http://%locale%.%vendor%.foo/?name=%name%&id=%id%&version=%version%&platversion=%platformversion%&abid=%appbuildid%&pbid=%platformbuildid%&app=%app%&os=%os%&abi=%xpcomabi%"; |
michael@0 | 41 | //XXX %APP%'s RegExp is not global, so it only replaces the first space |
michael@0 | 42 | var ulUrlRef = "http://" + locale + ".Mozilla.foo/?name=Url Formatter Test&id=urlformattertest@test.mozilla.org&version=1&platversion=2.0&abid=2007122405&pbid=2007122406&app=urlformatter test&os=XPCShell&abi=" + abi; |
michael@0 | 43 | var multiUrl = "http://%VENDOR%.%VENDOR%.%NAME%.%VENDOR%.%NAME%"; |
michael@0 | 44 | var multiUrlRef = "http://Mozilla.Mozilla.Url Formatter Test.Mozilla.Url Formatter Test"; |
michael@0 | 45 | var encodedUrl = "https://%LOCALE%.%VENDOR%.foo/?q=%E3%82%BF%E3%83%96&app=%NAME%&ver=%PLATFORMVERSION%"; |
michael@0 | 46 | var encodedUrlRef = "https://" + locale + ".Mozilla.foo/?q=%E3%82%BF%E3%83%96&app=Url Formatter Test&ver=2.0"; |
michael@0 | 47 | var advancedUrl = "http://test.mozilla.com/%NAME%/%VERSION%/%APPBUILDID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/"; |
michael@0 | 48 | var advancedUrlRef = "http://test.mozilla.com/Url Formatter Test/1/2007122405/XPCShell_" + abi + "/" + locale + "/" + channel + "/" + OSVersion + "/bacon/1.0/"; |
michael@0 | 49 | |
michael@0 | 50 | var pref = "xpcshell.urlformatter.test"; |
michael@0 | 51 | var str = Cc["@mozilla.org/supports-string;1"]. |
michael@0 | 52 | createInstance(Ci.nsISupportsString); |
michael@0 | 53 | str.data = upperUrlRaw; |
michael@0 | 54 | prefs.setComplexValue(pref, Ci.nsISupportsString, str); |
michael@0 | 55 | |
michael@0 | 56 | do_check_eq(formatter.formatURL(upperUrlRaw), ulUrlRef); |
michael@0 | 57 | do_check_eq(formatter.formatURLPref(pref), ulUrlRef); |
michael@0 | 58 | // Keys must be uppercase |
michael@0 | 59 | do_check_neq(formatter.formatURL(lowerUrlRaw), ulUrlRef); |
michael@0 | 60 | do_check_eq(formatter.formatURL(multiUrl), multiUrlRef); |
michael@0 | 61 | // Encoded strings must be kept as is (Bug 427304) |
michael@0 | 62 | do_check_eq(formatter.formatURL(encodedUrl), encodedUrlRef); |
michael@0 | 63 | |
michael@0 | 64 | do_check_eq(formatter.formatURL(advancedUrl), advancedUrlRef); |
michael@0 | 65 | } |