Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
| 31 #include "net/http/http_request_headers.h" | 31 #include "net/http/http_request_headers.h" |
| 32 #include "net/url_request/url_request.h" | 32 #include "net/url_request/url_request.h" |
| 33 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "webkit/fileapi/file_system_context.h" | 35 #include "webkit/fileapi/file_system_context.h" |
| 36 #include "webkit/fileapi/file_system_file_util.h" | 36 #include "webkit/fileapi/file_system_file_util.h" |
| 37 #include "webkit/fileapi/file_system_operation_context.h" | 37 #include "webkit/fileapi/file_system_operation_context.h" |
| 38 #include "webkit/fileapi/file_system_path_manager.h" | 38 #include "webkit/fileapi/file_system_path_manager.h" |
| 39 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 39 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 40 #include "webkit/quota/mock_special_storage_policy.h" | |
| 40 | 41 |
| 41 namespace fileapi { | 42 namespace fileapi { |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 // We always use the TEMPORARY FileSystem in this test. | 45 // We always use the TEMPORARY FileSystem in this test. |
| 45 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; | 46 const char kFileSystemURLPrefix[] = "filesystem:http://remote/temporary/"; |
| 46 const char kTestFileData[] = "0123456789"; | 47 const char kTestFileData[] = "0123456789"; |
| 47 | 48 |
| 48 void FillBuffer(char* buffer, size_t len) { | 49 void FillBuffer(char* buffer, size_t len) { |
| 49 static bool called = false; | 50 static bool called = false; |
| 50 if (!called) { | 51 if (!called) { |
| 51 called = true; | 52 called = true; |
| 52 int seed = static_cast<int>(base::Time::Now().ToInternalValue()); | 53 int seed = static_cast<int>(base::Time::Now().ToInternalValue()); |
| 53 srand(seed); | 54 srand(seed); |
| 54 } | 55 } |
| 55 | 56 |
| 56 for (size_t i = 0; i < len; i++) { | 57 for (size_t i = 0; i < len; i++) { |
| 57 buffer[i] = static_cast<char>(rand()); | 58 buffer[i] = static_cast<char>(rand()); |
| 58 if (!buffer[i]) | 59 if (!buffer[i]) |
| 59 buffer[i] = 'g'; | 60 buffer[i] = 'g'; |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy { | |
| 64 public: | |
| 65 virtual bool IsStorageProtected(const GURL& origin) { | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 virtual bool IsStorageUnlimited(const GURL& origin) { | |
|
marja
2011/08/16 10:54:25
IsStorageUnlimited & IsFileHandler in this file we
| |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 virtual bool IsFileHandler(const std::string& extension_id) { | |
| 74 return true; | |
| 75 } | |
| 76 }; | |
| 77 | |
| 78 } // namespace | 64 } // namespace |
| 79 | 65 |
| 80 class FileSystemURLRequestJobTest : public testing::Test { | 66 class FileSystemURLRequestJobTest : public testing::Test { |
| 81 protected: | 67 protected: |
| 82 FileSystemURLRequestJobTest() | 68 FileSystemURLRequestJobTest() |
| 83 : message_loop_(MessageLoop::TYPE_IO), // simulate an IO thread | 69 : message_loop_(MessageLoop::TYPE_IO), // simulate an IO thread |
| 84 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 70 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
| 85 } | 71 } |
| 86 | 72 |
| 87 virtual void SetUp() { | 73 virtual void SetUp() { |
| 88 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 74 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 89 | 75 |
| 90 special_storage_policy_ = new TestSpecialStoragePolicy(); | 76 special_storage_policy_ = new quota::MockSpecialStoragePolicy; |
| 91 // We use the main thread so that we can get the root path synchronously. | 77 // We use the main thread so that we can get the root path synchronously. |
| 92 // TODO(adamk): Run this on the FILE thread we've created as well. | 78 // TODO(adamk): Run this on the FILE thread we've created as well. |
| 93 file_system_context_ = | 79 file_system_context_ = |
| 94 new FileSystemContext( | 80 new FileSystemContext( |
| 95 base::MessageLoopProxy::CreateForCurrentThread(), | 81 base::MessageLoopProxy::CreateForCurrentThread(), |
| 96 base::MessageLoopProxy::CreateForCurrentThread(), | 82 base::MessageLoopProxy::CreateForCurrentThread(), |
| 97 special_storage_policy_, NULL, | 83 special_storage_policy_, NULL, |
| 98 FilePath(), false /* is_incognito */, | 84 FilePath(), false /* is_incognito */, |
| 99 false, true, | 85 false, true, |
| 100 new FileSystemPathManager( | 86 new FileSystemPathManager( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 net::URLRequestJob* temp = job_; | 195 net::URLRequestJob* temp = job_; |
| 210 job_ = NULL; | 196 job_ = NULL; |
| 211 return temp; | 197 return temp; |
| 212 } | 198 } |
| 213 | 199 |
| 214 // Put the message loop at the top, so that it's the last thing deleted. | 200 // Put the message loop at the top, so that it's the last thing deleted. |
| 215 MessageLoop message_loop_; | 201 MessageLoop message_loop_; |
| 216 | 202 |
| 217 ScopedTempDir temp_dir_; | 203 ScopedTempDir temp_dir_; |
| 218 FilePath origin_root_path_; | 204 FilePath origin_root_path_; |
| 219 scoped_refptr<TestSpecialStoragePolicy> special_storage_policy_; | 205 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy_; |
| 220 scoped_refptr<FileSystemContext> file_system_context_; | 206 scoped_refptr<FileSystemContext> file_system_context_; |
| 221 base::ScopedCallbackFactory<FileSystemURLRequestJobTest> callback_factory_; | 207 base::ScopedCallbackFactory<FileSystemURLRequestJobTest> callback_factory_; |
| 222 | 208 |
| 223 // NOTE: order matters, request must die before delegate | 209 // NOTE: order matters, request must die before delegate |
| 224 scoped_ptr<TestDelegate> delegate_; | 210 scoped_ptr<TestDelegate> delegate_; |
| 225 scoped_ptr<net::URLRequest> request_; | 211 scoped_ptr<net::URLRequest> request_; |
| 226 | 212 |
| 227 static net::URLRequestJob* job_; | 213 static net::URLRequestJob* job_; |
| 228 }; | 214 }; |
| 229 | 215 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 | 369 |
| 384 TestRequest(CreateFileSystemURL(kFilename)); | 370 TestRequest(CreateFileSystemURL(kFilename)); |
| 385 | 371 |
| 386 std::string mime_type_from_job; | 372 std::string mime_type_from_job; |
| 387 request_->GetMimeType(&mime_type_from_job); | 373 request_->GetMimeType(&mime_type_from_job); |
| 388 EXPECT_EQ(mime_type_direct, mime_type_from_job); | 374 EXPECT_EQ(mime_type_direct, mime_type_from_job); |
| 389 } | 375 } |
| 390 | 376 |
| 391 } // namespace (anonymous) | 377 } // namespace (anonymous) |
| 392 } // namespace fileapi | 378 } // namespace fileapi |
| OLD | NEW |