diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-30 21:49:21 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-30 21:49:21 +0000 |
commit | baf9e25f103eb1138fcd41d917728faee80e62e2 (patch) | |
tree | 8d9b78fc3afb7e9c79570873b2c7d5529d1a02be /webkit | |
parent | 1ea316d7174804dd49c43fe4abcb15620b248634 (diff) | |
download | chromium_src-baf9e25f103eb1138fcd41d917728faee80e62e2.zip chromium_src-baf9e25f103eb1138fcd41d917728faee80e62e2.tar.gz chromium_src-baf9e25f103eb1138fcd41d917728faee80e62e2.tar.bz2 |
Add FTP unit test in preparation for portable FTP implementation.
Clean up test server code.
Originally from issue 12939, written by Ibrar Ahmed (ibrar.ahmed@gmail.com)
Review URL: http://codereview.chromium.org/16490
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7508 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/mimetype_unittest.cc | 12 | ||||
-rw-r--r-- | webkit/glue/resource_fetcher_unittest.cc | 19 | ||||
-rw-r--r-- | webkit/glue/unittest_test_server.h | 18 |
3 files changed, 32 insertions, 17 deletions
diff --git a/webkit/glue/mimetype_unittest.cc b/webkit/glue/mimetype_unittest.cc index bbbf0f6..a746d96 100644 --- a/webkit/glue/mimetype_unittest.cc +++ b/webkit/glue/mimetype_unittest.cc @@ -23,7 +23,7 @@ class MimeTypeTests : public TestShellTest { test_shell_->LoadURL(UTF8ToWide(url.spec()).c_str()); test_shell_->WaitTestFinished(); } - + void CheckMimeType(const char* mimetype, const std::wstring& expected) { std::string path("contenttype?"); GURL url = server_->TestServerPage(path + mimetype); @@ -31,16 +31,17 @@ class MimeTypeTests : public TestShellTest { WebFrame* frame = test_shell_->webView()->GetMainFrame(); EXPECT_EQ(expected, webkit_glue::DumpDocumentText(frame)); } - - scoped_ptr<UnittestTestServer> server_; + + scoped_refptr<UnittestTestServer> server_; }; TEST_F(MimeTypeTests, MimeTypeTests) { - server_.reset(new UnittestTestServer); + server_ = UnittestTestServer::CreateServer(); + ASSERT_TRUE(NULL != server_.get()); std::wstring expected_src(L"<html>\n<body>\n" L"<p>HTML text</p>\n</body>\n</html>\n"); - + // These files should all be displayed as plain text. const char* plain_text[] = { "text/css", @@ -80,7 +81,6 @@ TEST_F(MimeTypeTests, MimeTypeTests) { // TODO(tc): make sure other mime types properly go to download (e.g., // image/foo). - server_.reset(NULL); } } // namespace diff --git a/webkit/glue/resource_fetcher_unittest.cc b/webkit/glue/resource_fetcher_unittest.cc index d996f3b..81d9646 100644 --- a/webkit/glue/resource_fetcher_unittest.cc +++ b/webkit/glue/resource_fetcher_unittest.cc @@ -153,14 +153,16 @@ FetcherDelegate* FetcherDelegate::instance_ = NULL; // Test a fetch from the test server. TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { - UnittestTestServer server; + scoped_refptr<UnittestTestServer> server = + UnittestTestServer::CreateServer(); + ASSERT_TRUE(NULL != server.get()); WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); // Not safe, but this is a unittest, so whatever. WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame); WebCore::Frame* frame = web_frame_impl->frame(); - GURL url = server.TestServerPage("files/test_shell/index.html"); + GURL url = server->TestServerPage("files/test_shell/index.html"); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcher( url, frame, delegate.get())); @@ -173,7 +175,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { EXPECT_TRUE(text.find("What is this page?") != std::string::npos); // Test 404 response. - url = server.TestServerPage("files/thisfiledoesntexist.html"); + url = server->TestServerPage("files/thisfiledoesntexist.html"); delegate.reset(new FetcherDelegate); fetcher.reset(new ResourceFetcher(url, frame, delegate.get())); @@ -185,7 +187,10 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDownload) { } TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { - UnittestTestServer server; + scoped_refptr<UnittestTestServer> server = + UnittestTestServer::CreateServer(); + ASSERT_TRUE(NULL != server.get()); + WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); // Not safe, but this is a unittest, so whatever. WebFrameImpl* web_frame_impl = reinterpret_cast<WebFrameImpl*>(web_frame); @@ -208,7 +213,9 @@ TEST_F(ResourceFetcherTests, ResourceFetcherDidFail) { } TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { - UnittestTestServer server; + scoped_refptr<UnittestTestServer> server = + UnittestTestServer::CreateServer(); + ASSERT_TRUE(NULL != server.get()); WebFrame* web_frame = test_shell_->webView()->GetMainFrame(); // Not safe, but this is a unittest, so whatever. @@ -217,7 +224,7 @@ TEST_F(ResourceFetcherTests, ResourceFetcherTimeout) { // Grab a page that takes at least 1 sec to respond, but set the fetcher to // timeout in 0 sec. - GURL url = server.TestServerPage("slow?1"); + GURL url = server->TestServerPage("slow?1"); scoped_ptr<FetcherDelegate> delegate(new FetcherDelegate); scoped_ptr<ResourceFetcher> fetcher(new ResourceFetcherWithTimeout( url, frame, 0, delegate.get())); diff --git a/webkit/glue/unittest_test_server.h b/webkit/glue/unittest_test_server.h index d9b4ce2..3e27b875 100644 --- a/webkit/glue/unittest_test_server.h +++ b/webkit/glue/unittest_test_server.h @@ -14,14 +14,22 @@ using webkit_glue::ResourceLoaderBridge; // We need to use ResourceLoaderBridge to communicate with the testserver // instead of using URLRequest directly because URLRequests need to be run on // the test_shell's IO thread. -class UnittestTestServer : public TestServer { +class UnittestTestServer : public HTTPTestServer { + protected: + UnittestTestServer() { + } + public: - UnittestTestServer() : TestServer(TestServer::ManualInit()) { - Init("localhost", 1337, L"webkit/data", std::wstring()); + static UnittestTestServer* CreateServer() { + UnittestTestServer* test_server = new UnittestTestServer(); + if (!test_server->Init("localhost", 1337, L"webkit/data")) { + delete test_server; + return NULL; + } + return test_server; } - ~UnittestTestServer() { - Shutdown(); + virtual ~UnittestTestServer() { } virtual bool MakeGETRequest(const std::string& page_name) { |