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

Unified Diff: net/base/sdch_manager_unittest.cc

Issue 423813002: Sdch view for net-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix component linkage Created 6 years, 1 month 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/sdch_manager.cc ('k') | net/base/sdch_net_log_params.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/sdch_manager_unittest.cc
diff --git a/net/base/sdch_manager_unittest.cc b/net/base/sdch_manager_unittest.cc
index d986879aaa4c9b9928039f3290731e5ca49f0b0f..c20be5838086956415006401df998e23a617b7a3 100644
--- a/net/base/sdch_manager_unittest.cc
+++ b/net/base/sdch_manager_unittest.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "net/base/net_log.h"
#include "net/base/sdch_manager.h"
#include "net/base/sdch_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -73,14 +74,7 @@ class SdchManagerTest : public testing::Test {
// failure.
bool AddSdchDictionary(const std::string& dictionary_text,
const GURL& gurl) {
- std::string list;
- sdch_manager_->GetAvailDictionaryList(gurl, &list);
- sdch_manager_->AddSdchDictionary(dictionary_text, gurl);
- std::string list2;
- sdch_manager_->GetAvailDictionaryList(gurl, &list2);
-
- // The list of hashes should change iff the addition succeeds.
- return (list != list2);
+ return sdch_manager_->AddSdchDictionary(dictionary_text, gurl) == SDCH_OK;
}
private:
@@ -105,31 +99,34 @@ TEST_F(SdchManagerTest, DomainSupported) {
GURL google_url("http://www.google.com");
SdchManager::EnableSdchSupport(false);
- EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url));
+ EXPECT_EQ(SDCH_DISABLED, sdch_manager()->IsInSupportedDomain(google_url));
SdchManager::EnableSdchSupport(true);
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url));
}
TEST_F(SdchManagerTest, DomainBlacklisting) {
GURL test_url("http://www.test.com");
GURL google_url("http://www.google.com");
- sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE);
- EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test_url));
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(google_url));
+ sdch_manager()->BlacklistDomain(test_url, SDCH_OK);
+ EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
+ sdch_manager()->IsInSupportedDomain(test_url));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(google_url));
- sdch_manager()->BlacklistDomain(google_url, SdchManager::MIN_PROBLEM_CODE);
- EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(google_url));
+ sdch_manager()->BlacklistDomain(google_url, SDCH_OK);
+ EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
+ sdch_manager()->IsInSupportedDomain(google_url));
}
TEST_F(SdchManagerTest, DomainBlacklistingCaseSensitivity) {
GURL test_url("http://www.TesT.com");
GURL test2_url("http://www.tEst.com");
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test_url));
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(test2_url));
- sdch_manager()->BlacklistDomain(test_url, SdchManager::MIN_PROBLEM_CODE);
- EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(test2_url));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(test_url));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(test2_url));
+ sdch_manager()->BlacklistDomain(test_url, SDCH_OK);
+ EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
+ sdch_manager()->IsInSupportedDomain(test2_url));
}
TEST_F(SdchManagerTest, BlacklistingReset) {
@@ -139,7 +136,7 @@ TEST_F(SdchManagerTest, BlacklistingReset) {
sdch_manager()->ClearBlacklistings();
EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 0);
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
}
TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) {
@@ -147,14 +144,15 @@ TEST_F(SdchManagerTest, BlacklistingSingleBlacklist) {
std::string domain(gurl.host());
sdch_manager()->ClearBlacklistings();
- sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE);
+ sdch_manager()->BlacklistDomain(gurl, SDCH_OK);
EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 1);
EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), 1);
// Check that any domain lookup reduces the blacklist counter.
- EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl));
+ EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
+ sdch_manager()->IsInSupportedDomain(gurl));
EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
}
TEST_F(SdchManagerTest, BlacklistingExponential) {
@@ -164,18 +162,19 @@ TEST_F(SdchManagerTest, BlacklistingExponential) {
int exponential = 1;
for (int i = 1; i < 100; ++i) {
- sdch_manager()->BlacklistDomain(gurl, SdchManager::MIN_PROBLEM_CODE);
+ sdch_manager()->BlacklistDomain(gurl, SDCH_OK);
EXPECT_EQ(sdch_manager()->BlacklistDomainExponential(domain), exponential);
EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential);
- EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(gurl));
+ EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
+ sdch_manager()->IsInSupportedDomain(gurl));
EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), exponential - 1);
// Simulate a large number of domain checks (which eventually remove the
// blacklisting).
sdch_manager()->ClearDomainBlacklisting(domain);
EXPECT_EQ(sdch_manager()->BlackListDomainCount(domain), 0);
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(gurl));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(gurl));
// Predict what exponential backoff will be.
exponential = 1 + 2 * exponential;
@@ -246,7 +245,8 @@ TEST_F(SdchManagerTest, CanUseHTTPSDictionaryOverHTTPSIfEnabled) {
std::string client_hash;
std::string server_hash;
sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
- sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
+ EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary(
+ server_hash, target_url, &dictionary));
EXPECT_TRUE(dictionary.get() != NULL);
}
@@ -269,7 +269,9 @@ TEST_F(SdchManagerTest, CanNotUseHTTPDictionaryOverHTTPS) {
std::string client_hash;
std::string server_hash;
sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
- sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
+ EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME,
+ sdch_manager()->GetVcdiffDictionary(server_hash, target_url,
+ &dictionary));
EXPECT_TRUE(dictionary.get() == NULL);
}
@@ -292,7 +294,9 @@ TEST_F(SdchManagerTest, CanNotUseHTTPSDictionaryOverHTTP) {
std::string client_hash;
std::string server_hash;
sdch_manager()->GenerateHash(dictionary_text, &client_hash, &server_hash);
- sdch_manager()->GetVcdiffDictionary(server_hash, target_url, &dictionary);
+ EXPECT_EQ(SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME,
+ sdch_manager()->GetVcdiffDictionary(server_hash, target_url,
+ &dictionary));
EXPECT_TRUE(dictionary.get() == NULL);
}
@@ -516,10 +520,10 @@ TEST_F(SdchManagerTest, CanUseMultipleManagers) {
EXPECT_TRUE(AddSdchDictionary(dictionary_text_1,
GURL("http://" + dictionary_domain_1)));
scoped_refptr<SdchManager::Dictionary> dictionary;
- sdch_manager()->GetVcdiffDictionary(
- server_hash_1,
- GURL("http://" + dictionary_domain_1 + "/random_url"),
- &dictionary);
+ EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary(
+ server_hash_1,
+ GURL("http://" + dictionary_domain_1 + "/random_url"),
+ &dictionary));
EXPECT_TRUE(dictionary.get());
second_manager.AddSdchDictionary(
@@ -530,16 +534,18 @@ TEST_F(SdchManagerTest, CanUseMultipleManagers) {
&dictionary);
EXPECT_TRUE(dictionary.get());
- sdch_manager()->GetVcdiffDictionary(
- server_hash_2,
- GURL("http://" + dictionary_domain_2 + "/random_url"),
- &dictionary);
+ EXPECT_EQ(
+ SDCH_DICTIONARY_HASH_NOT_FOUND,
+ sdch_manager()->GetVcdiffDictionary(
+ server_hash_2, GURL("http://" + dictionary_domain_2 + "/random_url"),
+ &dictionary));
EXPECT_FALSE(dictionary.get());
- second_manager.GetVcdiffDictionary(
- server_hash_1,
- GURL("http://" + dictionary_domain_1 + "/random_url"),
- &dictionary);
+ EXPECT_EQ(
+ SDCH_DICTIONARY_HASH_NOT_FOUND,
+ second_manager.GetVcdiffDictionary(
+ server_hash_1, GURL("http://" + dictionary_domain_1 + "/random_url"),
+ &dictionary));
EXPECT_FALSE(dictionary.get());
}
@@ -549,14 +555,15 @@ TEST_F(SdchManagerTest, HttpsCorrectlySupported) {
bool expect_https_support = true;
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
- EXPECT_EQ(expect_https_support,
- sdch_manager()->IsInSupportedDomain(secure_url));
+ SdchProblemCode expected_code =
+ expect_https_support ? SDCH_OK : SDCH_SECURE_SCHEME_NOT_SUPPORTED;
+
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(url));
+ EXPECT_EQ(expected_code, sdch_manager()->IsInSupportedDomain(secure_url));
SdchManager::EnableSecureSchemeSupport(!expect_https_support);
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(url));
- EXPECT_NE(expect_https_support,
- sdch_manager()->IsInSupportedDomain(secure_url));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(url));
+ EXPECT_NE(expected_code, sdch_manager()->IsInSupportedDomain(secure_url));
}
TEST_F(SdchManagerTest, ClearDictionaryData) {
@@ -572,25 +579,26 @@ TEST_F(SdchManagerTest, ClearDictionaryData) {
EXPECT_TRUE(AddSdchDictionary(dictionary_text,
GURL("http://" + dictionary_domain)));
scoped_refptr<SdchManager::Dictionary> dictionary;
- sdch_manager()->GetVcdiffDictionary(
- server_hash,
- GURL("http://" + dictionary_domain + "/random_url"),
- &dictionary);
+ EXPECT_EQ(SDCH_OK, sdch_manager()->GetVcdiffDictionary(
+ server_hash,
+ GURL("http://" + dictionary_domain + "/random_url"),
+ &dictionary));
EXPECT_TRUE(dictionary.get());
- sdch_manager()->BlacklistDomain(GURL(blacklist_url),
- SdchManager::MIN_PROBLEM_CODE);
- EXPECT_FALSE(sdch_manager()->IsInSupportedDomain(blacklist_url));
+ sdch_manager()->BlacklistDomain(GURL(blacklist_url), SDCH_OK);
+ EXPECT_EQ(SDCH_DOMAIN_BLACKLIST_INCLUDES_TARGET,
+ sdch_manager()->IsInSupportedDomain(blacklist_url));
sdch_manager()->ClearData();
dictionary = NULL;
- sdch_manager()->GetVcdiffDictionary(
- server_hash,
- GURL("http://" + dictionary_domain + "/random_url"),
- &dictionary);
+ EXPECT_EQ(
+ SDCH_DICTIONARY_HASH_NOT_FOUND,
+ sdch_manager()->GetVcdiffDictionary(
+ server_hash, GURL("http://" + dictionary_domain + "/random_url"),
+ &dictionary));
EXPECT_FALSE(dictionary.get());
- EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url));
+ EXPECT_EQ(SDCH_OK, sdch_manager()->IsInSupportedDomain(blacklist_url));
}
TEST_F(SdchManagerTest, GetDictionaryNotification) {
« no previous file with comments | « net/base/sdch_manager.cc ('k') | net/base/sdch_net_log_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698