Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Unified Diff: net/url_request/url_fetcher_impl_unittest.cc

Issue 12383015: Add SetUploadFilePath method to URLFetcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review changes Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_fetcher_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5d166b8ded3a624cd587a2b1d8966095dc809aee 100644
--- a/net/url_request/url_fetcher_impl_unittest.cc
+++ b/net/url_request/url_fetcher_impl_unittest.cc
@@ -237,6 +237,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 +520,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 +1049,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,
« no previous file with comments | « net/url_request/url_fetcher_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698