Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 | 21 |
| 22 using content::AsyncFileTestHelper; | 22 using content::AsyncFileTestHelper; |
| 23 using storage::FileSystemContext; | 23 using storage::FileSystemContext; |
| 24 using storage::FileSystemURL; | 24 using storage::FileSystemURL; |
| 25 using storage::IsolatedContext; | 25 using storage::IsolatedContext; |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const GURL kOrigin("http://www.example.com"); | 31 const GURL kOrigin1("http://www.example.com"); |
| 32 const GURL kOrigin2("https://www.example.com"); | |
| 32 const std::string kPlugin1("plugin1"); | 33 const std::string kPlugin1("plugin1"); |
| 33 const std::string kPlugin2("plugin2"); | 34 const std::string kPlugin2("plugin2"); |
| 34 const storage::FileSystemType kType = storage::kFileSystemTypePluginPrivate; | 35 const storage::FileSystemType kType = storage::kFileSystemTypePluginPrivate; |
| 35 const std::string kRootName = "pluginprivate"; | 36 const std::string kRootName = "pluginprivate"; |
| 36 | 37 |
| 37 void DidOpenFileSystem(base::File::Error* error_out, | 38 void DidOpenFileSystem(base::File::Error* error_out, |
| 38 base::File::Error error) { | 39 base::File::Error error) { |
| 39 *error_out = error; | 40 *error_out = error; |
| 40 } | 41 } |
| 41 | 42 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 65 | 66 |
| 66 storage::PluginPrivateFileSystemBackend* backend() const { | 67 storage::PluginPrivateFileSystemBackend* backend() const { |
| 67 return context_->plugin_private_backend(); | 68 return context_->plugin_private_backend(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 const base::FilePath& base_path() const { return backend()->base_path(); } | 71 const base::FilePath& base_path() const { return backend()->base_path(); } |
| 71 | 72 |
| 72 base::ScopedTempDir data_dir_; | 73 base::ScopedTempDir data_dir_; |
| 73 base::MessageLoop message_loop_; | 74 base::MessageLoop message_loop_; |
| 74 scoped_refptr<FileSystemContext> context_; | 75 scoped_refptr<FileSystemContext> context_; |
| 75 std::string filesystem_id_; | |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // TODO(kinuko,nhiroki): There are a lot of duplicate code in these tests. Write | |
| 79 // helper functions to simplify the tests. | |
| 80 | |
| 78 TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { | 81 TEST_F(PluginPrivateFileSystemBackendTest, OpenFileSystemBasic) { |
| 79 const std::string filesystem_id1 = RegisterFileSystem(); | 82 const std::string filesystem_id1 = RegisterFileSystem(); |
| 80 base::File::Error error = base::File::FILE_ERROR_FAILED; | 83 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 81 backend()->OpenPrivateFileSystem( | 84 backend()->OpenPrivateFileSystem( |
| 82 kOrigin, | 85 kOrigin1, |
| 83 kType, | 86 kType, |
| 84 filesystem_id1, | 87 filesystem_id1, |
| 85 kPlugin1, | 88 kPlugin1, |
| 86 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 89 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 87 base::Bind(&DidOpenFileSystem, &error)); | 90 base::Bind(&DidOpenFileSystem, &error)); |
| 88 base::RunLoop().RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
| 89 ASSERT_EQ(base::File::FILE_OK, error); | 92 ASSERT_EQ(base::File::FILE_OK, error); |
| 90 | 93 |
| 91 // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. | 94 // Run this again with FAIL_IF_NONEXISTENT to see if it succeeds. |
| 92 const std::string filesystem_id2 = RegisterFileSystem(); | 95 const std::string filesystem_id2 = RegisterFileSystem(); |
| 93 error = base::File::FILE_ERROR_FAILED; | 96 error = base::File::FILE_ERROR_FAILED; |
| 94 backend()->OpenPrivateFileSystem( | 97 backend()->OpenPrivateFileSystem( |
| 95 kOrigin, | 98 kOrigin1, |
| 96 kType, | 99 kType, |
| 97 filesystem_id2, | 100 filesystem_id2, |
| 98 kPlugin1, | 101 kPlugin1, |
| 99 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 102 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 100 base::Bind(&DidOpenFileSystem, &error)); | 103 base::Bind(&DidOpenFileSystem, &error)); |
| 101 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
| 102 ASSERT_EQ(base::File::FILE_OK, error); | 105 ASSERT_EQ(base::File::FILE_OK, error); |
| 103 | 106 |
| 104 const GURL root_url(storage::GetIsolatedFileSystemRootURIString( | 107 const GURL root_url(storage::GetIsolatedFileSystemRootURIString( |
| 105 kOrigin, filesystem_id1, kRootName)); | 108 kOrigin1, filesystem_id1, kRootName)); |
| 106 FileSystemURL file = CreateURL(root_url, "foo"); | 109 FileSystemURL file = CreateURL(root_url, "foo"); |
| 107 base::FilePath platform_path; | 110 base::FilePath platform_path; |
| 108 EXPECT_EQ(base::File::FILE_OK, | 111 EXPECT_EQ(base::File::FILE_OK, |
| 109 AsyncFileTestHelper::CreateFile(context_.get(), file)); | 112 AsyncFileTestHelper::CreateFile(context_.get(), file)); |
| 110 EXPECT_EQ(base::File::FILE_OK, | 113 EXPECT_EQ(base::File::FILE_OK, |
| 111 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, | 114 AsyncFileTestHelper::GetPlatformPath(context_.get(), file, |
| 112 &platform_path)); | 115 &platform_path)); |
| 113 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( | 116 EXPECT_TRUE(base_path().AppendASCII("000").AppendASCII(kPlugin1).IsParent( |
| 114 platform_path)); | 117 platform_path)); |
| 115 } | 118 } |
| 116 | 119 |
| 117 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { | 120 TEST_F(PluginPrivateFileSystemBackendTest, PluginIsolation) { |
| 118 // Open filesystem for kPlugin1 and kPlugin2. | 121 // Open filesystem for kPlugin1 and kPlugin2. |
| 119 const std::string filesystem_id1 = RegisterFileSystem(); | 122 const std::string filesystem_id1 = RegisterFileSystem(); |
| 120 base::File::Error error = base::File::FILE_ERROR_FAILED; | 123 base::File::Error error = base::File::FILE_ERROR_FAILED; |
| 121 backend()->OpenPrivateFileSystem( | 124 backend()->OpenPrivateFileSystem( |
| 122 kOrigin, | 125 kOrigin1, |
| 123 kType, | 126 kType, |
| 124 filesystem_id1, | 127 filesystem_id1, |
| 125 kPlugin1, | 128 kPlugin1, |
| 126 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 129 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 127 base::Bind(&DidOpenFileSystem, &error)); | 130 base::Bind(&DidOpenFileSystem, &error)); |
| 128 base::RunLoop().RunUntilIdle(); | 131 base::RunLoop().RunUntilIdle(); |
| 129 ASSERT_EQ(base::File::FILE_OK, error); | 132 ASSERT_EQ(base::File::FILE_OK, error); |
| 130 | 133 |
| 131 const std::string filesystem_id2 = RegisterFileSystem(); | 134 const std::string filesystem_id2 = RegisterFileSystem(); |
| 132 error = base::File::FILE_ERROR_FAILED; | 135 error = base::File::FILE_ERROR_FAILED; |
| 133 backend()->OpenPrivateFileSystem( | 136 backend()->OpenPrivateFileSystem( |
| 134 kOrigin, | 137 kOrigin1, |
| 135 kType, | 138 kType, |
| 136 filesystem_id2, | 139 filesystem_id2, |
| 137 kPlugin2, | 140 kPlugin2, |
| 138 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 141 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 139 base::Bind(&DidOpenFileSystem, &error)); | 142 base::Bind(&DidOpenFileSystem, &error)); |
| 140 base::RunLoop().RunUntilIdle(); | 143 base::RunLoop().RunUntilIdle(); |
| 141 ASSERT_EQ(base::File::FILE_OK, error); | 144 ASSERT_EQ(base::File::FILE_OK, error); |
| 142 | 145 |
| 143 // Create 'foo' in kPlugin1. | 146 // Create 'foo' in kPlugin1. |
| 144 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( | 147 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( |
| 145 kOrigin, filesystem_id1, kRootName)); | 148 kOrigin1, filesystem_id1, kRootName)); |
| 146 FileSystemURL file1 = CreateURL(root_url1, "foo"); | 149 FileSystemURL file1 = CreateURL(root_url1, "foo"); |
| 147 base::FilePath platform_path; | |
| 148 EXPECT_EQ(base::File::FILE_OK, | 150 EXPECT_EQ(base::File::FILE_OK, |
| 149 AsyncFileTestHelper::CreateFile(context_.get(), file1)); | 151 AsyncFileTestHelper::CreateFile(context_.get(), file1)); |
| 150 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | 152 EXPECT_TRUE(AsyncFileTestHelper::FileExists( |
| 151 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | 153 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); |
| 152 | 154 |
| 153 // See the same path is not available in kPlugin2. | 155 // See the same path is not available in kPlugin2. |
| 154 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( | 156 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( |
| 155 kOrigin, filesystem_id2, kRootName)); | 157 kOrigin1, filesystem_id2, kRootName)); |
| 156 FileSystemURL file2 = CreateURL(root_url2, "foo"); | 158 FileSystemURL file2 = CreateURL(root_url2, "foo"); |
| 157 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | 159 EXPECT_FALSE(AsyncFileTestHelper::FileExists( |
| 158 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | 160 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); |
| 159 } | 161 } |
| 160 | 162 |
| 161 // TODO(kinuko,nhiroki): also test if DeleteOriginDataOnFileThread | 163 TEST_F(PluginPrivateFileSystemBackendTest, OriginIsolation) { |
| 162 // works fine when there's multiple plugin partitions. | 164 // Open filesystem for kOrigin1 and kOrigin2. |
| 165 const std::string filesystem_id1 = RegisterFileSystem(); | |
| 166 base::File::Error error = base::File::FILE_ERROR_FAILED; | |
| 167 backend()->OpenPrivateFileSystem( | |
| 168 kOrigin1, | |
| 169 kType, | |
| 170 filesystem_id1, | |
| 171 kPlugin1, | |
| 172 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | |
| 173 base::Bind(&DidOpenFileSystem, &error)); | |
| 174 base::RunLoop().RunUntilIdle(); | |
| 175 ASSERT_EQ(base::File::FILE_OK, error); | |
| 176 | |
| 177 const std::string filesystem_id2 = RegisterFileSystem(); | |
| 178 error = base::File::FILE_ERROR_FAILED; | |
| 179 backend()->OpenPrivateFileSystem( | |
| 180 kOrigin2, | |
| 181 kType, | |
| 182 filesystem_id2, | |
| 183 kPlugin1, | |
| 184 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | |
| 185 base::Bind(&DidOpenFileSystem, &error)); | |
| 186 base::RunLoop().RunUntilIdle(); | |
| 187 ASSERT_EQ(base::File::FILE_OK, error); | |
| 188 | |
| 189 // Create 'foo' in kOrigin1. | |
| 190 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( | |
| 191 kOrigin1, filesystem_id1, kRootName)); | |
| 192 FileSystemURL file1 = CreateURL(root_url1, "foo"); | |
| 193 EXPECT_EQ(base::File::FILE_OK, | |
| 194 AsyncFileTestHelper::CreateFile(context_.get(), file1)); | |
| 195 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | |
| 196 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | |
| 197 | |
| 198 // See the same path is not available in kOrigin2. | |
| 199 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( | |
| 200 kOrigin2, filesystem_id2, kRootName)); | |
| 201 FileSystemURL file2 = CreateURL(root_url2, "foo"); | |
| 202 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | |
| 203 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | |
| 204 } | |
| 205 | |
| 206 TEST_F(PluginPrivateFileSystemBackendTest, DeleteOriginDirectory) { | |
| 207 // Open filesystem for kOrigin1 and kOrigin2. | |
| 208 const std::string filesystem_id1 = RegisterFileSystem(); | |
| 209 base::File::Error error = base::File::FILE_ERROR_FAILED; | |
| 210 backend()->OpenPrivateFileSystem( | |
| 211 kOrigin1, | |
| 212 kType, | |
| 213 filesystem_id1, | |
| 214 kPlugin1, | |
| 215 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | |
| 216 base::Bind(&DidOpenFileSystem, &error)); | |
| 217 base::RunLoop().RunUntilIdle(); | |
| 218 ASSERT_EQ(base::File::FILE_OK, error); | |
| 219 | |
| 220 const std::string filesystem_id2 = RegisterFileSystem(); | |
| 221 error = base::File::FILE_ERROR_FAILED; | |
| 222 backend()->OpenPrivateFileSystem( | |
| 223 kOrigin2, | |
| 224 kType, | |
| 225 filesystem_id2, | |
| 226 kPlugin1, | |
| 227 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | |
| 228 base::Bind(&DidOpenFileSystem, &error)); | |
| 229 base::RunLoop().RunUntilIdle(); | |
| 230 ASSERT_EQ(base::File::FILE_OK, error); | |
| 231 | |
| 232 // Create 'foo' in kOrigin1. | |
| 233 const GURL root_url1(storage::GetIsolatedFileSystemRootURIString( | |
| 234 kOrigin1, filesystem_id1, kRootName)); | |
| 235 FileSystemURL file1 = CreateURL(root_url1, "foo"); | |
| 236 EXPECT_EQ(base::File::FILE_OK, | |
| 237 AsyncFileTestHelper::CreateFile(context_.get(), file1)); | |
| 238 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | |
| 239 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | |
| 240 | |
| 241 // See the same path is not available in kOrigin2. | |
| 242 const GURL root_url2(storage::GetIsolatedFileSystemRootURIString( | |
| 243 kOrigin2, filesystem_id2, kRootName)); | |
| 244 FileSystemURL file2 = CreateURL(root_url2, "foo"); | |
| 245 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | |
| 246 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | |
| 247 | |
| 248 // Create 'foo' in kOrigin2. | |
| 249 EXPECT_EQ(base::File::FILE_OK, | |
| 250 AsyncFileTestHelper::CreateFile(context_.get(), file2)); | |
| 251 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | |
| 252 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | |
| 253 | |
| 254 // Delete data for kOrigin1. | |
| 255 error = backend()->DeleteOriginDataOnFileTaskRunner( | |
| 256 context_.get(), NULL, kOrigin1, kType); | |
| 257 EXPECT_EQ(base::File::FILE_OK, error); | |
| 258 | |
| 259 // Confirm 'foo' in kOrigin1 is deleted. | |
| 260 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | |
| 261 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | |
| 262 | |
| 263 // Confirm 'foo' in kOrigin2 is NOT deleted. | |
| 264 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | |
| 265 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | |
| 266 | |
| 267 // Create 'foo' in kOrigin1 again and make sure it still work. | |
| 268 EXPECT_EQ(base::File::FILE_OK, | |
| 269 AsyncFileTestHelper::CreateFile(context_.get(), file1)); | |
| 270 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | |
| 271 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | |
| 272 | |
| 273 // Delete data for kOrigin2. | |
| 274 error = backend()->DeleteOriginDataOnFileTaskRunner( | |
| 275 context_.get(), NULL, kOrigin2, kType); | |
| 276 EXPECT_EQ(base::File::FILE_OK, error); | |
| 277 | |
| 278 // Confirm 'foo' in kOrigin2 is deleted. | |
| 279 EXPECT_FALSE(AsyncFileTestHelper::FileExists( | |
| 280 context_.get(), file2, AsyncFileTestHelper::kDontCheckSize)); | |
| 281 | |
| 282 // Confirm 'foo' in kOrigin1 is NOT deleted. | |
| 283 EXPECT_TRUE(AsyncFileTestHelper::FileExists( | |
| 284 context_.get(), file1, AsyncFileTestHelper::kDontCheckSize)); | |
| 285 } | |
|
xhwang
2014/09/19 04:54:24
This test is failing with this CL:
[ RUN ] P
nhiroki
2014/09/19 17:17:19
"a backing file" means an actual file on the os-le
| |
| 163 | 286 |
| 164 } // namespace content | 287 } // namespace content |
| OLD | NEW |