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