diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-29 21:59:55 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-29 21:59:55 +0000 |
commit | cad01431b348b5c01ded71f05f2f30f8dcc41d22 (patch) | |
tree | 8594c4da331d50d7bd5db3e8abf96858da5d7fd8 /net/url_request | |
parent | 5ebeb1191489135b549a38e1490b5b944776a50d (diff) | |
download | chromium_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')
-rw-r--r-- | net/url_request/url_request_unittest.cc | 40 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.h | 31 |
2 files changed, 43 insertions, 28 deletions
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index c950492..5c9146f 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -84,7 +84,7 @@ class URLRequestTest : public PlatformTest { TEST_F(URLRequestTest, GetTest_NoCache) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); + HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; { @@ -106,7 +106,7 @@ TEST_F(URLRequestTest, GetTest_NoCache) { TEST_F(URLRequestTest, GetTest) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); + HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; { @@ -194,7 +194,7 @@ TEST_F(URLRequestTest, CancelTest) { TEST_F(URLRequestTest, CancelTest2) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); + HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); // error C2446: '!=' : no conversion from 'HTTPTestServer *const ' @@ -223,7 +223,7 @@ TEST_F(URLRequestTest, CancelTest2) { TEST_F(URLRequestTest, CancelTest3) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); + HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; { @@ -251,7 +251,7 @@ TEST_F(URLRequestTest, CancelTest3) { TEST_F(URLRequestTest, CancelTest4) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); + HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; { @@ -277,7 +277,7 @@ TEST_F(URLRequestTest, CancelTest4) { TEST_F(URLRequestTest, CancelTest5) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); + HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); @@ -313,7 +313,7 @@ TEST_F(URLRequestTest, CancelTest5) { TEST_F(URLRequestTest, PostTest) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data"); + HTTPTestServer::CreateServer(L"net/data", NULL); ASSERT_TRUE(NULL != server.get()); const int kMsgSize = 20000; // multiple of 10 const int kIterations = 50; @@ -365,7 +365,7 @@ TEST_F(URLRequestTest, PostTest) { TEST_F(URLRequestTest, PostEmptyTest) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data"); + HTTPTestServer::CreateServer(L"net/data", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; { @@ -390,7 +390,7 @@ TEST_F(URLRequestTest, PostEmptyTest) { TEST_F(URLRequestTest, PostFileTest) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data"); + HTTPTestServer::CreateServer(L"net/data", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; { @@ -521,7 +521,7 @@ TEST_F(URLRequestTest, DISABLED_DnsFailureTest) { TEST_F(URLRequestTest, ResponseHeadersTest) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); + HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; TestURLRequest req(server->TestServerPage("files/with-headers.html"), &d); @@ -546,7 +546,7 @@ TEST_F(URLRequestTest, ResponseHeadersTest) { TEST_F(URLRequestTest, BZip2ContentTest) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/filter_unittests"); + HTTPTestServer::CreateServer(L"net/data/filter_unittests", NULL); ASSERT_TRUE(NULL != server.get()); // for localhost domain, we also should support bzip2 encoding @@ -572,7 +572,7 @@ TEST_F(URLRequestTest, BZip2ContentTest) { TEST_F(URLRequestTest, BZip2ContentTest_IncrementalHeader) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/filter_unittests"); + HTTPTestServer::CreateServer(L"net/data/filter_unittests", NULL); ASSERT_TRUE(NULL != server.get()); // for localhost domain, we also should support bzip2 encoding @@ -673,7 +673,7 @@ TEST_F(URLRequestTest, ResolveShortcutTest) { TEST_F(URLRequestTest, ContentTypeNormalizationTest) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); + HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; @@ -722,7 +722,7 @@ TEST_F(URLRequestTest, FileDirCancelTest) { TEST_F(URLRequestTest, RestrictRedirects) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); + HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; @@ -737,7 +737,7 @@ TEST_F(URLRequestTest, RestrictRedirects) { TEST_F(URLRequestTest, NoUserPassInReferrer) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); + HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; TestURLRequest req(server->TestServerPage( @@ -751,7 +751,7 @@ TEST_F(URLRequestTest, NoUserPassInReferrer) { TEST_F(URLRequestTest, CancelRedirect) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); + HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; { @@ -770,7 +770,7 @@ TEST_F(URLRequestTest, CancelRedirect) { TEST_F(URLRequestTest, VaryHeader) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); + HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); ASSERT_TRUE(NULL != server.get()); scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); @@ -821,7 +821,7 @@ TEST_F(URLRequestTest, VaryHeader) { TEST_F(URLRequestTest, BasicAuth) { scoped_refptr<URLRequestContext> context = new URLRequestHttpCacheContext(); scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L""); + HTTPTestServer::CreateServer(L"", NULL); ASSERT_TRUE(NULL != server.get()); Time response_time; @@ -876,7 +876,7 @@ TEST_F(URLRequestTest, BasicAuth) { // http://code.google.com/p/chromium/issues/detail?id=843 TEST_F(URLRequestTest, Post302RedirectGet) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); + HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; TestURLRequest req(server->TestServerPage("files/redirect-to-echoall"), &d); @@ -916,7 +916,7 @@ TEST_F(URLRequestTest, Post302RedirectGet) { TEST_F(URLRequestTest, Post307RedirectPost) { scoped_refptr<HTTPTestServer> server = - HTTPTestServer::CreateServer(L"net/data/url_request_unittest"); + HTTPTestServer::CreateServer(L"net/data/url_request_unittest", NULL); ASSERT_TRUE(NULL != server.get()); TestDelegate d; TestURLRequest req(server->TestServerPage("files/redirect307-to-echoall"), 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 { |