browser/base/content/test/general/browser_urlbarCopying.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_urlbarCopying.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,204 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +const trimPref = "browser.urlbar.trimURLs";
     1.8 +const phishyUserPassPref = "network.http.phishy-userpass-length";
     1.9 +
    1.10 +function test() {
    1.11 +
    1.12 +  let tab = gBrowser.selectedTab = gBrowser.addTab();
    1.13 +
    1.14 +  registerCleanupFunction(function () {
    1.15 +    gBrowser.removeTab(tab);
    1.16 +    Services.prefs.clearUserPref(trimPref);
    1.17 +    Services.prefs.clearUserPref(phishyUserPassPref);
    1.18 +    URLBarSetURI();
    1.19 +  });
    1.20 +
    1.21 +  Services.prefs.setBoolPref(trimPref, true);
    1.22 +  Services.prefs.setIntPref(phishyUserPassPref, 32); // avoid prompting about phishing
    1.23 +
    1.24 +  waitForExplicitFinish();
    1.25 +
    1.26 +  nextTest();
    1.27 +}
    1.28 +
    1.29 +var tests = [
    1.30 +  // pageproxystate="invalid"
    1.31 +  {
    1.32 +    setURL: "http://example.com/",
    1.33 +    expectedURL: "example.com",
    1.34 +    copyExpected: "example.com"
    1.35 +  },
    1.36 +  {
    1.37 +    copyVal: "<e>xample.com",
    1.38 +    copyExpected: "e"
    1.39 +  },
    1.40 +
    1.41 +  // pageproxystate="valid" from this point on (due to the load)
    1.42 +  {
    1.43 +    loadURL: "http://example.com/",
    1.44 +    expectedURL: "example.com",
    1.45 +    copyExpected: "http://example.com/"
    1.46 +  },
    1.47 +  {
    1.48 +    copyVal: "<example.co>m",
    1.49 +    copyExpected: "example.co"
    1.50 +  },
    1.51 +  {
    1.52 +    copyVal: "e<x>ample.com",
    1.53 +    copyExpected: "x"
    1.54 +  },
    1.55 +  {
    1.56 +    copyVal: "<e>xample.com",
    1.57 +    copyExpected: "e"
    1.58 +  },
    1.59 +
    1.60 +  {
    1.61 +    loadURL: "http://example.com/foo",
    1.62 +    expectedURL: "example.com/foo",
    1.63 +    copyExpected: "http://example.com/foo"
    1.64 +  },
    1.65 +  {
    1.66 +    copyVal: "<example.com>/foo",
    1.67 +    copyExpected: "http://example.com"
    1.68 +  },
    1.69 +  {
    1.70 +    copyVal: "<example>.com/foo",
    1.71 +    copyExpected: "example"
    1.72 +  },
    1.73 +
    1.74 +  // Test that userPass is stripped out
    1.75 +  {
    1.76 +    loadURL: "http://user:pass@mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass",
    1.77 +    expectedURL: "mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass",
    1.78 +    copyExpected: "http://mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass"
    1.79 +  },
    1.80 +
    1.81 +  // Test escaping
    1.82 +  {
    1.83 +    loadURL: "http://example.com/()%C3%A9",
    1.84 +    expectedURL: "example.com/()\xe9",
    1.85 +    copyExpected: "http://example.com/%28%29%C3%A9"
    1.86 +  },
    1.87 +  {
    1.88 +    copyVal: "<example.com/(>)\xe9",
    1.89 +    copyExpected: "http://example.com/("
    1.90 +  },
    1.91 +  {
    1.92 +    copyVal: "e<xample.com/(>)\xe9",
    1.93 +    copyExpected: "xample.com/("
    1.94 +  },
    1.95 +
    1.96 +  {
    1.97 +    loadURL: "http://example.com/%C3%A9%C3%A9",
    1.98 +    expectedURL: "example.com/\xe9\xe9",
    1.99 +    copyExpected: "http://example.com/%C3%A9%C3%A9"
   1.100 +  },
   1.101 +  {
   1.102 +    copyVal: "e<xample.com/\xe9>\xe9",
   1.103 +    copyExpected: "xample.com/\xe9"
   1.104 +  },
   1.105 +  {
   1.106 +    copyVal: "<example.com/\xe9>\xe9",
   1.107 +    copyExpected: "http://example.com/\xe9"
   1.108 +  },
   1.109 +
   1.110 +  {
   1.111 +    loadURL: "http://example.com/?%C3%B7%C3%B7",
   1.112 +    expectedURL: "example.com/?\xf7\xf7",
   1.113 +    copyExpected: "http://example.com/?%C3%B7%C3%B7"
   1.114 +  },
   1.115 +  {
   1.116 +    copyVal: "e<xample.com/?\xf7>\xf7",
   1.117 +    copyExpected: "xample.com/?\xf7"
   1.118 +  },
   1.119 +  {
   1.120 +    copyVal: "<example.com/?\xf7>\xf7",
   1.121 +    copyExpected: "http://example.com/?\xf7"
   1.122 +  },
   1.123 +
   1.124 +  // data: and javsacript: URIs shouldn't be encoded
   1.125 +  {
   1.126 +    loadURL: "javascript:('%C3%A9')",
   1.127 +    expectedURL: "javascript:('\xe9')",
   1.128 +    copyExpected: "javascript:('\xe9')"
   1.129 +  },
   1.130 +  {
   1.131 +    copyVal: "<javascript:(>'\xe9')",
   1.132 +    copyExpected: "javascript:("
   1.133 +  },
   1.134 +
   1.135 +  {
   1.136 +    loadURL: "data:text/html,(%C3%A9)",
   1.137 +    expectedURL: "data:text/html,(\xe9)",
   1.138 +    copyExpected: "data:text/html,(\xe9)"
   1.139 +  },
   1.140 +  {
   1.141 +    copyVal: "<data:text/html,(>\xe9)",
   1.142 +    copyExpected: "data:text/html,("
   1.143 +  },
   1.144 +  {
   1.145 +    copyVal: "data:<text/html,(\xe9>)",
   1.146 +    copyExpected: "text/html,(\xe9"
   1.147 +  }
   1.148 +];
   1.149 +
   1.150 +function nextTest() {
   1.151 +  let test = tests.shift();
   1.152 +  if (tests.length == 0)
   1.153 +    runTest(test, finish);
   1.154 +  else
   1.155 +    runTest(test, nextTest);
   1.156 +}
   1.157 +
   1.158 +function runTest(test, cb) {
   1.159 +  function doCheck() {
   1.160 +    if (test.setURL || test.loadURL) {
   1.161 +      gURLBar.valueIsTyped = !!test.setURL;
   1.162 +      is(gURLBar.value, test.expectedURL, "url bar value set");
   1.163 +    }
   1.164 +
   1.165 +    testCopy(test.copyVal, test.copyExpected, cb);
   1.166 +  }
   1.167 +
   1.168 +  if (test.loadURL) {
   1.169 +    loadURL(test.loadURL, doCheck);
   1.170 +  } else {
   1.171 +    if (test.setURL)
   1.172 +      gURLBar.value = test.setURL;
   1.173 +    doCheck();
   1.174 +  }
   1.175 +}
   1.176 +
   1.177 +function testCopy(copyVal, targetValue, cb) {
   1.178 +  info("Expecting copy of: " + targetValue);
   1.179 +  waitForClipboard(targetValue, function () {
   1.180 +    gURLBar.focus();
   1.181 +    if (copyVal) {
   1.182 +      let startBracket = copyVal.indexOf("<");
   1.183 +      let endBracket = copyVal.indexOf(">");
   1.184 +      if (startBracket == -1 || endBracket == -1 ||
   1.185 +          startBracket > endBracket ||
   1.186 +          copyVal.replace("<", "").replace(">", "") != gURLBar.value) {
   1.187 +        ok(false, "invalid copyVal: " + copyVal);
   1.188 +      }
   1.189 +      gURLBar.selectionStart = startBracket;
   1.190 +      gURLBar.selectionEnd = endBracket - 1;
   1.191 +    } else {
   1.192 +      gURLBar.select();
   1.193 +    }
   1.194 +
   1.195 +    goDoCommand("cmd_copy");
   1.196 +  }, cb, cb);
   1.197 +}
   1.198 +
   1.199 +function loadURL(aURL, aCB) {
   1.200 +  gBrowser.selectedBrowser.addEventListener("load", function () {
   1.201 +    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
   1.202 +    is(gBrowser.currentURI.spec, aURL, "loaded expected URL");
   1.203 +    aCB();
   1.204 +  }, true);
   1.205 +
   1.206 +  gBrowser.loadURI(aURL);
   1.207 +}

mercurial