OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/fileapi/syncable/canned_syncable_file_system.h" | 5 #include "webkit/fileapi/syncable/canned_syncable_file_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 using quota::QuotaManager; | 22 using quota::QuotaManager; |
23 | 23 |
24 namespace fileapi { | 24 namespace fileapi { |
25 | 25 |
26 CannedSyncableFileSystem::CannedSyncableFileSystem( | 26 CannedSyncableFileSystem::CannedSyncableFileSystem( |
27 const GURL& origin, const std::string& service) | 27 const GURL& origin, const std::string& service) |
28 : service_name_(service), | 28 : service_name_(service), |
29 test_helper_(origin, kFileSystemTypeSyncable), | 29 test_helper_(origin, kFileSystemTypeSyncable), |
30 result_(base::PLATFORM_FILE_OK), | 30 result_(base::PLATFORM_FILE_OK), |
31 sync_status_(SYNC_STATUS_OK), | 31 sync_status_(SYNC_STATUS_OK), |
| 32 is_filesystem_set_up_(false), |
| 33 is_filesystem_opened_(false), |
32 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 34 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
33 } | 35 } |
34 | 36 |
35 CannedSyncableFileSystem::~CannedSyncableFileSystem() {} | 37 CannedSyncableFileSystem::~CannedSyncableFileSystem() {} |
36 | 38 |
37 void CannedSyncableFileSystem::SetUp() { | 39 void CannedSyncableFileSystem::SetUp() { |
| 40 ASSERT_FALSE(is_filesystem_set_up_); |
38 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 41 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
39 | 42 |
40 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = | 43 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = |
41 new quota::MockSpecialStoragePolicy(); | 44 new quota::MockSpecialStoragePolicy(); |
42 | 45 |
43 quota_manager_ = new QuotaManager( | 46 quota_manager_ = new QuotaManager( |
44 false /* is_incognito */, | 47 false /* is_incognito */, |
45 data_dir_.path(), | 48 data_dir_.path(), |
46 base::MessageLoopProxy::current(), | 49 base::MessageLoopProxy::current(), |
47 base::MessageLoopProxy::current(), | 50 base::MessageLoopProxy::current(), |
48 storage_policy); | 51 storage_policy); |
49 | 52 |
50 file_system_context_ = new FileSystemContext( | 53 file_system_context_ = new FileSystemContext( |
51 FileSystemTaskRunners::CreateMockTaskRunners(), | 54 FileSystemTaskRunners::CreateMockTaskRunners(), |
52 storage_policy, | 55 storage_policy, |
53 quota_manager_->proxy(), | 56 quota_manager_->proxy(), |
54 data_dir_.path(), | 57 data_dir_.path(), |
55 CreateAllowFileAccessOptions()); | 58 CreateAllowFileAccessOptions()); |
56 | 59 |
57 test_helper_.SetUp(file_system_context_.get(), NULL); | 60 test_helper_.SetUp(file_system_context_.get(), NULL); |
| 61 is_filesystem_set_up_ = true; |
58 } | 62 } |
59 | 63 |
60 void CannedSyncableFileSystem::TearDown() { | 64 void CannedSyncableFileSystem::TearDown() { |
61 quota_manager_ = NULL; | 65 quota_manager_ = NULL; |
62 test_helper_.TearDown(); | 66 test_helper_.TearDown(); |
63 } | 67 } |
64 | 68 |
65 FileSystemURL CannedSyncableFileSystem::URL(const std::string& path) const { | 69 FileSystemURL CannedSyncableFileSystem::URL(const std::string& path) const { |
| 70 EXPECT_TRUE(is_filesystem_set_up_); |
| 71 EXPECT_TRUE(is_filesystem_opened_); |
66 return FileSystemURL(GURL(root_url_.spec() + path)); | 72 return FileSystemURL(GURL(root_url_.spec() + path)); |
67 } | 73 } |
68 | 74 |
69 PlatformFileError CannedSyncableFileSystem::OpenFileSystem() { | 75 PlatformFileError CannedSyncableFileSystem::OpenFileSystem() { |
| 76 EXPECT_TRUE(is_filesystem_set_up_); |
| 77 EXPECT_FALSE(is_filesystem_opened_); |
70 file_system_context_->OpenSyncableFileSystem( | 78 file_system_context_->OpenSyncableFileSystem( |
71 service_name_, | 79 service_name_, |
72 test_helper_.origin(), test_helper_.type(), | 80 test_helper_.origin(), test_helper_.type(), |
73 true /* create */, | 81 true /* create */, |
74 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, | 82 base::Bind(&CannedSyncableFileSystem::DidOpenFileSystem, |
75 weak_factory_.GetWeakPtr())); | 83 weak_factory_.GetWeakPtr())); |
76 MessageLoop::current()->RunAllPending(); | 84 MessageLoop::current()->RunAllPending(); |
77 return result_; | 85 return result_; |
78 } | 86 } |
79 | 87 |
80 PlatformFileError CannedSyncableFileSystem::CreateDirectory( | 88 PlatformFileError CannedSyncableFileSystem::CreateDirectory( |
81 const FileSystemURL& url) { | 89 const FileSystemURL& url) { |
| 90 EXPECT_TRUE(is_filesystem_opened_); |
82 result_ = base::PLATFORM_FILE_ERROR_FAILED; | 91 result_ = base::PLATFORM_FILE_ERROR_FAILED; |
83 test_helper_.NewOperation()->CreateDirectory( | 92 test_helper_.NewOperation()->CreateDirectory( |
84 url, false /* exclusive */, false /* recursive */, | 93 url, false /* exclusive */, false /* recursive */, |
85 base::Bind(&CannedSyncableFileSystem::StatusCallback, | 94 base::Bind(&CannedSyncableFileSystem::StatusCallback, |
86 weak_factory_.GetWeakPtr())); | 95 weak_factory_.GetWeakPtr())); |
87 MessageLoop::current()->RunAllPending(); | 96 MessageLoop::current()->RunAllPending(); |
88 return result_; | 97 return result_; |
89 } | 98 } |
90 | 99 |
91 PlatformFileError CannedSyncableFileSystem::CreateFile( | 100 PlatformFileError CannedSyncableFileSystem::CreateFile( |
92 const FileSystemURL& url) { | 101 const FileSystemURL& url) { |
| 102 EXPECT_TRUE(is_filesystem_opened_); |
93 result_ = base::PLATFORM_FILE_ERROR_FAILED; | 103 result_ = base::PLATFORM_FILE_ERROR_FAILED; |
94 test_helper_.NewOperation()->CreateFile( | 104 test_helper_.NewOperation()->CreateFile( |
95 url, false /* exclusive */, | 105 url, false /* exclusive */, |
96 base::Bind(&CannedSyncableFileSystem::StatusCallback, | 106 base::Bind(&CannedSyncableFileSystem::StatusCallback, |
97 weak_factory_.GetWeakPtr())); | 107 weak_factory_.GetWeakPtr())); |
98 MessageLoop::current()->RunAllPending(); | 108 MessageLoop::current()->RunAllPending(); |
99 return result_; | 109 return result_; |
100 } | 110 } |
101 | 111 |
102 PlatformFileError CannedSyncableFileSystem::TruncateFile( | 112 PlatformFileError CannedSyncableFileSystem::TruncateFile( |
103 const FileSystemURL& url, int64 size) { | 113 const FileSystemURL& url, int64 size) { |
| 114 EXPECT_TRUE(is_filesystem_opened_); |
104 result_ = base::PLATFORM_FILE_ERROR_FAILED; | 115 result_ = base::PLATFORM_FILE_ERROR_FAILED; |
105 test_helper_.NewOperation()->Truncate( | 116 test_helper_.NewOperation()->Truncate( |
106 url, size, | 117 url, size, |
107 base::Bind(&CannedSyncableFileSystem::StatusCallback, | 118 base::Bind(&CannedSyncableFileSystem::StatusCallback, |
108 weak_factory_.GetWeakPtr())); | 119 weak_factory_.GetWeakPtr())); |
109 MessageLoop::current()->RunAllPending(); | 120 MessageLoop::current()->RunAllPending(); |
110 return result_; | 121 return result_; |
111 } | 122 } |
112 | 123 |
113 PlatformFileError CannedSyncableFileSystem::Remove( | 124 PlatformFileError CannedSyncableFileSystem::Remove( |
114 const FileSystemURL& url, bool recursive) { | 125 const FileSystemURL& url, bool recursive) { |
| 126 EXPECT_TRUE(is_filesystem_opened_); |
115 result_ = base::PLATFORM_FILE_ERROR_FAILED; | 127 result_ = base::PLATFORM_FILE_ERROR_FAILED; |
116 test_helper_.NewOperation()->Remove( | 128 test_helper_.NewOperation()->Remove( |
117 url, recursive, | 129 url, recursive, |
118 base::Bind(&CannedSyncableFileSystem::StatusCallback, | 130 base::Bind(&CannedSyncableFileSystem::StatusCallback, |
119 weak_factory_.GetWeakPtr())); | 131 weak_factory_.GetWeakPtr())); |
120 MessageLoop::current()->RunAllPending(); | 132 MessageLoop::current()->RunAllPending(); |
121 return result_; | 133 return result_; |
122 } | 134 } |
123 | 135 |
124 PlatformFileError CannedSyncableFileSystem::DeleteFileSystem() { | 136 PlatformFileError CannedSyncableFileSystem::DeleteFileSystem() { |
| 137 EXPECT_TRUE(is_filesystem_set_up_); |
125 file_system_context_->DeleteFileSystem( | 138 file_system_context_->DeleteFileSystem( |
126 test_helper_.origin(), test_helper_.type(), | 139 test_helper_.origin(), test_helper_.type(), |
127 base::Bind(&CannedSyncableFileSystem::StatusCallback, | 140 base::Bind(&CannedSyncableFileSystem::StatusCallback, |
128 weak_factory_.GetWeakPtr())); | 141 weak_factory_.GetWeakPtr())); |
129 MessageLoop::current()->RunAllPending(); | 142 MessageLoop::current()->RunAllPending(); |
130 return result_; | 143 return result_; |
131 } | 144 } |
132 | 145 |
133 void CannedSyncableFileSystem::DidOpenFileSystem( | 146 void CannedSyncableFileSystem::DidOpenFileSystem( |
134 PlatformFileError result, const std::string& name, const GURL& root) { | 147 PlatformFileError result, const std::string& name, const GURL& root) { |
135 result_ = result; | 148 result_ = result; |
136 root_url_ = root; | 149 root_url_ = root; |
| 150 is_filesystem_opened_ = true; |
137 } | 151 } |
138 | 152 |
139 void CannedSyncableFileSystem::StatusCallback(PlatformFileError result) { | 153 void CannedSyncableFileSystem::StatusCallback(PlatformFileError result) { |
140 result_ = result; | 154 result_ = result; |
141 } | 155 } |
142 | 156 |
143 FileSystemOperationContext* CannedSyncableFileSystem::NewOperationContext() { | 157 FileSystemOperationContext* CannedSyncableFileSystem::NewOperationContext() { |
144 FileSystemOperationContext* context = test_helper_.NewOperationContext(); | 158 FileSystemOperationContext* context = test_helper_.NewOperationContext(); |
145 context->set_allowed_bytes_growth(kint64max); | 159 context->set_allowed_bytes_growth(kint64max); |
146 return context; | 160 return context; |
147 } | 161 } |
148 | 162 |
149 } // namespace fileapi | 163 } // namespace fileapi |
OLD | NEW |