| 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 "webkit/browser/fileapi/sandbox_file_system_backend.h" | 5 #include "webkit/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/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "content/public/test/test_file_system_options.h" | 15 #include "content/public/test/test_file_system_options.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 #include "webkit/browser/fileapi/file_system_backend.h" | 18 #include "webkit/browser/fileapi/file_system_backend.h" |
| 19 #include "webkit/browser/fileapi/file_system_url.h" | 19 #include "webkit/browser/fileapi/file_system_url.h" |
| 20 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" | 20 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" |
| 21 #include "webkit/common/fileapi/file_system_util.h" | 21 #include "webkit/common/fileapi/file_system_util.h" |
| 22 | 22 |
| 23 using fileapi::SandboxFileSystemBackend; |
| 24 using fileapi::SandboxFileSystemBackendDelegate; |
| 25 |
| 23 // PS stands for path separator. | 26 // PS stands for path separator. |
| 24 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 27 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 25 #define PS "\\" | 28 #define PS "\\" |
| 26 #else | 29 #else |
| 27 #define PS "/" | 30 #define PS "/" |
| 28 #endif | 31 #endif |
| 29 | 32 |
| 30 namespace fileapi { | 33 namespace content { |
| 31 | 34 |
| 32 namespace { | 35 namespace { |
| 33 | 36 |
| 34 const struct RootPathTest { | 37 const struct RootPathTest { |
| 35 fileapi::FileSystemType type; | 38 fileapi::FileSystemType type; |
| 36 const char* origin_url; | 39 const char* origin_url; |
| 37 const char* expected_path; | 40 const char* expected_path; |
| 38 } kRootPathTestCases[] = { | 41 } kRootPathTestCases[] = { |
| 39 { fileapi::kFileSystemTypeTemporary, "http://foo:1/", | 42 { fileapi::kFileSystemTypeTemporary, "http://foo:1/", |
| 40 "000" PS "t" }, | 43 "000" PS "t" }, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 78 |
| 76 } // namespace | 79 } // namespace |
| 77 | 80 |
| 78 class SandboxFileSystemBackendTest : public testing::Test { | 81 class SandboxFileSystemBackendTest : public testing::Test { |
| 79 protected: | 82 protected: |
| 80 virtual void SetUp() { | 83 virtual void SetUp() { |
| 81 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 84 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 82 SetUpNewDelegate(CreateAllowFileAccessOptions()); | 85 SetUpNewDelegate(CreateAllowFileAccessOptions()); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void SetUpNewDelegate(const FileSystemOptions& options) { | 88 void SetUpNewDelegate(const fileapi::FileSystemOptions& options) { |
| 86 delegate_.reset(new SandboxFileSystemBackendDelegate( | 89 delegate_.reset(new SandboxFileSystemBackendDelegate( |
| 87 NULL /* quota_manager_proxy */, | 90 NULL /* quota_manager_proxy */, |
| 88 base::MessageLoopProxy::current().get(), | 91 base::MessageLoopProxy::current().get(), |
| 89 data_dir_.path(), | 92 data_dir_.path(), |
| 90 NULL /* special_storage_policy */, | 93 NULL /* special_storage_policy */, |
| 91 options)); | 94 options)); |
| 92 } | 95 } |
| 93 | 96 |
| 94 void SetUpNewBackend(const FileSystemOptions& options) { | 97 void SetUpNewBackend(const fileapi::FileSystemOptions& options) { |
| 95 SetUpNewDelegate(options); | 98 SetUpNewDelegate(options); |
| 96 backend_.reset(new SandboxFileSystemBackend(delegate_.get())); | 99 backend_.reset(new SandboxFileSystemBackend(delegate_.get())); |
| 97 } | 100 } |
| 98 | 101 |
| 99 SandboxFileSystemBackendDelegate::OriginEnumerator* | 102 fileapi::SandboxFileSystemBackendDelegate::OriginEnumerator* |
| 100 CreateOriginEnumerator() const { | 103 CreateOriginEnumerator() const { |
| 101 return backend_->CreateOriginEnumerator(); | 104 return backend_->CreateOriginEnumerator(); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void CreateOriginTypeDirectory(const GURL& origin, | 107 void CreateOriginTypeDirectory(const GURL& origin, |
| 105 fileapi::FileSystemType type) { | 108 fileapi::FileSystemType type) { |
| 106 base::FilePath target = delegate_-> | 109 base::FilePath target = delegate_-> |
| 107 GetBaseDirectoryForOriginAndType(origin, type, true); | 110 GetBaseDirectoryForOriginAndType(origin, type, true); |
| 108 ASSERT_TRUE(!target.empty()); | 111 ASSERT_TRUE(!target.empty()); |
| 109 ASSERT_TRUE(base::DirectoryExists(target)); | 112 ASSERT_TRUE(base::DirectoryExists(target)); |
| 110 } | 113 } |
| 111 | 114 |
| 112 bool GetRootPath(const GURL& origin_url, | 115 bool GetRootPath(const GURL& origin_url, |
| 113 fileapi::FileSystemType type, | 116 fileapi::FileSystemType type, |
| 114 OpenFileSystemMode mode, | 117 fileapi::OpenFileSystemMode mode, |
| 115 base::FilePath* root_path) { | 118 base::FilePath* root_path) { |
| 116 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 119 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
| 117 backend_->OpenFileSystem( | 120 backend_->OpenFileSystem( |
| 118 origin_url, type, mode, | 121 origin_url, type, mode, |
| 119 base::Bind(&DidOpenFileSystem, &error)); | 122 base::Bind(&DidOpenFileSystem, &error)); |
| 120 base::RunLoop().RunUntilIdle(); | 123 base::RunLoop().RunUntilIdle(); |
| 121 if (error != base::PLATFORM_FILE_OK) | 124 if (error != base::PLATFORM_FILE_OK) |
| 122 return false; | 125 return false; |
| 123 base::FilePath returned_root_path = | 126 base::FilePath returned_root_path = |
| 124 delegate_->GetBaseDirectoryForOriginAndType( | 127 delegate_->GetBaseDirectoryForOriginAndType( |
| 125 origin_url, type, false /* create */); | 128 origin_url, type, false /* create */); |
| 126 if (root_path) | 129 if (root_path) |
| 127 *root_path = returned_root_path; | 130 *root_path = returned_root_path; |
| 128 return !returned_root_path.empty(); | 131 return !returned_root_path.empty(); |
| 129 } | 132 } |
| 130 | 133 |
| 131 base::FilePath file_system_path() const { | 134 base::FilePath file_system_path() const { |
| 132 return data_dir_.path().Append( | 135 return data_dir_.path().Append( |
| 133 SandboxFileSystemBackendDelegate::kFileSystemDirectory); | 136 SandboxFileSystemBackendDelegate::kFileSystemDirectory); |
| 134 } | 137 } |
| 135 | 138 |
| 136 base::ScopedTempDir data_dir_; | 139 base::ScopedTempDir data_dir_; |
| 137 base::MessageLoop message_loop_; | 140 base::MessageLoop message_loop_; |
| 138 scoped_ptr<SandboxFileSystemBackendDelegate> delegate_; | 141 scoped_ptr<fileapi::SandboxFileSystemBackendDelegate> delegate_; |
| 139 scoped_ptr<SandboxFileSystemBackend> backend_; | 142 scoped_ptr<fileapi::SandboxFileSystemBackend> backend_; |
| 140 }; | 143 }; |
| 141 | 144 |
| 142 TEST_F(SandboxFileSystemBackendTest, Empty) { | 145 TEST_F(SandboxFileSystemBackendTest, Empty) { |
| 143 SetUpNewBackend(CreateAllowFileAccessOptions()); | 146 SetUpNewBackend(CreateAllowFileAccessOptions()); |
| 144 scoped_ptr<SandboxFileSystemBackendDelegate::OriginEnumerator> enumerator( | 147 scoped_ptr<SandboxFileSystemBackendDelegate::OriginEnumerator> enumerator( |
| 145 CreateOriginEnumerator()); | 148 CreateOriginEnumerator()); |
| 146 ASSERT_TRUE(enumerator->Next().is_empty()); | 149 ASSERT_TRUE(enumerator->Next().is_empty()); |
| 147 } | 150 } |
| 148 | 151 |
| 149 TEST_F(SandboxFileSystemBackendTest, EnumerateOrigins) { | 152 TEST_F(SandboxFileSystemBackendTest, EnumerateOrigins) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 163 size_t temporary_size = ARRAYSIZE_UNSAFE(temporary_origins); | 166 size_t temporary_size = ARRAYSIZE_UNSAFE(temporary_origins); |
| 164 size_t persistent_size = ARRAYSIZE_UNSAFE(persistent_origins); | 167 size_t persistent_size = ARRAYSIZE_UNSAFE(persistent_origins); |
| 165 std::set<GURL> temporary_set, persistent_set; | 168 std::set<GURL> temporary_set, persistent_set; |
| 166 for (size_t i = 0; i < temporary_size; ++i) { | 169 for (size_t i = 0; i < temporary_size; ++i) { |
| 167 CreateOriginTypeDirectory(GURL(temporary_origins[i]), | 170 CreateOriginTypeDirectory(GURL(temporary_origins[i]), |
| 168 fileapi::kFileSystemTypeTemporary); | 171 fileapi::kFileSystemTypeTemporary); |
| 169 temporary_set.insert(GURL(temporary_origins[i])); | 172 temporary_set.insert(GURL(temporary_origins[i])); |
| 170 } | 173 } |
| 171 for (size_t i = 0; i < persistent_size; ++i) { | 174 for (size_t i = 0; i < persistent_size; ++i) { |
| 172 CreateOriginTypeDirectory(GURL(persistent_origins[i]), | 175 CreateOriginTypeDirectory(GURL(persistent_origins[i]), |
| 173 kFileSystemTypePersistent); | 176 fileapi::kFileSystemTypePersistent); |
| 174 persistent_set.insert(GURL(persistent_origins[i])); | 177 persistent_set.insert(GURL(persistent_origins[i])); |
| 175 } | 178 } |
| 176 | 179 |
| 177 scoped_ptr<SandboxFileSystemBackendDelegate::OriginEnumerator> enumerator( | 180 scoped_ptr<SandboxFileSystemBackendDelegate::OriginEnumerator> enumerator( |
| 178 CreateOriginEnumerator()); | 181 CreateOriginEnumerator()); |
| 179 size_t temporary_actual_size = 0; | 182 size_t temporary_actual_size = 0; |
| 180 size_t persistent_actual_size = 0; | 183 size_t persistent_actual_size = 0; |
| 181 GURL current; | 184 GURL current; |
| 182 while (!(current = enumerator->Next()).is_empty()) { | 185 while (!(current = enumerator->Next()).is_empty()) { |
| 183 SCOPED_TRACE(testing::Message() << "EnumerateOrigin " << current.spec()); | 186 SCOPED_TRACE(testing::Message() << "EnumerateOrigin " << current.spec()); |
| 184 if (enumerator->HasFileSystemType(kFileSystemTypeTemporary)) { | 187 if (enumerator->HasFileSystemType(fileapi::kFileSystemTypeTemporary)) { |
| 185 ASSERT_TRUE(temporary_set.find(current) != temporary_set.end()); | 188 ASSERT_TRUE(temporary_set.find(current) != temporary_set.end()); |
| 186 ++temporary_actual_size; | 189 ++temporary_actual_size; |
| 187 } | 190 } |
| 188 if (enumerator->HasFileSystemType(kFileSystemTypePersistent)) { | 191 if (enumerator->HasFileSystemType(fileapi::kFileSystemTypePersistent)) { |
| 189 ASSERT_TRUE(persistent_set.find(current) != persistent_set.end()); | 192 ASSERT_TRUE(persistent_set.find(current) != persistent_set.end()); |
| 190 ++persistent_actual_size; | 193 ++persistent_actual_size; |
| 191 } | 194 } |
| 192 } | 195 } |
| 193 | 196 |
| 194 EXPECT_EQ(temporary_size, temporary_actual_size); | 197 EXPECT_EQ(temporary_size, temporary_actual_size); |
| 195 EXPECT_EQ(persistent_size, persistent_actual_size); | 198 EXPECT_EQ(persistent_size, persistent_actual_size); |
| 196 } | 199 } |
| 197 | 200 |
| 198 TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { | 201 TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { |
| 199 std::vector<base::FilePath> returned_root_path( | 202 std::vector<base::FilePath> returned_root_path( |
| 200 ARRAYSIZE_UNSAFE(kRootPathTestCases)); | 203 ARRAYSIZE_UNSAFE(kRootPathTestCases)); |
| 201 SetUpNewBackend(CreateAllowFileAccessOptions()); | 204 SetUpNewBackend(CreateAllowFileAccessOptions()); |
| 202 | 205 |
| 203 // Create a new root directory. | 206 // Create a new root directory. |
| 204 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | 207 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { |
| 205 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " " | 208 SCOPED_TRACE(testing::Message() << "RootPath (create) #" << i << " " |
| 206 << kRootPathTestCases[i].expected_path); | 209 << kRootPathTestCases[i].expected_path); |
| 207 | 210 |
| 208 base::FilePath root_path; | 211 base::FilePath root_path; |
| 209 EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), | 212 EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), |
| 210 kRootPathTestCases[i].type, | 213 kRootPathTestCases[i].type, |
| 211 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 214 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 212 &root_path)); | 215 &root_path)); |
| 213 | 216 |
| 214 base::FilePath expected = file_system_path().AppendASCII( | 217 base::FilePath expected = file_system_path().AppendASCII( |
| 215 kRootPathTestCases[i].expected_path); | 218 kRootPathTestCases[i].expected_path); |
| 216 EXPECT_EQ(expected.value(), root_path.value()); | 219 EXPECT_EQ(expected.value(), root_path.value()); |
| 217 EXPECT_TRUE(base::DirectoryExists(root_path)); | 220 EXPECT_TRUE(base::DirectoryExists(root_path)); |
| 218 ASSERT_TRUE(returned_root_path.size() > i); | 221 ASSERT_TRUE(returned_root_path.size() > i); |
| 219 returned_root_path[i] = root_path; | 222 returned_root_path[i] = root_path; |
| 220 } | 223 } |
| 221 | 224 |
| 222 // Get the root directory with create=false and see if we get the | 225 // Get the root directory with create=false and see if we get the |
| 223 // same directory. | 226 // same directory. |
| 224 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | 227 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { |
| 225 SCOPED_TRACE(testing::Message() << "RootPath (get) #" << i << " " | 228 SCOPED_TRACE(testing::Message() << "RootPath (get) #" << i << " " |
| 226 << kRootPathTestCases[i].expected_path); | 229 << kRootPathTestCases[i].expected_path); |
| 227 | 230 |
| 228 base::FilePath root_path; | 231 base::FilePath root_path; |
| 229 EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), | 232 EXPECT_TRUE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), |
| 230 kRootPathTestCases[i].type, | 233 kRootPathTestCases[i].type, |
| 231 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 234 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 232 &root_path)); | 235 &root_path)); |
| 233 ASSERT_TRUE(returned_root_path.size() > i); | 236 ASSERT_TRUE(returned_root_path.size() > i); |
| 234 EXPECT_EQ(returned_root_path[i].value(), root_path.value()); | 237 EXPECT_EQ(returned_root_path[i].value(), root_path.value()); |
| 235 } | 238 } |
| 236 } | 239 } |
| 237 | 240 |
| 238 TEST_F(SandboxFileSystemBackendTest, | 241 TEST_F(SandboxFileSystemBackendTest, |
| 239 GetRootPathCreateAndExamineWithNewBackend) { | 242 GetRootPathCreateAndExamineWithNewBackend) { |
| 240 std::vector<base::FilePath> returned_root_path( | 243 std::vector<base::FilePath> returned_root_path( |
| 241 ARRAYSIZE_UNSAFE(kRootPathTestCases)); | 244 ARRAYSIZE_UNSAFE(kRootPathTestCases)); |
| 242 SetUpNewBackend(CreateAllowFileAccessOptions()); | 245 SetUpNewBackend(CreateAllowFileAccessOptions()); |
| 243 | 246 |
| 244 GURL origin_url("http://foo.com:1/"); | 247 GURL origin_url("http://foo.com:1/"); |
| 245 | 248 |
| 246 base::FilePath root_path1; | 249 base::FilePath root_path1; |
| 247 EXPECT_TRUE(GetRootPath(origin_url, kFileSystemTypeTemporary, | 250 EXPECT_TRUE(GetRootPath(origin_url, fileapi::kFileSystemTypeTemporary, |
| 248 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 251 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 249 &root_path1)); | 252 &root_path1)); |
| 250 | 253 |
| 251 SetUpNewBackend(CreateDisallowFileAccessOptions()); | 254 SetUpNewBackend(CreateDisallowFileAccessOptions()); |
| 252 base::FilePath root_path2; | 255 base::FilePath root_path2; |
| 253 EXPECT_TRUE(GetRootPath(origin_url, kFileSystemTypeTemporary, | 256 EXPECT_TRUE(GetRootPath(origin_url, fileapi::kFileSystemTypeTemporary, |
| 254 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 257 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 255 &root_path2)); | 258 &root_path2)); |
| 256 | 259 |
| 257 EXPECT_EQ(root_path1.value(), root_path2.value()); | 260 EXPECT_EQ(root_path1.value(), root_path2.value()); |
| 258 } | 261 } |
| 259 | 262 |
| 260 TEST_F(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { | 263 TEST_F(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { |
| 261 SetUpNewBackend(CreateDisallowFileAccessOptions()); | 264 SetUpNewBackend(CreateDisallowFileAccessOptions()); |
| 262 | 265 |
| 263 // Try to get a root directory without creating. | 266 // Try to get a root directory without creating. |
| 264 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | 267 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { |
| 265 SCOPED_TRACE(testing::Message() << "RootPath (create=false) #" << i << " " | 268 SCOPED_TRACE(testing::Message() << "RootPath (create=false) #" << i << " " |
| 266 << kRootPathTestCases[i].expected_path); | 269 << kRootPathTestCases[i].expected_path); |
| 267 EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), | 270 EXPECT_FALSE(GetRootPath(GURL(kRootPathTestCases[i].origin_url), |
| 268 kRootPathTestCases[i].type, | 271 kRootPathTestCases[i].type, |
| 269 OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | 272 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, |
| 270 NULL)); | 273 NULL)); |
| 271 } | 274 } |
| 272 } | 275 } |
| 273 | 276 |
| 274 TEST_F(SandboxFileSystemBackendTest, GetRootPathInIncognito) { | 277 TEST_F(SandboxFileSystemBackendTest, GetRootPathInIncognito) { |
| 275 SetUpNewBackend(CreateIncognitoFileSystemOptions()); | 278 SetUpNewBackend(CreateIncognitoFileSystemOptions()); |
| 276 | 279 |
| 277 // Try to get a root directory. | 280 // Try to get a root directory. |
| 278 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { | 281 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathTestCases); ++i) { |
| 279 SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " | 282 SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " |
| 280 << kRootPathTestCases[i].expected_path); | 283 << kRootPathTestCases[i].expected_path); |
| 281 EXPECT_FALSE( | 284 EXPECT_FALSE( |
| 282 GetRootPath(GURL(kRootPathTestCases[i].origin_url), | 285 GetRootPath(GURL(kRootPathTestCases[i].origin_url), |
| 283 kRootPathTestCases[i].type, | 286 kRootPathTestCases[i].type, |
| 284 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 287 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 285 NULL)); | 288 NULL)); |
| 286 } | 289 } |
| 287 } | 290 } |
| 288 | 291 |
| 289 TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURI) { | 292 TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURI) { |
| 290 SetUpNewBackend(CreateDisallowFileAccessOptions()); | 293 SetUpNewBackend(CreateDisallowFileAccessOptions()); |
| 291 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { | 294 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { |
| 292 SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #" | 295 SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #" |
| 293 << i << " " << kRootPathFileURITestCases[i].expected_path); | 296 << i << " " << kRootPathFileURITestCases[i].expected_path); |
| 294 EXPECT_FALSE( | 297 EXPECT_FALSE( |
| 295 GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), | 298 GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), |
| 296 kRootPathFileURITestCases[i].type, | 299 kRootPathFileURITestCases[i].type, |
| 297 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 300 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 298 NULL)); | 301 NULL)); |
| 299 } | 302 } |
| 300 } | 303 } |
| 301 | 304 |
| 302 TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURIWithAllowFlag) { | 305 TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURIWithAllowFlag) { |
| 303 SetUpNewBackend(CreateAllowFileAccessOptions()); | 306 SetUpNewBackend(CreateAllowFileAccessOptions()); |
| 304 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { | 307 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kRootPathFileURITestCases); ++i) { |
| 305 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" | 308 SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" |
| 306 << i << " " << kRootPathFileURITestCases[i].expected_path); | 309 << i << " " << kRootPathFileURITestCases[i].expected_path); |
| 307 base::FilePath root_path; | 310 base::FilePath root_path; |
| 308 EXPECT_TRUE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), | 311 EXPECT_TRUE(GetRootPath(GURL(kRootPathFileURITestCases[i].origin_url), |
| 309 kRootPathFileURITestCases[i].type, | 312 kRootPathFileURITestCases[i].type, |
| 310 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 313 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 311 &root_path)); | 314 &root_path)); |
| 312 base::FilePath expected = file_system_path().AppendASCII( | 315 base::FilePath expected = file_system_path().AppendASCII( |
| 313 kRootPathFileURITestCases[i].expected_path); | 316 kRootPathFileURITestCases[i].expected_path); |
| 314 EXPECT_EQ(expected.value(), root_path.value()); | 317 EXPECT_EQ(expected.value(), root_path.value()); |
| 315 EXPECT_TRUE(base::DirectoryExists(root_path)); | 318 EXPECT_TRUE(base::DirectoryExists(root_path)); |
| 316 } | 319 } |
| 317 } | 320 } |
| 318 | 321 |
| 319 } // namespace fileapi | 322 } // namespace content |
| OLD | NEW |