| 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 "extensions/browser/value_store/leveldb_scoped_database.h" | 5 #include "extensions/browser/value_store/leveldb_scoped_database.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } // namespace | 21 } // namespace |
| 22 | 22 |
| 23 class LeveldbScopedDatabaseUnitTest : public testing::Test { | 23 class LeveldbScopedDatabaseUnitTest : public testing::Test { |
| 24 public: | 24 public: |
| 25 LeveldbScopedDatabaseUnitTest() {} | 25 LeveldbScopedDatabaseUnitTest() {} |
| 26 ~LeveldbScopedDatabaseUnitTest() override {} | 26 ~LeveldbScopedDatabaseUnitTest() override {} |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 void SetUp() override { | 29 void SetUp() override { |
| 30 ASSERT_TRUE(database_dir_.CreateUniqueTempDir()); | 30 ASSERT_TRUE(database_dir_.CreateUniqueTempDir()); |
| 31 db_ = new LeveldbScopedDatabase(kTestUMAClientName, database_dir_.path()); | 31 db_ = |
| 32 new LeveldbScopedDatabase(kTestUMAClientName, database_dir_.GetPath()); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void TearDown() override { | 35 void TearDown() override { |
| 35 db_ = nullptr; | 36 db_ = nullptr; |
| 36 base::DeleteFile(database_dir_.path(), true); | 37 base::DeleteFile(database_dir_.GetPath(), true); |
| 37 } | 38 } |
| 38 | 39 |
| 39 ValueStore::Status ReadAllValues( | 40 ValueStore::Status ReadAllValues( |
| 40 std::map<std::string, std::string>* values) const { | 41 std::map<std::string, std::string>* values) const { |
| 41 values->clear(); | 42 values->clear(); |
| 42 leveldb::ReadOptions read_options; | 43 leveldb::ReadOptions read_options; |
| 43 read_options.verify_checksums = true; | 44 read_options.verify_checksums = true; |
| 44 std::unique_ptr<leveldb::Iterator> iterator; | 45 std::unique_ptr<leveldb::Iterator> iterator; |
| 45 ValueStore::Status status = db_->CreateIterator(read_options, &iterator); | 46 ValueStore::Status status = db_->CreateIterator(read_options, &iterator); |
| 46 if (!status.ok()) | 47 if (!status.ok()) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 EXPECT_TRUE(db_->DeleteValues("scope2", keys).ok()); | 197 EXPECT_TRUE(db_->DeleteValues("scope2", keys).ok()); |
| 197 | 198 |
| 198 base::DictionaryValue read_s1_vals; | 199 base::DictionaryValue read_s1_vals; |
| 199 EXPECT_TRUE(db_->Read("scope1", &read_s1_vals).ok()); | 200 EXPECT_TRUE(db_->Read("scope1", &read_s1_vals).ok()); |
| 200 EXPECT_TRUE(scope1_values.Equals(&read_s1_vals)); | 201 EXPECT_TRUE(scope1_values.Equals(&read_s1_vals)); |
| 201 | 202 |
| 202 base::DictionaryValue read_s2_vals; | 203 base::DictionaryValue read_s2_vals; |
| 203 EXPECT_TRUE(db_->Read("scope2", &read_s2_vals).ok()); | 204 EXPECT_TRUE(db_->Read("scope2", &read_s2_vals).ok()); |
| 204 EXPECT_TRUE(read_s2_vals.empty()); | 205 EXPECT_TRUE(read_s2_vals.empty()); |
| 205 } | 206 } |
| OLD | NEW |