OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 | 5 |
6 #include "content/browser/dom_storage/session_storage_database.h" | 6 #include "content/browser/dom_storage/session_storage_database.h" |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Key is of the form "map-<mapid>-key". | 177 // Key is of the form "map-<mapid>-key". |
178 std::string map_id_str = key.substr(map_prefix.length(), | 178 std::string map_id_str = key.substr(map_prefix.length(), |
179 second_dash - map_prefix.length()); | 179 second_dash - map_prefix.length()); |
180 bool conversion_ok = base::StringToInt64(map_id_str, map_id); | 180 bool conversion_ok = base::StringToInt64(map_id_str, map_id); |
181 EXPECT_TRUE(conversion_ok); | 181 EXPECT_TRUE(conversion_ok); |
182 return true; | 182 return true; |
183 } | 183 } |
184 | 184 |
185 void SessionStorageDatabaseTest::ReadData(DataMap* data) const { | 185 void SessionStorageDatabaseTest::ReadData(DataMap* data) const { |
186 leveldb::DB* leveldb = db_->db_.get(); | 186 leveldb::DB* leveldb = db_->db_.get(); |
187 scoped_ptr<leveldb::Iterator> it( | 187 std::unique_ptr<leveldb::Iterator> it( |
188 leveldb->NewIterator(leveldb::ReadOptions())); | 188 leveldb->NewIterator(leveldb::ReadOptions())); |
189 for (it->SeekToFirst(); it->Valid(); it->Next()) { | 189 for (it->SeekToFirst(); it->Valid(); it->Next()) { |
190 (*data)[it->key().ToString()] = it->value().ToString(); | 190 (*data)[it->key().ToString()] = it->value().ToString(); |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 void SessionStorageDatabaseTest::CheckDatabaseConsistency() const { | 194 void SessionStorageDatabaseTest::CheckDatabaseConsistency() const { |
195 DataMap data; | 195 DataMap data; |
196 ReadData(&data); | 196 ReadData(&data); |
197 // Empty db is ok. | 197 // Empty db is ok. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 size_t valid_keys = 0; | 291 size_t valid_keys = 0; |
292 if (data.find(SessionStorageDatabase::NamespacePrefix()) != data.end()) | 292 if (data.find(SessionStorageDatabase::NamespacePrefix()) != data.end()) |
293 ++valid_keys; | 293 ++valid_keys; |
294 if (data.find(SessionStorageDatabase::NextMapIdKey()) != data.end()) | 294 if (data.find(SessionStorageDatabase::NextMapIdKey()) != data.end()) |
295 ++valid_keys; | 295 ++valid_keys; |
296 EXPECT_EQ(valid_keys, data.size()); | 296 EXPECT_EQ(valid_keys, data.size()); |
297 } | 297 } |
298 | 298 |
299 void SessionStorageDatabaseTest::DumpData() const { | 299 void SessionStorageDatabaseTest::DumpData() const { |
300 LOG(WARNING) << "---- Session storage contents"; | 300 LOG(WARNING) << "---- Session storage contents"; |
301 scoped_ptr<leveldb::Iterator> it( | 301 std::unique_ptr<leveldb::Iterator> it( |
302 db_->db_->NewIterator(leveldb::ReadOptions())); | 302 db_->db_->NewIterator(leveldb::ReadOptions())); |
303 for (it->SeekToFirst(); it->Valid(); it->Next()) { | 303 for (it->SeekToFirst(); it->Valid(); it->Next()) { |
304 int64_t dummy_map_id; | 304 int64_t dummy_map_id; |
305 if (IsMapValueKey(it->key().ToString(), &dummy_map_id)) { | 305 if (IsMapValueKey(it->key().ToString(), &dummy_map_id)) { |
306 // Convert the value back to base::string16. | 306 // Convert the value back to base::string16. |
307 base::string16 value; | 307 base::string16 value; |
308 size_t len = it->value().size() / sizeof(base::char16); | 308 size_t len = it->value().size() / sizeof(base::char16); |
309 value.resize(len); | 309 value.resize(len); |
310 value.assign( | 310 value.assign( |
311 reinterpret_cast<const base::char16*>(it->value().data()), len); | 311 reinterpret_cast<const base::char16*>(it->value().data()), len); |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin2, false, data2)); | 792 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin2, false, data2)); |
793 | 793 |
794 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin1)); | 794 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin1)); |
795 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2)); | 795 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2)); |
796 // Check that also the namespace start key was deleted. | 796 // Check that also the namespace start key was deleted. |
797 CheckDatabaseConsistency(); | 797 CheckDatabaseConsistency(); |
798 } | 798 } |
799 | 799 |
800 | 800 |
801 } // namespace content | 801 } // namespace content |
OLD | NEW |