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 "components/secure_display/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" |
11 #include "ui/gfx/text_utils.h" | 11 #include "ui/gfx/text_utils.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 using base::UTF8ToUTF16; | 14 using base::UTF8ToUTF16; |
15 using gfx::GetStringWidthF; | 15 using gfx::GetStringWidthF; |
16 using gfx::kEllipsis; | 16 using gfx::kEllipsis; |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 struct Testcase { | 20 struct Testcase { |
21 const std::string input; | 21 const std::string input; |
22 const std::string output; | 22 const std::string output; |
23 }; | 23 }; |
24 | 24 |
| 25 #if !defined(OS_ANDROID) |
25 void RunUrlTest(Testcase* testcases, size_t num_testcases) { | 26 void RunUrlTest(Testcase* testcases, size_t num_testcases) { |
26 static const gfx::FontList font_list; | 27 static const gfx::FontList font_list; |
27 for (size_t i = 0; i < num_testcases; ++i) { | 28 for (size_t i = 0; i < num_testcases; ++i) { |
28 const GURL url(testcases[i].input); | 29 const GURL url(testcases[i].input); |
29 // Should we test with non-empty language list? | 30 // Should we test with non-empty language list? |
30 // That's kinda redundant with net_util_unittests. | 31 // That's kinda redundant with net_util_unittests. |
31 const float available_width = | 32 const float available_width = |
32 GetStringWidthF(UTF8ToUTF16(testcases[i].output), font_list); | 33 GetStringWidthF(UTF8ToUTF16(testcases[i].output), font_list); |
33 EXPECT_EQ(UTF8ToUTF16(testcases[i].output), | 34 EXPECT_EQ(UTF8ToUTF16(testcases[i].output), |
34 ElideUrl(url, font_list, available_width, std::string())); | 35 secure_display::ElideUrl(url, font_list, available_width, |
| 36 std::string())); |
35 } | 37 } |
36 } | 38 } |
37 | 39 |
38 // Test eliding of commonplace URLs. | 40 // Test eliding of commonplace URLs. |
39 TEST(TextEliderTest, TestGeneralEliding) { | 41 TEST(TextEliderTest, TestGeneralEliding) { |
40 const std::string kEllipsisStr(kEllipsis); | 42 const std::string kEllipsisStr(kEllipsis); |
41 Testcase testcases[] = { | 43 Testcase testcases[] = { |
42 {"http://www.google.com/intl/en/ads/", | 44 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, |
43 "www.google.com/intl/en/ads/"}, | 45 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, |
44 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"}, | 46 {"http://www.google.com/intl/en/ads/", |
45 {"http://www.google.com/intl/en/ads/", | 47 "google.com/intl/" + kEllipsisStr + "/ads/"}, |
46 "google.com/intl/" + kEllipsisStr + "/ads/"}, | 48 {"http://www.google.com/intl/en/ads/", |
47 {"http://www.google.com/intl/en/ads/", | 49 "google.com/" + kEllipsisStr + "/ads/"}, |
48 "google.com/" + kEllipsisStr + "/ads/"}, | 50 {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr}, |
49 {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr}, | 51 {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr}, |
50 {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr}, | 52 {"https://subdomain.foo.com/bar/filename.html", |
51 {"https://subdomain.foo.com/bar/filename.html", | 53 "subdomain.foo.com/bar/filename.html"}, |
52 "subdomain.foo.com/bar/filename.html"}, | 54 {"https://subdomain.foo.com/bar/filename.html", |
53 {"https://subdomain.foo.com/bar/filename.html", | 55 "subdomain.foo.com/" + kEllipsisStr + "/filename.html"}, |
54 "subdomain.foo.com/" + kEllipsisStr + "/filename.html"}, | 56 {"http://subdomain.foo.com/bar/filename.html", |
55 {"http://subdomain.foo.com/bar/filename.html", | 57 kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"}, |
56 kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"}, | 58 {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired", |
57 {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired", | 59 "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr}, |
58 "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr}, | |
59 }; | 60 }; |
60 | 61 |
61 RunUrlTest(testcases, arraysize(testcases)); | 62 RunUrlTest(testcases, arraysize(testcases)); |
62 } | 63 } |
63 | 64 |
64 // When there is very little space available, the elision code will shorten | 65 // When there is very little space available, the elision code will shorten |
65 // both path AND file name to an ellipsis - ".../...". To avoid this result, | 66 // both path AND file name to an ellipsis - ".../...". To avoid this result, |
66 // there is a hack in place that simply treats them as one string in this | 67 // there is a hack in place that simply treats them as one string in this |
67 // case. | 68 // case. |
68 TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) { | 69 TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) { |
69 const std::string kEllipsisStr(kEllipsis); | 70 const std::string kEllipsisStr(kEllipsis); |
70 | 71 |
71 // Very little space, would cause double ellipsis. | 72 // Very little space, would cause double ellipsis. |
72 gfx::FontList font_list; | 73 gfx::FontList font_list; |
73 GURL url("http://battersbox.com/directory/foo/peter_paul_and_mary.html"); | 74 GURL url("http://battersbox.com/directory/foo/peter_paul_and_mary.html"); |
74 float available_width = GetStringWidthF( | 75 float available_width = GetStringWidthF( |
75 UTF8ToUTF16("battersbox.com/" + kEllipsisStr + "/" + kEllipsisStr), | 76 UTF8ToUTF16("battersbox.com/" + kEllipsisStr + "/" + kEllipsisStr), |
76 font_list); | 77 font_list); |
77 | 78 |
78 // Create the expected string, after elision. Depending on font size, the | 79 // Create the expected string, after elision. Depending on font size, the |
79 // directory might become /dir... or /di... or/d... - it never should be | 80 // directory might become /dir... or /di... or/d... - it never should be |
80 // shorter than that. (If it is, the font considers d... to be longer | 81 // shorter than that. (If it is, the font considers d... to be longer |
81 // than .../... - that should never happen). | 82 // than .../... - that should never happen). |
82 ASSERT_GT(GetStringWidthF(UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr), | 83 ASSERT_GT(GetStringWidthF(UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr), |
83 font_list), | 84 font_list), |
84 GetStringWidthF(UTF8ToUTF16("d" + kEllipsisStr), font_list)); | 85 GetStringWidthF(UTF8ToUTF16("d" + kEllipsisStr), font_list)); |
85 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc"); | 86 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc"); |
86 base::string16 expected = | 87 base::string16 expected = secure_display::ElideUrl( |
87 ElideUrl(long_url, font_list, available_width, std::string()); | 88 long_url, font_list, available_width, std::string()); |
88 // Ensure that the expected result still contains part of the directory name. | 89 // Ensure that the expected result still contains part of the directory name. |
89 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length()); | 90 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length()); |
90 EXPECT_EQ(expected, | 91 EXPECT_EQ(expected, secure_display::ElideUrl(url, font_list, available_width, |
91 ElideUrl(url, font_list, available_width, std::string())); | 92 std::string())); |
92 | 93 |
93 // More space available - elide directories, partially elide filename. | 94 // More space available - elide directories, partially elide filename. |
94 Testcase testcases[] = { | 95 Testcase testcases[] = { |
95 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html", | 96 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html", |
96 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr}, | 97 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr}, |
97 }; | 98 }; |
98 RunUrlTest(testcases, arraysize(testcases)); | 99 RunUrlTest(testcases, arraysize(testcases)); |
99 } | 100 } |
100 | 101 |
101 // Test eliding of empty strings, URLs with ports, passwords, queries, etc. | 102 // Test eliding of empty strings, URLs with ports, passwords, queries, etc. |
102 TEST(TextEliderTest, TestMoreEliding) { | 103 TEST(TextEliderTest, TestMoreEliding) { |
103 const std::string kEllipsisStr(kEllipsis); | 104 const std::string kEllipsisStr(kEllipsis); |
104 Testcase testcases[] = { | 105 Testcase testcases[] = { |
105 {"http://www.google.com/foo?bar", "www.google.com/foo?bar"}, | 106 {"http://www.google.com/foo?bar", "www.google.com/foo?bar"}, |
106 {"http://xyz.google.com/foo?bar", "xyz.google.com/foo?" + kEllipsisStr}, | 107 {"http://xyz.google.com/foo?bar", "xyz.google.com/foo?" + kEllipsisStr}, |
107 {"http://xyz.google.com/foo?bar", "xyz.google.com/foo" + kEllipsisStr}, | 108 {"http://xyz.google.com/foo?bar", "xyz.google.com/foo" + kEllipsisStr}, |
108 {"http://xyz.google.com/foo?bar", "xyz.google.com/fo" + kEllipsisStr}, | 109 {"http://xyz.google.com/foo?bar", "xyz.google.com/fo" + kEllipsisStr}, |
109 {"http://a.b.com/pathname/c?d", "a.b.com/" + kEllipsisStr + "/c?d"}, | 110 {"http://a.b.com/pathname/c?d", "a.b.com/" + kEllipsisStr + "/c?d"}, |
110 {"", ""}, | 111 {"", ""}, |
111 {"http://foo.bar..example.com...hello/test/filename.html", | 112 {"http://foo.bar..example.com...hello/test/filename.html", |
112 "foo.bar..example.com...hello/" + kEllipsisStr + "/filename.html"}, | 113 "foo.bar..example.com...hello/" + kEllipsisStr + "/filename.html"}, |
113 {"http://foo.bar../", "foo.bar.."}, | 114 {"http://foo.bar../", "foo.bar.."}, |
114 {"http://xn--1lq90i.cn/foo", "\xe5\x8c\x97\xe4\xba\xac.cn/foo"}, | 115 {"http://xn--1lq90i.cn/foo", "\xe5\x8c\x97\xe4\xba\xac.cn/foo"}, |
115 {"http://me:mypass@secrethost.com:99/foo?bar#baz", | 116 {"http://me:mypass@secrethost.com:99/foo?bar#baz", |
116 "secrethost.com:99/foo?bar#baz"}, | 117 "secrethost.com:99/foo?bar#baz"}, |
117 {"http://me:mypass@ss%xxfdsf.com/foo", "ss%25xxfdsf.com/foo"}, | 118 {"http://me:mypass@ss%xxfdsf.com/foo", "ss%25xxfdsf.com/foo"}, |
118 {"mailto:elgoato@elgoato.com", "mailto:elgoato@elgoato.com"}, | 119 {"mailto:elgoato@elgoato.com", "mailto:elgoato@elgoato.com"}, |
119 {"javascript:click(0)", "javascript:click(0)"}, | 120 {"javascript:click(0)", "javascript:click(0)"}, |
120 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", | 121 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", |
121 "chess.eecs.berkeley.edu:4430/login/arbitfilename"}, | 122 "chess.eecs.berkeley.edu:4430/login/arbitfilename"}, |
122 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", | 123 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename", |
123 kEllipsisStr + "berkeley.edu:4430/" + kEllipsisStr + "/arbitfilename"}, | 124 kEllipsisStr + "berkeley.edu:4430/" + kEllipsisStr + "/arbitfilename"}, |
124 | 125 |
125 // Unescaping. | 126 // Unescaping. |
126 {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", | 127 {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", |
127 "www/\xe4\xbd\xa0\xe5\xa5\xbd?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"}, | 128 "www/\xe4\xbd\xa0\xe5\xa5\xbd?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"}, |
128 | 129 |
129 // Invalid unescaping for path. The ref will always be valid UTF-8. We don't | 130 // Invalid unescaping for path. The ref will always be valid UTF-8. We |
130 // bother to do too many edge cases, since these are handled by the escaper | 131 // don't |
131 // unittest. | 132 // bother to do too many edge cases, since these are handled by the |
132 {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", | 133 // escaper |
133 "www/%E4%A0%E5%A5%BD?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"}, | 134 // unittest. |
| 135 {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0", |
| 136 "www/%E4%A0%E5%A5%BD?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"}, |
134 }; | 137 }; |
135 | 138 |
136 RunUrlTest(testcases, arraysize(testcases)); | 139 RunUrlTest(testcases, arraysize(testcases)); |
137 } | 140 } |
138 | 141 |
139 // Test eliding of file: URLs. | 142 // Test eliding of file: URLs. |
140 TEST(TextEliderTest, TestFileURLEliding) { | 143 TEST(TextEliderTest, TestFileURLEliding) { |
141 const std::string kEllipsisStr(kEllipsis); | 144 const std::string kEllipsisStr(kEllipsis); |
142 Testcase testcases[] = { | 145 Testcase testcases[] = { |
143 {"file:///C:/path1/path2/path3/filename", | 146 {"file:///C:/path1/path2/path3/filename", |
144 "file:///C:/path1/path2/path3/filename"}, | 147 "file:///C:/path1/path2/path3/filename"}, |
145 {"file:///C:/path1/path2/path3/filename", | 148 {"file:///C:/path1/path2/path3/filename", "C:/path1/path2/path3/filename"}, |
146 "C:/path1/path2/path3/filename"}, | |
147 // GURL parses "file:///C:path" differently on windows than it does on posix. | 149 // GURL parses "file:///C:path" differently on windows than it does on posix. |
148 #if defined(OS_WIN) | 150 #if defined(OS_WIN) |
149 {"file:///C:path1/path2/path3/filename", | 151 {"file:///C:path1/path2/path3/filename", |
150 "C:/path1/path2/" + kEllipsisStr + "/filename"}, | 152 "C:/path1/path2/" + kEllipsisStr + "/filename"}, |
151 {"file:///C:path1/path2/path3/filename", | 153 {"file:///C:path1/path2/path3/filename", |
152 "C:/path1/" + kEllipsisStr + "/filename"}, | 154 "C:/path1/" + kEllipsisStr + "/filename"}, |
153 {"file:///C:path1/path2/path3/filename", | 155 {"file:///C:path1/path2/path3/filename", |
154 "C:/" + kEllipsisStr + "/filename"}, | 156 "C:/" + kEllipsisStr + "/filename"}, |
155 #endif | 157 #endif // defined(OS_WIN) |
156 {"file://filer/foo/bar/file", "filer/foo/bar/file"}, | 158 {"file://filer/foo/bar/file", "filer/foo/bar/file"}, |
157 {"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"}, | 159 {"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"}, |
158 {"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"}, | 160 {"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"}, |
159 {"file://filer/foo/", "file://filer/foo/"}, | 161 {"file://filer/foo/", "file://filer/foo/"}, |
160 {"file://filer/foo/", "filer/foo/"}, | 162 {"file://filer/foo/", "filer/foo/"}, |
161 {"file://filer/foo/", "filer" + kEllipsisStr}, | 163 {"file://filer/foo/", "filer" + kEllipsisStr}, |
162 // Eliding file URLs with nothing after the ':' shouldn't crash. | 164 // Eliding file URLs with nothing after the ':' shouldn't crash. |
163 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:", "aaa" + kEllipsisStr}, | 165 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:", "aaa" + kEllipsisStr}, |
164 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:/", "aaa" + kEllipsisStr}, | 166 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:/", "aaa" + kEllipsisStr}, |
165 }; | 167 }; |
166 | 168 |
167 RunUrlTest(testcases, arraysize(testcases)); | 169 RunUrlTest(testcases, arraysize(testcases)); |
168 } | 170 } |
169 | 171 |
170 TEST(TextEliderTest, TestHostEliding) { | 172 TEST(TextEliderTest, TestHostEliding) { |
171 const std::string kEllipsisStr(kEllipsis); | 173 const std::string kEllipsisStr(kEllipsis); |
172 Testcase testcases[] = { | 174 Testcase testcases[] = { |
173 {"http://google.com", "google.com"}, | 175 {"http://google.com", "google.com"}, |
174 {"http://subdomain.google.com", kEllipsisStr + ".google.com"}, | 176 {"http://subdomain.google.com", kEllipsisStr + ".google.com"}, |
175 {"http://reallyreallyreallylongdomainname.com", | 177 {"http://reallyreallyreallylongdomainname.com", |
176 "reallyreallyreallylongdomainname.com"}, | 178 "reallyreallyreallylongdomainname.com"}, |
177 {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com"}, | 179 {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com"}, |
178 {"http://foo", "foo"}, | 180 {"http://foo", "foo"}, |
179 {"http://foo.bar", "foo.bar"}, | 181 {"http://foo.bar", "foo.bar"}, |
180 {"http://subdomain.foo.bar", kEllipsisStr + "in.foo.bar"}, | 182 {"http://subdomain.foo.bar", kEllipsisStr + "in.foo.bar"}, |
181 // IOS width calculations are off by a letter from other platforms for | 183 // IOS width calculations are off by a letter from other platforms for |
182 // some strings from other platforms, probably for strings with too | 184 // some strings from other platforms, probably for strings with too |
183 // many kerned letters on the default font set. | 185 // many kerned letters on the default font set. |
184 #if !defined(OS_IOS) | 186 #if !defined(OS_IOS) |
185 {"http://subdomain.reallylongdomainname.com", | 187 {"http://subdomain.reallylongdomainname.com", |
186 kEllipsisStr + "ain.reallylongdomainname.com"}, | 188 kEllipsisStr + "ain.reallylongdomainname.com"}, |
187 {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com"}, | 189 {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com"}, |
188 #endif | 190 #endif // !defined(OS_IOS) |
189 }; | 191 }; |
190 | 192 |
191 for (size_t i = 0; i < arraysize(testcases); ++i) { | 193 for (size_t i = 0; i < arraysize(testcases); ++i) { |
192 const float available_width = | 194 const float available_width = |
193 GetStringWidthF(UTF8ToUTF16(testcases[i].output), gfx::FontList()); | 195 GetStringWidthF(UTF8ToUTF16(testcases[i].output), gfx::FontList()); |
194 EXPECT_EQ(UTF8ToUTF16(testcases[i].output), ElideHost( | 196 EXPECT_EQ(UTF8ToUTF16(testcases[i].output), |
195 GURL(testcases[i].input), gfx::FontList(), available_width)); | 197 secure_display::ElideHost(GURL(testcases[i].input), |
| 198 gfx::FontList(), available_width)); |
196 } | 199 } |
197 | 200 |
198 // Trying to elide to a really short length will still keep the full TLD+1 | 201 // Trying to elide to a really short length will still keep the full TLD+1 |
199 EXPECT_EQ(base::ASCIIToUTF16("google.com"), | 202 EXPECT_EQ( |
200 ElideHost(GURL("http://google.com"), gfx::FontList(), 2)); | 203 base::ASCIIToUTF16("google.com"), |
| 204 secure_display::ElideHost(GURL("http://google.com"), gfx::FontList(), 2)); |
201 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), | 205 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"), |
202 ElideHost(GURL("http://subdomain.google.com"), gfx::FontList(), 2)); | 206 secure_display::ElideHost(GURL("http://subdomain.google.com"), |
203 EXPECT_EQ(base::ASCIIToUTF16("foo.bar"), | 207 gfx::FontList(), 2)); |
204 ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); | 208 EXPECT_EQ( |
| 209 base::ASCIIToUTF16("foo.bar"), |
| 210 secure_display::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2)); |
205 } | 211 } |
206 | 212 |
| 213 #endif // !defined(OS_ANDROID) |
| 214 |
207 TEST(TextEliderTest, FormatUrlForSecurityDisplay) { | 215 TEST(TextEliderTest, FormatUrlForSecurityDisplay) { |
208 struct OriginTestData { | 216 struct OriginTestData { |
209 const char* const description; | 217 const char* const description; |
210 const char* const input; | 218 const char* const input; |
211 const wchar_t* const output; | 219 const wchar_t* const output; |
212 }; | 220 }; |
213 | 221 |
214 const OriginTestData tests[] = { | 222 const OriginTestData tests[] = { |
215 {"Empty URL", "", L""}, | 223 {"Empty URL", "", L""}, |
216 {"HTTP URL", "http://www.google.com/", L"http://www.google.com"}, | 224 {"HTTP URL", "http://www.google.com/", L"http://www.google.com"}, |
217 {"HTTPS URL", "https://www.google.com/", L"https://www.google.com"}, | 225 {"HTTPS URL", "https://www.google.com/", L"https://www.google.com"}, |
218 {"Standard HTTP port", | 226 {"Standard HTTP port", "http://www.google.com:80/", |
219 "http://www.google.com:80/", | |
220 L"http://www.google.com"}, | 227 L"http://www.google.com"}, |
221 {"Standard HTTPS port", | 228 {"Standard HTTPS port", "https://www.google.com:443/", |
222 "https://www.google.com:443/", | |
223 L"https://www.google.com"}, | 229 L"https://www.google.com"}, |
224 {"Standard HTTP port, IDN Chinese", | 230 {"Standard HTTP port, IDN Chinese", |
225 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80", | 231 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80", |
226 L"http://xn--fiqs8s.icom.museum"}, | 232 L"http://xn--fiqs8s.icom.museum"}, |
227 {"HTTP URL, IDN Hebrew (RTL)", | 233 {"HTTP URL, IDN Hebrew (RTL)", |
228 "http://" | 234 "http://" |
229 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d." | 235 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d." |
230 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/", | 236 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/", |
231 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"}, | 237 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum"}, |
232 {"HTTP URL with query string, IDN Arabic (RTL)", | 238 {"HTTP URL with query string, IDN Arabic (RTL)", |
233 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no", | 239 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no", |
234 L"http://xn--wgbh1c.icom.museum"}, | 240 L"http://xn--wgbh1c.icom.museum"}, |
235 {"Non-standard HTTP port", | 241 {"Non-standard HTTP port", "http://www.google.com:9000/", |
236 "http://www.google.com:9000/", | |
237 L"http://www.google.com:9000"}, | 242 L"http://www.google.com:9000"}, |
238 {"Non-standard HTTPS port", | 243 {"Non-standard HTTPS port", "https://www.google.com:9000/", |
239 "https://www.google.com:9000/", | |
240 L"https://www.google.com:9000"}, | 244 L"https://www.google.com:9000"}, |
241 {"File URI", | 245 {"File URI", "file:///usr/example/file.html", |
242 "file:///usr/example/file.html", | |
243 L"file:///usr/example/file.html"}, | 246 L"file:///usr/example/file.html"}, |
244 {"File URI with hostname", | 247 {"File URI with hostname", "file://localhost/usr/example/file.html", |
245 "file://localhost/usr/example/file.html", | |
246 L"file:///usr/example/file.html"}, | 248 L"file:///usr/example/file.html"}, |
247 {"UNC File URI 1", | 249 {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls", |
248 "file:///CONTOSO/accounting/money.xls", | |
249 L"file:///CONTOSO/accounting/money.xls"}, | 250 L"file:///CONTOSO/accounting/money.xls"}, |
250 {"UNC File URI 2", | 251 {"UNC File URI 2", |
251 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", | 252 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO", |
252 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, | 253 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"}, |
253 {"HTTP URL with path", | 254 {"HTTP URL with path", "http://www.google.com/test.html", |
254 "http://www.google.com/test.html", | |
255 L"http://www.google.com"}, | 255 L"http://www.google.com"}, |
256 {"HTTPS URL with path", | 256 {"HTTPS URL with path", "https://www.google.com/test.html", |
257 "https://www.google.com/test.html", | |
258 L"https://www.google.com"}, | 257 L"https://www.google.com"}, |
259 {"Unusual secure scheme (wss)", | 258 {"Unusual secure scheme (wss)", "wss://www.google.com/", |
260 "wss://www.google.com/", | |
261 L"wss://www.google.com"}, | 259 L"wss://www.google.com"}, |
262 {"Unusual non-secure scheme (gopher)", | 260 {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/", |
263 "gopher://www.google.com/", | |
264 L"gopher://www.google.com"}, | 261 L"gopher://www.google.com"}, |
265 {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version"}, | 262 {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version"}, |
266 {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103"}, | 263 {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103"}, |
267 {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103"}, | 264 {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103"}, |
268 {"HTTP IPv6 address", | 265 {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", |
269 "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/", | |
270 L"http://[fe80::202:b3ff:fe1e:8329]"}, | 266 L"http://[fe80::202:b3ff:fe1e:8329]"}, |
271 {"HTTPS IPv6 address with port", | 267 {"HTTPS IPv6 address with port", "https://[2001:db8:0:1]:443/", |
272 "https://[2001:db8:0:1]:443/", | |
273 L"https://[2001:db8:0:1]"}, | 268 L"https://[2001:db8:0:1]"}, |
274 {"HTTPS IP address, non-default port", | 269 {"HTTPS IP address, non-default port", "https://173.194.65.103:8443", |
275 "https://173.194.65.103:8443", | |
276 L"https://173.194.65.103:8443"}, | 270 L"https://173.194.65.103:8443"}, |
277 {"HTTP filesystem: URL with path", | 271 {"HTTP filesystem: URL with path", |
278 "filesystem:http://www.google.com/temporary/test.html", | 272 "filesystem:http://www.google.com/temporary/test.html", |
279 L"filesystem:http://www.google.com"}, | 273 L"filesystem:http://www.google.com"}, |
280 {"File filesystem: URL with path", | 274 {"File filesystem: URL with path", |
281 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", | 275 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy", |
282 L"filesystem:file:///temporary/stuff/test.html"}, | 276 L"filesystem:file:///temporary/stuff/test.html"}, |
283 {"Invalid scheme 1", | 277 {"Invalid scheme 1", "twelve://www.cyber.org/wow.php", |
284 "twelve://www.cyber.org/wow.php", | |
285 L"twelve://www.cyber.org/wow.php"}, | 278 L"twelve://www.cyber.org/wow.php"}, |
286 {"Invalid scheme 2", | 279 {"Invalid scheme 2", "://www.cyber.org/wow.php", |
287 "://www.cyber.org/wow.php", | |
288 L"://www.cyber.org/wow.php"}, | 280 L"://www.cyber.org/wow.php"}, |
289 {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber.."}, | 281 {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber.."}, |
290 {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber"}, | 282 {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber"}, |
291 {"Invalid port 1", | 283 {"Invalid port 1", "https://173.194.65.103:000", |
292 "https://173.194.65.103:000", | |
293 L"https://173.194.65.103:0"}, | 284 L"https://173.194.65.103:0"}, |
294 {"Invalid port 2", | 285 {"Invalid port 2", "https://173.194.65.103:gruffle", |
295 "https://173.194.65.103:gruffle", | |
296 L"https://173.194.65.103:gruffle"}, | 286 L"https://173.194.65.103:gruffle"}, |
297 {"Invalid port 3", | 287 {"Invalid port 3", "https://173.194.65.103:/hello.aspx", |
298 "https://173.194.65.103:/hello.aspx", | |
299 L"https://173.194.65.103"}, | 288 L"https://173.194.65.103"}, |
300 {"Trailing dot in DNS name", | 289 {"Trailing dot in DNS name", "https://www.example.com./get/goat", |
301 "https://www.example.com./get/goat", | |
302 L"https://www.example.com."}, | 290 L"https://www.example.com."}, |
303 {"Blob URL", | 291 {"Blob URL", |
304 "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", | 292 "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9", |
305 L"blob:http%3A//www.html5rocks.com/" | 293 L"blob:http%3A//www.html5rocks.com/" |
306 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}, | 294 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}, |
307 }; | 295 }; |
308 | 296 |
309 const char languages[] = "zh-TW,en-US,en,am,ar-EG,ar"; | 297 const char languages[] = "zh-TW,en-US,en,am,ar-EG,ar"; |
310 for (size_t i = 0; i < arraysize(tests); ++i) { | 298 for (size_t i = 0; i < arraysize(tests); ++i) { |
311 base::string16 formatted = | 299 base::string16 formatted = secure_display::FormatUrlForSecurityDisplay( |
312 FormatUrlForSecurityDisplay(GURL(tests[i].input), std::string()); | 300 GURL(tests[i].input), std::string()); |
313 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) | 301 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted) |
314 << tests[i].description; | 302 << tests[i].description; |
315 base::string16 formatted_with_languages = | 303 base::string16 formatted_with_languages = |
316 FormatUrlForSecurityDisplay(GURL(tests[i].input), languages); | 304 secure_display::FormatUrlForSecurityDisplay(GURL(tests[i].input), |
| 305 languages); |
317 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted_with_languages) | 306 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted_with_languages) |
318 << tests[i].description; | 307 << tests[i].description; |
319 } | 308 } |
320 | 309 |
321 base::string16 formatted = FormatUrlForSecurityDisplay(GURL(), std::string()); | 310 base::string16 formatted = |
| 311 secure_display::FormatUrlForSecurityDisplay(GURL(), std::string()); |
322 EXPECT_EQ(base::string16(), formatted) | 312 EXPECT_EQ(base::string16(), formatted) |
323 << "Explicitly test the 0-argument GURL constructor"; | 313 << "Explicitly test the 0-argument GURL constructor"; |
324 } | 314 } |
325 | 315 |
326 } // namespace | 316 } // namespace |
OLD | NEW |