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/leveldb_wrapper_impl.h" | 5 #include "content/browser/leveldb_wrapper_impl.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "components/leveldb/public/cpp/util.h" | 9 #include "components/leveldb/public/cpp/util.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 void Complete(bool success) override { | 46 void Complete(bool success) override { |
47 *m_result = success; | 47 *m_result = success; |
48 m_callback.Run(); | 48 m_callback.Run(); |
49 } | 49 } |
50 | 50 |
51 bool* m_result; | 51 bool* m_result; |
52 base::Closure m_callback; | 52 base::Closure m_callback; |
53 }; | 53 }; |
54 | 54 |
55 void NoOp() {} | 55 void NoOp() {} |
| 56 std::vector<leveldb::mojom::BatchedOperationPtr> PrepareToCommitNoOp() { |
| 57 return std::vector<leveldb::mojom::BatchedOperationPtr>(); |
| 58 } |
56 | 59 |
57 void GetCallback(const base::Closure& callback, | 60 void GetCallback(const base::Closure& callback, |
58 bool* success_out, | 61 bool* success_out, |
59 std::vector<uint8_t>* value_out, | 62 std::vector<uint8_t>* value_out, |
60 bool success, | 63 bool success, |
61 const std::vector<uint8_t>& value) { | 64 const std::vector<uint8_t>& value) { |
62 *success_out = success; | 65 *success_out = success; |
63 *value_out = value; | 66 *value_out = value; |
64 callback.Run(); | 67 callback.Run(); |
65 } | 68 } |
(...skipping 19 matching lines...) Expand all Loading... |
85 }; | 88 }; |
86 | 89 |
87 LevelDBWrapperImplTest() | 90 LevelDBWrapperImplTest() |
88 : db_(&mock_data_), | 91 : db_(&mock_data_), |
89 level_db_wrapper_(&db_, | 92 level_db_wrapper_(&db_, |
90 kTestPrefix, | 93 kTestPrefix, |
91 kTestSizeLimit, | 94 kTestSizeLimit, |
92 base::TimeDelta::FromSeconds(5), | 95 base::TimeDelta::FromSeconds(5), |
93 10 * 1024 * 1024 /* max_bytes_per_hour */, | 96 10 * 1024 * 1024 /* max_bytes_per_hour */, |
94 60 /* max_commits_per_hour */, | 97 60 /* max_commits_per_hour */, |
95 base::Bind(&NoOp)), | 98 base::Bind(&NoOp), |
| 99 base::Bind(&PrepareToCommitNoOp)), |
96 observer_binding_(this) { | 100 observer_binding_(this) { |
97 set_mock_data(std::string(kTestPrefix) + "def", "defdata"); | 101 set_mock_data(std::string(kTestPrefix) + "def", "defdata"); |
98 set_mock_data(std::string(kTestPrefix) + "123", "123data"); | 102 set_mock_data(std::string(kTestPrefix) + "123", "123data"); |
99 set_mock_data("123", "baddata"); | 103 set_mock_data("123", "baddata"); |
100 | 104 |
101 level_db_wrapper_.Bind(mojo::MakeRequest(&level_db_wrapper_ptr_)); | 105 level_db_wrapper_.Bind(mojo::MakeRequest(&level_db_wrapper_ptr_)); |
102 mojom::LevelDBObserverAssociatedPtrInfo ptr_info; | 106 mojom::LevelDBObserverAssociatedPtrInfo ptr_info; |
103 observer_binding_.Bind(&ptr_info, associated_group()); | 107 observer_binding_.Bind(&ptr_info, associated_group()); |
104 level_db_wrapper_ptr_->AddObserver(std::move(ptr_info)); | 108 level_db_wrapper_ptr_->AddObserver(std::move(ptr_info)); |
105 } | 109 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // Reducing size should also succeed. | 424 // Reducing size should also succeed. |
421 value.clear(); | 425 value.clear(); |
422 EXPECT_TRUE(PutSync(key, value)); | 426 EXPECT_TRUE(PutSync(key, value)); |
423 | 427 |
424 // Increasing size should fail. | 428 // Increasing size should fail. |
425 value.resize(1, 'a'); | 429 value.resize(1, 'a'); |
426 EXPECT_FALSE(PutSync(key, value)); | 430 EXPECT_FALSE(PutSync(key, value)); |
427 } | 431 } |
428 | 432 |
429 } // namespace content | 433 } // namespace content |
OLD | NEW |