| 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 09155b81ccc014ee4923e47c9146d15394a25471..9344168793ec1347135033ffcbb40a11b0b2c4c0 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;
|
| };
|
|
|
| - virtual 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);
|
|
|