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 c8cbd1ac6f6c4389c8f52a4c74b338569a0434f7..1270d607c63dad1333357f150ef9a9ac02346ba2 100644 |
--- a/net/url_request/url_fetcher_impl_unittest.cc |
+++ b/net/url_request/url_fetcher_impl_unittest.cc |
@@ -10,6 +10,7 @@ |
#include "base/file_util.h" |
#include "base/files/scoped_temp_dir.h" |
#include "base/message_loop_proxy.h" |
+#include "base/rand_util.h" |
#include "base/stringprintf.h" |
#include "base/synchronization/waitable_event.h" |
#include "base/threading/thread.h" |
@@ -243,6 +244,13 @@ class URLFetcherPostFileTest : public URLFetcherTest { |
public: |
URLFetcherPostFileTest(); |
+ const base::FilePath& path() { return path_; } |
mmenke
2013/05/01 18:10:22
nit: "... path() const { ...", if you want to kee
hidehiko
2013/05/01 18:30:04
Just removed.
|
+ |
+ void SetUploadRange(uint64 range_offset, uint64 range_length) { |
+ range_offset_ = range_offset; |
+ range_length_ = range_length; |
+ } |
+ |
// URLFetcherTest: |
virtual void CreateFetcher(const GURL& url) OVERRIDE; |
@@ -251,6 +259,8 @@ class URLFetcherPostFileTest : public URLFetcherTest { |
private: |
base::FilePath path_; |
+ uint64 range_offset_; |
+ uint64 range_length_; |
}; |
// Version of URLFetcherTest that does a POST instead with empty upload body |
@@ -524,7 +534,9 @@ void URLFetcherPostTest::OnURLFetchComplete(const URLFetcher* source) { |
URLFetcherTest::OnURLFetchComplete(source); |
} |
-URLFetcherPostFileTest::URLFetcherPostFileTest() { |
+URLFetcherPostFileTest::URLFetcherPostFileTest() |
+ : range_offset_(0), |
+ range_length_(kuint64max) { |
PathService::Get(base::DIR_SOURCE_ROOT, &path_); |
path_ = path_.Append(FILE_PATH_LITERAL("net")); |
path_ = path_.Append(FILE_PATH_LITERAL("data")); |
@@ -538,19 +550,22 @@ void URLFetcherPostFileTest::CreateFetcher(const GURL& url) { |
io_message_loop_proxy(), request_context())); |
fetcher_->SetUploadFilePath("application/x-www-form-urlencoded", |
path_, |
+ range_offset_, |
+ range_length_, |
base::MessageLoopProxy::current()); |
fetcher_->Start(); |
} |
void URLFetcherPostFileTest::OnURLFetchComplete(const URLFetcher* source) { |
- int64 size = 0; |
- ASSERT_EQ(true, file_util::GetFileSize(path_, &size)); |
- scoped_ptr<char[]> expected(new char[size]); |
- ASSERT_EQ(size, file_util::ReadFile(path_, expected.get(), size)); |
+ std::string expected; |
+ ASSERT_TRUE(file_util::ReadFileToString(path_, &expected)); |
+ ASSERT_LE(range_offset_, expected.size()); |
+ size_t expected_size = std::min(static_cast<size_t>(range_length_), |
+ expected.size() - range_offset_); |
std::string data; |
EXPECT_TRUE(source->GetResponseAsString(&data)); |
- EXPECT_EQ(std::string(&expected[0], size), data); |
+ EXPECT_EQ(expected.substr(range_offset_, expected_size), data); |
URLFetcherTest::OnURLFetchComplete(source); |
} |
@@ -1063,6 +1078,22 @@ TEST_F(URLFetcherPostFileTest, Basic) { |
MessageLoop::current()->Run(); |
} |
+TEST_F(URLFetcherPostFileTest, Range) { |
+ TestServer test_server(TestServer::TYPE_HTTP, |
+ TestServer::kLocalhost, |
+ base::FilePath(kDocRoot)); |
+ ASSERT_TRUE(test_server.Start()); |
+ |
+ int64 size; |
+ ASSERT_TRUE(file_util::GetFileSize(path(), &size)); |
+ uint64 range_offset = base::RandGenerator(size); |
+ uint64 range_length = base::RandGenerator(size - range_offset); |
mmenke
2013/05/01 18:10:22
We generally avoid deliberate randomization in tes
hidehiko
2013/05/01 18:30:04
I see. Sorry that I misunderstood that I should se
mmenke
2013/05/01 18:34:48
Oh, I'm the one who should have been clearer. Sor
|
+ SetUploadRange(range_offset, range_length); |
+ |
+ CreateFetcher(test_server.GetURL("echo")); |
+ MessageLoop::current()->Run(); |
+} |
+ |
TEST_F(URLFetcherEmptyPostTest, Basic) { |
TestServer test_server(TestServer::TYPE_HTTP, |
TestServer::kLocalhost, |