Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/host_mapping_rules.h" | 5 #include "net/base/host_mapping_rules.h" |
| 6 | 6 |
| 7 #include "net/base/host_port_pair.h" | 7 #include "net/base/host_port_pair.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 EXPECT_TRUE(rules.RewriteHost(&host_port)); | 30 EXPECT_TRUE(rules.RewriteHost(&host_port)); |
| 31 EXPECT_EQ("baz", host_port.host()); | 31 EXPECT_EQ("baz", host_port.host()); |
| 32 EXPECT_EQ(80u, host_port.port()); | 32 EXPECT_EQ(80u, host_port.port()); |
| 33 | 33 |
| 34 host_port = HostPortPair("wtf.foo.com", 666); | 34 host_port = HostPortPair("wtf.foo.com", 666); |
| 35 EXPECT_FALSE(rules.RewriteHost(&host_port)); | 35 EXPECT_FALSE(rules.RewriteHost(&host_port)); |
| 36 EXPECT_EQ("wtf.foo.com", host_port.host()); | 36 EXPECT_EQ("wtf.foo.com", host_port.host()); |
| 37 EXPECT_EQ(666u, host_port.port()); | 37 EXPECT_EQ(666u, host_port.port()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 TEST(HostMappingRulesTest, PortSpecificMatching) { | |
| 41 HostMappingRules rules; | |
| 42 rules.SetRulesFromString( | |
| 43 "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.
| |
| 44 | |
| 45 // No match | |
| 46 HostPortPair host_port("test.com", 1234); | |
| 47 EXPECT_FALSE(rules.RewriteHost(&host_port)); | |
| 48 EXPECT_EQ("test.com", host_port.host()); | |
| 49 EXPECT_EQ(1234u, host_port.port()); | |
| 50 | |
| 51 // Match port 80 | |
| 52 host_port = HostPortPair("crack.com", 80); | |
| 53 EXPECT_TRUE(rules.RewriteHost(&host_port)); | |
| 54 EXPECT_EQ("baz", host_port.host()); | |
| 55 EXPECT_EQ(111u, host_port.port()); | |
| 56 | |
| 57 // Match port 443 | |
| 58 host_port = HostPortPair("wtf.com", 443); | |
|
eroman
2010/08/20 18:25:00
heh, colorful hostnames :)
| |
| 59 EXPECT_TRUE(rules.RewriteHost(&host_port)); | |
| 60 EXPECT_EQ("blat", host_port.host()); | |
| 61 EXPECT_EQ(333u, host_port.port()); | |
| 62 | |
| 63 // Match port 443, but excluded. | |
| 64 host_port = HostPortPair("wtf.foo.com", 443); | |
| 65 EXPECT_FALSE(rules.RewriteHost(&host_port)); | |
| 66 EXPECT_EQ("wtf.foo.com", host_port.host()); | |
| 67 EXPECT_EQ(443u, host_port.port()); | |
| 68 } | |
| 69 | |
| 40 // Parsing bad rules should silently discard the rule (and never crash). | 70 // Parsing bad rules should silently discard the rule (and never crash). |
| 41 TEST(HostMappingRulesTest, ParseInvalidRules) { | 71 TEST(HostMappingRulesTest, ParseInvalidRules) { |
| 42 HostMappingRules rules; | 72 HostMappingRules rules; |
| 43 | 73 |
| 44 EXPECT_FALSE(rules.AddRuleFromString("xyz")); | 74 EXPECT_FALSE(rules.AddRuleFromString("xyz")); |
| 45 EXPECT_FALSE(rules.AddRuleFromString("")); | 75 EXPECT_FALSE(rules.AddRuleFromString("")); |
| 46 EXPECT_FALSE(rules.AddRuleFromString(" ")); | 76 EXPECT_FALSE(rules.AddRuleFromString(" ")); |
| 47 EXPECT_FALSE(rules.AddRuleFromString("EXCLUDE")); | 77 EXPECT_FALSE(rules.AddRuleFromString("EXCLUDE")); |
| 48 EXPECT_FALSE(rules.AddRuleFromString("EXCLUDE foo bar")); | 78 EXPECT_FALSE(rules.AddRuleFromString("EXCLUDE foo bar")); |
| 49 EXPECT_FALSE(rules.AddRuleFromString("INCLUDE")); | 79 EXPECT_FALSE(rules.AddRuleFromString("INCLUDE")); |
| 50 EXPECT_FALSE(rules.AddRuleFromString("INCLUDE x")); | 80 EXPECT_FALSE(rules.AddRuleFromString("INCLUDE x")); |
| 51 EXPECT_FALSE(rules.AddRuleFromString("INCLUDE x :10")); | 81 EXPECT_FALSE(rules.AddRuleFromString("INCLUDE x :10")); |
| 52 } | 82 } |
| 53 | 83 |
| 54 } // namespace | 84 } // namespace |
| 55 | 85 |
| 56 } // namespace net | 86 } // namespace net |
| OLD | NEW |