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

Unified Diff: net/url_request/sdch_dictionary_fetcher_unittest.cc

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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/url_request/sdch_dictionary_fetcher.cc ('k') | net/url_request/url_fetcher_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 74%
rename from net/base/sdch_dictionary_fetcher_unittest.cc
rename to net/url_request/sdch_dictionary_fetcher_unittest.cc
index a8b814e77505e6e03a0aa9418013649c4faac43b..0febd7e9c4bc31c1438b196234fbb2cf3ef0c3f4 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"
@@ -31,8 +32,8 @@ class URLRequestSpecifiedResponseJob : public URLRequestSimpleJob {
static void AddUrlHandler() {
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
jobs_requested_ = 0;
- filter->AddHostnameHandler("http", kTestDomain,
- &URLRequestSpecifiedResponseJob::Factory);
+ filter->AddHostnameHandler(
+ "http", kTestDomain, &URLRequestSpecifiedResponseJob::Factory);
}
static void RemoveUrlHandler() {
@@ -41,17 +42,17 @@ class URLRequestSpecifiedResponseJob : public URLRequestSimpleJob {
jobs_requested_ = 0;
}
- static URLRequestJob* Factory(
- URLRequest* request,
- net::NetworkDelegate* network_delegate,
- const std::string& scheme) {
+ static URLRequestJob* Factory(URLRequest* request,
+ net::NetworkDelegate* network_delegate,
+ const std::string& scheme) {
++jobs_requested_;
return new URLRequestSpecifiedResponseJob(request, network_delegate);
}
static std::string ExpectedResponseForURL(const GURL& url) {
return base::StringPrintf("Response for %s\n%s\nEnd Response for %s\n",
- url.spec().c_str(), kSampleBufferContext,
+ url.spec().c_str(),
+ kSampleBufferContext,
url.spec().c_str());
}
@@ -73,21 +74,32 @@ 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,
const GURL& dictionary_url)
- : dictionary_text(dictionary_text),
- dictionary_url(dictionary_url) {}
-
+ : dictionary_text(dictionary_text), dictionary_url(dictionary_url) {}
std::string dictionary_text;
GURL dictionary_url;
};
- void AddSdchDictionary(const std::string& dictionary_text,
- const GURL& dictionary_url) override {
+ SdchDictionaryFetcherTest() {
+ URLRequestSpecifiedResponseJob::AddUrlHandler();
+ context_.reset(new TestURLRequestContext);
+ fetcher_.reset(new SdchDictionaryFetcher(
+ context_.get(),
+ base::Bind(&SdchDictionaryFetcherTest::OnDictionaryFetched,
+ base::Unretained(this))));
+ }
+
+ ~SdchDictionaryFetcherTest() {
+ URLRequestSpecifiedResponseJob::RemoveUrlHandler();
+ }
+
+ void OnDictionaryFetched(const std::string& dictionary_text,
+ const GURL& dictionary_url) {
dictionary_additions.push_back(
DictionaryAdditions(dictionary_text, dictionary_url));
}
@@ -97,33 +109,7 @@ class SdchTestDelegate : public SdchFetcher::Delegate {
dictionary_additions.clear();
}
- private:
- std::vector<DictionaryAdditions> dictionary_additions;
-};
-
-class SdchDictionaryFetcherTest : public ::testing::Test {
- public:
- SdchDictionaryFetcherTest() {}
-
- 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()));
- }
-
- void TearDown() override {
- URLRequestSpecifiedResponseJob::RemoveUrlHandler();
- fetcher_.reset();
- context_.reset();
- fetcher_delegate_.reset();
- }
-
SdchDictionaryFetcher* fetcher() { return fetcher_.get(); }
- SdchTestDelegate* manager() { return fetcher_delegate_.get(); }
// May not be called outside the SetUp()/TearDown() interval.
int JobsRequested() {
@@ -139,9 +125,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,11 +137,12 @@ 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);
+ EXPECT_EQ(
+ URLRequestSpecifiedResponseJob::ExpectedResponseForURL(dictionary_url),
+ additions[0].dictionary_text);
}
// Multiple fetches of the same URL should result in only one request.
@@ -167,11 +154,12 @@ 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);
+ EXPECT_EQ(
+ URLRequestSpecifiedResponseJob::ExpectedResponseForURL(dictionary_url),
+ additions[0].dictionary_text);
}
// A cancel should result in no actual requests being generated.
@@ -189,5 +177,4 @@ TEST_F(SdchDictionaryFetcherTest, Cancel) {
// Synchronous execution may have resulted in a single job being scheduled.
EXPECT_GE(1, JobsRequested());
}
-
}
« no previous file with comments | « net/url_request/sdch_dictionary_fetcher.cc ('k') | net/url_request/url_fetcher_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698