Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: url/gurl_unittest.cc

Issue 2956643002: Add GURL::HostNoBracketsPiece() (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « url/gurl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/gurl_unittest.cc
diff --git a/url/gurl_unittest.cc b/url/gurl_unittest.cc
index a20472d0aa33c284cac351f902f72ff00af34ac4..c68e7f2e6660d082e9b43006252d77a078c011ab 100644
--- a/url/gurl_unittest.cc
+++ b/url/gurl_unittest.cc
@@ -561,7 +561,29 @@ TEST(GURLTest, IPAddress) {
}
}
-TEST(GURLTest, HostNoBrackets) {
+// Type-parameterized test for variants of the host returning methods.
+template <typename StringType>
+class GURLHostTest : public ::testing::Test {
brettw 2017/06/30 19:33:14 This is a lot of hard-to-read complexity, when I t
Adam Rice 2017/07/03 04:51:51 Thank you! I was so fixated on the type difference
+ public:
+ // The GURL methods are wrapped to deal with having different method names for
+ // the types.
+ StringType host(const GURL& url) { return url.host(); }
+ StringType HostNoBrackets(const GURL& url) { return url.HostNoBrackets(); }
+};
+
+template <>
+class GURLHostTest<base::StringPiece> : public ::testing::Test {
+ public:
+ base::StringPiece host(const GURL& url) { return url.host_piece(); }
+ base::StringPiece HostNoBrackets(const GURL& url) {
+ return url.HostNoBracketsPiece();
+ }
+};
+
+using GURLHostTestTypes = ::testing::Types<std::string, base::StringPiece>;
+TYPED_TEST_CASE(GURLHostTest, GURLHostTestTypes);
+
+TYPED_TEST(GURLHostTest, HostNoBrackets) {
struct TestCase {
const char* input;
const char* expected_host;
@@ -582,8 +604,8 @@ TEST(GURLTest, HostNoBrackets) {
};
for (size_t i = 0; i < arraysize(cases); i++) {
GURL url(cases[i].input);
- EXPECT_EQ(cases[i].expected_host, url.host());
- EXPECT_EQ(cases[i].expected_plainhost, url.HostNoBrackets());
+ EXPECT_EQ(cases[i].expected_host, this->host(url));
+ EXPECT_EQ(cases[i].expected_plainhost, this->HostNoBrackets(url));
}
}
« no previous file with comments | « url/gurl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698