Chromium Code Reviews| Index: net/url_request/url_fetcher_impl_unittest.cc |
| diff --git a/net/url_request/url_fetcher_impl_unittest.cc b/net/url_request/url_fetcher_impl_unittest.cc |
| index 5e22ce06a072f76b7c6aea19485de8e8187a8fc1..fedde4377d46d4a7e00c06951cd6fe857f0121d3 100644 |
| --- a/net/url_request/url_fetcher_impl_unittest.cc |
| +++ b/net/url_request/url_fetcher_impl_unittest.cc |
| @@ -17,6 +17,8 @@ |
| #include "crypto/nss_util.h" |
| #include "net/base/mock_host_resolver.h" |
| #include "net/base/network_change_notifier.h" |
| +#include "net/base/upload_data_stream.h" |
| +#include "net/base/upload_file_element_reader.h" |
|
mmenke
2013/02/28 16:53:23
Neither of these is needed.
mattm
2013/02/28 22:13:05
Done.
|
| #include "net/http/http_response_headers.h" |
| #include "net/test/test_server.h" |
| #include "net/url_request/url_fetcher_delegate.h" |
| @@ -237,6 +239,22 @@ class URLFetcherPostTest : public URLFetcherTest { |
| virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| }; |
| +// Version of URLFetcherTest that does a POST of a file using |
| +// SetUploadDataStream |
| +class URLFetcherPostFileTest : public URLFetcherTest { |
| + public: |
| + URLFetcherPostFileTest(); |
| + |
| + // URLFetcherTest: |
| + virtual void CreateFetcher(const GURL& url) OVERRIDE; |
| + |
| + // URLFetcherDelegate: |
| + virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; |
| + |
| + private: |
| + base::FilePath path_; |
| +}; |
| + |
| // Version of URLFetcherTest that does a POST instead with empty upload body |
| class URLFetcherEmptyPostTest : public URLFetcherTest { |
| public: |
| @@ -504,6 +522,36 @@ void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) { |
| URLFetcherTest::OnURLFetchComplete(source); |
| } |
| +URLFetcherPostFileTest::URLFetcherPostFileTest() { |
| + PathService::Get(base::DIR_SOURCE_ROOT, &path_); |
| + path_ = path_.Append(FILE_PATH_LITERAL("net")); |
| + path_ = path_.Append(FILE_PATH_LITERAL("data")); |
| + path_ = path_.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| + path_ = path_.Append(FILE_PATH_LITERAL("BullRunSpeech.txt")); |
| +} |
| + |
| +void URLFetcherPostFileTest::CreateFetcher(const GURL& url) { |
| + fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); |
| + fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter( |
| + io_message_loop_proxy(), request_context())); |
| + fetcher_->SetUploadFilePath("application/x-www-form-urlencoded", |
| + path_, |
| + base::MessageLoopProxy::current()); |
| + fetcher_->Start(); |
| +} |
| + |
| +void URLFetcherPostFileTest::OnURLFetchComplete(const URLFetcher* source) { |
| + int64 size = 0; |
| + ASSERT_EQ(true, file_util::GetFileSize(path_, &size)); |
| + scoped_array<char> expected(new char[size]); |
| + ASSERT_EQ(size, file_util::ReadFile(path_, expected.get(), size)); |
| + |
| + std::string data; |
| + EXPECT_TRUE(source->GetResponseAsString(&data)); |
| + EXPECT_EQ(std::string(&expected[0], size), data); |
| + URLFetcherTest::OnURLFetchComplete(source); |
| +} |
| + |
| void URLFetcherEmptyPostTest::CreateFetcher(const GURL& url) { |
| fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this); |
| fetcher_->SetRequestContext(new TestURLRequestContextGetter( |
| @@ -1003,6 +1051,16 @@ TEST_F(URLFetcherPostTest, Basic) { |
| MessageLoop::current()->Run(); |
| } |
| +TEST_F(URLFetcherPostFileTest, Basic) { |
| + TestServer test_server(TestServer::TYPE_HTTP, |
| + TestServer::kLocalhost, |
| + base::FilePath(kDocRoot)); |
| + ASSERT_TRUE(test_server.Start()); |
| + |
| + CreateFetcher(test_server.GetURL("echo")); |
| + MessageLoop::current()->Run(); |
| +} |
| + |
| TEST_F(URLFetcherEmptyPostTest, Basic) { |
| TestServer test_server(TestServer::TYPE_HTTP, |
| TestServer::kLocalhost, |