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 "webkit/fileapi/file_system_file_stream_reader.h" | 5 #include "webkit/fileapi/file_system_file_stream_reader.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/base/test_completion_callback.h" | 16 #include "net/base/test_completion_callback.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webkit/fileapi/external_mount_points.h" | 18 #include "webkit/fileapi/external_mount_points.h" |
19 #include "webkit/fileapi/file_system_context.h" | 19 #include "webkit/fileapi/file_system_context.h" |
20 #include "webkit/fileapi/file_system_file_util.h" | 20 #include "webkit/fileapi/file_system_file_util.h" |
21 #include "webkit/fileapi/file_system_operation_context.h" | 21 #include "webkit/fileapi/file_system_operation_context.h" |
22 #include "webkit/fileapi/file_system_task_runners.h" | 22 #include "webkit/fileapi/file_system_task_runners.h" |
23 #include "webkit/fileapi/mock_file_system_options.h" | 23 #include "webkit/fileapi/mock_file_system_options.h" |
24 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 24 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
25 #include "webkit/quota/mock_special_storage_policy.h" | |
26 | 25 |
27 namespace fileapi { | 26 namespace fileapi { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 const char kURLOrigin[] = "http://remote/"; | 30 const char kURLOrigin[] = "http://remote/"; |
32 const char kTestFileName[] = "test.dat"; | 31 const char kTestFileName[] = "test.dat"; |
33 const char kTestData[] = "0123456789"; | 32 const char kTestData[] = "0123456789"; |
34 const int kTestDataSize = arraysize(kTestData) - 1; | 33 const int kTestDataSize = arraysize(kTestData) - 1; |
35 | 34 |
(...skipping 26 matching lines...) Expand all Loading... |
62 } // namespace | 61 } // namespace |
63 | 62 |
64 class FileSystemFileStreamReaderTest : public testing::Test { | 63 class FileSystemFileStreamReaderTest : public testing::Test { |
65 public: | 64 public: |
66 FileSystemFileStreamReaderTest() | 65 FileSystemFileStreamReaderTest() |
67 : message_loop_(MessageLoop::TYPE_IO) {} | 66 : message_loop_(MessageLoop::TYPE_IO) {} |
68 | 67 |
69 virtual void SetUp() OVERRIDE { | 68 virtual void SetUp() OVERRIDE { |
70 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 69 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
71 | 70 |
72 special_storage_policy_ = new quota::MockSpecialStoragePolicy; | |
73 file_system_context_ = | 71 file_system_context_ = |
74 new FileSystemContext( | 72 new FileSystemContext( |
75 FileSystemTaskRunners::CreateMockTaskRunners(), | 73 FileSystemTaskRunners::CreateMockTaskRunners(), |
76 ExternalMountPoints::CreateRefCounted().get(), | |
77 special_storage_policy_, | |
78 NULL, | 74 NULL, |
| 75 ScopedVector<FileSystemMountPointProvider>(), |
| 76 std::vector<MountPoints*>(), |
79 temp_dir_.path(), | 77 temp_dir_.path(), |
80 CreateDisallowFileAccessOptions()); | 78 CreateDisallowFileAccessOptions()); |
81 | 79 |
82 file_system_context_->sandbox_provider()->ValidateFileSystemRoot( | 80 file_system_context_->sandbox_provider()->ValidateFileSystemRoot( |
83 GURL(kURLOrigin), kFileSystemTypeTemporary, true, // create | 81 GURL(kURLOrigin), kFileSystemTypeTemporary, true, // create |
84 base::Bind(&OnValidateFileSystem)); | 82 base::Bind(&OnValidateFileSystem)); |
85 MessageLoop::current()->RunUntilIdle(); | 83 MessageLoop::current()->RunUntilIdle(); |
86 | 84 |
87 WriteFile(kTestFileName, kTestData, kTestDataSize, | 85 WriteFile(kTestFileName, kTestData, kTestDataSize, |
88 &test_file_modification_time_); | 86 &test_file_modification_time_); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 146 |
149 FileSystemURL GetFileSystemURL(const std::string& file_name) { | 147 FileSystemURL GetFileSystemURL(const std::string& file_name) { |
150 return file_system_context_->CreateCrackedFileSystemURL( | 148 return file_system_context_->CreateCrackedFileSystemURL( |
151 GURL(kURLOrigin), | 149 GURL(kURLOrigin), |
152 kFileSystemTypeTemporary, | 150 kFileSystemTypeTemporary, |
153 base::FilePath().AppendASCII(file_name)); | 151 base::FilePath().AppendASCII(file_name)); |
154 } | 152 } |
155 | 153 |
156 MessageLoop message_loop_; | 154 MessageLoop message_loop_; |
157 base::ScopedTempDir temp_dir_; | 155 base::ScopedTempDir temp_dir_; |
158 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; | |
159 scoped_refptr<FileSystemContext> file_system_context_; | 156 scoped_refptr<FileSystemContext> file_system_context_; |
160 base::Time test_file_modification_time_; | 157 base::Time test_file_modification_time_; |
161 }; | 158 }; |
162 | 159 |
163 TEST_F(FileSystemFileStreamReaderTest, NonExistent) { | 160 TEST_F(FileSystemFileStreamReaderTest, NonExistent) { |
164 const char kFileName[] = "nonexistent"; | 161 const char kFileName[] = "nonexistent"; |
165 scoped_ptr<FileSystemFileStreamReader> reader( | 162 scoped_ptr<FileSystemFileStreamReader> reader( |
166 CreateFileReader(kFileName, 0, base::Time())); | 163 CreateFileReader(kFileName, 0, base::Time())); |
167 int result = 0; | 164 int result = 0; |
168 std::string data; | 165 std::string data; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 new net::IOBufferWithSize(kTestDataSize)); | 279 new net::IOBufferWithSize(kTestDataSize)); |
283 int rv = reader->Read(buf, buf->size(), base::Bind(&NeverCalled)); | 280 int rv = reader->Read(buf, buf->size(), base::Bind(&NeverCalled)); |
284 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0); | 281 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0); |
285 | 282 |
286 // Delete immediately. | 283 // Delete immediately. |
287 // Should not crash; nor should NeverCalled be callback. | 284 // Should not crash; nor should NeverCalled be callback. |
288 reader.reset(); | 285 reader.reset(); |
289 } | 286 } |
290 | 287 |
291 } // namespace fileapi | 288 } // namespace fileapi |
OLD | NEW |