blob: 1d911a8e216eb55438fb464eea1791380477052e [file] [log] [blame]
miguelgdbcfb122015-07-23 10:45:111// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
rsleevi24f64dc22015-08-07 21:39:215#include "components/url_formatter/elide_url.h"
miguelgdbcfb122015-07-23 10:45:116
avi5dd91f82015-12-25 22:30:467#include <stddef.h>
8
justincohenb96612bf2015-07-24 22:26:099#include "base/ios/ios_util.h"
avi5dd91f82015-12-25 22:30:4610#include "base/macros.h"
miguelgdbcfb122015-07-23 10:45:1111#include "base/strings/utf_string_conversions.h"
avi5dd91f82015-12-25 22:30:4612#include "build/build_config.h"
miguelgdbcfb122015-07-23 10:45:1113#include "testing/gtest/include/gtest/gtest.h"
miguelgdbcfb122015-07-23 10:45:1114#include "url/gurl.h"
15
rsleevi24f64dc22015-08-07 21:39:2116#if !defined(OS_ANDROID)
17#include "ui/gfx/font_list.h" // nogncheck
18#include "ui/gfx/text_elider.h" // nogncheck
19#include "ui/gfx/text_utils.h" // nogncheck
20#endif
miguelgdbcfb122015-07-23 10:45:1121
22namespace {
23
24struct Testcase {
25 const std::string input;
26 const std::string output;
eugenebutbec2c5f2015-08-07 23:22:3227 enum SupportedPlatforms {
28 ALL = 0,
29 NO_IOS9_OR_LATER,
30 NO_IOS,
31 } platforms;
miguelgdbcfb122015-07-23 10:45:1132};
33
34#if !defined(OS_ANDROID)
35void RunUrlTest(Testcase* testcases, size_t num_testcases) {
36 static const gfx::FontList font_list;
37 for (size_t i = 0; i < num_testcases; ++i) {
38 const GURL url(testcases[i].input);
miguelgdbcfb122015-07-23 10:45:1139 const float available_width =
rsleevi24f64dc22015-08-07 21:39:2140 gfx::GetStringWidthF(base::UTF8ToUTF16(testcases[i].output), font_list);
41 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output),
jshin1fb76462016-04-05 22:13:0342 url_formatter::ElideUrl(url, font_list, available_width));
miguelgdbcfb122015-07-23 10:45:1143 }
44}
45
46// Test eliding of commonplace URLs.
47TEST(TextEliderTest, TestGeneralEliding) {
rsleevi24f64dc22015-08-07 21:39:2148 const std::string kEllipsisStr(gfx::kEllipsis);
miguelgdbcfb122015-07-23 10:45:1149 Testcase testcases[] = {
50 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
51 {"http://www.google.com/intl/en/ads/", "www.google.com/intl/en/ads/"},
52 {"http://www.google.com/intl/en/ads/",
53 "google.com/intl/" + kEllipsisStr + "/ads/"},
54 {"http://www.google.com/intl/en/ads/",
55 "google.com/" + kEllipsisStr + "/ads/"},
56 {"http://www.google.com/intl/en/ads/", "google.com/" + kEllipsisStr},
57 {"http://www.google.com/intl/en/ads/", "goog" + kEllipsisStr},
58 {"https://subdomain.foo.com/bar/filename.html",
59 "subdomain.foo.com/bar/filename.html"},
60 {"https://subdomain.foo.com/bar/filename.html",
61 "subdomain.foo.com/" + kEllipsisStr + "/filename.html"},
62 {"http://subdomain.foo.com/bar/filename.html",
63 kEllipsisStr + "foo.com/" + kEllipsisStr + "/filename.html"},
64 {"http://www.google.com/intl/en/ads/?aLongQueryWhichIsNotRequired",
65 "www.google.com/intl/en/ads/?aLongQ" + kEllipsisStr},
66 };
67
68 RunUrlTest(testcases, arraysize(testcases));
69}
70
71// When there is very little space available, the elision code will shorten
72// both path AND file name to an ellipsis - ".../...". To avoid this result,
73// there is a hack in place that simply treats them as one string in this
74// case.
75TEST(TextEliderTest, TestTrailingEllipsisSlashEllipsisHack) {
rsleevi24f64dc22015-08-07 21:39:2176 const std::string kEllipsisStr(gfx::kEllipsis);
miguelgdbcfb122015-07-23 10:45:1177
78 // Very little space, would cause double ellipsis.
79 gfx::FontList font_list;
80 GURL url("http://battersbox.com/directory/foo/peter_paul_and_mary.html");
rsleevi24f64dc22015-08-07 21:39:2181 float available_width = gfx::GetStringWidthF(
82 base::UTF8ToUTF16("battersbox.com/" + kEllipsisStr + "/" + kEllipsisStr),
miguelgdbcfb122015-07-23 10:45:1183 font_list);
84
85 // Create the expected string, after elision. Depending on font size, the
86 // directory might become /dir... or /di... or/d... - it never should be
87 // shorter than that. (If it is, the font considers d... to be longer
88 // than .../... - that should never happen).
rsleevi24f64dc22015-08-07 21:39:2189 ASSERT_GT(
90 gfx::GetStringWidthF(base::UTF8ToUTF16(kEllipsisStr + "/" + kEllipsisStr),
91 font_list),
92 gfx::GetStringWidthF(base::UTF8ToUTF16("d" + kEllipsisStr), font_list));
miguelgdbcfb122015-07-23 10:45:1193 GURL long_url("http://battersbox.com/directorynameisreallylongtoforcetrunc");
rsleevi24f64dc22015-08-07 21:39:2194 base::string16 expected = url_formatter::ElideUrl(
jshin1fb76462016-04-05 22:13:0395 long_url, font_list, available_width);
miguelgdbcfb122015-07-23 10:45:1196 // Ensure that the expected result still contains part of the directory name.
97 ASSERT_GT(expected.length(), std::string("battersbox.com/d").length());
jshin1fb76462016-04-05 22:13:0398 EXPECT_EQ(expected, url_formatter::ElideUrl(url, font_list, available_width));
miguelgdbcfb122015-07-23 10:45:1199
100 // More space available - elide directories, partially elide filename.
101 Testcase testcases[] = {
102 {"http://battersbox.com/directory/foo/peter_paul_and_mary.html",
103 "battersbox.com/" + kEllipsisStr + "/peter" + kEllipsisStr},
104 };
105 RunUrlTest(testcases, arraysize(testcases));
106}
107
108// Test eliding of empty strings, URLs with ports, passwords, queries, etc.
109TEST(TextEliderTest, TestMoreEliding) {
rsleevi24f64dc22015-08-07 21:39:21110 const std::string kEllipsisStr(gfx::kEllipsis);
miguelgdbcfb122015-07-23 10:45:11111 Testcase testcases[] = {
112 {"http://www.google.com/foo?bar", "www.google.com/foo?bar"},
113 {"http://xyz.google.com/foo?bar", "xyz.google.com/foo?" + kEllipsisStr},
114 {"http://xyz.google.com/foo?bar", "xyz.google.com/foo" + kEllipsisStr},
115 {"http://xyz.google.com/foo?bar", "xyz.google.com/fo" + kEllipsisStr},
116 {"http://a.b.com/pathname/c?d", "a.b.com/" + kEllipsisStr + "/c?d"},
117 {"", ""},
118 {"http://foo.bar..example.com...hello/test/filename.html",
119 "foo.bar..example.com...hello/" + kEllipsisStr + "/filename.html"},
120 {"http://foo.bar../", "foo.bar.."},
121 {"http://xn--1lq90i.cn/foo", "\xe5\x8c\x97\xe4\xba\xac.cn/foo"},
122 {"http://me:[email protected]:99/foo?bar#baz",
123 "secrethost.com:99/foo?bar#baz"},
124 {"http://me:mypass@ss%xxfdsf.com/foo", "ss%25xxfdsf.com/foo"},
125 {"mailto:[email protected]", "mailto:[email protected]"},
126 {"javascript:click(0)", "javascript:click(0)"},
127 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
128 "chess.eecs.berkeley.edu:4430/login/arbitfilename"},
129 {"https://chess.eecs.berkeley.edu:4430/login/arbitfilename",
130 kEllipsisStr + "berkeley.edu:4430/" + kEllipsisStr + "/arbitfilename"},
131
132 // Unescaping.
133 {"http://www/%E4%BD%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
134 "www/\xe4\xbd\xa0\xe5\xa5\xbd?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
135
136 // Invalid unescaping for path. The ref will always be valid UTF-8. We
137 // don't
138 // bother to do too many edge cases, since these are handled by the
139 // escaper
140 // unittest.
141 {"http://www/%E4%A0%E5%A5%BD?q=%E4%BD%A0%E5%A5%BD#\xe4\xbd\xa0",
142 "www/%E4%A0%E5%A5%BD?q=\xe4\xbd\xa0\xe5\xa5\xbd#\xe4\xbd\xa0"},
143 };
144
145 RunUrlTest(testcases, arraysize(testcases));
146}
147
148// Test eliding of file: URLs.
149TEST(TextEliderTest, TestFileURLEliding) {
rsleevi24f64dc22015-08-07 21:39:21150 const std::string kEllipsisStr(gfx::kEllipsis);
miguelgdbcfb122015-07-23 10:45:11151 Testcase testcases[] = {
152 {"file:///C:/path1/path2/path3/filename",
153 "file:///C:/path1/path2/path3/filename"},
154 {"file:///C:/path1/path2/path3/filename", "C:/path1/path2/path3/filename"},
155// GURL parses "file:///C:path" differently on windows than it does on posix.
156#if defined(OS_WIN)
157 {"file:///C:path1/path2/path3/filename",
158 "C:/path1/path2/" + kEllipsisStr + "/filename"},
159 {"file:///C:path1/path2/path3/filename",
160 "C:/path1/" + kEllipsisStr + "/filename"},
161 {"file:///C:path1/path2/path3/filename",
162 "C:/" + kEllipsisStr + "/filename"},
163#endif // defined(OS_WIN)
164 {"file://filer/foo/bar/file", "filer/foo/bar/file"},
165 {"file://filer/foo/bar/file", "filer/foo/" + kEllipsisStr + "/file"},
166 {"file://filer/foo/bar/file", "filer/" + kEllipsisStr + "/file"},
167 {"file://filer/foo/", "file://filer/foo/"},
168 {"file://filer/foo/", "filer/foo/"},
169 {"file://filer/foo/", "filer" + kEllipsisStr},
170 // Eliding file URLs with nothing after the ':' shouldn't crash.
171 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:", "aaa" + kEllipsisStr},
172 {"file:///aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:/", "aaa" + kEllipsisStr},
173 };
174
175 RunUrlTest(testcases, arraysize(testcases));
176}
177
178TEST(TextEliderTest, TestHostEliding) {
rsleevi24f64dc22015-08-07 21:39:21179 const std::string kEllipsisStr(gfx::kEllipsis);
miguelgdbcfb122015-07-23 10:45:11180 Testcase testcases[] = {
eugenebutbec2c5f2015-08-07 23:22:32181 {"http://google.com", "google.com"},
182 // iOS width calculations are off by a letter from other platforms for
183 // strings with too many kerned letters on the default font set.
184 // TODO(rohitrao): Fix secure_display::ElideHost for iOS
185 // (crbug.com/517604).
186 {"http://subdomain.google.com", kEllipsisStr + ".google.com",
187 Testcase::NO_IOS9_OR_LATER},
188 {"http://reallyreallyreallylongdomainname.com",
189 "reallyreallyreallylongdomainname.com"},
190 {"http://a.b.c.d.e.f.com", kEllipsisStr + "f.com",
191 Testcase::NO_IOS9_OR_LATER},
192 {"http://foo", "foo"},
193 {"http://foo.bar", "foo.bar"},
194 {"http://subdomain.foo.bar", kEllipsisStr + "in.foo.bar",
195 Testcase::NO_IOS9_OR_LATER},
196 {"http://subdomain.reallylongdomainname.com",
197 kEllipsisStr + "ain.reallylongdomainname.com", Testcase::NO_IOS},
198 {"http://a.b.c.d.e.f.com", kEllipsisStr + ".e.f.com", Testcase::NO_IOS},
miguelgdbcfb122015-07-23 10:45:11199 };
200
201 for (size_t i = 0; i < arraysize(testcases); ++i) {
eugenebutbec2c5f2015-08-07 23:22:32202#if defined(OS_IOS)
203 if (testcases[i].platforms == Testcase::NO_IOS ||
204 (testcases[i].platforms == Testcase::NO_IOS9_OR_LATER &&
205 base::ios::IsRunningOnIOS9OrLater())) {
206 continue;
207 }
208#endif
rsleevi24f64dc22015-08-07 21:39:21209 const float available_width = gfx::GetStringWidthF(
210 base::UTF8ToUTF16(testcases[i].output), gfx::FontList());
211 EXPECT_EQ(base::UTF8ToUTF16(testcases[i].output),
212 url_formatter::ElideHost(GURL(testcases[i].input),
213 gfx::FontList(), available_width));
miguelgdbcfb122015-07-23 10:45:11214 }
215
216 // Trying to elide to a really short length will still keep the full TLD+1
217 EXPECT_EQ(
218 base::ASCIIToUTF16("google.com"),
rsleevi24f64dc22015-08-07 21:39:21219 url_formatter::ElideHost(GURL("http://google.com"), gfx::FontList(), 2));
miguelgdbcfb122015-07-23 10:45:11220 EXPECT_EQ(base::UTF8ToUTF16(kEllipsisStr + ".google.com"),
rsleevi24f64dc22015-08-07 21:39:21221 url_formatter::ElideHost(GURL("http://subdomain.google.com"),
222 gfx::FontList(), 2));
miguelgdbcfb122015-07-23 10:45:11223 EXPECT_EQ(
224 base::ASCIIToUTF16("foo.bar"),
rsleevi24f64dc22015-08-07 21:39:21225 url_formatter::ElideHost(GURL("http://foo.bar"), gfx::FontList(), 2));
miguelgdbcfb122015-07-23 10:45:11226}
227
228#endif // !defined(OS_ANDROID)
229
230TEST(TextEliderTest, FormatUrlForSecurityDisplay) {
231 struct OriginTestData {
232 const char* const description;
233 const char* const input;
234 const wchar_t* const output;
palmer153af982015-09-15 02:04:19235 const wchar_t* const output_omit_scheme;
miguelgdbcfb122015-07-23 10:45:11236 };
237
238 const OriginTestData tests[] = {
palmer153af982015-09-15 02:04:19239 {"Empty URL", "", L"", L""},
240 {"HTTP URL", "http://www.google.com/", L"http://www.google.com",
241 L"www.google.com"},
242 {"HTTPS URL", "https://www.google.com/", L"https://www.google.com",
243 L"www.google.com"},
miguelgdbcfb122015-07-23 10:45:11244 {"Standard HTTP port", "http://www.google.com:80/",
palmer153af982015-09-15 02:04:19245 L"http://www.google.com", L"www.google.com"},
miguelgdbcfb122015-07-23 10:45:11246 {"Standard HTTPS port", "https://www.google.com:443/",
palmer153af982015-09-15 02:04:19247 L"https://www.google.com", L"www.google.com"},
miguelgdbcfb122015-07-23 10:45:11248 {"Standard HTTP port, IDN Chinese",
249 "http://\xe4\xb8\xad\xe5\x9b\xbd.icom.museum:80",
palmer153af982015-09-15 02:04:19250 L"http://xn--fiqs8s.icom.museum", L"xn--fiqs8s.icom.museum"},
miguelgdbcfb122015-07-23 10:45:11251 {"HTTP URL, IDN Hebrew (RTL)",
252 "http://"
253 "\xd7\x90\xd7\x99\xd7\xa7\xd7\x95\xd7\xb4\xd7\x9d."
254 "\xd7\x99\xd7\xa9\xd7\xa8\xd7\x90\xd7\x9c.museum/",
palmer153af982015-09-15 02:04:19255 L"http://xn--4dbklr2c8d.xn--4dbrk0ce.museum",
256 L"xn--4dbklr2c8d.xn--4dbrk0ce.museum"},
miguelgdbcfb122015-07-23 10:45:11257 {"HTTP URL with query string, IDN Arabic (RTL)",
258 "http://\xd9\x85\xd8\xb5\xd8\xb1.icom.museum/foo.html?yes=no",
palmer153af982015-09-15 02:04:19259 L"http://xn--wgbh1c.icom.museum", L"xn--wgbh1c.icom.museum"},
miguelgdbcfb122015-07-23 10:45:11260 {"Non-standard HTTP port", "http://www.google.com:9000/",
palmer153af982015-09-15 02:04:19261 L"http://www.google.com:9000", L"www.google.com:9000"},
miguelgdbcfb122015-07-23 10:45:11262 {"Non-standard HTTPS port", "https://www.google.com:9000/",
palmer153af982015-09-15 02:04:19263 L"https://www.google.com:9000", L"www.google.com:9000"},
miguelgdbcfb122015-07-23 10:45:11264 {"File URI", "file:///usr/example/file.html",
palmer153af982015-09-15 02:04:19265 L"file:///usr/example/file.html", L"file:///usr/example/file.html"},
miguelgdbcfb122015-07-23 10:45:11266 {"File URI with hostname", "file://localhost/usr/example/file.html",
palmer153af982015-09-15 02:04:19267 L"file:///usr/example/file.html", L"file:///usr/example/file.html"},
miguelgdbcfb122015-07-23 10:45:11268 {"UNC File URI 1", "file:///CONTOSO/accounting/money.xls",
palmer153af982015-09-15 02:04:19269 L"file:///CONTOSO/accounting/money.xls",
miguelgdbcfb122015-07-23 10:45:11270 L"file:///CONTOSO/accounting/money.xls"},
271 {"UNC File URI 2",
272 "file:///C:/Program%20Files/Music/Web%20Sys/main.html?REQUEST=RADIO",
palmer153af982015-09-15 02:04:19273 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html",
miguelgdbcfb122015-07-23 10:45:11274 L"file:///C:/Program%20Files/Music/Web%20Sys/main.html"},
275 {"HTTP URL with path", "http://www.google.com/test.html",
palmer153af982015-09-15 02:04:19276 L"http://www.google.com", L"www.google.com"},
miguelgdbcfb122015-07-23 10:45:11277 {"HTTPS URL with path", "https://www.google.com/test.html",
palmer153af982015-09-15 02:04:19278 L"https://www.google.com", L"www.google.com"},
miguelgdbcfb122015-07-23 10:45:11279 {"Unusual secure scheme (wss)", "wss://www.google.com/",
palmer153af982015-09-15 02:04:19280 L"wss://www.google.com", L"wss://www.google.com"},
miguelgdbcfb122015-07-23 10:45:11281 {"Unusual non-secure scheme (gopher)", "gopher://www.google.com/",
palmer153af982015-09-15 02:04:19282 L"gopher://www.google.com", L"gopher://www.google.com"},
283 {"Unlisted scheme (chrome)", "chrome://version", L"chrome://version",
284 L"chrome://version"},
285 {"HTTP IP address", "http://173.194.65.103", L"http://173.194.65.103",
286 L"173.194.65.103"},
287 {"HTTPS IP address", "https://173.194.65.103", L"https://173.194.65.103",
288 L"173.194.65.103"},
miguelgdbcfb122015-07-23 10:45:11289 {"HTTP IPv6 address", "http://[FE80:0000:0000:0000:0202:B3FF:FE1E:8329]/",
palmer153af982015-09-15 02:04:19290 L"http://[fe80::202:b3ff:fe1e:8329]", L"[fe80::202:b3ff:fe1e:8329]"},
miguelgdbcfb122015-07-23 10:45:11291 {"HTTPS IPv6 address with port", "https://[2001:db8:0:1]:443/",
palmer153af982015-09-15 02:04:19292 L"https://[2001:db8:0:1]", L"https://[2001:db8:0:1]"},
miguelgdbcfb122015-07-23 10:45:11293 {"HTTPS IP address, non-default port", "https://173.194.65.103:8443",
palmer153af982015-09-15 02:04:19294 L"https://173.194.65.103:8443", L"173.194.65.103:8443"},
miguelgdbcfb122015-07-23 10:45:11295 {"HTTP filesystem: URL with path",
296 "filesystem:http://www.google.com/temporary/test.html",
palmer153af982015-09-15 02:04:19297 L"filesystem:http://www.google.com",
miguelgdbcfb122015-07-23 10:45:11298 L"filesystem:http://www.google.com"},
299 {"File filesystem: URL with path",
300 "filesystem:file://localhost/temporary/stuff/test.html?z=fun&goat=billy",
palmer153af982015-09-15 02:04:19301 L"filesystem:file:///temporary/stuff/test.html",
miguelgdbcfb122015-07-23 10:45:11302 L"filesystem:file:///temporary/stuff/test.html"},
303 {"Invalid scheme 1", "twelve://www.cyber.org/wow.php",
palmer153af982015-09-15 02:04:19304 L"twelve://www.cyber.org/wow.php", L"twelve://www.cyber.org/wow.php"},
miguelgdbcfb122015-07-23 10:45:11305 {"Invalid scheme 2", "://www.cyber.org/wow.php",
palmer153af982015-09-15 02:04:19306 L"://www.cyber.org/wow.php", L"://www.cyber.org/wow.php"},
307 {"Invalid host 1", "https://www.cyber../wow.php", L"https://www.cyber..",
308 L"www.cyber.."},
309 {"Invalid host 2", "https://www...cyber/wow.php", L"https://www...cyber",
310 L"www...cyber"},
miguelgdbcfb122015-07-23 10:45:11311 {"Invalid port 1", "https://173.194.65.103:000",
palmer153af982015-09-15 02:04:19312 L"https://173.194.65.103:0", L"173.194.65.103:0"},
miguelgdbcfb122015-07-23 10:45:11313 {"Invalid port 2", "https://173.194.65.103:gruffle",
palmer153af982015-09-15 02:04:19314 L"https://173.194.65.103:gruffle", L"https://173.194.65.103:gruffle"},
miguelgdbcfb122015-07-23 10:45:11315 {"Invalid port 3", "https://173.194.65.103:/hello.aspx",
palmer153af982015-09-15 02:04:19316 L"https://173.194.65.103", L"173.194.65.103"},
miguelgdbcfb122015-07-23 10:45:11317 {"Trailing dot in DNS name", "https://www.example.com./get/goat",
palmer153af982015-09-15 02:04:19318 L"https://www.example.com.", L"www.example.com."},
miguelgdbcfb122015-07-23 10:45:11319 {"Blob URL",
320 "blob:http%3A//www.html5rocks.com/4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
321 L"blob:http%3A//www.html5rocks.com/"
palmer153af982015-09-15 02:04:19322 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9",
323 L"blob:http%3A//www.html5rocks.com/"
324 L"4d4ff040-6d61-4446-86d3-13ca07ec9ab9"}};
miguelgdbcfb122015-07-23 10:45:11325
miguelgdbcfb122015-07-23 10:45:11326 for (size_t i = 0; i < arraysize(tests); ++i) {
jshin1fb76462016-04-05 22:13:03327 base::string16 formatted =
328 url_formatter::FormatUrlForSecurityDisplay(GURL(tests[i].input));
miguelgdbcfb122015-07-23 10:45:11329 EXPECT_EQ(base::WideToUTF16(tests[i].output), formatted)
330 << tests[i].description;
palmer153af982015-09-15 02:04:19331
332 base::string16 formatted_omit_scheme =
333 url_formatter::FormatUrlForSecurityDisplayOmitScheme(
jshin1fb76462016-04-05 22:13:03334 GURL(tests[i].input));
palmer153af982015-09-15 02:04:19335 EXPECT_EQ(base::WideToUTF16(tests[i].output_omit_scheme),
336 formatted_omit_scheme)
337 << tests[i].description;
miguelgdbcfb122015-07-23 10:45:11338 }
339
340 base::string16 formatted =
jshin1fb76462016-04-05 22:13:03341 url_formatter::FormatUrlForSecurityDisplay(GURL());
miguelgdbcfb122015-07-23 10:45:11342 EXPECT_EQ(base::string16(), formatted)
343 << "Explicitly test the 0-argument GURL constructor";
palmer153af982015-09-15 02:04:19344
345 base::string16 formatted_omit_scheme =
jshin1fb76462016-04-05 22:13:03346 url_formatter::FormatUrlForSecurityDisplayOmitScheme(GURL());
palmer153af982015-09-15 02:04:19347 EXPECT_EQ(base::string16(), formatted_omit_scheme)
348 << "Explicitly test the 0-argument GURL constructor";
miguelgdbcfb122015-07-23 10:45:11349}
350
351} // namespace