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

Unified Diff: net/base/host_mapping_rules_unittest.cc

Issue 3177026: Add a feature to the HostResolverRules to be able to match rules only... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 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 | « net/base/host_mapping_rules.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/host_mapping_rules_unittest.cc
===================================================================
--- net/base/host_mapping_rules_unittest.cc (revision 56811)
+++ net/base/host_mapping_rules_unittest.cc (working copy)
@@ -37,6 +37,36 @@
EXPECT_EQ(666u, host_port.port());
}
+TEST(HostMappingRulesTest, PortSpecificMatching) {
+ HostMappingRules rules;
+ rules.SetRulesFromString(
+ "map *.com:80 baz:111 , map *.com:443 blat:333, EXCLUDE *.foo.com");
eroman 2010/08/20 18:25:00 nit: indent continued lines by 4.
+
+ // No match
+ HostPortPair host_port("test.com", 1234);
+ EXPECT_FALSE(rules.RewriteHost(&host_port));
+ EXPECT_EQ("test.com", host_port.host());
+ EXPECT_EQ(1234u, host_port.port());
+
+ // Match port 80
+ host_port = HostPortPair("crack.com", 80);
+ EXPECT_TRUE(rules.RewriteHost(&host_port));
+ EXPECT_EQ("baz", host_port.host());
+ EXPECT_EQ(111u, host_port.port());
+
+ // Match port 443
+ host_port = HostPortPair("wtf.com", 443);
eroman 2010/08/20 18:25:00 heh, colorful hostnames :)
+ EXPECT_TRUE(rules.RewriteHost(&host_port));
+ EXPECT_EQ("blat", host_port.host());
+ EXPECT_EQ(333u, host_port.port());
+
+ // Match port 443, but excluded.
+ host_port = HostPortPair("wtf.foo.com", 443);
+ EXPECT_FALSE(rules.RewriteHost(&host_port));
+ EXPECT_EQ("wtf.foo.com", host_port.host());
+ EXPECT_EQ(443u, host_port.port());
+}
+
// Parsing bad rules should silently discard the rule (and never crash).
TEST(HostMappingRulesTest, ParseInvalidRules) {
HostMappingRules rules;
« no previous file with comments | « net/base/host_mapping_rules.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698