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

Unified Diff: net/url_request/sdch_dictionary_fetcher_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: Sync'd to p300953. Created 6 years, 2 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/url_request/sdch_dictionary_fetcher_unittest.cc
diff --git a/net/base/sdch_dictionary_fetcher_unittest.cc b/net/url_request/sdch_dictionary_fetcher_unittest.cc
similarity index 88%
rename from net/base/sdch_dictionary_fetcher_unittest.cc
rename to net/url_request/sdch_dictionary_fetcher_unittest.cc
index af666813711e827267e172052f35919b4e207d8b..c3f3481c766dbaf13bac1d560c818f0272c6327c 100644
--- a/net/base/sdch_dictionary_fetcher_unittest.cc
+++ b/net/url_request/sdch_dictionary_fetcher_unittest.cc
@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/base/sdch_dictionary_fetcher.h"
+#include "net/url_request/sdch_dictionary_fetcher.h"
#include <string>
+#include "base/bind.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/thread_task_runner_handle.h"
@@ -73,7 +74,7 @@ class URLRequestSpecifiedResponseJob : public URLRequestSimpleJob {
int URLRequestSpecifiedResponseJob::jobs_requested_(0);
-class SdchTestDelegate : public SdchFetcher::Delegate {
+class SdchDictionaryFetcherTest : public ::testing::Test {
public:
struct DictionaryAdditions {
DictionaryAdditions(const std::string& dictionary_text,
@@ -86,44 +87,37 @@ class SdchTestDelegate : public SdchFetcher::Delegate {
GURL dictionary_url;
};
- void AddSdchDictionary(const std::string& dictionary_text,
- const GURL& dictionary_url) override {
- dictionary_additions.push_back(
- DictionaryAdditions(dictionary_text, dictionary_url));
- }
-
- void GetDictionaryAdditions(std::vector<DictionaryAdditions>* out) {
- out->swap(dictionary_additions);
- dictionary_additions.clear();
- }
-
- private:
- std::vector<DictionaryAdditions> dictionary_additions;
-};
-
-class SdchDictionaryFetcherTest : public ::testing::Test {
- public:
SdchDictionaryFetcherTest() {}
virtual void SetUp() override {
DCHECK(!fetcher_.get());
URLRequestSpecifiedResponseJob::AddUrlHandler();
- fetcher_delegate_.reset(new SdchTestDelegate);
context_.reset(new TestURLRequestContext);
fetcher_.reset(new SdchDictionaryFetcher(
- fetcher_delegate_.get(), context_.get()));
+ context_.get(),
+ base::Bind(&SdchDictionaryFetcherTest::OnDictionaryFetched,
+ base::Unretained(this))));
}
virtual void TearDown() override {
URLRequestSpecifiedResponseJob::RemoveUrlHandler();
fetcher_.reset();
context_.reset();
- fetcher_delegate_.reset();
+ }
+
+ void OnDictionaryFetched(const std::string& dictionary_text,
+ const GURL& dictionary_url) {
+ dictionary_additions.push_back(
+ DictionaryAdditions(dictionary_text, dictionary_url));
+ }
+
+ void GetDictionaryAdditions(std::vector<DictionaryAdditions>* out) {
+ out->swap(dictionary_additions);
+ dictionary_additions.clear();
}
SdchDictionaryFetcher* fetcher() { return fetcher_.get(); }
- SdchTestDelegate* manager() { return fetcher_delegate_.get(); }
// May not be called outside the SetUp()/TearDown() interval.
int JobsRequested() {
@@ -139,9 +133,9 @@ class SdchDictionaryFetcherTest : public ::testing::Test {
}
private:
- scoped_ptr<SdchTestDelegate> fetcher_delegate_;
scoped_ptr<TestURLRequestContext> context_;
scoped_ptr<SdchDictionaryFetcher> fetcher_;
+ std::vector<DictionaryAdditions> dictionary_additions;
};
// Schedule a fetch and make sure it happens.
@@ -151,8 +145,8 @@ TEST_F(SdchDictionaryFetcherTest, Basic) {
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, JobsRequested());
- std::vector<SdchTestDelegate::DictionaryAdditions> additions;
- manager()->GetDictionaryAdditions(&additions);
+ std::vector<DictionaryAdditions> additions;
+ GetDictionaryAdditions(&additions);
ASSERT_EQ(1u, additions.size());
EXPECT_EQ(URLRequestSpecifiedResponseJob::ExpectedResponseForURL(
dictionary_url), additions[0].dictionary_text);
@@ -167,8 +161,8 @@ TEST_F(SdchDictionaryFetcherTest, Multiple) {
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, JobsRequested());
- std::vector<SdchTestDelegate::DictionaryAdditions> additions;
- manager()->GetDictionaryAdditions(&additions);
+ std::vector<DictionaryAdditions> additions;
+ GetDictionaryAdditions(&additions);
ASSERT_EQ(1u, additions.size());
EXPECT_EQ(URLRequestSpecifiedResponseJob::ExpectedResponseForURL(
dictionary_url), additions[0].dictionary_text);

Powered by Google App Engine
This is Rietveld 408576698