Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: content/browser/leveldb_wrapper_impl_unittest.cc

Issue 2604273002: Migrate data from old localstorage format to new format. (Closed)
Patch Set: nit Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/leveldb_wrapper_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 : m_result(result), m_callback(callback) {} 45 : m_result(result), m_callback(callback) {}
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 class MockDelegate : public LevelDBWrapperImpl::Delegate {
56 std::vector<leveldb::mojom::BatchedOperationPtr> PrepareToCommitNoOp( 56 public:
57 const LevelDBWrapperImpl&) { 57 void OnNoBindings() override {}
58 return std::vector<leveldb::mojom::BatchedOperationPtr>(); 58 std::vector<leveldb::mojom::BatchedOperationPtr> PrepareToCommit() override {
59 } 59 return std::vector<leveldb::mojom::BatchedOperationPtr>();
60 }
61 void DidCommit(leveldb::mojom::DatabaseError error) override {}
62 };
60 63
61 void GetCallback(const base::Closure& callback, 64 void GetCallback(const base::Closure& callback,
62 bool* success_out, 65 bool* success_out,
63 std::vector<uint8_t>* value_out, 66 std::vector<uint8_t>* value_out,
64 bool success, 67 bool success,
65 const std::vector<uint8_t>& value) { 68 const std::vector<uint8_t>& value) {
66 *success_out = success; 69 *success_out = success;
67 *value_out = value; 70 *value_out = value;
68 callback.Run(); 71 callback.Run();
69 } 72 }
(...skipping 21 matching lines...) Expand all
91 }; 94 };
92 95
93 LevelDBWrapperImplTest() 96 LevelDBWrapperImplTest()
94 : db_(&mock_data_), 97 : db_(&mock_data_),
95 level_db_wrapper_(&db_, 98 level_db_wrapper_(&db_,
96 kTestPrefix, 99 kTestPrefix,
97 kTestSizeLimit, 100 kTestSizeLimit,
98 base::TimeDelta::FromSeconds(5), 101 base::TimeDelta::FromSeconds(5),
99 10 * 1024 * 1024 /* max_bytes_per_hour */, 102 10 * 1024 * 1024 /* max_bytes_per_hour */,
100 60 /* max_commits_per_hour */, 103 60 /* max_commits_per_hour */,
101 base::Bind(&NoOp), 104 &delegate_),
102 base::Bind(&PrepareToCommitNoOp)),
103 observer_binding_(this) { 105 observer_binding_(this) {
104 set_mock_data(std::string(kTestPrefix) + "def", "defdata"); 106 set_mock_data(std::string(kTestPrefix) + "def", "defdata");
105 set_mock_data(std::string(kTestPrefix) + "123", "123data"); 107 set_mock_data(std::string(kTestPrefix) + "123", "123data");
106 set_mock_data("123", "baddata"); 108 set_mock_data("123", "baddata");
107 109
108 level_db_wrapper_.Bind(mojo::MakeRequest(&level_db_wrapper_ptr_)); 110 level_db_wrapper_.Bind(mojo::MakeRequest(&level_db_wrapper_ptr_));
109 mojom::LevelDBObserverAssociatedPtrInfo ptr_info; 111 mojom::LevelDBObserverAssociatedPtrInfo ptr_info;
110 observer_binding_.Bind(&ptr_info, associated_group()); 112 observer_binding_.Bind(&ptr_info, associated_group());
111 level_db_wrapper_ptr_->AddObserver(std::move(ptr_info)); 113 level_db_wrapper_ptr_->AddObserver(std::move(ptr_info));
112 } 114 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 observations_.push_back({Observation::kDelete, Uint8VectorToStdString(key), 204 observations_.push_back({Observation::kDelete, Uint8VectorToStdString(key),
203 Uint8VectorToStdString(old_value), "", source}); 205 Uint8VectorToStdString(old_value), "", source});
204 } 206 }
205 void AllDeleted(const std::string& source) override { 207 void AllDeleted(const std::string& source) override {
206 observations_.push_back({Observation::kDeleteAll, "", "", "", source}); 208 observations_.push_back({Observation::kDeleteAll, "", "", "", source});
207 } 209 }
208 210
209 TestBrowserThreadBundle thread_bundle_; 211 TestBrowserThreadBundle thread_bundle_;
210 std::map<std::vector<uint8_t>, std::vector<uint8_t>> mock_data_; 212 std::map<std::vector<uint8_t>, std::vector<uint8_t>> mock_data_;
211 MockLevelDBDatabase db_; 213 MockLevelDBDatabase db_;
214 MockDelegate delegate_;
212 LevelDBWrapperImpl level_db_wrapper_; 215 LevelDBWrapperImpl level_db_wrapper_;
213 mojom::LevelDBWrapperPtr level_db_wrapper_ptr_; 216 mojom::LevelDBWrapperPtr level_db_wrapper_ptr_;
214 mojo::AssociatedBinding<mojom::LevelDBObserver> observer_binding_; 217 mojo::AssociatedBinding<mojom::LevelDBObserver> observer_binding_;
215 std::vector<Observation> observations_; 218 std::vector<Observation> observations_;
216 }; 219 };
217 220
218 TEST_F(LevelDBWrapperImplTest, GetLoadedFromMap) { 221 TEST_F(LevelDBWrapperImplTest, GetLoadedFromMap) {
219 std::vector<uint8_t> result; 222 std::vector<uint8_t> result;
220 EXPECT_TRUE(GetSync(StdStringToUint8Vector("123"), &result)); 223 EXPECT_TRUE(GetSync(StdStringToUint8Vector("123"), &result));
221 EXPECT_EQ(StdStringToUint8Vector("123data"), result); 224 EXPECT_EQ(StdStringToUint8Vector("123data"), result);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // Reducing size should also succeed. 469 // Reducing size should also succeed.
467 value.clear(); 470 value.clear();
468 EXPECT_TRUE(PutSync(key, value)); 471 EXPECT_TRUE(PutSync(key, value));
469 472
470 // Increasing size should fail. 473 // Increasing size should fail.
471 value.resize(1, 'a'); 474 value.resize(1, 'a');
472 EXPECT_FALSE(PutSync(key, value)); 475 EXPECT_FALSE(PutSync(key, value));
473 } 476 }
474 477
475 } // namespace content 478 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/leveldb_wrapper_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698