browser/base/content/test/general/browser_urlbarTrimURLs.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 function testVal(originalValue, targetValue) {
michael@0 6 gURLBar.value = originalValue;
michael@0 7 gURLBar.valueIsTyped = false;
michael@0 8 is(gURLBar.value, targetValue || originalValue, "url bar value set");
michael@0 9 }
michael@0 10
michael@0 11 function test() {
michael@0 12 const prefname = "browser.urlbar.trimURLs";
michael@0 13
michael@0 14 gBrowser.selectedTab = gBrowser.addTab();
michael@0 15
michael@0 16 registerCleanupFunction(function () {
michael@0 17 gBrowser.removeCurrentTab();
michael@0 18 Services.prefs.clearUserPref(prefname);
michael@0 19 URLBarSetURI();
michael@0 20 });
michael@0 21
michael@0 22 Services.prefs.setBoolPref(prefname, true);
michael@0 23
michael@0 24 testVal("http://mozilla.org/", "mozilla.org");
michael@0 25 testVal("https://mozilla.org/", "https://mozilla.org");
michael@0 26 testVal("http://mözilla.org/", "mözilla.org");
michael@0 27 testVal("http://mozilla.imaginatory/", "mozilla.imaginatory");
michael@0 28 testVal("http://www.mozilla.org/", "www.mozilla.org");
michael@0 29 testVal("http://sub.mozilla.org/", "sub.mozilla.org");
michael@0 30 testVal("http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org");
michael@0 31 testVal("http://mozilla.org/file.ext", "mozilla.org/file.ext");
michael@0 32 testVal("http://mozilla.org/sub/", "mozilla.org/sub/");
michael@0 33
michael@0 34 testVal("http://ftp.mozilla.org/", "http://ftp.mozilla.org");
michael@0 35 testVal("http://ftp1.mozilla.org/", "http://ftp1.mozilla.org");
michael@0 36 testVal("http://ftp42.mozilla.org/", "http://ftp42.mozilla.org");
michael@0 37 testVal("http://ftpx.mozilla.org/", "ftpx.mozilla.org");
michael@0 38 testVal("ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org");
michael@0 39 testVal("ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org");
michael@0 40 testVal("ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org");
michael@0 41 testVal("ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org");
michael@0 42
michael@0 43 testVal("https://user:pass@mozilla.org/", "https://user:pass@mozilla.org");
michael@0 44 testVal("http://user:pass@mozilla.org/", "http://user:pass@mozilla.org");
michael@0 45 testVal("http://sub.mozilla.org:666/", "sub.mozilla.org:666");
michael@0 46
michael@0 47 testVal("https://[fe80::222:19ff:fe11:8c76]/file.ext");
michael@0 48 testVal("http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]");
michael@0 49 testVal("https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext");
michael@0 50 testVal("http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext");
michael@0 51
michael@0 52 testVal("mailto:admin@mozilla.org");
michael@0 53 testVal("gopher://mozilla.org/");
michael@0 54 testVal("about:config");
michael@0 55 testVal("jar:http://mozilla.org/example.jar!/");
michael@0 56 testVal("view-source:http://mozilla.org/");
michael@0 57
michael@0 58 Services.prefs.setBoolPref(prefname, false);
michael@0 59
michael@0 60 testVal("http://mozilla.org/");
michael@0 61
michael@0 62 Services.prefs.setBoolPref(prefname, true);
michael@0 63
michael@0 64 waitForExplicitFinish();
michael@0 65
michael@0 66 gBrowser.selectedBrowser.addEventListener("load", function () {
michael@0 67 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 68
michael@0 69 is(gBrowser.currentURI.spec, "http://example.com/", "expected page should have loaded");
michael@0 70
michael@0 71 testCopy("example.com", "http://example.com/", function () {
michael@0 72 SetPageProxyState("invalid");
michael@0 73 gURLBar.valueIsTyped = true;
michael@0 74 testCopy("example.com", "example.com", finish);
michael@0 75 });
michael@0 76 }, true);
michael@0 77
michael@0 78 gBrowser.loadURI("http://example.com/");
michael@0 79 }
michael@0 80
michael@0 81 function testCopy(originalValue, targetValue, cb) {
michael@0 82 waitForClipboard(targetValue, function () {
michael@0 83 is(gURLBar.value, originalValue, "url bar copy value set");
michael@0 84
michael@0 85 gURLBar.focus();
michael@0 86 gURLBar.select();
michael@0 87 goDoCommand("cmd_copy");
michael@0 88 }, cb, cb);
michael@0 89 }

mercurial