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

Unified Diff: net/base/sdch_manager_unittest.cc

Issue 1133763003: SdchObserver: add OnDictionary{Added,Removed} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove manager parameter from SdchObserver Created 5 years, 7 months 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
Index: net/base/sdch_manager_unittest.cc
diff --git a/net/base/sdch_manager_unittest.cc b/net/base/sdch_manager_unittest.cc
index ba3248e3de8601c3b5701b4ac21c4376a55fb4df..9bb0e7ef05be4e7331fdf5a556c9c0bf3186acdb 100644
--- a/net/base/sdch_manager_unittest.cc
+++ b/net/base/sdch_manager_unittest.cc
@@ -29,10 +29,18 @@ static const char kTestVcdiffDictionary[] = "DictionaryFor"
class MockSdchObserver : public SdchObserver {
public:
MockSdchObserver()
- : dictionary_used_notifications_(0),
+ : dictionary_added_notifications_(0),
+ dictionary_removed_notifications_(0),
+ dictionary_used_notifications_(0),
get_dictionary_notifications_(0),
clear_dictionaries_notifications_(0) {}
+ int dictionary_added_notifications() const {
+ return dictionary_added_notifications_;
+ }
+ int dictionary_removed_notifications() const {
+ return dictionary_removed_notifications_;
+ }
std::string last_server_hash() const { return last_server_hash_; }
int dictionary_used_notifications() const {
return dictionary_used_notifications_;
@@ -50,24 +58,34 @@ class MockSdchObserver : public SdchObserver {
}
// SdchObserver implementation
- void OnDictionaryUsed(SdchManager* manager,
- const std::string& server_hash) override {
+ void OnDictionaryAdded(const GURL& dictionary_url,
+ const std::string& server_hash) override {
+ last_server_hash_ = server_hash;
+ last_dictionary_url_ = dictionary_url;
+ ++dictionary_added_notifications_;
+ }
+ void OnDictionaryRemoved(const std::string& server_hash) override {
+ last_server_hash_ = server_hash;
+ ++dictionary_removed_notifications_;
+ }
+ void OnDictionaryUsed(const std::string& server_hash) override {
last_server_hash_ = server_hash;
++dictionary_used_notifications_;
}
- void OnGetDictionary(SdchManager* manager,
- const GURL& request_url,
+ void OnGetDictionary(const GURL& request_url,
const GURL& dictionary_url) override {
++get_dictionary_notifications_;
last_dictionary_request_url_ = request_url;
last_dictionary_url_ = dictionary_url;
}
- void OnClearDictionaries(SdchManager* manager) override {
+ void OnClearDictionaries() override {
++clear_dictionaries_notifications_;
}
private:
+ int dictionary_added_notifications_;
+ int dictionary_removed_notifications_;
int dictionary_used_notifications_;
int get_dictionary_notifications_;
int clear_dictionaries_notifications_;
@@ -628,19 +646,37 @@ TEST_F(SdchManagerTest, SdchDictionaryUsed) {
std::string server_hash;
SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash);
EXPECT_TRUE(AddSdchDictionary(dictionary_text, target_gurl));
- EXPECT_EQ("xyzzy", observer.last_server_hash());
EXPECT_EQ(1, observer.dictionary_used_notifications());
EXPECT_TRUE(sdch_manager()->GetDictionarySet(target_gurl));
- EXPECT_EQ("xyzzy", observer.last_server_hash());
EXPECT_EQ(1, observer.dictionary_used_notifications());
sdch_manager()->RemoveObserver(&observer);
EXPECT_EQ(1, observer.dictionary_used_notifications());
- EXPECT_EQ("xyzzy", observer.last_server_hash());
sdch_manager()->OnDictionaryUsed("plugh");
EXPECT_EQ(1, observer.dictionary_used_notifications());
- EXPECT_EQ("xyzzy", observer.last_server_hash());
+}
+
+TEST_F(SdchManagerTest, AddRemoveNotifications) {
+ MockSdchObserver observer;
+ sdch_manager()->AddObserver(&observer);
+
+ std::string dictionary_domain("x.y.z.google.com");
+ GURL target_gurl("http://" + dictionary_domain);
+ std::string dictionary_text(NewSdchDictionary(dictionary_domain));
+ std::string client_hash;
+ std::string server_hash;
+ SdchManager::GenerateHash(dictionary_text, &client_hash, &server_hash);
+ EXPECT_TRUE(AddSdchDictionary(dictionary_text, target_gurl));
+ EXPECT_EQ(1, observer.dictionary_added_notifications());
+ EXPECT_EQ(target_gurl, observer.last_dictionary_url());
+ EXPECT_EQ(server_hash, observer.last_server_hash());
+
+ EXPECT_EQ(SDCH_OK, sdch_manager()->RemoveSdchDictionary(server_hash));
+ EXPECT_EQ(1, observer.dictionary_removed_notifications());
+ EXPECT_EQ(server_hash, observer.last_server_hash());
+
+ sdch_manager()->RemoveObserver(&observer);
}
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698