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