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 #include "webkit/fileapi/file_system_directory_database.h" | 5 #include "webkit/fileapi/file_system_directory_database.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 23 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
| 24 InitDatabase(); | 24 InitDatabase(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 FileSystemDirectoryDatabase* db() { | 27 FileSystemDirectoryDatabase* db() { |
| 28 return db_.get(); | 28 return db_.get(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void InitDatabase() { | 31 void InitDatabase() { |
| 32 db_.reset(); | 32 db_.reset(); |
| 33 FilePath path = base_.path().AppendASCII("db"); | 33 db_.reset(new FileSystemDirectoryDatabase(sandbox_path())); |
|
kinuko
2012/03/26 05:25:09
Do we need first db_.reset() on line 31?
tzik
2012/03/26 08:04:56
Yes, we need.
Without it, we make two FileSystemDi
| |
| 34 db_.reset(new FileSystemDirectoryDatabase(path)); | |
| 35 } | 34 } |
| 36 | 35 |
| 37 bool AddFileInfo(FileId parent_id, const FilePath::StringType& name) { | 36 bool AddFileInfo(FileId parent_id, const FilePath::StringType& name) { |
| 38 FileId file_id; | 37 FileId file_id; |
| 39 FileInfo info; | 38 FileInfo info; |
| 40 info.parent_id = parent_id; | 39 info.parent_id = parent_id; |
| 41 info.name = name; | 40 info.name = name; |
| 42 return db_->AddFileInfo(info, &file_id); | 41 return db_->AddFileInfo(info, &file_id); |
| 43 } | 42 } |
| 44 | 43 |
| 44 FilePath sandbox_path() const { | |
|
kinuko
2012/03/26 05:25:09
It's not used anywhere other than in InitDatabase?
tzik
2012/03/26 08:04:56
Done.
| |
| 45 return base_.path(); | |
| 46 } | |
| 47 | |
| 45 protected: | 48 protected: |
| 46 // Common temp base for nondestructive uses. | 49 // Common temp base for nondestructive uses. |
| 47 ScopedTempDir base_; | 50 ScopedTempDir base_; |
| 48 scoped_ptr<FileSystemDirectoryDatabase> db_; | 51 scoped_ptr<FileSystemDirectoryDatabase> db_; |
| 49 | 52 |
| 50 DISALLOW_COPY_AND_ASSIGN(FileSystemDirectoryDatabaseTest); | 53 DISALLOW_COPY_AND_ASSIGN(FileSystemDirectoryDatabaseTest); |
| 51 }; | 54 }; |
| 52 | 55 |
| 53 TEST_F(FileSystemDirectoryDatabaseTest, TestMissingFileGetInfo) { | 56 TEST_F(FileSystemDirectoryDatabaseTest, TestMissingFileGetInfo) { |
| 54 FileId file_id = 888; | 57 FileId file_id = 888; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 EXPECT_TRUE(db()->GetNextInteger(&next)); | 414 EXPECT_TRUE(db()->GetNextInteger(&next)); |
| 412 EXPECT_EQ(2, next); | 415 EXPECT_EQ(2, next); |
| 413 EXPECT_TRUE(db()->GetNextInteger(&next)); | 416 EXPECT_TRUE(db()->GetNextInteger(&next)); |
| 414 EXPECT_EQ(3, next); | 417 EXPECT_EQ(3, next); |
| 415 InitDatabase(); | 418 InitDatabase(); |
| 416 EXPECT_TRUE(db()->GetNextInteger(&next)); | 419 EXPECT_TRUE(db()->GetNextInteger(&next)); |
| 417 EXPECT_EQ(4, next); | 420 EXPECT_EQ(4, next); |
| 418 } | 421 } |
| 419 | 422 |
| 420 } // namespace fileapi | 423 } // namespace fileapi |
| OLD | NEW |