Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / quic / quic_address_mismatch_test.cc
blobb7c683b5a48a7f15a21197ec8a149e3c30d01187
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
3 // found in the LICENSE file.
5 #include "net/quic/quic_address_mismatch.h"
7 #include "net/base/ip_endpoint.h"
8 #include "net/base/net_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace net {
12 namespace test {
14 // Test all cases of the GetAddressMismatch function.
15 TEST(QuicAddressMismatchTest, GetAddressMismatch) {
16 IPAddressNumber ip4_1;
17 IPAddressNumber ip4_2;
18 IPAddressNumber ip6_1;
19 IPAddressNumber ip6_2;
20 IPAddressNumber ip4_mapped_1;
21 IPAddressNumber ip4_mapped_2;
22 ASSERT_TRUE(ParseIPLiteralToNumber("1.2.3.4", &ip4_1));
23 ASSERT_TRUE(ParseIPLiteralToNumber("5.6.7.8", &ip4_2));
24 ASSERT_TRUE(ParseIPLiteralToNumber("1234::1", &ip6_1));
25 ASSERT_TRUE(ParseIPLiteralToNumber("1234::2", &ip6_2));
26 ip4_mapped_1 = ConvertIPv4NumberToIPv6Number(ip4_1);
27 ip4_mapped_2 = ConvertIPv4NumberToIPv6Number(ip4_2);
28 ASSERT_NE(ip4_1, ip4_2);
29 ASSERT_NE(ip6_1, ip6_2);
30 ASSERT_NE(ip4_mapped_1, ip4_mapped_2);
32 EXPECT_EQ(-1, GetAddressMismatch(IPEndPoint(), IPEndPoint()));
33 EXPECT_EQ(-1, GetAddressMismatch(IPEndPoint(), IPEndPoint(ip4_1, 443)));
34 EXPECT_EQ(-1, GetAddressMismatch(IPEndPoint(ip4_1, 443), IPEndPoint()));
36 EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V4_V4,
37 GetAddressMismatch(IPEndPoint(ip4_1, 443),
38 IPEndPoint(ip4_1, 443)));
39 EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V4_V4,
40 GetAddressMismatch(IPEndPoint(ip4_1, 443),
41 IPEndPoint(ip4_mapped_1, 443)));
42 EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V4_V4,
43 GetAddressMismatch(IPEndPoint(ip4_mapped_1, 443),
44 IPEndPoint(ip4_mapped_1, 443)));
45 EXPECT_EQ(QUIC_ADDRESS_AND_PORT_MATCH_V6_V6,
46 GetAddressMismatch(IPEndPoint(ip6_1, 443),
47 IPEndPoint(ip6_1, 443)));
49 EXPECT_EQ(QUIC_PORT_MISMATCH_V4_V4,
50 GetAddressMismatch(IPEndPoint(ip4_1, 80),
51 IPEndPoint(ip4_1, 443)));
52 EXPECT_EQ(QUIC_PORT_MISMATCH_V4_V4,
53 GetAddressMismatch(IPEndPoint(ip4_1, 80),
54 IPEndPoint(ip4_mapped_1, 443)));
55 EXPECT_EQ(QUIC_PORT_MISMATCH_V4_V4,
56 GetAddressMismatch(IPEndPoint(ip4_mapped_1, 80),
57 IPEndPoint(ip4_mapped_1, 443)));
58 EXPECT_EQ(QUIC_PORT_MISMATCH_V6_V6,
59 GetAddressMismatch(IPEndPoint(ip6_1, 80),
60 IPEndPoint(ip6_1, 443)));
62 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
63 GetAddressMismatch(IPEndPoint(ip4_1, 443),
64 IPEndPoint(ip4_2, 443)));
65 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
66 GetAddressMismatch(IPEndPoint(ip4_1, 443),
67 IPEndPoint(ip4_mapped_2, 443)));
68 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
69 GetAddressMismatch(IPEndPoint(ip4_mapped_1, 443),
70 IPEndPoint(ip4_mapped_2, 443)));
71 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
72 GetAddressMismatch(IPEndPoint(ip4_1, 80),
73 IPEndPoint(ip4_2, 443)));
74 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
75 GetAddressMismatch(IPEndPoint(ip4_1, 80),
76 IPEndPoint(ip4_mapped_2, 443)));
77 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V4,
78 GetAddressMismatch(IPEndPoint(ip4_mapped_1, 80),
79 IPEndPoint(ip4_mapped_2, 443)));
80 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V6,
81 GetAddressMismatch(IPEndPoint(ip6_1, 443),
82 IPEndPoint(ip6_2, 443)));
83 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V6,
84 GetAddressMismatch(IPEndPoint(ip6_1, 80),
85 IPEndPoint(ip6_2, 443)));
86 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6,
87 GetAddressMismatch(IPEndPoint(ip4_1, 443),
88 IPEndPoint(ip6_1, 443)));
89 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6,
90 GetAddressMismatch(IPEndPoint(ip4_mapped_1, 443),
91 IPEndPoint(ip6_1, 443)));
92 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6,
93 GetAddressMismatch(IPEndPoint(ip4_1, 80),
94 IPEndPoint(ip6_1, 443)));
95 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V4_V6,
96 GetAddressMismatch(IPEndPoint(ip4_mapped_1, 80),
97 IPEndPoint(ip6_1, 443)));
98 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4,
99 GetAddressMismatch(IPEndPoint(ip6_1, 443),
100 IPEndPoint(ip4_1, 443)));
101 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4,
102 GetAddressMismatch(IPEndPoint(ip6_1, 443),
103 IPEndPoint(ip4_mapped_1, 443)));
104 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4,
105 GetAddressMismatch(IPEndPoint(ip6_1, 80),
106 IPEndPoint(ip4_1, 443)));
107 EXPECT_EQ(QUIC_ADDRESS_MISMATCH_V6_V4,
108 GetAddressMismatch(IPEndPoint(ip6_1, 80),
109 IPEndPoint(ip4_mapped_1, 443)));
112 } // namespace test
113 } // namespace net