michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: function testVal(originalValue, targetValue) { michael@0: gURLBar.value = originalValue; michael@0: gURLBar.valueIsTyped = false; michael@0: is(gURLBar.value, targetValue || originalValue, "url bar value set"); michael@0: } michael@0: michael@0: function test() { michael@0: const prefname = "browser.urlbar.trimURLs"; michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: michael@0: registerCleanupFunction(function () { michael@0: gBrowser.removeCurrentTab(); michael@0: Services.prefs.clearUserPref(prefname); michael@0: URLBarSetURI(); michael@0: }); michael@0: michael@0: Services.prefs.setBoolPref(prefname, true); michael@0: michael@0: testVal("http://mozilla.org/", "mozilla.org"); michael@0: testVal("https://mozilla.org/", "https://mozilla.org"); michael@0: testVal("http://mözilla.org/", "mözilla.org"); michael@0: testVal("http://mozilla.imaginatory/", "mozilla.imaginatory"); michael@0: testVal("http://www.mozilla.org/", "www.mozilla.org"); michael@0: testVal("http://sub.mozilla.org/", "sub.mozilla.org"); michael@0: testVal("http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org"); michael@0: testVal("http://mozilla.org/file.ext", "mozilla.org/file.ext"); michael@0: testVal("http://mozilla.org/sub/", "mozilla.org/sub/"); michael@0: michael@0: testVal("http://ftp.mozilla.org/", "http://ftp.mozilla.org"); michael@0: testVal("http://ftp1.mozilla.org/", "http://ftp1.mozilla.org"); michael@0: testVal("http://ftp42.mozilla.org/", "http://ftp42.mozilla.org"); michael@0: testVal("http://ftpx.mozilla.org/", "ftpx.mozilla.org"); michael@0: testVal("ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org"); michael@0: testVal("ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org"); michael@0: testVal("ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org"); michael@0: testVal("ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org"); michael@0: michael@0: testVal("https://user:pass@mozilla.org/", "https://user:pass@mozilla.org"); michael@0: testVal("http://user:pass@mozilla.org/", "http://user:pass@mozilla.org"); michael@0: testVal("http://sub.mozilla.org:666/", "sub.mozilla.org:666"); michael@0: michael@0: testVal("https://[fe80::222:19ff:fe11:8c76]/file.ext"); michael@0: testVal("http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]"); michael@0: testVal("https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"); michael@0: testVal("http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext"); michael@0: michael@0: testVal("mailto:admin@mozilla.org"); michael@0: testVal("gopher://mozilla.org/"); michael@0: testVal("about:config"); michael@0: testVal("jar:http://mozilla.org/example.jar!/"); michael@0: testVal("view-source:http://mozilla.org/"); michael@0: michael@0: Services.prefs.setBoolPref(prefname, false); michael@0: michael@0: testVal("http://mozilla.org/"); michael@0: michael@0: Services.prefs.setBoolPref(prefname, true); michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("load", function () { michael@0: gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); michael@0: michael@0: is(gBrowser.currentURI.spec, "http://example.com/", "expected page should have loaded"); michael@0: michael@0: testCopy("example.com", "http://example.com/", function () { michael@0: SetPageProxyState("invalid"); michael@0: gURLBar.valueIsTyped = true; michael@0: testCopy("example.com", "example.com", finish); michael@0: }); michael@0: }, true); michael@0: michael@0: gBrowser.loadURI("http://example.com/"); michael@0: } michael@0: michael@0: function testCopy(originalValue, targetValue, cb) { michael@0: waitForClipboard(targetValue, function () { michael@0: is(gURLBar.value, originalValue, "url bar copy value set"); michael@0: michael@0: gURLBar.focus(); michael@0: gURLBar.select(); michael@0: goDoCommand("cmd_copy"); michael@0: }, cb, cb); michael@0: }