Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: webkit/fileapi/file_system_operation_write_unittest.cc

Issue 6833007: More filesystem cleanup: convert URL-encoded-as-FilePath to actual URL, where (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) 5 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit)
6 // rather than as part of test_shell_tests because they rely on being able 6 // rather than as part of test_shell_tests because they rely on being able
7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses
8 // TYPE_UI, which URLRequest doesn't allow. 8 // TYPE_UI, which URLRequest doesn't allow.
9 // 9 //
10 10
11 #include "webkit/fileapi/file_system_operation.h" 11 #include "webkit/fileapi/file_system_operation.h"
12 12
13 #include "base/logging.h"
14 #include "base/message_loop.h" 13 #include "base/message_loop.h"
15 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_temp_dir.h" 15 #include "base/memory/scoped_temp_dir.h"
17 #include "base/message_loop.h" 16 #include "base/message_loop.h"
18 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
19 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_context.h" 19 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_job.h" 20 #include "net/url_request/url_request_job.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 #include "webkit/blob/blob_data.h" 22 #include "webkit/blob/blob_data.h"
(...skipping 30 matching lines...) Expand all
54 EXPECT_FALSE(complete_); 53 EXPECT_FALSE(complete_);
55 complete_ = complete; 54 complete_ = complete;
56 } 55 }
57 int64 bytes_written() const { return bytes_written_; } 56 int64 bytes_written() const { return bytes_written_; }
58 bool complete() const { return complete_; } 57 bool complete() const { return complete_; }
59 58
60 virtual void SetUp(); 59 virtual void SetUp();
61 virtual void TearDown(); 60 virtual void TearDown();
62 61
63 protected: 62 protected:
63 GURL URLForRelativePath(const std::string& path) const {
64 // Only the path will actually get used.
65 return GURL("file://").Resolve(file_.value()).Resolve(path);
66 }
67
68 GURL URLForPath(const FilePath& path) const {
69 // Only the path will actually get used.
70 return GURL("file://").Resolve(path.value());
71 }
72
64 MessageLoop loop_; 73 MessageLoop loop_;
65 74
66 ScopedTempDir dir_; 75 ScopedTempDir dir_;
67 FilePath file_; 76 FilePath file_;
68 77
69 // For post-operation status. 78 // For post-operation status.
70 base::PlatformFileError status_; 79 base::PlatformFileError status_;
71 int64 bytes_written_; 80 int64 bytes_written_;
72 bool complete_; 81 bool complete_;
73 82
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 const FilePath& platform_path) { 124 const FilePath& platform_path) {
116 ADD_FAILURE(); 125 ADD_FAILURE();
117 } 126 }
118 127
119 virtual void DidReadDirectory( 128 virtual void DidReadDirectory(
120 const std::vector<base::FileUtilProxy::Entry>& entries, 129 const std::vector<base::FileUtilProxy::Entry>& entries,
121 bool /* has_more */) { 130 bool /* has_more */) {
122 ADD_FAILURE(); 131 ADD_FAILURE();
123 } 132 }
124 133
125 virtual void DidOpenFileSystem(const std::string&, const FilePath&) { 134 virtual void DidOpenFileSystem(const std::string&, const GURL&) {
126 ADD_FAILURE(); 135 ADD_FAILURE();
127 } 136 }
128 137
129 virtual void DidWrite(int64 bytes, bool complete) { 138 virtual void DidWrite(int64 bytes, bool complete) {
130 test_->add_bytes_written(bytes, complete); 139 test_->add_bytes_written(bytes, complete);
131 MessageLoop::current()->Quit(); 140 MessageLoop::current()->Quit();
132 } 141 }
133 142
134 private: 143 private:
135 FileSystemOperationWriteTest* test_; 144 FileSystemOperationWriteTest* test_;
(...skipping 27 matching lines...) Expand all
163 TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { 172 TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) {
164 GURL blob_url("blob:success"); 173 GURL blob_url("blob:success");
165 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); 174 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
166 blob_data->AppendData("Hello, world!\n"); 175 blob_data->AppendData("Hello, world!\n");
167 176
168 scoped_refptr<TestURLRequestContext> url_request_context( 177 scoped_refptr<TestURLRequestContext> url_request_context(
169 new TestURLRequestContext()); 178 new TestURLRequestContext());
170 url_request_context->blob_storage_controller()-> 179 url_request_context->blob_storage_controller()->
171 RegisterBlobUrl(blob_url, blob_data); 180 RegisterBlobUrl(blob_url, blob_data);
172 181
173 operation()->Write(url_request_context, file_, blob_url, 0); 182 operation()->Write(url_request_context, URLForPath(file_), blob_url, 0);
174 MessageLoop::current()->Run(); 183 MessageLoop::current()->Run();
175 184
176 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); 185 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url);
177 186
178 EXPECT_EQ(14, bytes_written()); 187 EXPECT_EQ(14, bytes_written());
179 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 188 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
180 EXPECT_TRUE(complete()); 189 EXPECT_TRUE(complete());
181 } 190 }
182 191
183 TEST_F(FileSystemOperationWriteTest, TestWriteZero) { 192 TEST_F(FileSystemOperationWriteTest, TestWriteZero) {
184 GURL blob_url("blob:zero"); 193 GURL blob_url("blob:zero");
185 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); 194 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
186 blob_data->AppendData(""); 195 blob_data->AppendData("");
187 196
188 scoped_refptr<TestURLRequestContext> url_request_context( 197 scoped_refptr<TestURLRequestContext> url_request_context(
189 new TestURLRequestContext()); 198 new TestURLRequestContext());
190 url_request_context->blob_storage_controller()-> 199 url_request_context->blob_storage_controller()->
191 RegisterBlobUrl(blob_url, blob_data); 200 RegisterBlobUrl(blob_url, blob_data);
192 201
193 operation()->Write(url_request_context, file_, blob_url, 0); 202 operation()->Write(url_request_context, URLForPath(file_), blob_url, 0);
194 MessageLoop::current()->Run(); 203 MessageLoop::current()->Run();
195 204
196 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); 205 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url);
197 206
198 EXPECT_EQ(0, bytes_written()); 207 EXPECT_EQ(0, bytes_written());
199 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 208 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
200 EXPECT_TRUE(complete()); 209 EXPECT_TRUE(complete());
201 } 210 }
202 211
203 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidBlobUrl) { 212 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidBlobUrl) {
204 scoped_refptr<TestURLRequestContext> url_request_context( 213 scoped_refptr<TestURLRequestContext> url_request_context(
205 new TestURLRequestContext()); 214 new TestURLRequestContext());
206 215
207 operation()->Write(url_request_context, file_, GURL("blob:invalid"), 0); 216 operation()->Write(url_request_context, URLForPath(file_),
217 GURL("blob:invalid"), 0);
208 MessageLoop::current()->Run(); 218 MessageLoop::current()->Run();
209 219
210 EXPECT_EQ(0, bytes_written()); 220 EXPECT_EQ(0, bytes_written());
211 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 221 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
212 EXPECT_TRUE(complete()); 222 EXPECT_TRUE(complete());
213 } 223 }
214 224
215 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) { 225 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) {
216 GURL blob_url("blob:writeinvalidfile"); 226 GURL blob_url("blob:writeinvalidfile");
217 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); 227 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
218 blob_data->AppendData("It\'ll not be written."); 228 blob_data->AppendData("It\'ll not be written.");
219 229
220 scoped_refptr<TestURLRequestContext> url_request_context( 230 scoped_refptr<TestURLRequestContext> url_request_context(
221 new TestURLRequestContext()); 231 new TestURLRequestContext());
222 url_request_context->blob_storage_controller()-> 232 url_request_context->blob_storage_controller()->
223 RegisterBlobUrl(blob_url, blob_data); 233 RegisterBlobUrl(blob_url, blob_data);
224 234
225 operation()->Write(url_request_context, 235 operation()->Write(url_request_context,
226 FilePath(FILE_PATH_LITERAL("/nonexist")), blob_url, 0); 236 URLForRelativePath("nonexist"), blob_url, 0);
227 MessageLoop::current()->Run(); 237 MessageLoop::current()->Run();
228 238
229 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); 239 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url);
230 240
231 EXPECT_EQ(0, bytes_written()); 241 EXPECT_EQ(0, bytes_written());
232 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 242 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
233 EXPECT_TRUE(complete()); 243 EXPECT_TRUE(complete());
234 } 244 }
235 245
236 TEST_F(FileSystemOperationWriteTest, TestWriteDir) { 246 TEST_F(FileSystemOperationWriteTest, TestWriteDir) {
237 GURL blob_url("blob:writedir"); 247 GURL blob_url("blob:writedir");
238 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); 248 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
239 blob_data->AppendData("It\'ll not be written, too."); 249 blob_data->AppendData("It\'ll not be written, too.");
240 250
241 scoped_refptr<TestURLRequestContext> url_request_context( 251 scoped_refptr<TestURLRequestContext> url_request_context(
242 new TestURLRequestContext()); 252 new TestURLRequestContext());
243 url_request_context->blob_storage_controller()-> 253 url_request_context->blob_storage_controller()->
244 RegisterBlobUrl(blob_url, blob_data); 254 RegisterBlobUrl(blob_url, blob_data);
245 255
246 operation()->Write(url_request_context, dir_.path(), blob_url, 0); 256 operation()->Write(url_request_context, URLForPath(dir_.path()), blob_url, 0);
247 MessageLoop::current()->Run(); 257 MessageLoop::current()->Run();
248 258
249 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url); 259 url_request_context->blob_storage_controller()->UnregisterBlobUrl(blob_url);
250 260
251 EXPECT_EQ(0, bytes_written()); 261 EXPECT_EQ(0, bytes_written());
252 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ACCESS_DENIED, status()); 262 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ACCESS_DENIED, status());
253 EXPECT_TRUE(complete()); 263 EXPECT_TRUE(complete());
254 } 264 }
255 265
256 // TODO(ericu,dmikurube): Add tests for Cancel. 266 // TODO(ericu,dmikurube): Add tests for Cancel.
257 267
258 } // namespace fileapi 268 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_operation_unittest.cc ('k') | webkit/fileapi/file_system_path_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698