| 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 "chrome/browser/chromeos/gdata/gdata_db.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_db.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" |
| 7 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 8 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 9 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 9 #include "chrome/browser/chromeos/gdata/gdata_db_factory.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_db_factory.h" |
| 10 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 11 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 namespace gdata { | 16 namespace gdata { |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 class GDataDBTest : public testing::Test { | 19 class GDataDBTest : public testing::Test { |
| 18 public: | 20 public: |
| 19 GDataDBTest() { | 21 GDataDBTest() { |
| 20 } | 22 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 61 |
| 60 // Tests GDataDB::NewIterator and GDataDBIter::GetNext. | 62 // Tests GDataDB::NewIterator and GDataDBIter::GetNext. |
| 61 // Creates an iterator with start at |parent|, and iterates comparing with | 63 // Creates an iterator with start at |parent|, and iterates comparing with |
| 62 // expected |filenames|. | 64 // expected |filenames|. |
| 63 void TestIter(const std::string& parent, | 65 void TestIter(const std::string& parent, |
| 64 const char* file_paths[], | 66 const char* file_paths[], |
| 65 size_t file_paths_size); | 67 size_t file_paths_size); |
| 66 | 68 |
| 67 scoped_ptr<TestingProfile> profile_; | 69 scoped_ptr<TestingProfile> profile_; |
| 68 scoped_ptr<GDataDB> gdata_db_; | 70 scoped_ptr<GDataDB> gdata_db_; |
| 71 MessageLoopForUI message_loop; |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 void GDataDBTest::SetUp() { | 74 void GDataDBTest::SetUp() { |
| 72 profile_.reset(new TestingProfile()); | 75 profile_.reset(new TestingProfile()); |
| 73 gdata_db_ = db_factory::CreateGDataDB( | 76 gdata_db_ = db_factory::CreateGDataDB( |
| 74 profile_->GetPath().Append("testdb")); | 77 profile_->GetPath().Append("testdb")); |
| 75 } | 78 } |
| 76 | 79 |
| 77 void GDataDBTest::TestGetNotFound(const GDataEntry& source) { | 80 void GDataDBTest::TestGetNotFound(const GDataEntry& source) { |
| 78 scoped_ptr<GDataEntry> entry; | 81 scoped_ptr<GDataEntry> entry; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 139 |
| 137 GDataDirectory* GDataDBTest::AddDirectory( | 140 GDataDirectory* GDataDBTest::AddDirectory( |
| 138 GDataDirectory* parent, | 141 GDataDirectory* parent, |
| 139 GDataDirectoryService* directory_service, | 142 GDataDirectoryService* directory_service, |
| 140 int sequence_id) { | 143 int sequence_id) { |
| 141 GDataDirectory* dir = new GDataDirectory(parent, directory_service); | 144 GDataDirectory* dir = new GDataDirectory(parent, directory_service); |
| 142 const std::string dir_name = "dir" + base::IntToString(sequence_id); | 145 const std::string dir_name = "dir" + base::IntToString(sequence_id); |
| 143 const std::string resource_id = std::string("dir_resource_id:") + | 146 const std::string resource_id = std::string("dir_resource_id:") + |
| 144 dir_name; | 147 dir_name; |
| 145 dir->set_title(dir_name); | 148 dir->set_title(dir_name); |
| 149 dir->SetBaseNameFromTitle(); |
| 146 dir->set_resource_id(resource_id); | 150 dir->set_resource_id(resource_id); |
| 147 parent->AddEntry(dir); | 151 GDataFileError error = GDATA_FILE_ERROR_FAILED; |
| 152 directory_service->AddEntryAt( |
| 153 parent->GetFilePath(), |
| 154 dir, |
| 155 base::Bind(&test_util::CopyResultFromFileOperationCallback, &error)); |
| 156 test_util::RunBlockingPoolTask(); |
| 157 EXPECT_EQ(GDATA_FILE_OK, error); |
| 148 | 158 |
| 149 GDataDB::Status status = gdata_db_->Put(*dir); | 159 GDataDB::Status status = gdata_db_->Put(*dir); |
| 150 EXPECT_EQ(GDataDB::DB_OK, status); | 160 EXPECT_EQ(GDataDB::DB_OK, status); |
| 151 DVLOG(1) << "AddDirectory " << dir->GetFilePath().value() | 161 DVLOG(1) << "AddDirectory " << dir->GetFilePath().value() |
| 152 << ", " << resource_id; | 162 << ", " << resource_id; |
| 153 return dir; | 163 return dir; |
| 154 } | 164 } |
| 155 | 165 |
| 156 GDataFile* GDataDBTest::AddFile(GDataDirectory* parent, | 166 GDataFile* GDataDBTest::AddFile(GDataDirectory* parent, |
| 157 GDataDirectoryService* directory_service, | 167 GDataDirectoryService* directory_service, |
| 158 int sequence_id) { | 168 int sequence_id) { |
| 159 GDataFile* file = new GDataFile(parent, directory_service); | 169 GDataFile* file = new GDataFile(parent, directory_service); |
| 160 const std::string title = "file" + base::IntToString(sequence_id); | 170 const std::string title = "file" + base::IntToString(sequence_id); |
| 161 const std::string resource_id = std::string("file_resource_id:") + | 171 const std::string resource_id = std::string("file_resource_id:") + |
| 162 title; | 172 title; |
| 163 file->set_title(title); | 173 file->set_title(title); |
| 174 file->SetBaseNameFromTitle(); |
| 164 file->set_resource_id(resource_id); | 175 file->set_resource_id(resource_id); |
| 165 parent->AddEntry(file); | 176 GDataFileError error = GDATA_FILE_ERROR_FAILED; |
| 177 directory_service->AddEntryAt( |
| 178 parent->GetFilePath(), |
| 179 file, |
| 180 base::Bind(&test_util::CopyResultFromFileOperationCallback, &error)); |
| 181 test_util::RunBlockingPoolTask(); |
| 182 EXPECT_EQ(GDATA_FILE_OK, error); |
| 166 | 183 |
| 167 GDataDB::Status status = gdata_db_->Put(*file); | 184 GDataDB::Status status = gdata_db_->Put(*file); |
| 168 EXPECT_EQ(GDataDB::DB_OK, status); | 185 EXPECT_EQ(GDataDB::DB_OK, status); |
| 169 DVLOG(1) << "AddFile " << file->GetFilePath().value() | 186 DVLOG(1) << "AddFile " << file->GetFilePath().value() |
| 170 << ", " << resource_id; | 187 << ", " << resource_id; |
| 171 return file; | 188 return file; |
| 172 } | 189 } |
| 173 | 190 |
| 174 void GDataDBTest::TestIter(const std::string& parent, | 191 void GDataDBTest::TestIter(const std::string& parent, |
| 175 const char* file_paths[], | 192 const char* file_paths[], |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 entry_proto.SerializeToString(&serialized_proto); | 340 entry_proto.SerializeToString(&serialized_proto); |
| 324 gdata_db_->PutRawForTesting("file_resource_id", serialized_proto); | 341 gdata_db_->PutRawForTesting("file_resource_id", serialized_proto); |
| 325 | 342 |
| 326 // Check if the corruption is detected. | 343 // Check if the corruption is detected. |
| 327 TestGetCorrupt(file); | 344 TestGetCorrupt(file); |
| 328 // We should no longer be able to find the file by iteration. | 345 // We should no longer be able to find the file by iteration. |
| 329 TestIter("", NULL, 0); | 346 TestIter("", NULL, 0); |
| 330 } | 347 } |
| 331 | 348 |
| 332 } // namespace gdata | 349 } // namespace gdata |
| OLD | NEW |