| OLD | NEW |
| 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 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) | 5 // NOTE: These tests are run as part of "unit_tests" (in chrome/test/unit) |
| 6 // rather than as part of test_shell_tests because they rely on being able | 6 // rather than as part of test_shell_tests because they rely on being able |
| 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses | 7 // to instantiate a MessageLoop of type TYPE_IO. test_shell_tests uses |
| 8 // TYPE_UI, which URLRequest doesn't allow. | 8 // TYPE_UI, which URLRequest doesn't allow. |
| 9 // | 9 // |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "webkit/fileapi/file_system_context.h" | 29 #include "webkit/fileapi/file_system_context.h" |
| 30 #include "webkit/fileapi/file_system_file_util.h" | 30 #include "webkit/fileapi/file_system_file_util.h" |
| 31 #include "webkit/fileapi/file_system_operation_context.h" | 31 #include "webkit/fileapi/file_system_operation_context.h" |
| 32 #include "webkit/fileapi/file_system_path_manager.h" | 32 #include "webkit/fileapi/file_system_path_manager.h" |
| 33 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 33 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 34 | 34 |
| 35 namespace fileapi { | 35 namespace fileapi { |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // We always use the TEMPORARY FileSystem in this test. | 38 // We always use the TEMPORARY FileSystem in this test. |
| 39 static const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"
; | 39 static const char kFileSystemURLPrefix[] = |
| 40 "filesystem:http://remote/temporary/"; |
| 40 | 41 |
| 41 class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy { | 42 class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy { |
| 42 public: | 43 public: |
| 43 virtual bool IsStorageProtected(const GURL& origin) { | 44 virtual bool IsStorageProtected(const GURL& origin) { |
| 44 return false; | 45 return false; |
| 45 } | 46 } |
| 46 | 47 |
| 47 virtual bool IsStorageUnlimited(const GURL& origin) { | 48 virtual bool IsStorageUnlimited(const GURL& origin) { |
| 48 return true; | 49 return true; |
| 49 } | 50 } |
| 50 | 51 |
| 51 virtual bool IsFileHandler(const std::string& extension_id) { | 52 virtual bool IsFileHandler(const std::string& extension_id) { |
| 52 return true; | 53 return true; |
| 53 } | 54 } |
| 54 }; | 55 }; |
| 55 | 56 |
| 57 } // namespace |
| 58 |
| 56 class FileSystemDirURLRequestJobTest : public testing::Test { | 59 class FileSystemDirURLRequestJobTest : public testing::Test { |
| 57 protected: | 60 protected: |
| 58 FileSystemDirURLRequestJobTest() | 61 FileSystemDirURLRequestJobTest() |
| 59 : message_loop_(MessageLoop::TYPE_IO), // simulate an IO thread | 62 : message_loop_(MessageLoop::TYPE_IO), // simulate an IO thread |
| 60 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 63 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
| 61 } | 64 } |
| 62 | 65 |
| 63 virtual void SetUp() { | 66 virtual void SetUp() { |
| 64 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 67 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 65 | 68 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 new FileSystemPathManager( | 79 new FileSystemPathManager( |
| 77 file_thread_proxy_, temp_dir_.path(), | 80 file_thread_proxy_, temp_dir_.path(), |
| 78 NULL, false, false)); | 81 NULL, false, false)); |
| 79 | 82 |
| 80 file_system_context_->path_manager()->ValidateFileSystemRootAndGetURL( | 83 file_system_context_->path_manager()->ValidateFileSystemRootAndGetURL( |
| 81 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create | 84 GURL("http://remote/"), kFileSystemTypeTemporary, true, // create |
| 82 callback_factory_.NewCallback( | 85 callback_factory_.NewCallback( |
| 83 &FileSystemDirURLRequestJobTest::OnGetRootPath)); | 86 &FileSystemDirURLRequestJobTest::OnGetRootPath)); |
| 84 MessageLoop::current()->RunAllPending(); | 87 MessageLoop::current()->RunAllPending(); |
| 85 | 88 |
| 86 net::URLRequest::RegisterProtocolFactory( | 89 net::URLRequest::Deprecated::RegisterProtocolFactory( |
| 87 "filesystem", &FileSystemDirURLRequestJobFactory); | 90 "filesystem", &FileSystemDirURLRequestJobFactory); |
| 88 } | 91 } |
| 89 | 92 |
| 90 virtual void TearDown() { | 93 virtual void TearDown() { |
| 91 // NOTE: order matters, request must die before delegate | 94 // NOTE: order matters, request must die before delegate |
| 92 request_.reset(NULL); | 95 request_.reset(NULL); |
| 93 delegate_.reset(NULL); | 96 delegate_.reset(NULL); |
| 94 | 97 |
| 95 net::URLRequest::RegisterProtocolFactory("filesystem", NULL); | 98 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); |
| 96 } | 99 } |
| 97 | 100 |
| 98 void OnGetRootPath(bool success, const FilePath& root_path, | 101 void OnGetRootPath(bool success, const FilePath& root_path, |
| 99 const std::string& name) { | 102 const std::string& name) { |
| 100 ASSERT_TRUE(success); | 103 ASSERT_TRUE(success); |
| 101 root_path_ = root_path; | 104 root_path_ = root_path; |
| 102 } | 105 } |
| 103 | 106 |
| 104 void TestRequestHelper(const GURL& url, bool run_to_completion) { | 107 void TestRequestHelper(const GURL& url, bool run_to_completion) { |
| 105 delegate_.reset(new TestDelegate()); | 108 delegate_.reset(new TestDelegate()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 scoped_refptr<TestSpecialStoragePolicy> special_storage_policy_; | 169 scoped_refptr<TestSpecialStoragePolicy> special_storage_policy_; |
| 167 scoped_refptr<FileSystemContext> file_system_context_; | 170 scoped_refptr<FileSystemContext> file_system_context_; |
| 168 base::ScopedCallbackFactory<FileSystemDirURLRequestJobTest> callback_factory_; | 171 base::ScopedCallbackFactory<FileSystemDirURLRequestJobTest> callback_factory_; |
| 169 | 172 |
| 170 static net::URLRequestJob* job_; | 173 static net::URLRequestJob* job_; |
| 171 }; | 174 }; |
| 172 | 175 |
| 173 // static | 176 // static |
| 174 net::URLRequestJob* FileSystemDirURLRequestJobTest::job_ = NULL; | 177 net::URLRequestJob* FileSystemDirURLRequestJobTest::job_ = NULL; |
| 175 | 178 |
| 179 namespace { |
| 180 |
| 176 // TODO(adamk): Write tighter tests once we've decided on a format for directory | 181 // TODO(adamk): Write tighter tests once we've decided on a format for directory |
| 177 // listing responses. | 182 // listing responses. |
| 178 TEST_F(FileSystemDirURLRequestJobTest, DirectoryListing) { | 183 TEST_F(FileSystemDirURLRequestJobTest, DirectoryListing) { |
| 179 CreateDirectory("foo"); | 184 CreateDirectory("foo"); |
| 180 CreateDirectory("foo/bar"); | 185 CreateDirectory("foo/bar"); |
| 181 CreateDirectory("foo/bar/baz"); | 186 CreateDirectory("foo/bar/baz"); |
| 182 | 187 |
| 183 TestRequest(CreateFileSystemURL("foo/bar/")); | 188 TestRequest(CreateFileSystemURL("foo/bar/")); |
| 184 | 189 |
| 185 ASSERT_FALSE(request_->is_pending()); | 190 ASSERT_FALSE(request_->is_pending()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 MessageLoop::current()->PostTask(FROM_HERE, new QuitNowTask); | 229 MessageLoop::current()->PostTask(FROM_HERE, new QuitNowTask); |
| 225 MessageLoop::current()->Run(); | 230 MessageLoop::current()->Run(); |
| 226 | 231 |
| 227 request_.reset(); | 232 request_.reset(); |
| 228 MessageLoop::current()->RunAllPending(); | 233 MessageLoop::current()->RunAllPending(); |
| 229 // If we get here, success! we didn't crash! | 234 // If we get here, success! we didn't crash! |
| 230 } | 235 } |
| 231 | 236 |
| 232 } // namespace (anonymous) | 237 } // namespace (anonymous) |
| 233 } // namespace fileapi | 238 } // namespace fileapi |
| OLD | NEW |