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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_urlbarTrimURLs.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +function testVal(originalValue, targetValue) {
     1.9 +  gURLBar.value = originalValue;
    1.10 +  gURLBar.valueIsTyped = false;
    1.11 +  is(gURLBar.value, targetValue || originalValue, "url bar value set");
    1.12 +}
    1.13 +
    1.14 +function test() {
    1.15 +  const prefname = "browser.urlbar.trimURLs";
    1.16 +
    1.17 +  gBrowser.selectedTab = gBrowser.addTab();
    1.18 +
    1.19 +  registerCleanupFunction(function () {
    1.20 +    gBrowser.removeCurrentTab();
    1.21 +    Services.prefs.clearUserPref(prefname);
    1.22 +    URLBarSetURI();
    1.23 +  });
    1.24 +
    1.25 +  Services.prefs.setBoolPref(prefname, true);
    1.26 +
    1.27 +  testVal("http://mozilla.org/", "mozilla.org");
    1.28 +  testVal("https://mozilla.org/", "https://mozilla.org");
    1.29 +  testVal("http://mözilla.org/", "mözilla.org");
    1.30 +  testVal("http://mozilla.imaginatory/", "mozilla.imaginatory");
    1.31 +  testVal("http://www.mozilla.org/", "www.mozilla.org");
    1.32 +  testVal("http://sub.mozilla.org/", "sub.mozilla.org");
    1.33 +  testVal("http://sub1.sub2.sub3.mozilla.org/", "sub1.sub2.sub3.mozilla.org");
    1.34 +  testVal("http://mozilla.org/file.ext", "mozilla.org/file.ext");
    1.35 +  testVal("http://mozilla.org/sub/", "mozilla.org/sub/");
    1.36 +
    1.37 +  testVal("http://ftp.mozilla.org/", "http://ftp.mozilla.org");
    1.38 +  testVal("http://ftp1.mozilla.org/", "http://ftp1.mozilla.org");
    1.39 +  testVal("http://ftp42.mozilla.org/", "http://ftp42.mozilla.org");
    1.40 +  testVal("http://ftpx.mozilla.org/", "ftpx.mozilla.org");
    1.41 +  testVal("ftp://ftp.mozilla.org/", "ftp://ftp.mozilla.org");
    1.42 +  testVal("ftp://ftp1.mozilla.org/", "ftp://ftp1.mozilla.org");
    1.43 +  testVal("ftp://ftp42.mozilla.org/", "ftp://ftp42.mozilla.org");
    1.44 +  testVal("ftp://ftpx.mozilla.org/", "ftp://ftpx.mozilla.org");
    1.45 +
    1.46 +  testVal("https://user:pass@mozilla.org/", "https://user:pass@mozilla.org");
    1.47 +  testVal("http://user:pass@mozilla.org/", "http://user:pass@mozilla.org");
    1.48 +  testVal("http://sub.mozilla.org:666/", "sub.mozilla.org:666");
    1.49 +
    1.50 +  testVal("https://[fe80::222:19ff:fe11:8c76]/file.ext");
    1.51 +  testVal("http://[fe80::222:19ff:fe11:8c76]/", "[fe80::222:19ff:fe11:8c76]");
    1.52 +  testVal("https://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext");
    1.53 +  testVal("http://user:pass@[fe80::222:19ff:fe11:8c76]:666/file.ext");
    1.54 +
    1.55 +  testVal("mailto:admin@mozilla.org");
    1.56 +  testVal("gopher://mozilla.org/");
    1.57 +  testVal("about:config");
    1.58 +  testVal("jar:http://mozilla.org/example.jar!/");
    1.59 +  testVal("view-source:http://mozilla.org/");
    1.60 +
    1.61 +  Services.prefs.setBoolPref(prefname, false);
    1.62 +
    1.63 +  testVal("http://mozilla.org/");
    1.64 +
    1.65 +  Services.prefs.setBoolPref(prefname, true);
    1.66 +
    1.67 +  waitForExplicitFinish();
    1.68 +
    1.69 +  gBrowser.selectedBrowser.addEventListener("load", function () {
    1.70 +    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
    1.71 +
    1.72 +    is(gBrowser.currentURI.spec, "http://example.com/", "expected page should have loaded");
    1.73 +
    1.74 +    testCopy("example.com", "http://example.com/", function () {
    1.75 +      SetPageProxyState("invalid");
    1.76 +      gURLBar.valueIsTyped = true;
    1.77 +      testCopy("example.com", "example.com", finish);
    1.78 +    });
    1.79 +  }, true);
    1.80 +
    1.81 +  gBrowser.loadURI("http://example.com/");
    1.82 +}
    1.83 +
    1.84 +function testCopy(originalValue, targetValue, cb) {
    1.85 +  waitForClipboard(targetValue, function () {
    1.86 +    is(gURLBar.value, originalValue, "url bar copy value set");
    1.87 +
    1.88 +    gURLBar.focus();
    1.89 +    gURLBar.select();
    1.90 +    goDoCommand("cmd_copy");
    1.91 +  }, cb, cb);
    1.92 +}

mercurial