From cad01431b348b5c01ded71f05f2f30f8dcc41d22 Mon Sep 17 00:00:00 2001 From: "sky@google.com" Date: Thu, 29 Jan 2009 21:59:55 +0000 Subject: 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 --- net/url_request/url_request_unittest.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'net/url_request/url_request_unittest.h') 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 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 { -- cgit v1.1