OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/elide_url.h" | 5 #include "chrome/browser/ui/elide_url.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/font_list.h" | 9 #include "ui/gfx/font_list.h" |
10 #include "ui/gfx/text_elider.h" | 10 #include "ui/gfx/text_elider.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 | 197 |
198 // Trying to elide to a really short length will still keep the full TLD+1 | 198 // Trying to elide to a really short length will still keep the full TLD+1 |
199 EXPECT_EQ(base::ASCIIToUTF16("google.com"), | 199 EXPECT_EQ(base::ASCIIToUTF16("google.com"), |
200 ElideHost(GURL("http://google.com"), gfx::FontList(), 2)); | 200 ElideHost(GURL("http://google.com"), gfx::FontList(), 2)); |
201 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), | 201 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), |
202 ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2)); | 202 ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2)); |
203 EXPECT_EQ(base::ASCIIToUTF16("foo.bar"), | 203 EXPECT_EQ(base::ASCIIToUTF16("foo.bar"), |
204 ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); | 204 ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); |
205 } | 205 } |
206 | 206 |
207 struct OriginTestData { | |
208 const char* description; | |
209 const char* input; | |
210 const char* languages; | |
msw
2015/05/29 00:18:51
None of the test cases supply languages, can this
palmer
2015/05/29 17:52:13
Done.
| |
211 const bool omit_scheme; | |
212 const wchar_t* output; | |
213 }; | |
214 | |
215 TEST(TextEliderTest, FormatOriginForDisplay) { | |
216 const OriginTestData tests[] = { | |
217 {"Empty URL", "", "", false, L""}, | |
218 {"HTTP URL, no omit scheme", | |
219 "http://www.google.com/", | |
220 "", | |
221 false, | |
222 L"http://www.google.com"}, | |
223 {"HTTP URL, omit scheme", | |
224 "http://www.google.com/", | |
225 "", | |
226 true, | |
227 L"www.google.com"}, | |
228 {"HTTPS URL, no omit scheme", | |
229 "https://www.google.com/", | |
230 "", | |
231 false, | |
232 L"https://www.google.com"}, | |
233 {"HTTPS URL, omit scheme", | |
234 "https://www.google.com/", | |
235 "", | |
236 true, | |
237 L"www.google.com"}, | |
238 {"Standard HTTP port", | |
239 "http://www.google.com:80/", | |
240 "", | |
241 false, | |
242 L"http://www.google.com"}, | |
243 {"Standard HTTPS port", | |
244 "https://www.google.com:443/", | |
245 "", | |
246 false, | |
247 L"https://www.google.com"}, | |
248 {"Non-standard HTTP port", | |
249 "http://www.google.com:9000/", | |
250 "", | |
251 false, | |
252 L"http://www.google.com:9000"}, | |
253 {"Non-standard HTTPS port", | |
254 "https://www.google.com:9000/", | |
255 "", | |
256 false, | |
257 L"https://www.google.com:9000"}, | |
258 {"File URI, omit scheme", | |
259 "file:///usr/example/file.html", | |
260 "", | |
261 true, | |
262 L"/usr/example/file.html"}, | |
263 {"File URI, no omit scheme", | |
264 "file:///usr/example/file.html", | |
265 "", | |
266 false, | |
267 L"file:///usr/example/file.html"}, | |
268 {"File URI with hostname, omit scheme", | |
269 "file://localhost/usr/example/file.html", | |
270 "", | |
271 true, | |
272 L"/usr/example/file.html"}, | |
273 {"File URI with hostname, no omit scheme", | |
274 "file://localhost/usr/example/file.html", | |
275 "", | |
276 false, | |
277 L"file:///usr/example/file.html"}, | |
278 {"HTTP URL with path", | |
279 "http://www.google.com/test.html", | |
280 "", | |
281 false, | |
282 L"http://www.google.com"}, | |
283 {"HTTPS URL with path", | |
284 "https://www.google.com/test.html", | |
285 "", | |
286 false, | |
287 L"https://www.google.com"}, | |
288 {"Unusual secure scheme (wss)", | |
289 "wss://www.google.com/", | |
290 "", | |
291 false, | |
292 L"wss://www.google.com"}, | |
293 {"Unusual non-secure scheme (gopher)", | |
294 "gopher://www.google.com/", | |
295 "", | |
296 false, | |
297 L"gopher://www.google.com"}, | |
298 {"Unlisted scheme (chrome)", | |
299 "chrome://version", | |
300 "", | |
301 false, | |
302 L"chrome://version"}, | |
303 {"HTTP IP address", | |
304 "http://173.194.65.103", | |
305 "", | |
306 false, | |
307 L"http://173.194.65.103"}, | |
308 {"HTTPS IP address", | |
309 "https://173.194.65.103", | |
310 "", | |
311 false, | |
312 L"https://173.194.65.103"}, | |
313 {"HTTPS IP address, non-default port", | |
314 "https://173.194.65.103:8443", | |
315 "", | |
316 false, | |
317 L"https://173.194.65.103:8443"}, | |
318 {"HTTPS IP address, omit scheme", | |
319 "https://173.194.65.103", | |
320 "", | |
321 true, | |
322 L"173.194.65.103"}, | |
323 {"HTTP filesystem: URL with path", | |
324 "filesystem:http://www.google.com/temporary/test.html", | |
325 "", | |
326 false, | |
327 L"filesystem:http://www.google.com"}, | |
328 {"HTTP filesystem: URL with path, omit scheme", | |
329 "filesystem:http://www.google.com/persistent/test.html", | |
330 "", | |
331 true, | |
332 L"filesystem:www.google.com"}, | |
333 {"File filesystem: URL with path", | |
334 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", | |
335 "", | |
336 false, | |
337 L"filesystem:file:///temporary/stuff/test.html"}, | |
338 {"File filesystem: URL with path, omit scheme", | |
339 "filesystem:file://cyber.com/persistent/stuff/test.html?y=z#abc", | |
340 "", | |
341 true, | |
342 L"filesystem:/persistent/stuff/test.html"}, | |
343 {"Invalid scheme 1", | |
344 "twelve://www.cyber.org/wow.php", | |
345 "", | |
346 false, | |
347 L"twelve://www.cyber.org/wow.php"}, | |
348 {"Invalid scheme 2", | |
349 "://www.cyber.org/wow.php", | |
350 "", | |
351 false, | |
352 L"://www.cyber.org/wow.php"}, | |
353 {"Invalid host 1", | |
354 "https://www.cyber../wow.php", | |
355 "", | |
356 false, | |
357 L"https://www.cyber.."}, | |
358 {"Invalid host 2", | |
359 "https://www...cyber/wow.php", | |
360 "", | |
361 false, | |
362 L"https://www...cyber"}, | |
363 {"Invalid port 1", | |
364 "https://173.194.65.103:000", | |
365 "", | |
366 false, | |
367 L"https://173.194.65.103"}, | |
368 {"Invalid port 2", | |
369 "https://173.194.65.103:gruffle", | |
370 "", | |
371 false, | |
372 L"https://173.194.65.103:gruffle"}, | |
373 {"Invalid port 3", | |
374 "https://173.194.65.103:/hello.aspx", | |
375 "", | |
376 false, | |
377 L"https://173.194.65.103"}, | |
378 }; | |
379 for (size_t i = 0; i < arraysize(tests); ++i) { | |
380 base::string16 formatted = FormatOriginForDisplay( | |
381 GURL(tests[i].input), tests[i].languages, tests[i].omit_scheme); | |
382 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) | |
383 << tests[i].description; | |
384 } | |
385 | |
386 base::string16 formatted = FormatOriginForDisplay(GURL(), "", false); | |
387 EXPECT_EQ(base::string16(), formatted) | |
388 << "Explicitly test the 0-argument GURL constructor"; | |
389 } | |
390 | |
207 } // namespace | 391 } // namespace |
OLD | NEW |