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

Unified Diff: net/base/sdch_manager_unittest.cc

Issue 664263002: Restructure SDCH layering to allow more separation (observer/1->[0,n] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated comments. 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
Index: net/base/sdch_manager_unittest.cc
diff --git a/net/base/sdch_manager_unittest.cc b/net/base/sdch_manager_unittest.cc
index 40b55c671ec4bf7543092a7a5bd130d0d234a197..e4dd1bb54247c5e269973644b56b6b9220aa45d7 100644
--- a/net/base/sdch_manager_unittest.cc
+++ b/net/base/sdch_manager_unittest.cc
@@ -9,7 +9,9 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/sdch_manager.h"
+#include "net/base/sdch_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
namespace net {
@@ -25,16 +27,20 @@ static const char kTestVcdiffDictionary[] = "DictionaryFor"
//------------------------------------------------------------------------------
-class SdchManagerTest : public testing::Test {
+class SdchManagerTest : public testing::Test, public SdchObserver {
protected:
SdchManagerTest()
: sdch_manager_(new SdchManager),
default_support_(false),
- default_https_support_(false) {
+ default_https_support_(false),
+ get_dictionary_notifications_(0) {
default_support_ = sdch_manager_->sdch_enabled();
default_https_support_ = sdch_manager_->secure_scheme_supported();
+ sdch_manager_->AddObserver(this);
}
+ virtual ~SdchManagerTest() { sdch_manager_->RemoveObserver(this); }
+
SdchManager* sdch_manager() { return sdch_manager_.get(); }
// Reset globals back to default state.
@@ -57,10 +63,29 @@ class SdchManagerTest : public testing::Test {
return (list != list2);
}
+ const GURL& last_dictionary_request_url() {
+ return last_dictionary_request_url_;
+ }
+ const GURL& last_dictionary_url() { return last_dictionary_url_; }
+ int get_dictionary_notifications() { return get_dictionary_notifications_; }
+
+ // SdchObserver implementation
+ void OnGetDictionary(SdchManager* manager,
+ 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 {}
+
private:
scoped_ptr<SdchManager> sdch_manager_;
bool default_support_;
bool default_https_support_;
+ int get_dictionary_notifications_;
+ GURL last_dictionary_request_url_;
+ GURL last_dictionary_url_;
};
static std::string NewSdchDictionary(const std::string& domain) {
@@ -572,6 +597,17 @@ TEST_F(SdchManagerTest, ClearDictionaryData) {
EXPECT_TRUE(sdch_manager()->IsInSupportedDomain(blacklist_url));
}
+TEST_F(SdchManagerTest, GetDictionaryNotification) {
Ryan Sleevi 2014/11/05 22:21:39 Pedantry: You don't test that _removing_ the obser
Randy Smith (Not in Mondays) 2014/11/05 23:49:59 Good point. Done.
+ GURL test_request_gurl(GURL("http://www.example.com/data"));
+ GURL test_dictionary_gurl(GURL("http://www.example.com/dict"));
+
+ EXPECT_EQ(0, get_dictionary_notifications());
+ sdch_manager()->OnGetDictionary(test_request_gurl, test_dictionary_gurl);
+ EXPECT_EQ(1, get_dictionary_notifications());
+ EXPECT_EQ(test_request_gurl, last_dictionary_request_url());
+ EXPECT_EQ(test_dictionary_gurl, last_dictionary_url());
+}
+
#else
TEST(SdchManagerTest, SdchOffByDefault) {

Powered by Google App Engine
This is Rietveld 408576698