Commit 69ae835f authored by dcheng@chromium.org's avatar dcheng@chromium.org

base::Bind() cleanup in URLFetcherImpl test.

BUG=none
TEST=content_unittests --gtest_filter=URLFetcher*

Review URL: http://codereview.chromium.org/8885002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114136 0039d316-1c4b-4281-b951-d872f2087c98
parent f4c1ca41
...@@ -326,24 +326,6 @@ TEST_F(URLFetcherTempFileTest, CanTakeOwnershipOfFile) { ...@@ -326,24 +326,6 @@ TEST_F(URLFetcherTempFileTest, CanTakeOwnershipOfFile) {
<< temp_file_.value() << " not removed."; << temp_file_.value() << " not removed.";
} }
// Wrapper that lets us call CreateFetcher() on a thread of our choice. We
// could make URLFetcherTest refcounted and use PostTask(FROM_HERE.. ) to call
// CreateFetcher() directly, but the ownership of the URLFetcherTest is a bit
// confusing in that case because GTest doesn't know about the refcounting.
// It's less confusing to just do it this way.
class FetcherWrapperTask : public Task {
public:
FetcherWrapperTask(URLFetcherTest* test, const GURL& url)
: test_(test), url_(url) { }
virtual void Run() {
test_->CreateFetcher(url_);
}
private:
URLFetcherTest* test_;
GURL url_;
};
void URLFetcherPostTest::CreateFetcher(const GURL& url) { void URLFetcherPostTest::CreateFetcher(const GURL& url) {
fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this); fetcher_ = new URLFetcherImpl(url, content::URLFetcher::POST, this);
fetcher_->SetRequestContext(new TestURLRequestContextGetter( fetcher_->SetRequestContext(new TestURLRequestContextGetter(
...@@ -571,8 +553,11 @@ TEST_F(URLFetcherTest, DifferentThreadsTest) { ...@@ -571,8 +553,11 @@ TEST_F(URLFetcherTest, DifferentThreadsTest) {
// scope. // scope.
base::Thread t("URLFetcher test thread"); base::Thread t("URLFetcher test thread");
ASSERT_TRUE(t.Start()); ASSERT_TRUE(t.Start());
t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, t.message_loop()->PostTask(
test_server.GetURL("defaultresponse"))); FROM_HERE,
base::Bind(&URLFetcherTest::CreateFetcher,
base::Unretained(this),
test_server.GetURL("defaultresponse")));
MessageLoop::current()->Run(); MessageLoop::current()->Run();
} }
...@@ -726,7 +711,9 @@ TEST_F(URLFetcherCancelTest, ReleasesContext) { ...@@ -726,7 +711,9 @@ TEST_F(URLFetcherCancelTest, ReleasesContext) {
// scope. // scope.
base::Thread t("URLFetcher test thread"); base::Thread t("URLFetcher test thread");
ASSERT_TRUE(t.Start()); ASSERT_TRUE(t.Start());
t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); t.message_loop()->PostTask(
FROM_HERE,
base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url));
MessageLoop::current()->Run(); MessageLoop::current()->Run();
...@@ -757,7 +744,9 @@ TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) { ...@@ -757,7 +744,9 @@ TEST_F(URLFetcherCancelTest, CancelWhileDelayedStartTaskPending) {
base::Thread t("URLFetcher test thread"); base::Thread t("URLFetcher test thread");
ASSERT_TRUE(t.Start()); ASSERT_TRUE(t.Start());
t.message_loop()->PostTask(FROM_HERE, new FetcherWrapperTask(this, url)); t.message_loop()->PostTask(
FROM_HERE,
base::Bind(&URLFetcherTest::CreateFetcher, base::Unretained(this), url));
MessageLoop::current()->Run(); MessageLoop::current()->Run();
...@@ -792,8 +781,7 @@ TEST_F(URLFetcherTest, CancelAll) { ...@@ -792,8 +781,7 @@ TEST_F(URLFetcherTest, CancelAll) {
io_message_loop_proxy()->PostTaskAndReply( io_message_loop_proxy()->PostTaskAndReply(
FROM_HERE, FROM_HERE,
base::Bind(&CancelAllOnIO), base::Bind(&CancelAllOnIO),
base::Bind(&MessageLoop::Quit, MessageLoop::QuitClosure());
base::Unretained(MessageLoop::current())));
MessageLoop::current()->Run(); MessageLoop::current()->Run();
EXPECT_EQ(0, GetNumFetcherCores()); EXPECT_EQ(0, GetNumFetcherCores());
delete fetcher_; delete fetcher_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment