| 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 "storage/browser/fileapi/sandbox_file_system_backend.h" | 5 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 "http://www.foo.com/", | 148 "http://www.foo.com/", |
| 149 "http://www.foo.com:1/", | 149 "http://www.foo.com:1/", |
| 150 "http://www.example.com:8080/", | 150 "http://www.example.com:8080/", |
| 151 "http://www.google.com:80/", | 151 "http://www.google.com:80/", |
| 152 }; | 152 }; |
| 153 const char* persistent_origins[] = { | 153 const char* persistent_origins[] = { |
| 154 "http://www.bar.com/", | 154 "http://www.bar.com/", |
| 155 "http://www.foo.com:8080/", | 155 "http://www.foo.com:8080/", |
| 156 "http://www.foo.com:80/", | 156 "http://www.foo.com:80/", |
| 157 }; | 157 }; |
| 158 size_t temporary_size = ARRAYSIZE_UNSAFE(temporary_origins); | 158 size_t temporary_size = arraysize(temporary_origins); |
| 159 size_t persistent_size = ARRAYSIZE_UNSAFE(persistent_origins); | 159 size_t persistent_size = arraysize(persistent_origins); |
| 160 std::set<GURL> temporary_set, persistent_set; | 160 std::set<GURL> temporary_set, persistent_set; |
| 161 for (size_t i = 0; i < temporary_size; ++i) { | 161 for (size_t i = 0; i < temporary_size; ++i) { |
| 162 CreateOriginTypeDirectory(GURL(temporary_origins[i]), | 162 CreateOriginTypeDirectory(GURL(temporary_origins[i]), |
| 163 storage::kFileSystemTypeTemporary); | 163 storage::kFileSystemTypeTemporary); |
| 164 temporary_set.insert(GURL(temporary_origins[i])); | 164 temporary_set.insert(GURL(temporary_origins[i])); |
| 165 } | 165 } |
| 166 for (size_t i = 0; i < persistent_size; ++i) { | 166 for (size_t i = 0; i < persistent_size; ++i) { |
| 167 CreateOriginTypeDirectory(GURL(persistent_origins[i]), | 167 CreateOriginTypeDirectory(GURL(persistent_origins[i]), |
| 168 storage::kFileSystemTypePersistent); | 168 storage::kFileSystemTypePersistent); |
| 169 persistent_set.insert(GURL(persistent_origins[i])); | 169 persistent_set.insert(GURL(persistent_origins[i])); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 184 ASSERT_TRUE(persistent_set.find(current) != persistent_set.end()); | 184 ASSERT_TRUE(persistent_set.find(current) != persistent_set.end()); |
| 185 ++persistent_actual_size; | 185 ++persistent_actual_size; |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 EXPECT_EQ(temporary_size, temporary_actual_size); | 189 EXPECT_EQ(temporary_size, temporary_actual_size); |
| 190 EXPECT_EQ(persistent_size, persistent_actual_size); | 190 EXPECT_EQ(persistent_size, persistent_actual_size); |
| 191 } | 191 } |
| 192 | 192 |
| 193 TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { | 193 TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { |
| 194 std::vector<base::FilePath> returned_root_path( | 194 std::vector<base::FilePath> returned_root_path(arraysize(kRootPathTestCases)); |
| 195 ARRAYSIZE_UNSAFE(kRootPathTestCases)); | |
| 196 SetUpNewBackend(CreateAllowFileAccessOptions()); | 195 SetUpNewBackend(CreateAllowFileAccessOptions()); |
| 197 | 196 |
| 198 // Create a new root directory. | 197 // Create a new root directory. |
| 199 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | 198 for (size_t i = 0; i < arraysize(kRootPathTestCases); ++i) { |
| 200 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " " | 199 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " " |
| 201 << kRootPathTestCases[i].expected_path); | 200 << kRootPathTestCases[i].expected_path); |
| 202 | 201 |
| 203 base::FilePath root_path; | 202 base::FilePath root_path; |
| 204 EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), | 203 EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), |
| 205 kRootPathTestCases[i].type, | 204 kRootPathTestCases[i].type, |
| 206 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 205 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 207 &root_path)); | 206 &root_path)); |
| 208 | 207 |
| 209 base::FilePath expected = file_system_path().AppendASCII( | 208 base::FilePath expected = file_system_path().AppendASCII( |
| 210 kRootPathTestCases[i].expected_path); | 209 kRootPathTestCases[i].expected_path); |
| 211 EXPECT_EQ(expected.value(), root_path.value()); | 210 EXPECT_EQ(expected.value(), root_path.value()); |
| 212 EXPECT_TRUE(base::DirectoryExists(root_path)); | 211 EXPECT_TRUE(base::DirectoryExists(root_path)); |
| 213 ASSERT_TRUE(returned_root_path.size() > i); | 212 ASSERT_TRUE(returned_root_path.size() > i); |
| 214 returned_root_path[i] = root_path; | 213 returned_root_path[i] = root_path; |
| 215 } | 214 } |
| 216 | 215 |
| 217 // Get the root directory with create=false and see if we get the | 216 // Get the root directory with create=false and see if we get the |
| 218 // same directory. | 217 // same directory. |
| 219 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | 218 for (size_t i = 0; i < arraysize(kRootPathTestCases); ++i) { |
| 220 SCOPED_TRACE(testing::Message() << "RootPath (get) #" << i << " " | 219 SCOPED_TRACE(testing::Message() << "RootPath (get) #" << i << " " |
| 221 << kRootPathTestCases[i].expected_path); | 220 << kRootPathTestCases[i].expected_path); |
| 222 | 221 |
| 223 base::FilePath root_path; | 222 base::FilePath root_path; |
| 224 EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), | 223 EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), |
| 225 kRootPathTestCases[i].type, | 224 kRootPathTestCases[i].type, |
| 226 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 225 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 227 &root_path)); | 226 &root_path)); |
| 228 ASSERT_TRUE(returned_root_path.size() > i); | 227 ASSERT_TRUE(returned_root_path.size() > i); |
| 229 EXPECT_EQ(returned_root_path[i].value(), root_path.value()); | 228 EXPECT_EQ(returned_root_path[i].value(), root_path.value()); |
| 230 } | 229 } |
| 231 } | 230 } |
| 232 | 231 |
| 233 TEST_F(SandboxFileSystemBackendTest, | 232 TEST_F(SandboxFileSystemBackendTest, |
| 234 GetRootPathCreateAndExamineWithNewBackend) { | 233 GetRootPathCreateAndExamineWithNewBackend) { |
| 235 std::vector<base::FilePath> returned_root_path( | 234 std::vector<base::FilePath> returned_root_path(arraysize(kRootPathTestCases)); |
| 236 ARRAYSIZE_UNSAFE(kRootPathTestCases)); | |
| 237 SetUpNewBackend(CreateAllowFileAccessOptions()); | 235 SetUpNewBackend(CreateAllowFileAccessOptions()); |
| 238 | 236 |
| 239 GURL origin_url("http://foo.com:1/"); | 237 GURL origin_url("http://foo.com:1/"); |
| 240 | 238 |
| 241 base::FilePath root_path1; | 239 base::FilePath root_path1; |
| 242 EXPECT_TRUE(GetRootPath(origin_url, | 240 EXPECT_TRUE(GetRootPath(origin_url, |
| 243 storage::kFileSystemTypeTemporary, | 241 storage::kFileSystemTypeTemporary, |
| 244 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 242 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 245 &root_path1)); | 243 &root_path1)); |
| 246 | 244 |
| 247 SetUpNewBackend(CreateDisallowFileAccessOptions()); | 245 SetUpNewBackend(CreateDisallowFileAccessOptions()); |
| 248 base::FilePath root_path2; | 246 base::FilePath root_path2; |
| 249 EXPECT_TRUE(GetRootPath(origin_url, | 247 EXPECT_TRUE(GetRootPath(origin_url, |
| 250 storage::kFileSystemTypeTemporary, | 248 storage::kFileSystemTypeTemporary, |
| 251 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 249 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 252 &root_path2)); | 250 &root_path2)); |
| 253 | 251 |
| 254 EXPECT_EQ(root_path1.value(), root_path2.value()); | 252 EXPECT_EQ(root_path1.value(), root_path2.value()); |
| 255 } | 253 } |
| 256 | 254 |
| 257 TEST_F(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { | 255 TEST_F(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { |
| 258 SetUpNewBackend(CreateDisallowFileAccessOptions()); | 256 SetUpNewBackend(CreateDisallowFileAccessOptions()); |
| 259 | 257 |
| 260 // Try to get a root directory without creating. | 258 // Try to get a root directory without creating. |
| 261 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | 259 for (size_t i = 0; i < arraysize(kRootPathTestCases); ++i) { |
| 262 SCOPED_TRACE(testing::Message() << "RootPath (create=false) #" << i << " " | 260 SCOPED_TRACE(testing::Message() << "RootPath (create=false) #" << i << " " |
| 263 << kRootPathTestCases[i].expected_path); | 261 << kRootPathTestCases[i].expected_path); |
| 264 EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), | 262 EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), |
| 265 kRootPathTestCases[i].type, | 263 kRootPathTestCases[i].type, |
| 266 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 264 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 267 NULL)); | 265 NULL)); |
| 268 } | 266 } |
| 269 } | 267 } |
| 270 | 268 |
| 271 TEST_F(SandboxFileSystemBackendTest, GetRootPathInIncognito) { | 269 TEST_F(SandboxFileSystemBackendTest, GetRootPathInIncognito) { |
| 272 SetUpNewBackend(CreateIncognitoFileSystemOptions()); | 270 SetUpNewBackend(CreateIncognitoFileSystemOptions()); |
| 273 | 271 |
| 274 // Try to get a root directory. | 272 // Try to get a root directory. |
| 275 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | 273 for (size_t i = 0; i < arraysize(kRootPathTestCases); ++i) { |
| 276 SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " | 274 SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " |
| 277 << kRootPathTestCases[i].expected_path); | 275 << kRootPathTestCases[i].expected_path); |
| 278 EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), | 276 EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), |
| 279 kRootPathTestCases[i].type, | 277 kRootPathTestCases[i].type, |
| 280 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 278 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 281 NULL)); | 279 NULL)); |
| 282 } | 280 } |
| 283 } | 281 } |
| 284 | 282 |
| 285 TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURI) { | 283 TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURI) { |
| 286 SetUpNewBackend(CreateDisallowFileAccessOptions()); | 284 SetUpNewBackend(CreateDisallowFileAccessOptions()); |
| 287 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { | 285 for (size_t i = 0; i < arraysize(kRootPathFileURITestCases); ++i) { |
| 288 SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #" | 286 SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #" |
| 289 << i << " " << kRootPathFileURITestCases[i].expected_path); | 287 << i << " " << kRootPathFileURITestCases[i].expected_path); |
| 290 EXPECT_FALSE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), | 288 EXPECT_FALSE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), |
| 291 kRootPathFileURITestCases[i].type, | 289 kRootPathFileURITestCases[i].type, |
| 292 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 290 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 293 NULL)); | 291 NULL)); |
| 294 } | 292 } |
| 295 } | 293 } |
| 296 | 294 |
| 297 TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURIWithAllowFlag) { | 295 TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURIWithAllowFlag) { |
| 298 SetUpNewBackend(CreateAllowFileAccessOptions()); | 296 SetUpNewBackend(CreateAllowFileAccessOptions()); |
| 299 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { | 297 for (size_t i = 0; i < arraysize(kRootPathFileURITestCases); ++i) { |
| 300 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" | 298 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" |
| 301 << i << " " << kRootPathFileURITestCases[i].expected_path); | 299 << i << " " << kRootPathFileURITestCases[i].expected_path); |
| 302 base::FilePath root_path; | 300 base::FilePath root_path; |
| 303 EXPECT_TRUE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), | 301 EXPECT_TRUE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), |
| 304 kRootPathFileURITestCases[i].type, | 302 kRootPathFileURITestCases[i].type, |
| 305 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 303 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 306 &root_path)); | 304 &root_path)); |
| 307 base::FilePath expected = file_system_path().AppendASCII( | 305 base::FilePath expected = file_system_path().AppendASCII( |
| 308 kRootPathFileURITestCases[i].expected_path); | 306 kRootPathFileURITestCases[i].expected_path); |
| 309 EXPECT_EQ(expected.value(), root_path.value()); | 307 EXPECT_EQ(expected.value(), root_path.value()); |
| 310 EXPECT_TRUE(base::DirectoryExists(root_path)); | 308 EXPECT_TRUE(base::DirectoryExists(root_path)); |
| 311 } | 309 } |
| 312 } | 310 } |
| 313 | 311 |
| 314 } // namespace content | 312 } // namespace content |
| OLD | NEW |