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 | |
michael@0 | 5 | function testVal(aExpected) { |
michael@0 | 6 | gURLBar.value = aExpected.replace(/[<>]/g, ""); |
michael@0 | 7 | |
michael@0 | 8 | let selectionController = gURLBar.editor.selectionController; |
michael@0 | 9 | let selection = selectionController.getSelection(selectionController.SELECTION_URLSECONDARY); |
michael@0 | 10 | let value = gURLBar.editor.rootElement.textContent; |
michael@0 | 11 | let result = ""; |
michael@0 | 12 | for (let i = 0; i < selection.rangeCount; i++) { |
michael@0 | 13 | let range = selection.getRangeAt(i).toString(); |
michael@0 | 14 | let pos = value.indexOf(range); |
michael@0 | 15 | result += value.substring(0, pos) + "<" + range + ">"; |
michael@0 | 16 | value = value.substring(pos + range.length); |
michael@0 | 17 | } |
michael@0 | 18 | result += value; |
michael@0 | 19 | is(result, aExpected); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function test() { |
michael@0 | 23 | const prefname = "browser.urlbar.formatting.enabled"; |
michael@0 | 24 | |
michael@0 | 25 | registerCleanupFunction(function () { |
michael@0 | 26 | Services.prefs.clearUserPref(prefname); |
michael@0 | 27 | URLBarSetURI(); |
michael@0 | 28 | }); |
michael@0 | 29 | |
michael@0 | 30 | Services.prefs.setBoolPref(prefname, true); |
michael@0 | 31 | |
michael@0 | 32 | gURLBar.focus(); |
michael@0 | 33 | |
michael@0 | 34 | testVal("https://mozilla.org"); |
michael@0 | 35 | |
michael@0 | 36 | gBrowser.selectedBrowser.focus(); |
michael@0 | 37 | |
michael@0 | 38 | testVal("<https://>mozilla.org"); |
michael@0 | 39 | testVal("<https://>mözilla.org"); |
michael@0 | 40 | testVal("<https://>mozilla.imaginatory"); |
michael@0 | 41 | |
michael@0 | 42 | testVal("<https://www.>mozilla.org"); |
michael@0 | 43 | testVal("<https://sub.>mozilla.org"); |
michael@0 | 44 | testVal("<https://sub1.sub2.sub3.>mozilla.org"); |
michael@0 | 45 | testVal("<www.>mozilla.org"); |
michael@0 | 46 | testVal("<sub.>mozilla.org"); |
michael@0 | 47 | testVal("<sub1.sub2.sub3.>mozilla.org"); |
michael@0 | 48 | |
michael@0 | 49 | testVal("<http://ftp.>mozilla.org"); |
michael@0 | 50 | testVal("<ftp://ftp.>mozilla.org"); |
michael@0 | 51 | |
michael@0 | 52 | testVal("<https://sub.>mozilla.org"); |
michael@0 | 53 | testVal("<https://sub1.sub2.sub3.>mozilla.org"); |
michael@0 | 54 | testVal("<https://user:pass@sub1.sub2.sub3.>mozilla.org"); |
michael@0 | 55 | testVal("<https://user:pass@>mozilla.org"); |
michael@0 | 56 | |
michael@0 | 57 | testVal("<https://>mozilla.org</file.ext>"); |
michael@0 | 58 | testVal("<https://>mozilla.org</sub/file.ext>"); |
michael@0 | 59 | testVal("<https://>mozilla.org</sub/file.ext?foo>"); |
michael@0 | 60 | testVal("<https://>mozilla.org</sub/file.ext?foo&bar>"); |
michael@0 | 61 | testVal("<https://>mozilla.org</sub/file.ext?foo&bar#top>"); |
michael@0 | 62 | testVal("<https://>mozilla.org</sub/file.ext?foo&bar#top>"); |
michael@0 | 63 | |
michael@0 | 64 | testVal("<https://sub.>mozilla.org<:666/file.ext>"); |
michael@0 | 65 | testVal("<sub.>mozilla.org<:666/file.ext>"); |
michael@0 | 66 | testVal("localhost<:666/file.ext>"); |
michael@0 | 67 | |
michael@0 | 68 | let IPs = ["192.168.1.1", |
michael@0 | 69 | "[::]", |
michael@0 | 70 | "[::1]", |
michael@0 | 71 | "[1::]", |
michael@0 | 72 | "[::]", |
michael@0 | 73 | "[::1]", |
michael@0 | 74 | "[1::]", |
michael@0 | 75 | "[1:2:3:4:5:6:7::]", |
michael@0 | 76 | "[::1:2:3:4:5:6:7]", |
michael@0 | 77 | "[1:2:a:B:c:D:e:F]", |
michael@0 | 78 | "[1::8]", |
michael@0 | 79 | "[1:2::8]", |
michael@0 | 80 | "[fe80::222:19ff:fe11:8c76]", |
michael@0 | 81 | "[0000:0123:4567:89AB:CDEF:abcd:ef00:0000]", |
michael@0 | 82 | "[::192.168.1.1]", |
michael@0 | 83 | "[1::0.0.0.0]", |
michael@0 | 84 | "[1:2::255.255.255.255]", |
michael@0 | 85 | "[1:2:3::255.255.255.255]", |
michael@0 | 86 | "[1:2:3:4::255.255.255.255]", |
michael@0 | 87 | "[1:2:3:4:5::255.255.255.255]", |
michael@0 | 88 | "[1:2:3:4:5:6:255.255.255.255]"]; |
michael@0 | 89 | IPs.forEach(function (IP) { |
michael@0 | 90 | testVal(IP); |
michael@0 | 91 | testVal(IP + "</file.ext>"); |
michael@0 | 92 | testVal(IP + "<:666/file.ext>"); |
michael@0 | 93 | testVal("<https://>" + IP); |
michael@0 | 94 | testVal("<https://>" + IP + "</file.ext>"); |
michael@0 | 95 | testVal("<https://user:pass@>" + IP + "<:666/file.ext>"); |
michael@0 | 96 | testVal("<http://user:pass@>" + IP + "<:666/file.ext>"); |
michael@0 | 97 | }); |
michael@0 | 98 | |
michael@0 | 99 | testVal("mailto:admin@mozilla.org"); |
michael@0 | 100 | testVal("gopher://mozilla.org/"); |
michael@0 | 101 | testVal("about:config"); |
michael@0 | 102 | testVal("jar:http://mozilla.org/example.jar!/"); |
michael@0 | 103 | testVal("view-source:http://mozilla.org/"); |
michael@0 | 104 | testVal("foo9://mozilla.org/"); |
michael@0 | 105 | testVal("foo+://mozilla.org/"); |
michael@0 | 106 | testVal("foo.://mozilla.org/"); |
michael@0 | 107 | testVal("foo-://mozilla.org/"); |
michael@0 | 108 | |
michael@0 | 109 | Services.prefs.setBoolPref(prefname, false); |
michael@0 | 110 | |
michael@0 | 111 | testVal("https://mozilla.org"); |
michael@0 | 112 | } |