michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: function run_test() { michael@0: var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"]. michael@0: getService(Ci.nsIURLFormatter); michael@0: var locale = Cc["@mozilla.org/chrome/chrome-registry;1"]. michael@0: getService(Ci.nsIXULChromeRegistry). michael@0: getSelectedLocale('global'); michael@0: var prefs = Cc['@mozilla.org/preferences-service;1']. michael@0: getService(Ci.nsIPrefBranch); michael@0: var sysInfo = Cc["@mozilla.org/system-info;1"]. michael@0: getService(Ci.nsIPropertyBag2); michael@0: var OSVersion = sysInfo.getProperty("name") + " " + michael@0: sysInfo.getProperty("version"); michael@0: try { michael@0: OSVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")"; michael@0: } catch (e) {} michael@0: OSVersion = encodeURIComponent(OSVersion); michael@0: var macutils = null; michael@0: try { michael@0: macutils = Cc["@mozilla.org/xpcom/mac-utils;1"]. michael@0: getService(Ci.nsIMacUtils); michael@0: } catch (e) {} michael@0: var appInfo = Cc["@mozilla.org/xre/app-info;1"]. michael@0: getService(Ci.nsIXULAppInfo). michael@0: QueryInterface(Ci.nsIXULRuntime); michael@0: var abi = macutils && macutils.isUniversalBinary ? "Universal-gcc3" : appInfo.XPCOMABI; michael@0: michael@0: let channel = "default"; michael@0: let defaults = prefs.QueryInterface(Ci.nsIPrefService).getDefaultBranch(null); michael@0: try { michael@0: channel = defaults.getCharPref("app.update.channel"); michael@0: } catch (e) {} michael@0: // Set distribution values. michael@0: defaults.setCharPref("distribution.id", "bacon"); michael@0: defaults.setCharPref("distribution.version", "1.0"); michael@0: michael@0: 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: 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: //XXX %APP%'s RegExp is not global, so it only replaces the first space michael@0: 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: var multiUrl = "http://%VENDOR%.%VENDOR%.%NAME%.%VENDOR%.%NAME%"; michael@0: var multiUrlRef = "http://Mozilla.Mozilla.Url Formatter Test.Mozilla.Url Formatter Test"; michael@0: var encodedUrl = "https://%LOCALE%.%VENDOR%.foo/?q=%E3%82%BF%E3%83%96&app=%NAME%&ver=%PLATFORMVERSION%"; michael@0: var encodedUrlRef = "https://" + locale + ".Mozilla.foo/?q=%E3%82%BF%E3%83%96&app=Url Formatter Test&ver=2.0"; michael@0: var advancedUrl = "http://test.mozilla.com/%NAME%/%VERSION%/%APPBUILDID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/"; michael@0: var advancedUrlRef = "http://test.mozilla.com/Url Formatter Test/1/2007122405/XPCShell_" + abi + "/" + locale + "/" + channel + "/" + OSVersion + "/bacon/1.0/"; michael@0: michael@0: var pref = "xpcshell.urlformatter.test"; michael@0: var str = Cc["@mozilla.org/supports-string;1"]. michael@0: createInstance(Ci.nsISupportsString); michael@0: str.data = upperUrlRaw; michael@0: prefs.setComplexValue(pref, Ci.nsISupportsString, str); michael@0: michael@0: do_check_eq(formatter.formatURL(upperUrlRaw), ulUrlRef); michael@0: do_check_eq(formatter.formatURLPref(pref), ulUrlRef); michael@0: // Keys must be uppercase michael@0: do_check_neq(formatter.formatURL(lowerUrlRaw), ulUrlRef); michael@0: do_check_eq(formatter.formatURL(multiUrl), multiUrlRef); michael@0: // Encoded strings must be kept as is (Bug 427304) michael@0: do_check_eq(formatter.formatURL(encodedUrl), encodedUrlRef); michael@0: michael@0: do_check_eq(formatter.formatURL(advancedUrl), advancedUrlRef); michael@0: }