| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/dom_storage/local_storage_context_mojo.h" | 5 #include "content/browser/dom_storage/local_storage_context_mojo.h" |
| 6 | 6 |
| 7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 DoTestPut(context.get(), key, value); | 812 DoTestPut(context.get(), key, value); |
| 813 std::vector<uint8_t> result; | 813 std::vector<uint8_t> result; |
| 814 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); | 814 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); |
| 815 EXPECT_EQ(value, result); | 815 EXPECT_EQ(value, result); |
| 816 | 816 |
| 817 context.reset(); | 817 context.reset(); |
| 818 base::RunLoop().RunUntilIdle(); | 818 base::RunLoop().RunUntilIdle(); |
| 819 | 819 |
| 820 { | 820 { |
| 821 // Mess up version number in database. | 821 // Mess up version number in database. |
| 822 leveldb_env::ChromiumEnv env; | |
| 823 leveldb::DB* db = nullptr; | 822 leveldb::DB* db = nullptr; |
| 824 leveldb::Options options; | 823 leveldb::Options options; |
| 825 options.env = &env; | |
| 826 base::FilePath db_path = | 824 base::FilePath db_path = |
| 827 temp_path().Append(test_path).Append(FILE_PATH_LITERAL("leveldb")); | 825 temp_path().Append(test_path).Append(FILE_PATH_LITERAL("leveldb")); |
| 828 ASSERT_TRUE(leveldb::DB::Open(options, db_path.AsUTF8Unsafe(), &db).ok()); | 826 ASSERT_TRUE(leveldb::DB::Open(options, db_path.AsUTF8Unsafe(), &db).ok()); |
| 829 std::unique_ptr<leveldb::DB> db_owner(db); | 827 std::unique_ptr<leveldb::DB> db_owner(db); |
| 830 ASSERT_TRUE(db->Put(leveldb::WriteOptions(), "VERSION", "argh").ok()); | 828 ASSERT_TRUE(db->Put(leveldb::WriteOptions(), "VERSION", "argh").ok()); |
| 831 } | 829 } |
| 832 | 830 |
| 833 // Make sure data is gone. | 831 // Make sure data is gone. |
| 834 context = base::MakeUnique<LocalStorageContextMojo>( | 832 context = base::MakeUnique<LocalStorageContextMojo>( |
| 835 connector(), nullptr, base::FilePath(), test_path); | 833 connector(), nullptr, base::FilePath(), test_path); |
| 836 EXPECT_FALSE(DoTestGet(context.get(), key, &result)); | 834 EXPECT_FALSE(DoTestGet(context.get(), key, &result)); |
| 837 | 835 |
| 838 // Write data again. | 836 // Write data again. |
| 839 DoTestPut(context.get(), key, value); | 837 DoTestPut(context.get(), key, value); |
| 840 | 838 |
| 841 context.reset(); | 839 context.reset(); |
| 842 base::RunLoop().RunUntilIdle(); | 840 base::RunLoop().RunUntilIdle(); |
| 843 | 841 |
| 844 // Data should have been preserved now. | 842 // Data should have been preserved now. |
| 845 context = base::MakeUnique<LocalStorageContextMojo>( | 843 context = base::MakeUnique<LocalStorageContextMojo>( |
| 846 connector(), nullptr, base::FilePath(), test_path); | 844 connector(), nullptr, base::FilePath(), test_path); |
| 847 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); | 845 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); |
| 848 EXPECT_EQ(value, result); | 846 EXPECT_EQ(value, result); |
| 849 } | 847 } |
| 850 | 848 |
| 851 } // namespace content | 849 } // namespace content |
| OLD | NEW |