summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-08 21:09:04 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-08 21:09:04 +0000
commit40e89fed7e91bd118aff7958cc44de16bf0d6d6e (patch)
tree70625002daad43eaa59ea0032b45baaa3443c4e4 /chrome/common
parent0510362557c58a6d3f26b9681b06a0e605c9cfd5 (diff)
downloadchromium_src-40e89fed7e91bd118aff7958cc44de16bf0d6d6e.zip
chromium_src-40e89fed7e91bd118aff7958cc44de16bf0d6d6e.tar.gz
chromium_src-40e89fed7e91bd118aff7958cc44de16bf0d6d6e.tar.bz2
Make TestURLFetcherFactory able to remove fetchers from its map, and add an ID accessor on TestURLFetcher, in preparation for more careful fetchre tracking in the GoogleURLTracker unittest.
BUG=54274 TEST=none Review URL: http://codereview.chromium.org/4509002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/net/test_url_fetcher_factory.cc14
-rw-r--r--chrome/common/net/test_url_fetcher_factory.h19
2 files changed, 24 insertions, 9 deletions
diff --git a/chrome/common/net/test_url_fetcher_factory.cc b/chrome/common/net/test_url_fetcher_factory.cc
index 6ab3a49..d99f442 100644
--- a/chrome/common/net/test_url_fetcher_factory.cc
+++ b/chrome/common/net/test_url_fetcher_factory.cc
@@ -1,13 +1,15 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/net/test_url_fetcher_factory.h"
-TestURLFetcher::TestURLFetcher(const GURL& url,
+TestURLFetcher::TestURLFetcher(int id,
+ const GURL& url,
URLFetcher::RequestType request_type,
URLFetcher::Delegate* d)
: URLFetcher(url, request_type, d),
+ id_(id),
original_url_(url) {
}
@@ -16,7 +18,7 @@ URLFetcher* TestURLFetcherFactory::CreateURLFetcher(
const GURL& url,
URLFetcher::RequestType request_type,
URLFetcher::Delegate* d) {
- TestURLFetcher* fetcher = new TestURLFetcher(url, request_type, d);
+ TestURLFetcher* fetcher = new TestURLFetcher(id, url, request_type, d);
fetchers_[id] = fetcher;
return fetcher;
}
@@ -25,3 +27,9 @@ TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const {
Fetchers::const_iterator i = fetchers_.find(id);
return i == fetchers_.end() ? NULL : i->second;
}
+
+void TestURLFetcherFactory::RemoveFetcherFromMap(int id) {
+ Fetchers::const_iterator i = fetchers_.find(id);
+ DCHECK(i != fetchers_.end());
+ fetchers_.erase(i);
+}
diff --git a/chrome/common/net/test_url_fetcher_factory.h b/chrome/common/net/test_url_fetcher_factory.h
index a831e3a..3afa19e 100644
--- a/chrome/common/net/test_url_fetcher_factory.h
+++ b/chrome/common/net/test_url_fetcher_factory.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -39,14 +39,17 @@
class TestURLFetcher : public URLFetcher {
public:
- TestURLFetcher(const GURL& url, RequestType request_type, Delegate* d);
-
- // Returns the delegate installed on the URLFetcher.
- Delegate* delegate() const { return URLFetcher::delegate(); }
+ TestURLFetcher(int id,
+ const GURL& url,
+ RequestType request_type,
+ Delegate* d);
// Overriden to do nothing. It is assumed the caller will notify the delegate.
virtual void Start() {}
+ // Unique ID in our factory.
+ int id() const { return id_; }
+
// URL we were created with. Because of how we're using URLFetcher url()
// always returns an empty URL. Chances are you'll want to use original_url()
// in your tests.
@@ -55,7 +58,11 @@ class TestURLFetcher : public URLFetcher {
// Returns the data uploaded on this URLFetcher.
const std::string& upload_data() const { return URLFetcher::upload_data(); }
+ // Returns the delegate installed on the URLFetcher.
+ Delegate* delegate() const { return URLFetcher::delegate(); }
+
private:
+ const int id_;
const GURL original_url_;
DISALLOW_COPY_AND_ASSIGN(TestURLFetcher);
@@ -71,8 +78,8 @@ class TestURLFetcherFactory : public URLFetcher::Factory {
const GURL& url,
URLFetcher::RequestType request_type,
URLFetcher::Delegate* d);
-
TestURLFetcher* GetFetcherByID(int id) const;
+ void RemoveFetcherFromMap(int id);
private:
// Maps from id passed to create to the returned URLFetcher.