OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <limits.h> | 5 #include <limits.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 | 1225 |
1226 TEST_F(SdchFilterTest, CanSetExactMatchDictionary) { | 1226 TEST_F(SdchFilterTest, CanSetExactMatchDictionary) { |
1227 std::string dictionary_domain("x.y.z.google.com"); | 1227 std::string dictionary_domain("x.y.z.google.com"); |
1228 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 1228 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
1229 | 1229 |
1230 // Perfect match should work. | 1230 // Perfect match should work. |
1231 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, | 1231 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, |
1232 GURL("http://" + dictionary_domain))); | 1232 GURL("http://" + dictionary_domain))); |
1233 } | 1233 } |
1234 | 1234 |
| 1235 TEST_F(SdchFilterTest, CanAdvertiseDictionaryOverHTTP) { |
| 1236 std::string dictionary_domain("x.y.z.google.com"); |
| 1237 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 1238 |
| 1239 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, |
| 1240 GURL("http://" + dictionary_domain))); |
| 1241 |
| 1242 std::string dictionary_list; |
| 1243 // HTTP target URL can advertise dictionary. |
| 1244 sdch_manager_->GetAvailDictionaryList( |
| 1245 GURL("http://" + dictionary_domain + "/test"), |
| 1246 &dictionary_list); |
| 1247 EXPECT_FALSE(dictionary_list.empty()); |
| 1248 } |
| 1249 |
| 1250 TEST_F(SdchFilterTest, CanNotAdvertiseDictionaryOverHTTPS) { |
| 1251 std::string dictionary_domain("x.y.z.google.com"); |
| 1252 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 1253 |
| 1254 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, |
| 1255 GURL("http://" + dictionary_domain))); |
| 1256 |
| 1257 std::string dictionary_list; |
| 1258 // HTTPS target URL should NOT advertise dictionary. |
| 1259 sdch_manager_->GetAvailDictionaryList( |
| 1260 GURL("https://" + dictionary_domain + "/test"), |
| 1261 &dictionary_list); |
| 1262 EXPECT_TRUE(dictionary_list.empty()); |
| 1263 } |
| 1264 |
| 1265 TEST_F(SdchFilterTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) { |
| 1266 std::string dictionary_domain("x.y.z.google.com"); |
| 1267 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 1268 |
| 1269 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, |
| 1270 GURL("https://" + dictionary_domain))); |
| 1271 |
| 1272 GURL target_url("https://" + dictionary_domain + "/test"); |
| 1273 std::string dictionary_list; |
| 1274 // HTTPS target URL should advertise dictionary if secure scheme support is |
| 1275 // enabled. |
| 1276 sdch_manager_->EnableSecureSchemeSupport(true); |
| 1277 sdch_manager_->GetAvailDictionaryList(target_url, &dictionary_list); |
| 1278 EXPECT_FALSE(dictionary_list.empty()); |
| 1279 |
| 1280 // Dictionary should be available. |
| 1281 SdchManager::Dictionary* dictionary = NULL; |
| 1282 std::string client_hash; |
| 1283 std::string server_hash; |
| 1284 sdch_manager_->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 1285 sdch_manager_->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
| 1286 EXPECT_TRUE(dictionary != NULL); |
| 1287 } |
| 1288 |
| 1289 TEST_F(SdchFilterTest, CanNotUseHTTPDictionaryOverHTTPS) { |
| 1290 std::string dictionary_domain("x.y.z.google.com"); |
| 1291 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
| 1292 |
| 1293 EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_text, |
| 1294 GURL("http://" + dictionary_domain))); |
| 1295 |
| 1296 GURL target_url("https://" + dictionary_domain + "/test"); |
| 1297 std::string dictionary_list; |
| 1298 // HTTPS target URL should not advertise dictionary acquired over HTTP even if |
| 1299 // secure scheme support is enabled. |
| 1300 sdch_manager_->EnableSecureSchemeSupport(true); |
| 1301 sdch_manager_->GetAvailDictionaryList(target_url, &dictionary_list); |
| 1302 EXPECT_TRUE(dictionary_list.empty()); |
| 1303 |
| 1304 SdchManager::Dictionary* dictionary = NULL; |
| 1305 std::string client_hash; |
| 1306 std::string server_hash; |
| 1307 sdch_manager_->GenerateHash(dictionary_text, &client_hash, &server_hash); |
| 1308 sdch_manager_->GetVcdiffDictionary(server_hash, target_url, &dictionary); |
| 1309 EXPECT_TRUE(dictionary == NULL); |
| 1310 } |
| 1311 |
1235 TEST_F(SdchFilterTest, FailToSetDomainMismatchDictionary) { | 1312 TEST_F(SdchFilterTest, FailToSetDomainMismatchDictionary) { |
1236 std::string dictionary_domain("x.y.z.google.com"); | 1313 std::string dictionary_domain("x.y.z.google.com"); |
1237 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); | 1314 std::string dictionary_text(NewSdchDictionary(dictionary_domain)); |
1238 | 1315 |
1239 // Fail the "domain match" requirement. | 1316 // Fail the "domain match" requirement. |
1240 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, | 1317 EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary_text, |
1241 GURL("http://y.z.google.com"))); | 1318 GURL("http://y.z.google.com"))); |
1242 } | 1319 } |
1243 | 1320 |
1244 TEST_F(SdchFilterTest, FailToSetDotHostPrefixDomainDictionary) { | 1321 TEST_F(SdchFilterTest, FailToSetDotHostPrefixDomainDictionary) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 sdch_manager_->SetAllowLatencyExperiment(url, false); | 1461 sdch_manager_->SetAllowLatencyExperiment(url, false); |
1385 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); | 1462 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); |
1386 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); | 1463 EXPECT_TRUE(sdch_manager_->AllowLatencyExperiment(url2)); |
1387 | 1464 |
1388 sdch_manager_->SetAllowLatencyExperiment(url2, false); | 1465 sdch_manager_->SetAllowLatencyExperiment(url2, false); |
1389 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); | 1466 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url)); |
1390 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); | 1467 EXPECT_FALSE(sdch_manager_->AllowLatencyExperiment(url2)); |
1391 } | 1468 } |
1392 | 1469 |
1393 } // namespace net | 1470 } // namespace net |
OLD | NEW |