| 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/contacts/contact_database.h" | 5 #include "chrome/browser/chromeos/contacts/contact_database.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_enumerator.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 16 #include "chrome/browser/chromeos/contacts/contact.pb.h" | 17 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
| 17 #include "chrome/browser/chromeos/contacts/contact_test_util.h" | 18 #include "chrome/browser/chromeos/contacts/contact_test_util.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 metadata_to_save.Pass(), | 308 metadata_to_save.Pass(), |
| 308 true); | 309 true); |
| 309 LoadContacts(&loaded_contacts, &loaded_metadata); | 310 LoadContacts(&loaded_contacts, &loaded_metadata); |
| 310 EXPECT_TRUE(loaded_contacts->empty()); | 311 EXPECT_TRUE(loaded_contacts->empty()); |
| 311 } | 312 } |
| 312 | 313 |
| 313 // Test that we create a new database when we encounter a corrupted one. | 314 // Test that we create a new database when we encounter a corrupted one. |
| 314 TEST_F(ContactDatabaseTest, DeleteWhenCorrupt) { | 315 TEST_F(ContactDatabaseTest, DeleteWhenCorrupt) { |
| 315 DestroyDatabase(); | 316 DestroyDatabase(); |
| 316 // Overwrite all of the files in the database with a space character. | 317 // Overwrite all of the files in the database with a space character. |
| 317 file_util::FileEnumerator enumerator( | 318 base::FileEnumerator enumerator( |
| 318 database_path(), false, file_util::FileEnumerator::FILES); | 319 database_path(), false, base::FileEnumerator::FILES); |
| 319 for (base::FilePath path = enumerator.Next(); !path.empty(); | 320 for (base::FilePath path = enumerator.Next(); !path.empty(); |
| 320 path = enumerator.Next()) { | 321 path = enumerator.Next()) { |
| 321 file_util::WriteFile(path, " ", 1); | 322 file_util::WriteFile(path, " ", 1); |
| 322 } | 323 } |
| 323 CreateDatabase(); | 324 CreateDatabase(); |
| 324 | 325 |
| 325 // Make sure that the resulting database is usable. | 326 // Make sure that the resulting database is usable. |
| 326 scoped_ptr<Contact> contact(new Contact); | 327 scoped_ptr<Contact> contact(new Contact); |
| 327 InitContact("1", "1", false, contact.get()); | 328 InitContact("1", "1", false, contact.get()); |
| 328 scoped_ptr<ContactPointers> contacts_to_save(new ContactPointers); | 329 scoped_ptr<ContactPointers> contacts_to_save(new ContactPointers); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 contact_ids_to_delete.Pass(), | 408 contact_ids_to_delete.Pass(), |
| 408 metadata_to_save.Pass(), | 409 metadata_to_save.Pass(), |
| 409 false); | 410 false); |
| 410 LoadContacts(&loaded_contacts, &loaded_metadata); | 411 LoadContacts(&loaded_contacts, &loaded_metadata); |
| 411 EXPECT_EQ(VarContactsToString(1, contact3.get()), | 412 EXPECT_EQ(VarContactsToString(1, contact3.get()), |
| 412 ContactsToString(*loaded_contacts)); | 413 ContactsToString(*loaded_contacts)); |
| 413 } | 414 } |
| 414 | 415 |
| 415 } // namespace test | 416 } // namespace test |
| 416 } // namespace contacts | 417 } // namespace contacts |
| OLD | NEW |