summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_unittest.h
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-29 21:59:55 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-29 21:59:55 +0000
commitcad01431b348b5c01ded71f05f2f30f8dcc41d22 (patch)
tree8594c4da331d50d7bd5db3e8abf96858da5d7fd8 /net/url_request/url_request_unittest.h
parent5ebeb1191489135b549a38e1490b5b944776a50d (diff)
downloadchromium_src-cad01431b348b5c01ded71f05f2f30f8dcc41d22.zip
chromium_src-cad01431b348b5c01ded71f05f2f30f8dcc41d22.tar.gz
chromium_src-cad01431b348b5c01ded71f05f2f30f8dcc41d22.tar.bz2
Provide the option for HTTPServer to be created with a specific
MessageLoop. I'm going to need this when running ui tests in process. In this case I'll pass in the IO thread. I'll change all callers to use the new method, but before doing that wanted to make sure you're ok with it. BUG=none TEST=none Review URL: http://codereview.chromium.org/19039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8915 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request/url_request_unittest.h')
-rw-r--r--net/url_request/url_request_unittest.h31
1 files changed, 23 insertions, 8 deletions
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index 9389ce8..fff11f3 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -410,12 +410,16 @@ class BaseTestServer : public base::ProcessFilter,
class HTTPTestServer : public BaseTestServer {
protected:
- HTTPTestServer() {
+ explicit HTTPTestServer() : loop_(NULL) {
}
public:
- static HTTPTestServer* CreateServer(const std::wstring& document_root) {
+ // Creates and returns a new HTTPTestServer. If |loop| is non-null, requests
+ // are serviced on it, otherwise a new thread and message loop are created.
+ static HTTPTestServer* CreateServer(const std::wstring& document_root,
+ MessageLoop* loop) {
HTTPTestServer* test_server = new HTTPTestServer();
+ test_server->loop_ = loop;
if (!test_server->Init(kDefaultHostName, kHTTPDefaultPort, document_root)) {
delete test_server;
return NULL;
@@ -456,12 +460,18 @@ class HTTPTestServer : public BaseTestServer {
// message loop, we also want to avoid spinning a nested message loop.
SyncTestDelegate d;
{
- base::Thread io_thread("MakeGETRequest");
- base::Thread::Options options;
- options.message_loop_type = MessageLoop::TYPE_IO;
- io_thread.StartWithOptions(options);
- io_thread.message_loop()->PostTask(FROM_HERE, NewRunnableFunction(
- &HTTPTestServer::StartGETRequest, url, &d));
+ MessageLoop* loop = loop_;
+ scoped_ptr<base::Thread> io_thread;
+
+ if (!loop) {
+ io_thread.reset(new base::Thread("MakeGETRequest"));
+ base::Thread::Options options;
+ options.message_loop_type = MessageLoop::TYPE_IO;
+ io_thread->StartWithOptions(options);
+ loop = io_thread->message_loop();
+ }
+ loop->PostTask(FROM_HERE, NewRunnableFunction(
+ &HTTPTestServer::StartGETRequest, url, &d));
// Build bot wait for only 300 seconds we should ensure wait do not take
// more than 300 seconds
@@ -519,6 +529,11 @@ class HTTPTestServer : public BaseTestServer {
command_line->push_back("--data-dir=" + WideToUTF8(test_data_directory));
}
#endif
+
+ private:
+ // If non-null a background thread isn't created and instead this message loop
+ // is used.
+ MessageLoop* loop_;
};
class HTTPSTestServer : public HTTPTestServer {