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

Unified Diff: chrome/browser/net/url_fetcher_unittest.cc

Issue 1702016: Changed UrlFetcher to use a MessageLoopProxy instead of directly relying on C... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 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
« no previous file with comments | « chrome/browser/net/url_fetcher.cc ('k') | chrome/browser/net/url_request_context_getter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/url_fetcher_unittest.cc
===================================================================
--- chrome/browser/net/url_fetcher_unittest.cc (revision 46098)
+++ chrome/browser/net/url_fetcher_unittest.cc (working copy)
@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/message_loop_proxy.h"
#include "base/thread.h"
-#include "base/time.h"
-#include "base/timer.h"
+#include "base/waitable_event.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/url_fetcher.h"
#include "chrome/browser/net/url_fetcher_protect.h"
@@ -31,6 +31,10 @@
context_ = new TestURLRequestContext();
return context_;
}
+ virtual scoped_refptr<MessageLoopProxy> GetIOMessageLoopProxy() {
+ return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO);
+ }
+
private:
~TestURLRequestContextGetter() {}
@@ -159,9 +163,6 @@
const std::string& data);
void CancelRequest();
-
- private:
- base::OneShotTimer<URLFetcherCancelTest> timer_;
};
// Version of TestURLRequestContext that posts a Quit task to the IO
@@ -175,15 +176,26 @@
class CancelTestURLRequestContextGetter : public URLRequestContextGetter {
public:
+ CancelTestURLRequestContextGetter() : context_created_(false, false) {
+ }
virtual URLRequestContext* GetURLRequestContext() {
- if (!context_)
+ if (!context_) {
context_ = new CancelTestURLRequestContext();
+ context_created_.Signal();
+ }
return context_;
}
+ virtual scoped_refptr<MessageLoopProxy> GetIOMessageLoopProxy() {
+ return ChromeThread::GetMessageLoopProxyForThread(ChromeThread::IO);
+ }
+ void WaitForContextCreation() {
+ context_created_.Wait();
+ }
private:
~CancelTestURLRequestContextGetter() {}
+ base::WaitableEvent context_created_;
scoped_refptr<URLRequestContext> context_;
};
@@ -374,16 +386,14 @@
void URLFetcherCancelTest::CreateFetcher(const GURL& url) {
fetcher_ = new URLFetcher(url, URLFetcher::GET, this);
- // We need to force the creation of the URLRequestContext, since we
- // rely on it being destroyed as a signal to end the test.
- URLRequestContextGetter* context_getter =
- new CancelTestURLRequestContextGetter();
- context_getter->GetURLRequestContext();
+ CancelTestURLRequestContextGetter* context_getter =
+ new CancelTestURLRequestContextGetter;
fetcher_->set_request_context(context_getter);
fetcher_->Start();
- // Make sure we give the IO thread a chance to run.
- timer_.Start(TimeDelta::FromMilliseconds(300), this,
- &URLFetcherCancelTest::CancelRequest);
+ // We need to wait for the creation of the URLRequestContext, since we
+ // rely on it being destroyed as a signal to end the test.
+ context_getter->WaitForContextCreation();
+ CancelRequest();
}
void URLFetcherCancelTest::OnURLFetchComplete(const URLFetcher* source,
@@ -401,7 +411,6 @@
void URLFetcherCancelTest::CancelRequest() {
delete fetcher_;
- timer_.Stop();
// The URLFetcher's test context will post a Quit task once it is
// deleted. So if this test simply hangs, it means cancellation
// did not work.
« no previous file with comments | « chrome/browser/net/url_fetcher.cc ('k') | chrome/browser/net/url_request_context_getter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698