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 c8cbd1ac6f6c4389c8f52a4c74b338569a0434f7..cfc2c2d1c71c8e9f0640cf1b08c3112478d4251a 100644 |
| --- a/net/url_request/url_fetcher_impl_unittest.cc |
| +++ b/net/url_request/url_fetcher_impl_unittest.cc |
| @@ -253,6 +253,24 @@ 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_; |
| + uint64 range_offset_; |
| + uint64 range_length_; |
| +}; |
| + |
| // Version of URLFetcherTest that does a POST instead with empty upload body |
| class URLFetcherEmptyPostTest : public URLFetcherTest { |
| public: |
| @@ -538,6 +556,8 @@ void URLFetcherPostFileTest::CreateFetcher(const GURL& url) { |
| io_message_loop_proxy(), request_context())); |
| fetcher_->SetUploadFilePath("application/x-www-form-urlencoded", |
| path_, |
| + 0, |
| + kuint64max, |
| base::MessageLoopProxy::current()); |
| fetcher_->Start(); |
| } |
| @@ -554,6 +574,43 @@ 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; |
|
mmenke
2013/05/01 15:37:01
I think it's a little weird to make these variable
mmenke
2013/05/01 15:37:01
Also, these should be set in initializer lists.
hidehiko
2013/05/01 17:38:12
I see. So how about this? Merged two test fixtures
|
| +} |
| + |
| +void URLFetcherPostFileWithRangeTest::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_, |
| + range_offset_, |
| + range_length_, |
| + base::MessageLoopProxy::current()); |
| + fetcher_->Start(); |
| +} |
| + |
| +void URLFetcherPostFileWithRangeTest::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 +1120,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, |