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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 m_key3 = IndexedDBKey(ASCIIToUTF16("key3")); | 44 m_key3 = IndexedDBKey(ASCIIToUTF16("key3")); |
45 } | 45 } |
46 | 46 |
47 protected: | 47 protected: |
48 scoped_refptr<IndexedDBBackingStore> backing_store_; | 48 scoped_refptr<IndexedDBBackingStore> backing_store_; |
49 | 49 |
50 // Sample keys and values that are consistent. | 50 // Sample keys and values that are consistent. |
51 IndexedDBKey m_key1; | 51 IndexedDBKey m_key1; |
52 IndexedDBKey m_key2; | 52 IndexedDBKey m_key2; |
53 IndexedDBKey m_key3; | 53 IndexedDBKey m_key3; |
54 std::vector<char> m_value1; | 54 std::string m_value1; |
55 std::vector<char> m_value2; | 55 std::string m_value2; |
56 std::vector<char> m_value3; | 56 std::string m_value3; |
57 }; | 57 }; |
58 | 58 |
59 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { | 59 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { |
60 { | 60 { |
61 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 61 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
62 transaction1.Begin(); | 62 transaction1.Begin(); |
63 IndexedDBBackingStore::RecordIdentifier record; | 63 IndexedDBBackingStore::RecordIdentifier record; |
64 bool ok = backing_store_->PutRecord( | 64 bool ok = backing_store_->PutRecord( |
65 &transaction1, 1, 1, m_key1, m_value1, &record); | 65 &transaction1, 1, 1, m_key1, m_value1, &record); |
66 EXPECT_TRUE(ok); | 66 EXPECT_TRUE(ok); |
67 transaction1.Commit(); | 67 transaction1.Commit(); |
68 } | 68 } |
69 | 69 |
70 { | 70 { |
71 IndexedDBBackingStore::Transaction transaction2(backing_store_); | 71 IndexedDBBackingStore::Transaction transaction2(backing_store_); |
72 transaction2.Begin(); | 72 transaction2.Begin(); |
73 std::vector<char> result_value; | 73 std::string result_value; |
74 bool ok = | 74 bool ok = |
75 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value); | 75 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value); |
76 transaction2.Commit(); | 76 transaction2.Commit(); |
77 EXPECT_TRUE(ok); | 77 EXPECT_TRUE(ok); |
78 EXPECT_EQ(m_value1, result_value); | 78 EXPECT_EQ(m_value1, result_value); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 // Make sure that using very high ( more than 32 bit ) values for database_id | 82 // Make sure that using very high ( more than 32 bit ) values for database_id |
83 // and object_store_id still work. | 83 // and object_store_id still work. |
84 TEST_F(IndexedDBBackingStoreTest, HighIds) { | 84 TEST_F(IndexedDBBackingStoreTest, HighIds) { |
85 const int64 high_database_id = 1ULL << 35; | 85 const int64 high_database_id = 1ULL << 35; |
86 const int64 high_object_store_id = 1ULL << 39; | 86 const int64 high_object_store_id = 1ULL << 39; |
87 // index_ids are capped at 32 bits for storage purposes. | 87 // index_ids are capped at 32 bits for storage purposes. |
88 const int64 high_index_id = 1ULL << 29; | 88 const int64 high_index_id = 1ULL << 29; |
89 | 89 |
90 const int64 invalid_high_index_id = 1ULL << 37; | 90 const int64 invalid_high_index_id = 1ULL << 37; |
91 | 91 |
92 const IndexedDBKey& index_key = m_key2; | 92 const IndexedDBKey& index_key = m_key2; |
93 std::vector<char> index_key_raw; | 93 std::string index_key_raw; |
94 EncodeIDBKey(index_key, &index_key_raw); | 94 EncodeIDBKey(index_key, &index_key_raw); |
95 { | 95 { |
96 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 96 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
97 transaction1.Begin(); | 97 transaction1.Begin(); |
98 IndexedDBBackingStore::RecordIdentifier record; | 98 IndexedDBBackingStore::RecordIdentifier record; |
99 bool ok = backing_store_->PutRecord(&transaction1, | 99 bool ok = backing_store_->PutRecord(&transaction1, |
100 high_database_id, | 100 high_database_id, |
101 high_object_store_id, | 101 high_object_store_id, |
102 m_key1, | 102 m_key1, |
103 m_value1, | 103 m_value1, |
(...skipping 16 matching lines...) Expand all Loading... |
120 record); | 120 record); |
121 EXPECT_TRUE(ok); | 121 EXPECT_TRUE(ok); |
122 | 122 |
123 ok = transaction1.Commit(); | 123 ok = transaction1.Commit(); |
124 EXPECT_TRUE(ok); | 124 EXPECT_TRUE(ok); |
125 } | 125 } |
126 | 126 |
127 { | 127 { |
128 IndexedDBBackingStore::Transaction transaction2(backing_store_); | 128 IndexedDBBackingStore::Transaction transaction2(backing_store_); |
129 transaction2.Begin(); | 129 transaction2.Begin(); |
130 std::vector<char> result_value; | 130 std::string result_value; |
131 bool ok = backing_store_->GetRecord(&transaction2, | 131 bool ok = backing_store_->GetRecord(&transaction2, |
132 high_database_id, | 132 high_database_id, |
133 high_object_store_id, | 133 high_object_store_id, |
134 m_key1, | 134 m_key1, |
135 &result_value); | 135 &result_value); |
136 EXPECT_TRUE(ok); | 136 EXPECT_TRUE(ok); |
137 EXPECT_EQ(m_value1, result_value); | 137 EXPECT_EQ(m_value1, result_value); |
138 | 138 |
139 scoped_ptr<IndexedDBKey> new_primary_key; | 139 scoped_ptr<IndexedDBKey> new_primary_key; |
140 ok = backing_store_->GetPrimaryKeyViaIndex(&transaction2, | 140 ok = backing_store_->GetPrimaryKeyViaIndex(&transaction2, |
(...skipping 19 matching lines...) Expand all Loading... |
160 } | 160 } |
161 | 161 |
162 // Make sure that other invalid ids do not crash. | 162 // Make sure that other invalid ids do not crash. |
163 TEST_F(IndexedDBBackingStoreTest, InvalidIds) { | 163 TEST_F(IndexedDBBackingStoreTest, InvalidIds) { |
164 // valid ids for use when testing invalid ids | 164 // valid ids for use when testing invalid ids |
165 const int64 database_id = 1; | 165 const int64 database_id = 1; |
166 const int64 object_store_id = 1; | 166 const int64 object_store_id = 1; |
167 const int64 index_id = kMinimumIndexId; | 167 const int64 index_id = kMinimumIndexId; |
168 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId | 168 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId |
169 | 169 |
170 std::vector<char> result_value; | 170 std::string result_value; |
171 | 171 |
172 IndexedDBBackingStore::Transaction transaction1(backing_store_); | 172 IndexedDBBackingStore::Transaction transaction1(backing_store_); |
173 transaction1.Begin(); | 173 transaction1.Begin(); |
174 | 174 |
175 IndexedDBBackingStore::RecordIdentifier record; | 175 IndexedDBBackingStore::RecordIdentifier record; |
176 bool ok = backing_store_->PutRecord(&transaction1, | 176 bool ok = backing_store_->PutRecord(&transaction1, |
177 database_id, | 177 database_id, |
178 KeyPrefix::kInvalidId, | 178 KeyPrefix::kInvalidId, |
179 m_key1, | 179 m_key1, |
180 m_value1, | 180 m_value1, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 421 |
422 GURL ok_origin("http://someorigin.com:82/"); | 422 GURL ok_origin("http://someorigin.com:82/"); |
423 scoped_refptr<IndexedDBBackingStore> diskStore2 = | 423 scoped_refptr<IndexedDBBackingStore> diskStore2 = |
424 factory->TestOpenBackingStore(ok_origin, base_path); | 424 factory->TestOpenBackingStore(ok_origin, base_path); |
425 EXPECT_TRUE(diskStore2); | 425 EXPECT_TRUE(diskStore2); |
426 } | 426 } |
427 | 427 |
428 } // namespace | 428 } // namespace |
429 | 429 |
430 } // namespace content | 430 } // namespace content |
OLD | NEW |