Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 10 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
| 11 #include "content/browser/indexed_db/indexed_db_value.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/WebKit/public/platform/WebIDBTypes.h" | 13 #include "third_party/WebKit/public/platform/WebIDBTypes.h" |
| 13 | 14 |
| 14 using base::ASCIIToUTF16; | 15 using base::ASCIIToUTF16; |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 class IndexedDBBackingStoreTest : public testing::Test { | 21 class IndexedDBBackingStoreTest : public testing::Test { |
| 21 public: | 22 public: |
| 22 IndexedDBBackingStoreTest() {} | 23 IndexedDBBackingStoreTest() {} |
| 23 virtual void SetUp() { | 24 virtual void SetUp() { |
| 24 const GURL origin("http://localhost:81"); | 25 const GURL origin("http://localhost:81"); |
| 25 backing_store_ = IndexedDBBackingStore::OpenInMemory(origin); | 26 backing_store_ = IndexedDBBackingStore::OpenInMemory(origin); |
| 26 | 27 |
| 27 // useful keys and values during tests | 28 // useful keys and values during tests |
| 28 m_value1 = "value1"; | 29 m_value1 = IndexedDBValue("value1", std::vector<IndexedDBBlobInfo>()); |
| 29 m_value2 = "value2"; | 30 m_value2 = IndexedDBValue("value2", std::vector<IndexedDBBlobInfo>()); |
| 30 m_value3 = "value3"; | 31 |
| 31 m_key1 = IndexedDBKey(99, blink::WebIDBKeyTypeNumber); | 32 m_key1 = IndexedDBKey(99, blink::WebIDBKeyTypeNumber); |
| 32 m_key2 = IndexedDBKey(ASCIIToUTF16("key2")); | 33 m_key2 = IndexedDBKey(ASCIIToUTF16("key2")); |
| 33 m_key3 = IndexedDBKey(ASCIIToUTF16("key3")); | 34 m_key3 = IndexedDBKey(ASCIIToUTF16("key3")); |
| 34 } | 35 } |
| 35 | 36 |
| 36 protected: | 37 protected: |
| 37 scoped_refptr<IndexedDBBackingStore> backing_store_; | 38 scoped_refptr<IndexedDBBackingStore> backing_store_; |
| 38 | 39 |
| 39 // Sample keys and values that are consistent. | 40 // Sample keys and values that are consistent. |
| 40 IndexedDBKey m_key1; | 41 IndexedDBKey m_key1; |
| 41 IndexedDBKey m_key2; | 42 IndexedDBKey m_key2; |
| 42 IndexedDBKey m_key3; | 43 IndexedDBKey m_key3; |
| 43 std::string m_value1; | 44 IndexedDBValue m_value1; |
| 44 std::string m_value2; | 45 IndexedDBValue m_value2; |
|
cmumford
2014/03/14 00:36:16
is m_key3 still needed? Not sure why value3 went a
ericu
2014/03/14 01:17:23
Nope; neither's used in current code.
Removed.
| |
| 45 std::string m_value3; | |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStoreTest); | 48 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStoreTest); |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { | 51 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { |
| 52 { | 52 { |
| 53 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 53 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
| 54 transaction1.Begin(); | 54 transaction1.Begin(); |
| 55 IndexedDBBackingStore::RecordIdentifier record; | 55 IndexedDBBackingStore::RecordIdentifier record; |
| 56 leveldb::Status s = backing_store_->PutRecord( | 56 leveldb::Status s = backing_store_->PutRecord( |
| 57 &transaction1, 1, 1, m_key1, m_value1, &record); | 57 &transaction1, 1, 1, m_key1, m_value1, &record); |
| 58 EXPECT_TRUE(s.ok()); | 58 EXPECT_TRUE(s.ok()); |
| 59 transaction1.Commit(); | 59 transaction1.Commit(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 { | 62 { |
| 63 IndexedDBBackingStore::Transaction transaction2(backing_store_); | 63 IndexedDBBackingStore::Transaction transaction2(backing_store_); |
| 64 transaction2.Begin(); | 64 transaction2.Begin(); |
| 65 std::string result_value; | 65 IndexedDBValue result_value; |
| 66 leveldb::Status s = | 66 leveldb::Status s = |
| 67 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value); | 67 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value); |
| 68 transaction2.Commit(); | 68 transaction2.Commit(); |
| 69 EXPECT_TRUE(s.ok()); | 69 EXPECT_TRUE(s.ok()); |
| 70 EXPECT_EQ(m_value1, result_value); | 70 EXPECT_EQ(m_value1.bits, result_value.bits); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Make sure that using very high ( more than 32 bit ) values for database_id | 74 // Make sure that using very high ( more than 32 bit ) values for database_id |
| 75 // and object_store_id still work. | 75 // and object_store_id still work. |
| 76 TEST_F(IndexedDBBackingStoreTest, HighIds) { | 76 TEST_F(IndexedDBBackingStoreTest, HighIds) { |
| 77 const int64 high_database_id = 1ULL << 35; | 77 const int64 high_database_id = 1ULL << 35; |
| 78 const int64 high_object_store_id = 1ULL << 39; | 78 const int64 high_object_store_id = 1ULL << 39; |
| 79 // index_ids are capped at 32 bits for storage purposes. | 79 // index_ids are capped at 32 bits for storage purposes. |
| 80 const int64 high_index_id = 1ULL << 29; | 80 const int64 high_index_id = 1ULL << 29; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 record); | 112 record); |
| 113 EXPECT_TRUE(s.ok()); | 113 EXPECT_TRUE(s.ok()); |
| 114 | 114 |
| 115 s = transaction1.Commit(); | 115 s = transaction1.Commit(); |
| 116 EXPECT_TRUE(s.ok()); | 116 EXPECT_TRUE(s.ok()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 { | 119 { |
| 120 IndexedDBBackingStore::Transaction transaction2(backing_store_); | 120 IndexedDBBackingStore::Transaction transaction2(backing_store_); |
| 121 transaction2.Begin(); | 121 transaction2.Begin(); |
| 122 std::string result_value; | 122 IndexedDBValue result_value; |
| 123 leveldb::Status s = backing_store_->GetRecord(&transaction2, | 123 leveldb::Status s = backing_store_->GetRecord(&transaction2, |
| 124 high_database_id, | 124 high_database_id, |
| 125 high_object_store_id, | 125 high_object_store_id, |
| 126 m_key1, | 126 m_key1, |
| 127 &result_value); | 127 &result_value); |
| 128 EXPECT_TRUE(s.ok()); | 128 EXPECT_TRUE(s.ok()); |
| 129 EXPECT_EQ(m_value1, result_value); | 129 EXPECT_EQ(m_value1.bits, result_value.bits); |
| 130 | 130 |
| 131 scoped_ptr<IndexedDBKey> new_primary_key; | 131 scoped_ptr<IndexedDBKey> new_primary_key; |
| 132 s = backing_store_->GetPrimaryKeyViaIndex(&transaction2, | 132 s = backing_store_->GetPrimaryKeyViaIndex(&transaction2, |
| 133 high_database_id, | 133 high_database_id, |
| 134 high_object_store_id, | 134 high_object_store_id, |
| 135 invalid_high_index_id, | 135 invalid_high_index_id, |
| 136 index_key, | 136 index_key, |
| 137 &new_primary_key); | 137 &new_primary_key); |
| 138 EXPECT_FALSE(s.ok()); | 138 EXPECT_FALSE(s.ok()); |
| 139 | 139 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Make sure that other invalid ids do not crash. | 154 // Make sure that other invalid ids do not crash. |
| 155 TEST_F(IndexedDBBackingStoreTest, InvalidIds) { | 155 TEST_F(IndexedDBBackingStoreTest, InvalidIds) { |
| 156 // valid ids for use when testing invalid ids | 156 // valid ids for use when testing invalid ids |
| 157 const int64 database_id = 1; | 157 const int64 database_id = 1; |
| 158 const int64 object_store_id = 1; | 158 const int64 object_store_id = 1; |
| 159 const int64 index_id = kMinimumIndexId; | 159 const int64 index_id = kMinimumIndexId; |
| 160 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId | 160 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId |
| 161 | 161 |
| 162 std::string result_value; | 162 IndexedDBValue result_value; |
| 163 | 163 |
| 164 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 164 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
| 165 transaction1.Begin(); | 165 transaction1.Begin(); |
| 166 | 166 |
| 167 IndexedDBBackingStore::RecordIdentifier record; | 167 IndexedDBBackingStore::RecordIdentifier record; |
| 168 leveldb::Status s = backing_store_->PutRecord(&transaction1, | 168 leveldb::Status s = backing_store_->PutRecord(&transaction1, |
| 169 database_id, | 169 database_id, |
| 170 KeyPrefix::kInvalidId, | 170 KeyPrefix::kInvalidId, |
| 171 m_key1, | 171 m_key1, |
| 172 m_value1, | 172 m_value1, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 EXPECT_EQ(index_name, index.name); | 314 EXPECT_EQ(index_name, index.name); |
| 315 EXPECT_EQ(index_key_path, index.key_path); | 315 EXPECT_EQ(index_key_path, index.key_path); |
| 316 EXPECT_EQ(unique, index.unique); | 316 EXPECT_EQ(unique, index.unique); |
| 317 EXPECT_EQ(multi_entry, index.multi_entry); | 317 EXPECT_EQ(multi_entry, index.multi_entry); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 } // namespace | 321 } // namespace |
| 322 | 322 |
| 323 } // namespace content | 323 } // namespace content |
| OLD | NEW |