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

Side by Side Diff: content/browser/indexed_db/indexed_db_backing_store_unittest.cc

Issue 18075008: IndexedDB: Switch key/value handling from vector<char> to std::string (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove C++11ism Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
22 namespace { 22 namespace {
23 23
24 class IndexedDBBackingStoreTest : public testing::Test { 24 class IndexedDBBackingStoreTest : public testing::Test {
25 public: 25 public:
26 IndexedDBBackingStoreTest() {} 26 IndexedDBBackingStoreTest() {}
27 virtual void SetUp() { 27 virtual void SetUp() {
28 std::string file_identifier; 28 std::string file_identifier;
29 backing_store_ = IndexedDBBackingStore::OpenInMemory(file_identifier); 29 backing_store_ = IndexedDBBackingStore::OpenInMemory(file_identifier);
30 30
31 // useful keys and values during tests 31 // useful keys and values during tests
32 const char raw_value1[] = "value1"; 32 m_value1 = "value1";
33 33 m_value2 = "value2";
34 const char raw_value2[] = "value2"; 34 m_value3 = "value3";
35 const char raw_value3[] = "value3";
36 m_value1.insert(
37 m_value1.end(), &raw_value1[0], &raw_value1[0] + sizeof(raw_value1));
38 m_value2.insert(
39 m_value2.end(), &raw_value2[0], &raw_value2[0] + sizeof(raw_value2));
40 m_value3.insert(
41 m_value3.end(), &raw_value3[0], &raw_value3[0] + sizeof(raw_value3));
42 m_key1 = IndexedDBKey(99, WebIDBKey::NumberType); 35 m_key1 = IndexedDBKey(99, WebIDBKey::NumberType);
43 m_key2 = IndexedDBKey(ASCIIToUTF16("key2")); 36 m_key2 = IndexedDBKey(ASCIIToUTF16("key2"));
44 m_key3 = IndexedDBKey(ASCIIToUTF16("key3")); 37 m_key3 = IndexedDBKey(ASCIIToUTF16("key3"));
45 } 38 }
46 39
47 protected: 40 protected:
48 scoped_refptr<IndexedDBBackingStore> backing_store_; 41 scoped_refptr<IndexedDBBackingStore> backing_store_;
49 42
50 // Sample keys and values that are consistent. 43 // Sample keys and values that are consistent.
51 IndexedDBKey m_key1; 44 IndexedDBKey m_key1;
52 IndexedDBKey m_key2; 45 IndexedDBKey m_key2;
53 IndexedDBKey m_key3; 46 IndexedDBKey m_key3;
54 std::vector<char> m_value1; 47 std::string m_value1;
55 std::vector<char> m_value2; 48 std::string m_value2;
56 std::vector<char> m_value3; 49 std::string m_value3;
57 }; 50 };
58 51
59 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { 52 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) {
60 { 53 {
61 IndexedDBBackingStore::Transaction transaction1(backing_store_); 54 IndexedDBBackingStore::Transaction transaction1(backing_store_);
62 transaction1.Begin(); 55 transaction1.Begin();
63 IndexedDBBackingStore::RecordIdentifier record; 56 IndexedDBBackingStore::RecordIdentifier record;
64 bool ok = backing_store_->PutRecord( 57 bool ok = backing_store_->PutRecord(
65 &transaction1, 1, 1, m_key1, m_value1, &record); 58 &transaction1, 1, 1, m_key1, m_value1, &record);
66 EXPECT_TRUE(ok); 59 EXPECT_TRUE(ok);
67 transaction1.Commit(); 60 transaction1.Commit();
68 } 61 }
69 62
70 { 63 {
71 IndexedDBBackingStore::Transaction transaction2(backing_store_); 64 IndexedDBBackingStore::Transaction transaction2(backing_store_);
72 transaction2.Begin(); 65 transaction2.Begin();
73 std::vector<char> result_value; 66 std::string result_value;
74 bool ok = 67 bool ok =
75 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value); 68 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value);
76 transaction2.Commit(); 69 transaction2.Commit();
77 EXPECT_TRUE(ok); 70 EXPECT_TRUE(ok);
78 EXPECT_EQ(m_value1, result_value); 71 EXPECT_EQ(m_value1, result_value);
79 } 72 }
80 } 73 }
81 74
82 // Make sure that using very high ( more than 32 bit ) values for database_id 75 // Make sure that using very high ( more than 32 bit ) values for database_id
83 // and object_store_id still work. 76 // and object_store_id still work.
84 TEST_F(IndexedDBBackingStoreTest, HighIds) { 77 TEST_F(IndexedDBBackingStoreTest, HighIds) {
85 const int64 high_database_id = 1ULL << 35; 78 const int64 high_database_id = 1ULL << 35;
86 const int64 high_object_store_id = 1ULL << 39; 79 const int64 high_object_store_id = 1ULL << 39;
87 // index_ids are capped at 32 bits for storage purposes. 80 // index_ids are capped at 32 bits for storage purposes.
88 const int64 high_index_id = 1ULL << 29; 81 const int64 high_index_id = 1ULL << 29;
89 82
90 const int64 invalid_high_index_id = 1ULL << 37; 83 const int64 invalid_high_index_id = 1ULL << 37;
91 84
92 const IndexedDBKey& index_key = m_key2; 85 const IndexedDBKey& index_key = m_key2;
93 std::vector<char> index_key_raw; 86 std::string index_key_raw;
94 EncodeIDBKey(index_key, &index_key_raw); 87 EncodeIDBKey(index_key, &index_key_raw);
95 { 88 {
96 IndexedDBBackingStore::Transaction transaction1(backing_store_); 89 IndexedDBBackingStore::Transaction transaction1(backing_store_);
97 transaction1.Begin(); 90 transaction1.Begin();
98 IndexedDBBackingStore::RecordIdentifier record; 91 IndexedDBBackingStore::RecordIdentifier record;
99 bool ok = backing_store_->PutRecord(&transaction1, 92 bool ok = backing_store_->PutRecord(&transaction1,
100 high_database_id, 93 high_database_id,
101 high_object_store_id, 94 high_object_store_id,
102 m_key1, 95 m_key1,
103 m_value1, 96 m_value1,
(...skipping 16 matching lines...) Expand all
120 record); 113 record);
121 EXPECT_TRUE(ok); 114 EXPECT_TRUE(ok);
122 115
123 ok = transaction1.Commit(); 116 ok = transaction1.Commit();
124 EXPECT_TRUE(ok); 117 EXPECT_TRUE(ok);
125 } 118 }
126 119
127 { 120 {
128 IndexedDBBackingStore::Transaction transaction2(backing_store_); 121 IndexedDBBackingStore::Transaction transaction2(backing_store_);
129 transaction2.Begin(); 122 transaction2.Begin();
130 std::vector<char> result_value; 123 std::string result_value;
131 bool ok = backing_store_->GetRecord(&transaction2, 124 bool ok = backing_store_->GetRecord(&transaction2,
132 high_database_id, 125 high_database_id,
133 high_object_store_id, 126 high_object_store_id,
134 m_key1, 127 m_key1,
135 &result_value); 128 &result_value);
136 EXPECT_TRUE(ok); 129 EXPECT_TRUE(ok);
137 EXPECT_EQ(m_value1, result_value); 130 EXPECT_EQ(m_value1, result_value);
138 131
139 scoped_ptr<IndexedDBKey> new_primary_key; 132 scoped_ptr<IndexedDBKey> new_primary_key;
140 ok = backing_store_->GetPrimaryKeyViaIndex(&transaction2, 133 ok = backing_store_->GetPrimaryKeyViaIndex(&transaction2,
(...skipping 19 matching lines...) Expand all
160 } 153 }
161 154
162 // Make sure that other invalid ids do not crash. 155 // Make sure that other invalid ids do not crash.
163 TEST_F(IndexedDBBackingStoreTest, InvalidIds) { 156 TEST_F(IndexedDBBackingStoreTest, InvalidIds) {
164 // valid ids for use when testing invalid ids 157 // valid ids for use when testing invalid ids
165 const int64 database_id = 1; 158 const int64 database_id = 1;
166 const int64 object_store_id = 1; 159 const int64 object_store_id = 1;
167 const int64 index_id = kMinimumIndexId; 160 const int64 index_id = kMinimumIndexId;
168 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId 161 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId
169 162
170 std::vector<char> result_value; 163 std::string result_value;
171 164
172 IndexedDBBackingStore::Transaction transaction1(backing_store_); 165 IndexedDBBackingStore::Transaction transaction1(backing_store_);
173 transaction1.Begin(); 166 transaction1.Begin();
174 167
175 IndexedDBBackingStore::RecordIdentifier record; 168 IndexedDBBackingStore::RecordIdentifier record;
176 bool ok = backing_store_->PutRecord(&transaction1, 169 bool ok = backing_store_->PutRecord(&transaction1,
177 database_id, 170 database_id,
178 KeyPrefix::kInvalidId, 171 KeyPrefix::kInvalidId,
179 m_key1, 172 m_key1,
180 m_value1, 173 m_value1,
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 414
422 GURL ok_origin("http://someorigin.com:82/"); 415 GURL ok_origin("http://someorigin.com:82/");
423 scoped_refptr<IndexedDBBackingStore> diskStore2 = 416 scoped_refptr<IndexedDBBackingStore> diskStore2 =
424 factory->TestOpenBackingStore(ok_origin, base_path); 417 factory->TestOpenBackingStore(ok_origin, base_path);
425 EXPECT_TRUE(diskStore2); 418 EXPECT_TRUE(diskStore2);
426 } 419 }
427 420
428 } // namespace 421 } // namespace
429 422
430 } // namespace content 423 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_backing_store.cc ('k') | content/browser/indexed_db/indexed_db_callbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698