OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/upload_data.h" | 5 #include "net/base/upload_data.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ASSERT_TRUE(upload_data_->IsInMemory()); | 96 ASSERT_TRUE(upload_data_->IsInMemory()); |
97 } | 97 } |
98 | 98 |
99 TEST_F(UploadDataTest, IsInMemory_File) { | 99 TEST_F(UploadDataTest, IsInMemory_File) { |
100 upload_data_->AppendFileRange( | 100 upload_data_->AppendFileRange( |
101 FilePath(FILE_PATH_LITERAL("random_file_name.txt")), | 101 FilePath(FILE_PATH_LITERAL("random_file_name.txt")), |
102 0, 0, base::Time()); | 102 0, 0, base::Time()); |
103 ASSERT_FALSE(upload_data_->IsInMemory()); | 103 ASSERT_FALSE(upload_data_->IsInMemory()); |
104 } | 104 } |
105 | 105 |
106 TEST_F(UploadDataTest, IsInMemory_Blob) { | |
107 upload_data_->AppendBlob(GURL("blog:internal:12345")); | |
108 // Until it's resolved, we don't know what blob contains. | |
109 ASSERT_FALSE(upload_data_->IsInMemory()); | |
110 } | |
111 | |
112 TEST_F(UploadDataTest, IsInMemory_Chunk) { | 106 TEST_F(UploadDataTest, IsInMemory_Chunk) { |
113 upload_data_->set_is_chunked(true); | 107 upload_data_->set_is_chunked(true); |
114 ASSERT_FALSE(upload_data_->IsInMemory()); | 108 ASSERT_FALSE(upload_data_->IsInMemory()); |
115 } | 109 } |
116 | 110 |
117 TEST_F(UploadDataTest, IsInMemory_Mixed) { | 111 TEST_F(UploadDataTest, IsInMemory_Mixed) { |
118 ASSERT_TRUE(upload_data_->IsInMemory()); | 112 ASSERT_TRUE(upload_data_->IsInMemory()); |
119 | 113 |
120 upload_data_->AppendBytes("123", 3); | 114 upload_data_->AppendBytes("123", 3); |
121 upload_data_->AppendBytes("abc", 3); | 115 upload_data_->AppendBytes("abc", 3); |
(...skipping 20 matching lines...) Expand all Loading... |
142 FilePath temp_file_path; | 136 FilePath temp_file_path; |
143 ASSERT_TRUE(CreateTemporaryFile(kData, &temp_file_path)); | 137 ASSERT_TRUE(CreateTemporaryFile(kData, &temp_file_path)); |
144 upload_data_->AppendFileRange(temp_file_path, 0, kuint64max, base::Time()); | 138 upload_data_->AppendFileRange(temp_file_path, 0, kuint64max, base::Time()); |
145 | 139 |
146 // The length is returned asynchronously. | 140 // The length is returned asynchronously. |
147 TestContentLengthCallback callback; | 141 TestContentLengthCallback callback; |
148 upload_data_->GetContentLength(callback.callback()); | 142 upload_data_->GetContentLength(callback.callback()); |
149 ASSERT_EQ(kData.size(), callback.WaitForResult()); | 143 ASSERT_EQ(kData.size(), callback.WaitForResult()); |
150 } | 144 } |
151 | 145 |
152 TEST_F(UploadDataTest, GetContentLength_Blob) { | |
153 upload_data_->AppendBlob(GURL("blog:internal:12345")); | |
154 ASSERT_EQ(0U, upload_data_->GetContentLengthSync()); | |
155 } | |
156 | |
157 TEST_F(UploadDataTest, GetContentLength_Chunk) { | 146 TEST_F(UploadDataTest, GetContentLength_Chunk) { |
158 upload_data_->set_is_chunked(true); | 147 upload_data_->set_is_chunked(true); |
159 ASSERT_EQ(0U, upload_data_->GetContentLengthSync()); | 148 ASSERT_EQ(0U, upload_data_->GetContentLengthSync()); |
160 } | 149 } |
161 | 150 |
162 TEST_F(UploadDataTest, GetContentLength_Mixed) { | 151 TEST_F(UploadDataTest, GetContentLength_Mixed) { |
163 upload_data_->AppendBytes("123", 3); | 152 upload_data_->AppendBytes("123", 3); |
164 upload_data_->AppendBytes("abc", 3); | 153 upload_data_->AppendBytes("abc", 3); |
165 | 154 |
166 const uint64 content_length = upload_data_->GetContentLengthSync(); | 155 const uint64 content_length = upload_data_->GetContentLengthSync(); |
167 ASSERT_EQ(6U, content_length); | 156 ASSERT_EQ(6U, content_length); |
168 | 157 |
169 // Append a file. | 158 // Append a file. |
170 const std::string kData = "hello"; | 159 const std::string kData = "hello"; |
171 FilePath temp_file_path; | 160 FilePath temp_file_path; |
172 ASSERT_TRUE(CreateTemporaryFile(kData, &temp_file_path)); | 161 ASSERT_TRUE(CreateTemporaryFile(kData, &temp_file_path)); |
173 upload_data_->AppendFileRange(temp_file_path, 0, kuint64max, base::Time()); | 162 upload_data_->AppendFileRange(temp_file_path, 0, kuint64max, base::Time()); |
174 | 163 |
175 TestContentLengthCallback callback; | 164 TestContentLengthCallback callback; |
176 upload_data_->GetContentLength(callback.callback()); | 165 upload_data_->GetContentLength(callback.callback()); |
177 ASSERT_EQ(content_length + kData.size(), callback.WaitForResult()); | 166 ASSERT_EQ(content_length + kData.size(), callback.WaitForResult()); |
178 } | 167 } |
179 | 168 |
180 } // namespace net | 169 } // namespace net |
OLD | NEW |