Chromium Code Reviews| 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 // 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 <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 16 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
| 17 #include "base/scoped_temp_dir.h" | 18 #include "base/scoped_temp_dir.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 20 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 21 #include "net/url_request/url_request_job.h" | 22 #include "net/url_request/url_request_job.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "webkit/blob/blob_data.h" | 24 #include "webkit/blob/blob_data.h" |
| 24 #include "webkit/blob/blob_storage_controller.h" | 25 #include "webkit/blob/blob_storage_controller.h" |
| 25 #include "webkit/blob/blob_url_request_job.h" | 26 #include "webkit/blob/blob_url_request_job.h" |
| 26 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 27 #include "webkit/fileapi/file_system_context.h" | 27 #include "webkit/fileapi/file_system_context.h" |
| 28 #include "webkit/fileapi/file_system_file_util.h" | 28 #include "webkit/fileapi/file_system_file_util.h" |
| 29 #include "webkit/fileapi/file_system_operation.h" | 29 #include "webkit/fileapi/file_system_operation.h" |
| 30 #include "webkit/fileapi/file_system_test_helper.h" | 30 #include "webkit/fileapi/file_system_test_helper.h" |
| 31 #include "webkit/fileapi/file_system_util.h" | 31 #include "webkit/fileapi/file_system_util.h" |
| 32 #include "webkit/fileapi/local_file_util.h" | 32 #include "webkit/fileapi/local_file_util.h" |
| 33 #include "webkit/fileapi/quota_file_util.h" | 33 #include "webkit/fileapi/quota_file_util.h" |
| 34 #include "webkit/quota/quota_manager.h" | 34 #include "webkit/quota/quota_manager.h" |
| 35 | 35 |
| 36 using quota::QuotaManager; | 36 using quota::QuotaManager; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 58 void set_usage(int64 usage) { usage_ = usage; } | 58 void set_usage(int64 usage) { usage_ = usage; } |
| 59 void set_quota(int64 quota) { quota_ = quota; } | 59 void set_quota(int64 quota) { quota_ = quota; } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 int64 usage_; | 62 int64 usage_; |
| 63 int64 quota_; | 63 int64 quota_; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 } // namespace (anonymous) | 66 } // namespace (anonymous) |
| 67 | 67 |
| 68 class FileSystemOperationWriteTest : public testing::Test { | 68 class FileSystemOperationWriteTest |
| 69 : public testing::Test, | |
| 70 public base::SupportsWeakPtr<FileSystemOperationWriteTest> { | |
| 69 public: | 71 public: |
| 70 FileSystemOperationWriteTest() | 72 FileSystemOperationWriteTest() |
| 71 : local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())), | 73 : local_file_util_(new LocalFileUtil(QuotaFileUtil::CreateDefault())), |
| 72 loop_(MessageLoop::TYPE_IO), | 74 loop_(MessageLoop::TYPE_IO), |
| 73 status_(base::PLATFORM_FILE_OK), | 75 status_(base::PLATFORM_FILE_OK), |
| 76 cancel_status_(base::PLATFORM_FILE_ERROR_FAILED), | |
| 74 bytes_written_(0), | 77 bytes_written_(0), |
| 75 complete_(false) {} | 78 complete_(false) {} |
| 76 | 79 |
| 77 FileSystemOperation* operation(); | 80 FileSystemOperation* operation(); |
| 78 | 81 |
| 79 void set_failure_status(base::PlatformFileError status) { | |
| 80 EXPECT_FALSE(complete_); | |
| 81 EXPECT_EQ(status_, base::PLATFORM_FILE_OK); | |
| 82 EXPECT_NE(status, base::PLATFORM_FILE_OK); | |
| 83 complete_ = true; | |
| 84 status_ = status; | |
| 85 } | |
| 86 base::PlatformFileError status() const { return status_; } | 82 base::PlatformFileError status() const { return status_; } |
| 83 base::PlatformFileError cancel_status() const { return cancel_status_; } | |
| 87 void add_bytes_written(int64 bytes, bool complete) { | 84 void add_bytes_written(int64 bytes, bool complete) { |
| 88 bytes_written_ += bytes; | 85 bytes_written_ += bytes; |
| 89 EXPECT_FALSE(complete_); | 86 EXPECT_FALSE(complete_); |
| 90 complete_ = complete; | 87 complete_ = complete; |
| 91 } | 88 } |
| 92 int64 bytes_written() const { return bytes_written_; } | 89 int64 bytes_written() const { return bytes_written_; } |
| 93 bool complete() const { return complete_; } | 90 bool complete() const { return complete_; } |
| 94 | 91 |
| 95 virtual void SetUp(); | 92 virtual void SetUp(); |
| 96 virtual void TearDown(); | 93 virtual void TearDown(); |
| 97 | 94 |
| 98 protected: | 95 protected: |
| 99 GURL URLForPath(const FilePath& path) const { | 96 GURL URLForPath(const FilePath& path) const { |
| 100 return test_helper_.GetURLForPath(path); | 97 return test_helper_.GetURLForPath(path); |
| 101 } | 98 } |
| 102 | 99 |
| 100 // Callback function for recording test results. | |
| 101 FileSystemOperationInterface::WriteCallback RecordWriteCallback() { | |
| 102 return base::Bind(&FileSystemOperationWriteTest::DidWrite, AsWeakPtr()); | |
| 103 } | |
| 104 | |
| 105 FileSystemOperationInterface::StatusCallback RecordCancelCallback() { | |
| 106 return base::Bind(&FileSystemOperationWriteTest::DidCancel, AsWeakPtr()); | |
| 107 } | |
| 108 | |
| 109 void DidWrite(base::PlatformFileError status, int64 bytes, bool complete) { | |
| 110 if (status == base::PLATFORM_FILE_OK) { | |
| 111 add_bytes_written(bytes, complete); | |
| 112 if (complete) { | |
| 113 if (MessageLoop::current()->is_running()) | |
|
kinuko
2012/02/13 10:10:21
This is ok but I guess it will never be false?
kinaba
2012/02/14 02:17:47
Done.
| |
| 114 MessageLoop::current()->Quit(); | |
| 115 } | |
| 116 } else { | |
| 117 EXPECT_FALSE(complete_); | |
| 118 EXPECT_EQ(status_, base::PLATFORM_FILE_OK); | |
| 119 complete_ = true; | |
| 120 status_ = status; | |
| 121 if (MessageLoop::current()->is_running()) | |
| 122 MessageLoop::current()->Quit(); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 void DidCancel(base::PlatformFileError status) { | |
| 127 cancel_status_ = status; | |
| 128 } | |
| 129 | |
| 103 scoped_ptr<LocalFileUtil> local_file_util_; | 130 scoped_ptr<LocalFileUtil> local_file_util_; |
| 104 scoped_refptr<MockQuotaManager> quota_manager_; | 131 scoped_refptr<MockQuotaManager> quota_manager_; |
| 105 FileSystemTestOriginHelper test_helper_; | 132 FileSystemTestOriginHelper test_helper_; |
| 106 | 133 |
| 107 MessageLoop loop_; | 134 MessageLoop loop_; |
| 108 | 135 |
| 109 ScopedTempDir dir_; | 136 ScopedTempDir dir_; |
| 110 FilePath filesystem_dir_; | 137 FilePath filesystem_dir_; |
| 111 FilePath file_; | 138 FilePath file_; |
| 112 FilePath virtual_path_; | 139 FilePath virtual_path_; |
| 113 | 140 |
| 114 // For post-operation status. | 141 // For post-operation status. |
| 115 base::PlatformFileError status_; | 142 base::PlatformFileError status_; |
| 143 base::PlatformFileError cancel_status_; | |
| 116 int64 bytes_written_; | 144 int64 bytes_written_; |
| 117 bool complete_; | 145 bool complete_; |
| 118 | 146 |
| 119 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationWriteTest); | 147 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationWriteTest); |
| 120 }; | 148 }; |
| 121 | 149 |
| 122 namespace { | 150 namespace { |
| 123 | 151 |
| 124 class TestURLRequestContext : public net::URLRequestContext { | 152 class TestURLRequestContext : public net::URLRequestContext { |
| 125 public: | 153 public: |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 140 const std::string& scheme) { | 168 const std::string& scheme) { |
| 141 webkit_blob::BlobStorageController* blob_storage_controller = | 169 webkit_blob::BlobStorageController* blob_storage_controller = |
| 142 static_cast<const TestURLRequestContext*>(request->context())-> | 170 static_cast<const TestURLRequestContext*>(request->context())-> |
| 143 blob_storage_controller(); | 171 blob_storage_controller(); |
| 144 return new webkit_blob::BlobURLRequestJob( | 172 return new webkit_blob::BlobURLRequestJob( |
| 145 request, | 173 request, |
| 146 blob_storage_controller->GetBlobDataFromUrl(request->url()), | 174 blob_storage_controller->GetBlobDataFromUrl(request->url()), |
| 147 base::MessageLoopProxy::current()); | 175 base::MessageLoopProxy::current()); |
| 148 } | 176 } |
| 149 | 177 |
| 150 class MockDispatcher : public FileSystemCallbackDispatcher { | |
| 151 public: | |
| 152 MockDispatcher(FileSystemOperationWriteTest* test) : test_(test) { } | |
| 153 | |
| 154 virtual void DidFail(base::PlatformFileError status) { | |
| 155 test_->set_failure_status(status); | |
| 156 MessageLoop::current()->Quit(); | |
| 157 } | |
| 158 | |
| 159 virtual void DidSucceed() { | |
| 160 ADD_FAILURE(); | |
| 161 } | |
| 162 | |
| 163 virtual void DidReadMetadata( | |
| 164 const base::PlatformFileInfo& info, | |
| 165 const FilePath& platform_path) { | |
| 166 ADD_FAILURE(); | |
| 167 } | |
| 168 | |
| 169 virtual void DidReadDirectory( | |
| 170 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 171 bool /* has_more */) { | |
| 172 ADD_FAILURE(); | |
| 173 } | |
| 174 | |
| 175 virtual void DidOpenFileSystem(const std::string&, const GURL&) { | |
| 176 ADD_FAILURE(); | |
| 177 } | |
| 178 | |
| 179 virtual void DidWrite(int64 bytes, bool complete) { | |
| 180 test_->add_bytes_written(bytes, complete); | |
| 181 if (complete) | |
| 182 MessageLoop::current()->Quit(); | |
| 183 } | |
| 184 | |
| 185 private: | |
| 186 FileSystemOperationWriteTest* test_; | |
| 187 }; | |
| 188 | |
| 189 } // namespace (anonymous) | 178 } // namespace (anonymous) |
| 190 | 179 |
| 191 void FileSystemOperationWriteTest::SetUp() { | 180 void FileSystemOperationWriteTest::SetUp() { |
| 192 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 181 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
| 193 FilePath base_dir = dir_.path().AppendASCII("filesystem"); | 182 FilePath base_dir = dir_.path().AppendASCII("filesystem"); |
| 194 | 183 |
| 195 quota_manager_ = new MockQuotaManager(base_dir, 1024); | 184 quota_manager_ = new MockQuotaManager(base_dir, 1024); |
| 196 test_helper_.SetUp(base_dir, | 185 test_helper_.SetUp(base_dir, |
| 197 false /* unlimited quota */, | 186 false /* unlimited quota */, |
| 198 quota_manager_->proxy(), | 187 quota_manager_->proxy(), |
| 199 local_file_util_.get()); | 188 local_file_util_.get()); |
| 200 filesystem_dir_ = test_helper_.GetOriginRootPath(); | 189 filesystem_dir_ = test_helper_.GetOriginRootPath(); |
| 201 | 190 |
| 202 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(filesystem_dir_, &file_)); | 191 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(filesystem_dir_, &file_)); |
| 203 virtual_path_ = file_.BaseName(); | 192 virtual_path_ = file_.BaseName(); |
| 204 | 193 |
| 205 net::URLRequest::Deprecated::RegisterProtocolFactory( | 194 net::URLRequest::Deprecated::RegisterProtocolFactory( |
| 206 "blob", &BlobURLRequestJobFactory); | 195 "blob", &BlobURLRequestJobFactory); |
| 207 } | 196 } |
| 208 | 197 |
| 209 void FileSystemOperationWriteTest::TearDown() { | 198 void FileSystemOperationWriteTest::TearDown() { |
| 210 net::URLRequest::Deprecated::RegisterProtocolFactory("blob", NULL); | 199 net::URLRequest::Deprecated::RegisterProtocolFactory("blob", NULL); |
| 211 quota_manager_ = NULL; | 200 quota_manager_ = NULL; |
| 212 test_helper_.TearDown(); | 201 test_helper_.TearDown(); |
| 213 } | 202 } |
| 214 | 203 |
| 215 FileSystemOperation* FileSystemOperationWriteTest::operation() { | 204 FileSystemOperation* FileSystemOperationWriteTest::operation() { |
| 216 return test_helper_.NewOperation(new MockDispatcher(this)); | 205 return test_helper_.NewOperation(); |
| 217 } | 206 } |
| 218 | 207 |
| 219 TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { | 208 TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { |
| 220 GURL blob_url("blob:success"); | 209 GURL blob_url("blob:success"); |
| 221 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 210 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
| 222 blob_data->AppendData("Hello, world!\n"); | 211 blob_data->AppendData("Hello, world!\n"); |
| 223 | 212 |
| 224 scoped_refptr<TestURLRequestContext> url_request_context( | 213 scoped_refptr<TestURLRequestContext> url_request_context( |
| 225 new TestURLRequestContext()); | 214 new TestURLRequestContext()); |
| 226 url_request_context->blob_storage_controller()->AddFinishedBlob( | 215 url_request_context->blob_storage_controller()->AddFinishedBlob( |
| 227 blob_url, blob_data); | 216 blob_url, blob_data); |
| 228 | 217 |
| 229 operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, | 218 operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, |
| 230 0); | 219 0, RecordWriteCallback()); |
| 231 MessageLoop::current()->Run(); | 220 MessageLoop::current()->Run(); |
| 232 | 221 |
| 233 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); | 222 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
| 234 | 223 |
| 235 EXPECT_EQ(14, bytes_written()); | 224 EXPECT_EQ(14, bytes_written()); |
| 236 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 225 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 237 EXPECT_TRUE(complete()); | 226 EXPECT_TRUE(complete()); |
| 238 } | 227 } |
| 239 | 228 |
| 240 TEST_F(FileSystemOperationWriteTest, TestWriteZero) { | 229 TEST_F(FileSystemOperationWriteTest, TestWriteZero) { |
| 241 GURL blob_url("blob:zero"); | 230 GURL blob_url("blob:zero"); |
| 242 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 231 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
| 243 blob_data->AppendData(""); | 232 blob_data->AppendData(""); |
| 244 | 233 |
| 245 scoped_refptr<TestURLRequestContext> url_request_context( | 234 scoped_refptr<TestURLRequestContext> url_request_context( |
| 246 new TestURLRequestContext()); | 235 new TestURLRequestContext()); |
| 247 url_request_context->blob_storage_controller()->AddFinishedBlob( | 236 url_request_context->blob_storage_controller()->AddFinishedBlob( |
| 248 blob_url, blob_data); | 237 blob_url, blob_data); |
| 249 | 238 |
| 250 operation()->Write(url_request_context, URLForPath(virtual_path_), | 239 operation()->Write(url_request_context, URLForPath(virtual_path_), |
| 251 blob_url, 0); | 240 blob_url, 0, RecordWriteCallback()); |
| 252 MessageLoop::current()->Run(); | 241 MessageLoop::current()->Run(); |
| 253 | 242 |
| 254 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); | 243 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
| 255 | 244 |
| 256 EXPECT_EQ(0, bytes_written()); | 245 EXPECT_EQ(0, bytes_written()); |
| 257 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); | 246 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); |
| 258 EXPECT_TRUE(complete()); | 247 EXPECT_TRUE(complete()); |
| 259 } | 248 } |
| 260 | 249 |
| 261 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidBlobUrl) { | 250 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidBlobUrl) { |
| 262 scoped_refptr<TestURLRequestContext> url_request_context( | 251 scoped_refptr<TestURLRequestContext> url_request_context( |
| 263 new TestURLRequestContext()); | 252 new TestURLRequestContext()); |
| 264 | 253 |
| 265 operation()->Write(url_request_context, URLForPath(virtual_path_), | 254 operation()->Write(url_request_context, URLForPath(virtual_path_), |
| 266 GURL("blob:invalid"), 0); | 255 GURL("blob:invalid"), 0, RecordWriteCallback()); |
| 267 MessageLoop::current()->Run(); | 256 MessageLoop::current()->Run(); |
| 268 | 257 |
| 269 EXPECT_EQ(0, bytes_written()); | 258 EXPECT_EQ(0, bytes_written()); |
| 270 EXPECT_EQ(base::PLATFORM_FILE_ERROR_FAILED, status()); | 259 EXPECT_EQ(base::PLATFORM_FILE_ERROR_FAILED, status()); |
| 271 EXPECT_TRUE(complete()); | 260 EXPECT_TRUE(complete()); |
| 272 } | 261 } |
| 273 | 262 |
| 274 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) { | 263 TEST_F(FileSystemOperationWriteTest, TestWriteInvalidFile) { |
| 275 GURL blob_url("blob:writeinvalidfile"); | 264 GURL blob_url("blob:writeinvalidfile"); |
| 276 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 265 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
| 277 blob_data->AppendData("It\'ll not be written."); | 266 blob_data->AppendData("It\'ll not be written."); |
| 278 | 267 |
| 279 scoped_refptr<TestURLRequestContext> url_request_context( | 268 scoped_refptr<TestURLRequestContext> url_request_context( |
| 280 new TestURLRequestContext()); | 269 new TestURLRequestContext()); |
| 281 url_request_context->blob_storage_controller()->AddFinishedBlob( | 270 url_request_context->blob_storage_controller()->AddFinishedBlob( |
| 282 blob_url, blob_data); | 271 blob_url, blob_data); |
| 283 | 272 |
| 284 operation()->Write(url_request_context, | 273 operation()->Write(url_request_context, |
| 285 URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), | 274 URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))), |
| 286 blob_url, 0); | 275 blob_url, 0, RecordWriteCallback()); |
| 287 MessageLoop::current()->Run(); | 276 MessageLoop::current()->Run(); |
| 288 | 277 |
| 289 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); | 278 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
| 290 | 279 |
| 291 EXPECT_EQ(0, bytes_written()); | 280 EXPECT_EQ(0, bytes_written()); |
| 292 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 281 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 293 EXPECT_TRUE(complete()); | 282 EXPECT_TRUE(complete()); |
| 294 } | 283 } |
| 295 | 284 |
| 296 TEST_F(FileSystemOperationWriteTest, TestWriteDir) { | 285 TEST_F(FileSystemOperationWriteTest, TestWriteDir) { |
| 297 FilePath subdir; | 286 FilePath subdir; |
| 298 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(filesystem_dir_, | 287 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(filesystem_dir_, |
| 299 FILE_PATH_LITERAL("d"), | 288 FILE_PATH_LITERAL("d"), |
| 300 &subdir)); | 289 &subdir)); |
| 301 FilePath virtual_subdir_path = subdir.BaseName(); | 290 FilePath virtual_subdir_path = subdir.BaseName(); |
| 302 | 291 |
| 303 GURL blob_url("blob:writedir"); | 292 GURL blob_url("blob:writedir"); |
| 304 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 293 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
| 305 blob_data->AppendData("It\'ll not be written, too."); | 294 blob_data->AppendData("It\'ll not be written, too."); |
| 306 | 295 |
| 307 scoped_refptr<TestURLRequestContext> url_request_context( | 296 scoped_refptr<TestURLRequestContext> url_request_context( |
| 308 new TestURLRequestContext()); | 297 new TestURLRequestContext()); |
| 309 url_request_context->blob_storage_controller()->AddFinishedBlob( | 298 url_request_context->blob_storage_controller()->AddFinishedBlob( |
| 310 blob_url, blob_data); | 299 blob_url, blob_data); |
| 311 | 300 |
| 312 operation()->Write(url_request_context, URLForPath(virtual_subdir_path), | 301 operation()->Write(url_request_context, URLForPath(virtual_subdir_path), |
| 313 blob_url, 0); | 302 blob_url, 0, RecordWriteCallback()); |
| 314 MessageLoop::current()->Run(); | 303 MessageLoop::current()->Run(); |
| 315 | 304 |
| 316 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); | 305 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
| 317 | 306 |
| 318 EXPECT_EQ(0, bytes_written()); | 307 EXPECT_EQ(0, bytes_written()); |
| 319 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ACCESS_DENIED, status()); | 308 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ACCESS_DENIED, status()); |
| 320 EXPECT_TRUE(complete()); | 309 EXPECT_TRUE(complete()); |
| 321 } | 310 } |
| 322 | 311 |
| 323 TEST_F(FileSystemOperationWriteTest, TestWriteFailureByQuota) { | 312 TEST_F(FileSystemOperationWriteTest, TestWriteFailureByQuota) { |
| 324 GURL blob_url("blob:success"); | 313 GURL blob_url("blob:success"); |
| 325 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | 314 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); |
| 326 blob_data->AppendData("Hello, world!\n"); | 315 blob_data->AppendData("Hello, world!\n"); |
| 327 | 316 |
| 328 scoped_refptr<TestURLRequestContext> url_request_context( | 317 scoped_refptr<TestURLRequestContext> url_request_context( |
| 329 new TestURLRequestContext()); | 318 new TestURLRequestContext()); |
| 330 url_request_context->blob_storage_controller()->AddFinishedBlob( | 319 url_request_context->blob_storage_controller()->AddFinishedBlob( |
| 331 blob_url, blob_data); | 320 blob_url, blob_data); |
| 332 | 321 |
| 333 quota_manager_->set_quota(10); | 322 quota_manager_->set_quota(10); |
| 334 operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, | 323 operation()->Write(url_request_context, URLForPath(virtual_path_), blob_url, |
| 335 0); | 324 0, RecordWriteCallback()); |
| 336 MessageLoop::current()->Run(); | 325 MessageLoop::current()->Run(); |
| 337 | 326 |
| 338 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); | 327 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); |
| 339 | 328 |
| 340 EXPECT_EQ(10, bytes_written()); | 329 EXPECT_EQ(10, bytes_written()); |
| 341 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); | 330 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); |
| 342 EXPECT_TRUE(complete()); | 331 EXPECT_TRUE(complete()); |
| 343 } | 332 } |
| 344 | 333 |
| 345 // TODO(ericu,dmikurube): Add tests for Cancel. | 334 TEST_F(FileSystemOperationWriteTest, TestImmediateCancel) { |
| 335 GURL blob_url("blob:success"); | |
| 336 scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); | |
| 337 blob_data->AppendData("Hello, world!\n"); | |
| 338 | |
| 339 scoped_refptr<TestURLRequestContext> url_request_context( | |
| 340 new TestURLRequestContext()); | |
| 341 url_request_context->blob_storage_controller()->AddFinishedBlob( | |
| 342 blob_url, blob_data); | |
| 343 | |
| 344 FileSystemOperationInterface* write_operation = operation(); | |
| 345 write_operation->Write(url_request_context, URLForPath(virtual_path_), | |
| 346 blob_url, 0, RecordWriteCallback()); | |
| 347 write_operation->Cancel(RecordCancelCallback()); | |
| 348 MessageLoop::current()->RunAllPending(); | |
|
kinuko
2012/02/13 10:10:21
Could we add a comment why we call RunAllPending()
kinaba
2012/02/14 02:17:47
Done.
| |
| 349 | |
| 350 url_request_context->blob_storage_controller()->RemoveBlob(blob_url); | |
| 351 | |
| 352 // Issued Cancel() before receiving any response from Write(), | |
| 353 // so nothing should have happen. | |
| 354 EXPECT_EQ(0, bytes_written()); | |
| 355 EXPECT_EQ(base::PLATFORM_FILE_ERROR_ABORT, status()); | |
| 356 EXPECT_EQ(base::PLATFORM_FILE_OK, cancel_status()); | |
| 357 EXPECT_TRUE(complete()); | |
| 358 } | |
| 359 | |
| 360 // TODO(ericu,dmikurube): Add more tests for Cancel. | |
| 346 | 361 |
| 347 } // namespace fileapi | 362 } // namespace fileapi |
| OLD | NEW |