Index: net/base/upload_data_unittest.cc |
diff --git a/net/base/upload_data_unittest.cc b/net/base/upload_data_unittest.cc |
index 98bb23d064085ce7cc3f4c18f102d58ee6ccc165..91162dca7a6525ab0ebc385c0311a3d18069a918 100644 |
--- a/net/base/upload_data_unittest.cc |
+++ b/net/base/upload_data_unittest.cc |
@@ -18,72 +18,12 @@ |
namespace net { |
-// Simplified version of TestCompletionCallback for ContentLengthCallback, |
-// that handles uint64 rather than int. |
-class TestContentLengthCallback { |
- public: |
- TestContentLengthCallback() |
- : result_(0), |
- callback_(ALLOW_THIS_IN_INITIALIZER_LIST( |
- base::Bind(&TestContentLengthCallback::SetResult, |
- base::Unretained(this)))) { |
- } |
- |
- ~TestContentLengthCallback() {} |
- |
- const UploadData::ContentLengthCallback& callback() const { |
- return callback_; |
- } |
- |
- // Waits for the result and returns it. |
- uint64 WaitForResult() { |
- MessageLoop::current()->Run(); |
- return result_; |
- } |
- |
- private: |
- // Sets the result and stops the message loop. |
- void SetResult(uint64 result) { |
- result_ = result; |
- MessageLoop::current()->Quit(); |
- } |
- |
- uint64 result_; |
- const UploadData::ContentLengthCallback callback_; |
- |
- DISALLOW_COPY_AND_ASSIGN(TestContentLengthCallback); |
-}; |
- |
class UploadDataTest : public PlatformTest { |
protected: |
- virtual void SetUp() { |
+ virtual void SetUp() OVERRIDE { |
upload_data_= new UploadData; |
- // To ensure that file IO is not performed on the main thread in the |
- // test (i.e. GetContentLengthSync() will fail if file IO is performed). |
- base::ThreadRestrictions::SetIOAllowed(false); |
- } |
- |
- virtual void TearDown() { |
- base::ThreadRestrictions::SetIOAllowed(true); |
} |
- // Creates a temporary file with the given data. The temporary file is |
- // deleted by temp_dir_. Returns true on success. |
- bool CreateTemporaryFile(const std::string& data, |
- FilePath* temp_file_path) { |
- base::ThreadRestrictions::ScopedAllowIO allow_io; |
- if (!temp_dir_.CreateUniqueTempDir()) |
- return false; |
- if (!file_util::CreateTemporaryFileInDir(temp_dir_.path(), temp_file_path)) |
- return false; |
- if (static_cast<int>(data.size()) != |
- file_util::WriteFile(*temp_file_path, data.data(), data.size())) |
- return false; |
- |
- return true; |
- } |
- |
- ScopedTempDir temp_dir_; |
scoped_refptr<UploadData> upload_data_; |
}; |
@@ -121,49 +61,4 @@ TEST_F(UploadDataTest, IsInMemory_Mixed) { |
ASSERT_FALSE(upload_data_->IsInMemory()); |
} |
-TEST_F(UploadDataTest, GetContentLength_Empty) { |
- ASSERT_EQ(0U, upload_data_->GetContentLengthSync()); |
-} |
- |
-TEST_F(UploadDataTest, GetContentLength_Bytes) { |
- upload_data_->AppendBytes("123", 3); |
- ASSERT_EQ(3U, upload_data_->GetContentLengthSync()); |
-} |
- |
-TEST_F(UploadDataTest, GetContentLength_File) { |
- // Create a temporary file with some data. |
- const std::string kData = "hello"; |
- FilePath temp_file_path; |
- ASSERT_TRUE(CreateTemporaryFile(kData, &temp_file_path)); |
- upload_data_->AppendFileRange(temp_file_path, 0, kuint64max, base::Time()); |
- |
- // The length is returned asynchronously. |
- TestContentLengthCallback callback; |
- upload_data_->GetContentLength(callback.callback()); |
- ASSERT_EQ(kData.size(), callback.WaitForResult()); |
-} |
- |
-TEST_F(UploadDataTest, GetContentLength_Chunk) { |
- upload_data_->set_is_chunked(true); |
- ASSERT_EQ(0U, upload_data_->GetContentLengthSync()); |
-} |
- |
-TEST_F(UploadDataTest, GetContentLength_Mixed) { |
- upload_data_->AppendBytes("123", 3); |
- upload_data_->AppendBytes("abc", 3); |
- |
- const uint64 content_length = upload_data_->GetContentLengthSync(); |
- ASSERT_EQ(6U, content_length); |
- |
- // Append a file. |
- const std::string kData = "hello"; |
- FilePath temp_file_path; |
- ASSERT_TRUE(CreateTemporaryFile(kData, &temp_file_path)); |
- upload_data_->AppendFileRange(temp_file_path, 0, kuint64max, base::Time()); |
- |
- TestContentLengthCallback callback; |
- upload_data_->GetContentLength(callback.callback()); |
- ASSERT_EQ(content_length + kData.size(), callback.WaitForResult()); |
-} |
- |
} // namespace net |