Wed, 31 Dec 2014 06:09:35 +0100
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 | const trimPref = "browser.urlbar.trimURLs"; |
michael@0 | 5 | const phishyUserPassPref = "network.http.phishy-userpass-length"; |
michael@0 | 6 | |
michael@0 | 7 | function test() { |
michael@0 | 8 | |
michael@0 | 9 | let tab = gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 10 | |
michael@0 | 11 | registerCleanupFunction(function () { |
michael@0 | 12 | gBrowser.removeTab(tab); |
michael@0 | 13 | Services.prefs.clearUserPref(trimPref); |
michael@0 | 14 | Services.prefs.clearUserPref(phishyUserPassPref); |
michael@0 | 15 | URLBarSetURI(); |
michael@0 | 16 | }); |
michael@0 | 17 | |
michael@0 | 18 | Services.prefs.setBoolPref(trimPref, true); |
michael@0 | 19 | Services.prefs.setIntPref(phishyUserPassPref, 32); // avoid prompting about phishing |
michael@0 | 20 | |
michael@0 | 21 | waitForExplicitFinish(); |
michael@0 | 22 | |
michael@0 | 23 | nextTest(); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | var tests = [ |
michael@0 | 27 | // pageproxystate="invalid" |
michael@0 | 28 | { |
michael@0 | 29 | setURL: "http://example.com/", |
michael@0 | 30 | expectedURL: "example.com", |
michael@0 | 31 | copyExpected: "example.com" |
michael@0 | 32 | }, |
michael@0 | 33 | { |
michael@0 | 34 | copyVal: "<e>xample.com", |
michael@0 | 35 | copyExpected: "e" |
michael@0 | 36 | }, |
michael@0 | 37 | |
michael@0 | 38 | // pageproxystate="valid" from this point on (due to the load) |
michael@0 | 39 | { |
michael@0 | 40 | loadURL: "http://example.com/", |
michael@0 | 41 | expectedURL: "example.com", |
michael@0 | 42 | copyExpected: "http://example.com/" |
michael@0 | 43 | }, |
michael@0 | 44 | { |
michael@0 | 45 | copyVal: "<example.co>m", |
michael@0 | 46 | copyExpected: "example.co" |
michael@0 | 47 | }, |
michael@0 | 48 | { |
michael@0 | 49 | copyVal: "e<x>ample.com", |
michael@0 | 50 | copyExpected: "x" |
michael@0 | 51 | }, |
michael@0 | 52 | { |
michael@0 | 53 | copyVal: "<e>xample.com", |
michael@0 | 54 | copyExpected: "e" |
michael@0 | 55 | }, |
michael@0 | 56 | |
michael@0 | 57 | { |
michael@0 | 58 | loadURL: "http://example.com/foo", |
michael@0 | 59 | expectedURL: "example.com/foo", |
michael@0 | 60 | copyExpected: "http://example.com/foo" |
michael@0 | 61 | }, |
michael@0 | 62 | { |
michael@0 | 63 | copyVal: "<example.com>/foo", |
michael@0 | 64 | copyExpected: "http://example.com" |
michael@0 | 65 | }, |
michael@0 | 66 | { |
michael@0 | 67 | copyVal: "<example>.com/foo", |
michael@0 | 68 | copyExpected: "example" |
michael@0 | 69 | }, |
michael@0 | 70 | |
michael@0 | 71 | // Test that userPass is stripped out |
michael@0 | 72 | { |
michael@0 | 73 | loadURL: "http://user:pass@mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass", |
michael@0 | 74 | expectedURL: "mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass", |
michael@0 | 75 | copyExpected: "http://mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass" |
michael@0 | 76 | }, |
michael@0 | 77 | |
michael@0 | 78 | // Test escaping |
michael@0 | 79 | { |
michael@0 | 80 | loadURL: "http://example.com/()%C3%A9", |
michael@0 | 81 | expectedURL: "example.com/()\xe9", |
michael@0 | 82 | copyExpected: "http://example.com/%28%29%C3%A9" |
michael@0 | 83 | }, |
michael@0 | 84 | { |
michael@0 | 85 | copyVal: "<example.com/(>)\xe9", |
michael@0 | 86 | copyExpected: "http://example.com/(" |
michael@0 | 87 | }, |
michael@0 | 88 | { |
michael@0 | 89 | copyVal: "e<xample.com/(>)\xe9", |
michael@0 | 90 | copyExpected: "xample.com/(" |
michael@0 | 91 | }, |
michael@0 | 92 | |
michael@0 | 93 | { |
michael@0 | 94 | loadURL: "http://example.com/%C3%A9%C3%A9", |
michael@0 | 95 | expectedURL: "example.com/\xe9\xe9", |
michael@0 | 96 | copyExpected: "http://example.com/%C3%A9%C3%A9" |
michael@0 | 97 | }, |
michael@0 | 98 | { |
michael@0 | 99 | copyVal: "e<xample.com/\xe9>\xe9", |
michael@0 | 100 | copyExpected: "xample.com/\xe9" |
michael@0 | 101 | }, |
michael@0 | 102 | { |
michael@0 | 103 | copyVal: "<example.com/\xe9>\xe9", |
michael@0 | 104 | copyExpected: "http://example.com/\xe9" |
michael@0 | 105 | }, |
michael@0 | 106 | |
michael@0 | 107 | { |
michael@0 | 108 | loadURL: "http://example.com/?%C3%B7%C3%B7", |
michael@0 | 109 | expectedURL: "example.com/?\xf7\xf7", |
michael@0 | 110 | copyExpected: "http://example.com/?%C3%B7%C3%B7" |
michael@0 | 111 | }, |
michael@0 | 112 | { |
michael@0 | 113 | copyVal: "e<xample.com/?\xf7>\xf7", |
michael@0 | 114 | copyExpected: "xample.com/?\xf7" |
michael@0 | 115 | }, |
michael@0 | 116 | { |
michael@0 | 117 | copyVal: "<example.com/?\xf7>\xf7", |
michael@0 | 118 | copyExpected: "http://example.com/?\xf7" |
michael@0 | 119 | }, |
michael@0 | 120 | |
michael@0 | 121 | // data: and javsacript: URIs shouldn't be encoded |
michael@0 | 122 | { |
michael@0 | 123 | loadURL: "javascript:('%C3%A9')", |
michael@0 | 124 | expectedURL: "javascript:('\xe9')", |
michael@0 | 125 | copyExpected: "javascript:('\xe9')" |
michael@0 | 126 | }, |
michael@0 | 127 | { |
michael@0 | 128 | copyVal: "<javascript:(>'\xe9')", |
michael@0 | 129 | copyExpected: "javascript:(" |
michael@0 | 130 | }, |
michael@0 | 131 | |
michael@0 | 132 | { |
michael@0 | 133 | loadURL: "data:text/html,(%C3%A9)", |
michael@0 | 134 | expectedURL: "data:text/html,(\xe9)", |
michael@0 | 135 | copyExpected: "data:text/html,(\xe9)" |
michael@0 | 136 | }, |
michael@0 | 137 | { |
michael@0 | 138 | copyVal: "<data:text/html,(>\xe9)", |
michael@0 | 139 | copyExpected: "data:text/html,(" |
michael@0 | 140 | }, |
michael@0 | 141 | { |
michael@0 | 142 | copyVal: "data:<text/html,(\xe9>)", |
michael@0 | 143 | copyExpected: "text/html,(\xe9" |
michael@0 | 144 | } |
michael@0 | 145 | ]; |
michael@0 | 146 | |
michael@0 | 147 | function nextTest() { |
michael@0 | 148 | let test = tests.shift(); |
michael@0 | 149 | if (tests.length == 0) |
michael@0 | 150 | runTest(test, finish); |
michael@0 | 151 | else |
michael@0 | 152 | runTest(test, nextTest); |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | function runTest(test, cb) { |
michael@0 | 156 | function doCheck() { |
michael@0 | 157 | if (test.setURL || test.loadURL) { |
michael@0 | 158 | gURLBar.valueIsTyped = !!test.setURL; |
michael@0 | 159 | is(gURLBar.value, test.expectedURL, "url bar value set"); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | testCopy(test.copyVal, test.copyExpected, cb); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | if (test.loadURL) { |
michael@0 | 166 | loadURL(test.loadURL, doCheck); |
michael@0 | 167 | } else { |
michael@0 | 168 | if (test.setURL) |
michael@0 | 169 | gURLBar.value = test.setURL; |
michael@0 | 170 | doCheck(); |
michael@0 | 171 | } |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | function testCopy(copyVal, targetValue, cb) { |
michael@0 | 175 | info("Expecting copy of: " + targetValue); |
michael@0 | 176 | waitForClipboard(targetValue, function () { |
michael@0 | 177 | gURLBar.focus(); |
michael@0 | 178 | if (copyVal) { |
michael@0 | 179 | let startBracket = copyVal.indexOf("<"); |
michael@0 | 180 | let endBracket = copyVal.indexOf(">"); |
michael@0 | 181 | if (startBracket == -1 || endBracket == -1 || |
michael@0 | 182 | startBracket > endBracket || |
michael@0 | 183 | copyVal.replace("<", "").replace(">", "") != gURLBar.value) { |
michael@0 | 184 | ok(false, "invalid copyVal: " + copyVal); |
michael@0 | 185 | } |
michael@0 | 186 | gURLBar.selectionStart = startBracket; |
michael@0 | 187 | gURLBar.selectionEnd = endBracket - 1; |
michael@0 | 188 | } else { |
michael@0 | 189 | gURLBar.select(); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | goDoCommand("cmd_copy"); |
michael@0 | 193 | }, cb, cb); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | function loadURL(aURL, aCB) { |
michael@0 | 197 | gBrowser.selectedBrowser.addEventListener("load", function () { |
michael@0 | 198 | gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 199 | is(gBrowser.currentURI.spec, aURL, "loaded expected URL"); |
michael@0 | 200 | aCB(); |
michael@0 | 201 | }, true); |
michael@0 | 202 | |
michael@0 | 203 | gBrowser.loadURI(aURL); |
michael@0 | 204 | } |