michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const trimPref = "browser.urlbar.trimURLs"; michael@0: const phishyUserPassPref = "network.http.phishy-userpass-length"; michael@0: michael@0: function test() { michael@0: michael@0: let tab = gBrowser.selectedTab = gBrowser.addTab(); michael@0: michael@0: registerCleanupFunction(function () { michael@0: gBrowser.removeTab(tab); michael@0: Services.prefs.clearUserPref(trimPref); michael@0: Services.prefs.clearUserPref(phishyUserPassPref); michael@0: URLBarSetURI(); michael@0: }); michael@0: michael@0: Services.prefs.setBoolPref(trimPref, true); michael@0: Services.prefs.setIntPref(phishyUserPassPref, 32); // avoid prompting about phishing michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: nextTest(); michael@0: } michael@0: michael@0: var tests = [ michael@0: // pageproxystate="invalid" michael@0: { michael@0: setURL: "http://example.com/", michael@0: expectedURL: "example.com", michael@0: copyExpected: "example.com" michael@0: }, michael@0: { michael@0: copyVal: "xample.com", michael@0: copyExpected: "e" michael@0: }, michael@0: michael@0: // pageproxystate="valid" from this point on (due to the load) michael@0: { michael@0: loadURL: "http://example.com/", michael@0: expectedURL: "example.com", michael@0: copyExpected: "http://example.com/" michael@0: }, michael@0: { michael@0: copyVal: "m", michael@0: copyExpected: "example.co" michael@0: }, michael@0: { michael@0: copyVal: "eample.com", michael@0: copyExpected: "x" michael@0: }, michael@0: { michael@0: copyVal: "xample.com", michael@0: copyExpected: "e" michael@0: }, michael@0: michael@0: { michael@0: loadURL: "http://example.com/foo", michael@0: expectedURL: "example.com/foo", michael@0: copyExpected: "http://example.com/foo" michael@0: }, michael@0: { michael@0: copyVal: "/foo", michael@0: copyExpected: "http://example.com" michael@0: }, michael@0: { michael@0: copyVal: ".com/foo", michael@0: copyExpected: "example" michael@0: }, michael@0: michael@0: // Test that userPass is stripped out michael@0: { michael@0: loadURL: "http://user:pass@mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass", michael@0: expectedURL: "mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass", michael@0: copyExpected: "http://mochi.test:8888/browser/browser/base/content/test/general/authenticate.sjs?user=user&pass=pass" michael@0: }, michael@0: michael@0: // Test escaping michael@0: { michael@0: loadURL: "http://example.com/()%C3%A9", michael@0: expectedURL: "example.com/()\xe9", michael@0: copyExpected: "http://example.com/%28%29%C3%A9" michael@0: }, michael@0: { michael@0: copyVal: ")\xe9", michael@0: copyExpected: "http://example.com/(" michael@0: }, michael@0: { michael@0: copyVal: "e)\xe9", michael@0: copyExpected: "xample.com/(" michael@0: }, michael@0: michael@0: { michael@0: loadURL: "http://example.com/%C3%A9%C3%A9", michael@0: expectedURL: "example.com/\xe9\xe9", michael@0: copyExpected: "http://example.com/%C3%A9%C3%A9" michael@0: }, michael@0: { michael@0: copyVal: "e\xe9", michael@0: copyExpected: "xample.com/\xe9" michael@0: }, michael@0: { michael@0: copyVal: "\xe9", michael@0: copyExpected: "http://example.com/\xe9" michael@0: }, michael@0: michael@0: { michael@0: loadURL: "http://example.com/?%C3%B7%C3%B7", michael@0: expectedURL: "example.com/?\xf7\xf7", michael@0: copyExpected: "http://example.com/?%C3%B7%C3%B7" michael@0: }, michael@0: { michael@0: copyVal: "e\xf7", michael@0: copyExpected: "xample.com/?\xf7" michael@0: }, michael@0: { michael@0: copyVal: "\xf7", michael@0: copyExpected: "http://example.com/?\xf7" michael@0: }, michael@0: michael@0: // data: and javsacript: URIs shouldn't be encoded michael@0: { michael@0: loadURL: "javascript:('%C3%A9')", michael@0: expectedURL: "javascript:('\xe9')", michael@0: copyExpected: "javascript:('\xe9')" michael@0: }, michael@0: { michael@0: copyVal: "'\xe9')", michael@0: copyExpected: "javascript:(" michael@0: }, michael@0: michael@0: { michael@0: loadURL: "data:text/html,(%C3%A9)", michael@0: expectedURL: "data:text/html,(\xe9)", michael@0: copyExpected: "data:text/html,(\xe9)" michael@0: }, michael@0: { michael@0: copyVal: "\xe9)", michael@0: copyExpected: "data:text/html,(" michael@0: }, michael@0: { michael@0: copyVal: "data:)", michael@0: copyExpected: "text/html,(\xe9" michael@0: } michael@0: ]; michael@0: michael@0: function nextTest() { michael@0: let test = tests.shift(); michael@0: if (tests.length == 0) michael@0: runTest(test, finish); michael@0: else michael@0: runTest(test, nextTest); michael@0: } michael@0: michael@0: function runTest(test, cb) { michael@0: function doCheck() { michael@0: if (test.setURL || test.loadURL) { michael@0: gURLBar.valueIsTyped = !!test.setURL; michael@0: is(gURLBar.value, test.expectedURL, "url bar value set"); michael@0: } michael@0: michael@0: testCopy(test.copyVal, test.copyExpected, cb); michael@0: } michael@0: michael@0: if (test.loadURL) { michael@0: loadURL(test.loadURL, doCheck); michael@0: } else { michael@0: if (test.setURL) michael@0: gURLBar.value = test.setURL; michael@0: doCheck(); michael@0: } michael@0: } michael@0: michael@0: function testCopy(copyVal, targetValue, cb) { michael@0: info("Expecting copy of: " + targetValue); michael@0: waitForClipboard(targetValue, function () { michael@0: gURLBar.focus(); michael@0: if (copyVal) { michael@0: let startBracket = copyVal.indexOf("<"); michael@0: let endBracket = copyVal.indexOf(">"); michael@0: if (startBracket == -1 || endBracket == -1 || michael@0: startBracket > endBracket || michael@0: copyVal.replace("<", "").replace(">", "") != gURLBar.value) { michael@0: ok(false, "invalid copyVal: " + copyVal); michael@0: } michael@0: gURLBar.selectionStart = startBracket; michael@0: gURLBar.selectionEnd = endBracket - 1; michael@0: } else { michael@0: gURLBar.select(); michael@0: } michael@0: michael@0: goDoCommand("cmd_copy"); michael@0: }, cb, cb); michael@0: } michael@0: michael@0: function loadURL(aURL, aCB) { michael@0: gBrowser.selectedBrowser.addEventListener("load", function () { michael@0: gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); michael@0: is(gBrowser.currentURI.spec, aURL, "loaded expected URL"); michael@0: aCB(); michael@0: }, true); michael@0: michael@0: gBrowser.loadURI(aURL); michael@0: }