Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: webkit/fileapi/file_system_mount_point_provider_unittest.cc

Issue 9016020: Cleanup FileSystemOperation for preparing for adding FSO-factory method (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more cleanup around ValidateFileSystemRoot Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 class FileSystemMountPointProviderTest : public testing::Test { 216 class FileSystemMountPointProviderTest : public testing::Test {
217 public: 217 public:
218 FileSystemMountPointProviderTest() 218 FileSystemMountPointProviderTest()
219 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 219 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
220 } 220 }
221 221
222 void SetUp() { 222 void SetUp() {
223 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 223 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
224 root_path_callback_status_ = false; 224 root_path_callback_status_ = false;
225 root_path_.clear(); 225 root_path_.clear();
226 file_system_name_.clear();
227 special_storage_policy_ = new quota::MockSpecialStoragePolicy; 226 special_storage_policy_ = new quota::MockSpecialStoragePolicy;
228 } 227 }
229 228
230 protected: 229 protected:
231 void SetupNewContext(FileSystemOptions* options) { 230 void SetupNewContext(FileSystemOptions* options) {
232 ASSERT_TRUE(options != NULL); 231 ASSERT_TRUE(options != NULL);
233 file_system_context_ = new FileSystemContext( 232 file_system_context_ = new FileSystemContext(
234 base::MessageLoopProxy::current(), 233 base::MessageLoopProxy::current(),
235 base::MessageLoopProxy::current(), 234 base::MessageLoopProxy::current(),
236 special_storage_policy_, 235 special_storage_policy_,
237 NULL, 236 NULL,
238 data_dir_.path(), 237 data_dir_.path(),
239 options); 238 options);
240 #if defined(OS_CHROMEOS) 239 #if defined(OS_CHROMEOS)
241 fileapi::ExternalFileSystemMountPointProvider* ext_provider = 240 fileapi::ExternalFileSystemMountPointProvider* ext_provider =
242 file_system_context_->external_provider(); 241 file_system_context_->external_provider();
243 ext_provider->AddMountPoint(FilePath("/tmp/testing")); 242 ext_provider->AddMountPoint(FilePath("/tmp/testing"));
244 #endif 243 #endif
245 } 244 }
246 245
247 FileSystemMountPointProvider* provider(FileSystemType type) { 246 FileSystemMountPointProvider* provider(FileSystemType type) {
248 DCHECK(file_system_context_); 247 DCHECK(file_system_context_);
249 return file_system_context_->GetMountPointProvider(type); 248 return file_system_context_->GetMountPointProvider(type);
250 } 249 }
251 250
252 void OnGetRootPath(bool success,
253 const FilePath& root_path,
254 const std::string& name) {
255 root_path_callback_status_ = success;
256 root_path_ = root_path;
257 file_system_name_ = name;
258 }
259
260 bool GetRootPath(const GURL& origin_url, 251 bool GetRootPath(const GURL& origin_url,
261 fileapi::FileSystemType type, 252 fileapi::FileSystemType type,
262 bool create, 253 bool create,
263 FilePath* root_path) { 254 FilePath* root_path) {
264 provider(type)->ValidateFileSystemRootAndGetURL( 255 root_path_ = provider(type)->GetFileSystemRootPathOnFileThread(
265 origin_url, type, create, 256 origin_url, type, FilePath(), create);
266 base::Bind(&FileSystemMountPointProviderTest::OnGetRootPath,
267 weak_factory_.GetWeakPtr()));
268 MessageLoop::current()->RunAllPending();
269 if (root_path) 257 if (root_path)
270 *root_path = root_path_; 258 *root_path = root_path_;
271 return root_path_callback_status_; 259 return !root_path_.empty();
272 } 260 }
273 261
274 FilePath data_path() { return data_dir_.path(); } 262 FilePath data_path() { return data_dir_.path(); }
275 FilePath file_system_path() { 263 FilePath file_system_path() {
276 return data_dir_.path().Append( 264 return data_dir_.path().Append(
277 SandboxMountPointProvider::kNewFileSystemDirectory); 265 SandboxMountPointProvider::kNewFileSystemDirectory);
278 } 266 }
279 FilePath external_file_system_path() { 267 FilePath external_file_system_path() {
280 return FilePath::FromUTF8Unsafe(fileapi::kExternalDir); 268 return FilePath::FromUTF8Unsafe(fileapi::kExternalDir);
281 } 269 }
282 FilePath external_file_path_root() { 270 FilePath external_file_path_root() {
283 return FilePath::FromUTF8Unsafe("/tmp"); 271 return FilePath::FromUTF8Unsafe("/tmp");
284 } 272 }
285 273
286 private: 274 private:
287 ScopedTempDir data_dir_; 275 ScopedTempDir data_dir_;
288 base::WeakPtrFactory<FileSystemMountPointProviderTest> weak_factory_; 276 base::WeakPtrFactory<FileSystemMountPointProviderTest> weak_factory_;
289 277
290 bool root_path_callback_status_; 278 bool root_path_callback_status_;
291 FilePath root_path_; 279 FilePath root_path_;
292 std::string file_system_name_;
293 280
294 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; 281 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
295 scoped_refptr<FileSystemContext> file_system_context_; 282 scoped_refptr<FileSystemContext> file_system_context_;
296 283
297 DISALLOW_COPY_AND_ASSIGN(FileSystemMountPointProviderTest); 284 DISALLOW_COPY_AND_ASSIGN(FileSystemMountPointProviderTest);
298 }; 285 };
299 286
300 TEST_F(FileSystemMountPointProviderTest, GetRootPathCreateAndExamine) { 287 TEST_F(FileSystemMountPointProviderTest, GetRootPathCreateAndExamine) {
301 std::vector<FilePath> returned_root_path( 288 std::vector<FilePath> returned_root_path(
302 ARRAYSIZE_UNSAFE(kRootPathTestCases)); 289 ARRAYSIZE_UNSAFE(kRootPathTestCases));
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { 411 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) {
425 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " 412 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " "
426 << kIsRestrictedNameTestCases[i].name); 413 << kIsRestrictedNameTestCases[i].name);
427 FilePath name(kIsRestrictedNameTestCases[i].name); 414 FilePath name(kIsRestrictedNameTestCases[i].name);
428 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, 415 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous,
429 provider(kFileSystemTypeTemporary)->IsRestrictedFileName(name)); 416 provider(kFileSystemTypeTemporary)->IsRestrictedFileName(name));
430 } 417 }
431 } 418 }
432 419
433 } // namespace fileapi 420 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698