| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/http_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 TEST_F(SpdyServerPropertiesTest, Initialize) { | 35 TEST_F(SpdyServerPropertiesTest, Initialize) { |
| 36 HostPortPair spdy_server_google("www.google.com", 443); | 36 HostPortPair spdy_server_google("www.google.com", 443); |
| 37 std::string spdy_server_g = spdy_server_google.ToString(); | 37 std::string spdy_server_g = spdy_server_google.ToString(); |
| 38 | 38 |
| 39 HostPortPair spdy_server_docs("docs.google.com", 443); | 39 HostPortPair spdy_server_docs("docs.google.com", 443); |
| 40 std::string spdy_server_d = spdy_server_docs.ToString(); | 40 std::string spdy_server_d = spdy_server_docs.ToString(); |
| 41 | 41 |
| 42 // Check by initializing NULL spdy servers. | 42 // Check by initializing NULL spdy servers. |
| 43 impl_.InitializeSpdyServers(NULL, true); | 43 impl_.InitializeSpdyServers(NULL, true); |
| 44 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | 44 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 45 | 45 |
| 46 // Check by initializing empty spdy servers. | 46 // Check by initializing empty spdy servers. |
| 47 std::vector<std::string> spdy_servers; | 47 std::vector<std::string> spdy_servers; |
| 48 impl_.InitializeSpdyServers(&spdy_servers, true); | 48 impl_.InitializeSpdyServers(&spdy_servers, true); |
| 49 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | 49 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 50 | 50 |
| 51 // Check by initializing with www.google.com:443 spdy server. | 51 // Check by initializing with www.google.com:443 spdy server. |
| 52 std::vector<std::string> spdy_servers1; | 52 std::vector<std::string> spdy_servers1; |
| 53 spdy_servers1.push_back(spdy_server_g); | 53 spdy_servers1.push_back(spdy_server_g); |
| 54 impl_.InitializeSpdyServers(&spdy_servers1, true); | 54 impl_.InitializeSpdyServers(&spdy_servers1, true); |
| 55 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | 55 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 56 | 56 |
| 57 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy | 57 // Check by initializing with www.google.com:443 and docs.google.com:443 spdy |
| 58 // servers. | 58 // servers. |
| 59 std::vector<std::string> spdy_servers2; | 59 std::vector<std::string> spdy_servers2; |
| 60 spdy_servers2.push_back(spdy_server_g); | 60 spdy_servers2.push_back(spdy_server_g); |
| 61 spdy_servers2.push_back(spdy_server_d); | 61 spdy_servers2.push_back(spdy_server_d); |
| 62 impl_.InitializeSpdyServers(&spdy_servers2, true); | 62 impl_.InitializeSpdyServers(&spdy_servers2, true); |
| 63 | 63 |
| 64 // Verify spdy_server_g and spdy_server_d are in the list in the same order. | 64 // Verify spdy_server_g and spdy_server_d are in the list in the same order. |
| 65 base::ListValue spdy_server_list; | 65 base::ListValue spdy_server_list; |
| 66 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 66 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 67 EXPECT_EQ(2U, spdy_server_list.GetSize()); | 67 EXPECT_EQ(2U, spdy_server_list.GetSize()); |
| 68 std::string string_value_g; | 68 std::string string_value_g; |
| 69 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 69 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 70 ASSERT_EQ(spdy_server_g, string_value_g); | 70 ASSERT_EQ(spdy_server_g, string_value_g); |
| 71 std::string string_value_d; | 71 std::string string_value_d; |
| 72 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_d)); | 72 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_d)); |
| 73 ASSERT_EQ(spdy_server_d, string_value_d); | 73 ASSERT_EQ(spdy_server_d, string_value_d); |
| 74 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | 74 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 75 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs)); | 75 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TEST_F(SpdyServerPropertiesTest, SupportsSpdyTest) { | 78 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { |
| 79 HostPortPair spdy_server_empty(std::string(), 443); | 79 HostPortPair spdy_server_empty(std::string(), 443); |
| 80 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty)); | 80 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); |
| 81 | 81 |
| 82 // Add www.google.com:443 as supporting SPDY. | 82 // Add www.google.com:443 as supporting SPDY. |
| 83 HostPortPair spdy_server_google("www.google.com", 443); | 83 HostPortPair spdy_server_google("www.google.com", 443); |
| 84 impl_.SetSupportsSpdy(spdy_server_google, true); | 84 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 85 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | 85 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 86 | 86 |
| 87 // Add mail.google.com:443 as not supporting SPDY. | 87 // Add mail.google.com:443 as not supporting SPDY. |
| 88 HostPortPair spdy_server_mail("mail.google.com", 443); | 88 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 89 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); | 89 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 90 | 90 |
| 91 // Add docs.google.com:443 as supporting SPDY. | 91 // Add docs.google.com:443 as supporting SPDY. |
| 92 HostPortPair spdy_server_docs("docs.google.com", 443); | 92 HostPortPair spdy_server_docs("docs.google.com", 443); |
| 93 impl_.SetSupportsSpdy(spdy_server_docs, true); | 93 impl_.SetSupportsSpdy(spdy_server_docs, true); |
| 94 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs)); | 94 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 95 |
| 96 // Add www.youtube.com:443 as supporting QUIC. |
| 97 HostPortPair quic_server_youtube("www.youtube.com", 443); |
| 98 impl_.SetAlternateProtocol(quic_server_youtube, 443, QUIC, 1); |
| 99 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
| 95 | 100 |
| 96 // Verify all the entries are the same after additions. | 101 // Verify all the entries are the same after additions. |
| 97 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | 102 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 98 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); | 103 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 99 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_docs)); | 104 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 100 } | 105 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
| 101 | |
| 102 TEST_F(SpdyServerPropertiesTest, SetSupportsSpdy) { | |
| 103 HostPortPair spdy_server_empty(std::string(), 443); | |
| 104 impl_.SetSupportsSpdy(spdy_server_empty, true); | |
| 105 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_empty)); | |
| 106 | |
| 107 // Add www.google.com:443 as supporting SPDY. | |
| 108 HostPortPair spdy_server_google("www.google.com", 443); | |
| 109 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | |
| 110 impl_.SetSupportsSpdy(spdy_server_google, true); | |
| 111 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | |
| 112 | |
| 113 // Make www.google.com:443 as not supporting SPDY. | |
| 114 impl_.SetSupportsSpdy(spdy_server_google, false); | |
| 115 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | |
| 116 | |
| 117 // Add mail.google.com:443 as supporting SPDY. | |
| 118 HostPortPair spdy_server_mail("mail.google.com", 443); | |
| 119 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); | |
| 120 impl_.SetSupportsSpdy(spdy_server_mail, true); | |
| 121 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail)); | |
| 122 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | |
| 123 } | 106 } |
| 124 | 107 |
| 125 TEST_F(SpdyServerPropertiesTest, Clear) { | 108 TEST_F(SpdyServerPropertiesTest, Clear) { |
| 126 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. | 109 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. |
| 127 HostPortPair spdy_server_google("www.google.com", 443); | 110 HostPortPair spdy_server_google("www.google.com", 443); |
| 128 impl_.SetSupportsSpdy(spdy_server_google, true); | 111 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 129 HostPortPair spdy_server_mail("mail.google.com", 443); | 112 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 130 impl_.SetSupportsSpdy(spdy_server_mail, true); | 113 impl_.SetSupportsSpdy(spdy_server_mail, true); |
| 131 | 114 |
| 132 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | 115 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 133 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_mail)); | 116 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 134 | 117 |
| 135 impl_.Clear(); | 118 impl_.Clear(); |
| 136 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | 119 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 137 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); | 120 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 138 } | 121 } |
| 139 | 122 |
| 140 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { | 123 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { |
| 141 base::ListValue spdy_server_list; | 124 base::ListValue spdy_server_list; |
| 142 | 125 |
| 143 // Check there are no spdy_servers. | 126 // Check there are no spdy_servers. |
| 144 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 127 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 145 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 128 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| 146 | 129 |
| 147 // Check empty server is not added. | 130 // Check empty server is not added. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 impl_.SetSupportsSpdy(spdy_server_mail, true); | 199 impl_.SetSupportsSpdy(spdy_server_mail, true); |
| 217 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 200 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 218 ASSERT_EQ(2U, spdy_server_list.GetSize()); | 201 ASSERT_EQ(2U, spdy_server_list.GetSize()); |
| 219 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); | 202 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); |
| 220 ASSERT_EQ(spdy_server_m, string_value_m); | 203 ASSERT_EQ(spdy_server_m, string_value_m); |
| 221 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g)); | 204 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g)); |
| 222 ASSERT_EQ(spdy_server_g, string_value_g); | 205 ASSERT_EQ(spdy_server_g, string_value_g); |
| 223 | 206 |
| 224 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it | 207 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it |
| 225 // is www.google.com:443 is the MRU server. | 208 // is www.google.com:443 is the MRU server. |
| 226 EXPECT_TRUE(impl_.SupportsSpdy(spdy_server_google)); | 209 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 227 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 210 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 228 ASSERT_EQ(2U, spdy_server_list.GetSize()); | 211 ASSERT_EQ(2U, spdy_server_list.GetSize()); |
| 229 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 212 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 230 ASSERT_EQ(spdy_server_g, string_value_g); | 213 ASSERT_EQ(spdy_server_g, string_value_g); |
| 231 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | 214 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); |
| 232 ASSERT_EQ(spdy_server_m, string_value_m); | 215 ASSERT_EQ(spdy_server_m, string_value_m); |
| 233 } | 216 } |
| 234 | 217 |
| 235 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 218 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
| 236 | 219 |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 778 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); |
| 796 | 779 |
| 797 impl_.Clear(); | 780 impl_.Clear(); |
| 798 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); | 781 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); |
| 799 EXPECT_EQ(NULL, stats3); | 782 EXPECT_EQ(NULL, stats3); |
| 800 } | 783 } |
| 801 | 784 |
| 802 } // namespace | 785 } // namespace |
| 803 | 786 |
| 804 } // namespace net | 787 } // namespace net |
| OLD | NEW |