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

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: build fix Created 8 years, 11 months 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) 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 <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(const FileSystemOptions& options) { 230 void SetupNewContext(const FileSystemOptions& options) {
232 file_system_context_ = new FileSystemContext( 231 file_system_context_ = new FileSystemContext(
233 base::MessageLoopProxy::current(), 232 base::MessageLoopProxy::current(),
234 base::MessageLoopProxy::current(), 233 base::MessageLoopProxy::current(),
235 special_storage_policy_, 234 special_storage_policy_,
236 NULL, 235 NULL,
237 data_dir_.path(), 236 data_dir_.path(),
238 options); 237 options);
239 #if defined(OS_CHROMEOS) 238 #if defined(OS_CHROMEOS)
240 fileapi::ExternalFileSystemMountPointProvider* ext_provider = 239 fileapi::ExternalFileSystemMountPointProvider* ext_provider =
241 file_system_context_->external_provider(); 240 file_system_context_->external_provider();
242 ext_provider->AddMountPoint(FilePath("/tmp/testing")); 241 ext_provider->AddMountPoint(FilePath("/tmp/testing"));
243 #endif 242 #endif
244 } 243 }
245 244
246 FileSystemMountPointProvider* provider(FileSystemType type) { 245 FileSystemMountPointProvider* provider(FileSystemType type) {
247 DCHECK(file_system_context_); 246 DCHECK(file_system_context_);
248 return file_system_context_->GetMountPointProvider(type); 247 return file_system_context_->GetMountPointProvider(type);
249 } 248 }
250 249
251 void OnGetRootPath(bool success,
252 const FilePath& root_path,
253 const std::string& name) {
254 root_path_callback_status_ = success;
255 root_path_ = root_path;
256 file_system_name_ = name;
257 }
258
259 bool GetRootPath(const GURL& origin_url, 250 bool GetRootPath(const GURL& origin_url,
260 fileapi::FileSystemType type, 251 fileapi::FileSystemType type,
261 bool create, 252 bool create,
262 FilePath* root_path) { 253 FilePath* root_path) {
263 provider(type)->ValidateFileSystemRootAndGetURL( 254 root_path_ = provider(type)->GetFileSystemRootPathOnFileThread(
264 origin_url, type, create, 255 origin_url, type, FilePath(), create);
265 base::Bind(&FileSystemMountPointProviderTest::OnGetRootPath,
266 weak_factory_.GetWeakPtr()));
267 MessageLoop::current()->RunAllPending();
268 if (root_path) 256 if (root_path)
269 *root_path = root_path_; 257 *root_path = root_path_;
270 return root_path_callback_status_; 258 return !root_path_.empty();
271 } 259 }
272 260
273 FilePath data_path() { return data_dir_.path(); } 261 FilePath data_path() { return data_dir_.path(); }
274 FilePath file_system_path() { 262 FilePath file_system_path() {
275 return data_dir_.path().Append( 263 return data_dir_.path().Append(
276 SandboxMountPointProvider::kNewFileSystemDirectory); 264 SandboxMountPointProvider::kNewFileSystemDirectory);
277 } 265 }
278 FilePath external_file_system_path() { 266 FilePath external_file_system_path() {
279 return FilePath::FromUTF8Unsafe(fileapi::kExternalDir); 267 return FilePath::FromUTF8Unsafe(fileapi::kExternalDir);
280 } 268 }
281 FilePath external_file_path_root() { 269 FilePath external_file_path_root() {
282 return FilePath::FromUTF8Unsafe("/tmp"); 270 return FilePath::FromUTF8Unsafe("/tmp");
283 } 271 }
284 272
285 private: 273 private:
286 ScopedTempDir data_dir_; 274 ScopedTempDir data_dir_;
287 base::WeakPtrFactory<FileSystemMountPointProviderTest> weak_factory_; 275 base::WeakPtrFactory<FileSystemMountPointProviderTest> weak_factory_;
288 276
289 bool root_path_callback_status_; 277 bool root_path_callback_status_;
290 FilePath root_path_; 278 FilePath root_path_;
291 std::string file_system_name_;
292 279
293 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; 280 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
294 scoped_refptr<FileSystemContext> file_system_context_; 281 scoped_refptr<FileSystemContext> file_system_context_;
295 282
296 DISALLOW_COPY_AND_ASSIGN(FileSystemMountPointProviderTest); 283 DISALLOW_COPY_AND_ASSIGN(FileSystemMountPointProviderTest);
297 }; 284 };
298 285
299 TEST_F(FileSystemMountPointProviderTest, GetRootPathCreateAndExamine) { 286 TEST_F(FileSystemMountPointProviderTest, GetRootPathCreateAndExamine) {
300 std::vector<FilePath> returned_root_path( 287 std::vector<FilePath> returned_root_path(
301 ARRAYSIZE_UNSAFE(kRootPathTestCases)); 288 ARRAYSIZE_UNSAFE(kRootPathTestCases));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) { 436 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kIsRestrictedNameTestCases); ++i) {
450 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " " 437 SCOPED_TRACE(testing::Message() << "IsRestrictedName #" << i << " "
451 << kIsRestrictedNameTestCases[i].name); 438 << kIsRestrictedNameTestCases[i].name);
452 FilePath name(kIsRestrictedNameTestCases[i].name); 439 FilePath name(kIsRestrictedNameTestCases[i].name);
453 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous, 440 EXPECT_EQ(kIsRestrictedNameTestCases[i].expected_dangerous,
454 provider(kFileSystemTypeTemporary)->IsRestrictedFileName(name)); 441 provider(kFileSystemTypeTemporary)->IsRestrictedFileName(name));
455 } 442 }
456 } 443 }
457 444
458 } // namespace fileapi 445 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698