| 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..e5e3c6128bacd26dd841e7cb3ee011224c2b1838 100644
|
| --- a/net/url_request/url_fetcher_impl_unittest.cc
|
| +++ b/net/url_request/url_fetcher_impl_unittest.cc
|
| @@ -253,6 +253,22 @@ class URLFetcherPostFileTest : public URLFetcherTest {
|
| base::FilePath path_;
|
| };
|
|
|
| +// Version of URLFetcherTest that does a POST of a file using
|
| +// SetUploadDataStream
|
| +class URLFetcherPostFileWithRangeTest : public URLFetcherTest {
|
| + public:
|
| + URLFetcherPostFileWithRangeTest();
|
| +
|
| + // 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:
|
| @@ -554,6 +570,42 @@ void URLFetcherPostFileTest::OnURLFetchComplete(const URLFetcher* source) {
|
| URLFetcherTest::OnURLFetchComplete(source);
|
| }
|
|
|
| +URLFetcherPostFileWithRangeTest::URLFetcherPostFileWithRangeTest() {
|
| + 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"));
|
| +
|
| + range_offset_ = 30;
|
| + range_length_ = 100;
|
| +}
|
| +
|
| +void URLFetcherPostFileWithRangeTest::CreateFetcher(const GURL& url) {
|
| + fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
|
| + fetcher_->SetRequestContext(new ThrottlingTestURLRequestContextGetter(
|
| + io_message_loop_proxy(), request_context()));
|
| + fetcher_->SetUploadFilePathWithRange("application/x-www-form-urlencoded",
|
| + path_,
|
| + range_offset_,
|
| + range_length_,
|
| + base::MessageLoopProxy::current());
|
| + fetcher_->Start();
|
| +}
|
| +
|
| +void URLFetcherPostFileTest::OnURLFetchComplete(const URLFetcher* source) {
|
| + std::string expected;
|
| + ASSERT_TRUE(file_util::ReadFileToString(path_, &expected));
|
| + ASSERT_LE(range_offset_, expected.size());
|
| + ASSERT_LE(range_offset_ + range_length_, expected.size());
|
| + expected = expected.substr(range_offset_, range_length_);
|
| +
|
| + std::string data;
|
| + EXPECT_TRUE(source->GetResponseAsString(&data));
|
| + EXPECT_EQ(expected, data);
|
| + URLFetcherTest::OnURLFetchComplete(source);
|
| +}
|
| +
|
| void URLFetcherEmptyPostTest::CreateFetcher(const GURL& url) {
|
| fetcher_ = new URLFetcherImpl(url, URLFetcher::POST, this);
|
| fetcher_->SetRequestContext(new TestURLRequestContextGetter(
|
| @@ -1063,6 +1115,16 @@ TEST_F(URLFetcherPostFileTest, Basic) {
|
| MessageLoop::current()->Run();
|
| }
|
|
|
| +TEST_F(URLFetcherPostFileWithRangeTest, 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,
|
|
|