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

Unified Diff: net/url_request/url_fetcher_impl_unittest.cc

Issue 809663003: net: Add SetUploadStream method to URLFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix retrying. Created 6 years 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
« net/url_request/url_fetcher_core.cc ('K') | « 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 fce7ace52848e518e0e93238d6abf4d5b8e92344..9ec64e38216bb40bd1c41e8c872b795c87444b3b 100644
--- a/net/url_request/url_fetcher_impl_unittest.cc
+++ b/net/url_request/url_fetcher_impl_unittest.cc
@@ -17,7 +17,11 @@
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "crypto/nss_util.h"
+#include "net/base/elements_upload_data_stream.h"
#include "net/base/network_change_notifier.h"
+#include "net/base/upload_bytes_element_reader.h"
+#include "net/base/upload_element_reader.h"
+#include "net/base/upload_file_element_reader.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_response_headers.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
@@ -45,6 +49,18 @@ const base::FilePath::CharType kDocRoot[] =
FILE_PATH_LITERAL("net/data/url_fetcher_impl_unittest");
const char kTestServerFilePrefix[] = "files/";
+scoped_ptr<UploadDataStream> CreateUploadStream(const base::FilePath& path) {
+ ScopedVector<UploadElementReader> readers;
+ const std::string str("bobsyeruncle\n");
+ std::vector<char> buffer(str.begin(), str.end());
+ readers.push_back(new UploadOwnedBytesElementReader(&buffer));
+ readers.push_back(
+ new UploadFileElementReader(base::MessageLoopProxy::current().get(), path,
+ 0, kuint64max, base::Time()));
+ return make_scoped_ptr<UploadDataStream>(
+ new ElementsUploadDataStream(readers.Pass(), 0)).Pass();
mmenke 2015/01/09 17:42:25 Do we get anything from having multiple elements h
hirono 2015/01/15 08:14:27 No, let me simplify it.
+}
+
class ThrottlingTestURLRequestContext : public TestURLRequestContext {
public:
ThrottlingTestURLRequestContext() : TestURLRequestContext(true) {
@@ -259,6 +275,20 @@ class URLFetcherPostFileTest : public URLFetcherTest {
uint64 range_length_;
};
+class URLFetcherPostStreamTest : public URLFetcherTest {
+ public:
+ URLFetcherPostStreamTest();
+
+ // URLFetcherTest:
+ void CreateFetcher(const GURL& url) override;
+
+ // URLFetcherDelegate:
+ 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:
@@ -571,6 +601,34 @@ void URLFetcherPostFileTest::OnURLFetchComplete(const URLFetcher* source) {
URLFetcherTest::OnURLFetchComplete(source);
}
+URLFetcherPostStreamTest::URLFetcherPostStreamTest() {
+ 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 URLFetcherPostStreamTest::CreateFetcher(const GURL& url) {
mmenke 2015/01/09 17:42:25 We really should make sure the test actually retri
hirono 2015/01/15 08:14:27 I added status parameter to the "echo" URL. Done.
+ fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
+ fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
+ io_message_loop_proxy().get(), request_context()));
+ fetcher_->SetUploadStreamFactory("text/plain",
+ base::Bind(CreateUploadStream, path_));
+ fetcher_->Start();
+}
+
+void URLFetcherPostStreamTest::OnURLFetchComplete(const URLFetcher* source) {
+ std::string data;
+ EXPECT_TRUE(source->GetResponseAsString(&data));
+
+ std::string expected;
+ ASSERT_TRUE(base::ReadFileToString(path_, &expected));
+ EXPECT_EQ(std::string("bobsyeruncle\n") + expected, data);
+
+ URLFetcherTest::OnURLFetchComplete(source);
+}
+
void URLFetcherEmptyPostTest::CreateFetcher(const GURL& url) {
fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
fetcher_->SetRequestContext(new TestURLRequestContextGetter(
@@ -1085,6 +1143,16 @@ TEST_F(URLFetcherPostFileTest, Range) {
base::MessageLoop::current()->Run();
}
+TEST_F(URLFetcherPostStreamTest, Basic) {
+ SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP,
+ SpawnedTestServer::kLocalhost,
+ base::FilePath(kDocRoot));
+ ASSERT_TRUE(test_server.Start());
+
+ CreateFetcher(test_server.GetURL("echo"));
+ base::MessageLoop::current()->Run();
+}
+
TEST_F(URLFetcherEmptyPostTest, Basic) {
SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP,
SpawnedTestServer::kLocalhost,
« net/url_request/url_fetcher_core.cc ('K') | « 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