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