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

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

Issue 197753011: Add IndexedDBValue wrapper class to group blob info with bits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Yet still happier clang, I hope. Created 6 years, 9 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/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 } 34 }
35 35
36 protected: 36 protected:
37 scoped_refptr<IndexedDBBackingStore> backing_store_; 37 scoped_refptr<IndexedDBBackingStore> backing_store_;
38 38
39 // Sample keys and values that are consistent. 39 // Sample keys and values that are consistent.
40 IndexedDBKey m_key1; 40 IndexedDBKey m_key1;
41 IndexedDBKey m_key2; 41 IndexedDBKey m_key2;
42 IndexedDBKey m_key3; 42 IndexedDBValue m_value1;
43 std::string m_value1; 43 IndexedDBValue m_value2;
44 std::string m_value2;
45 std::string m_value3;
46 44
47 private: 45 private:
48 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStoreTest); 46 DISALLOW_COPY_AND_ASSIGN(IndexedDBBackingStoreTest);
49 }; 47 };
50 48
51 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { 49 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) {
52 { 50 {
53 IndexedDBBackingStore::Transaction transaction1(backing_store_); 51 IndexedDBBackingStore::Transaction transaction1(backing_store_);
54 transaction1.Begin(); 52 transaction1.Begin();
55 IndexedDBBackingStore::RecordIdentifier record; 53 IndexedDBBackingStore::RecordIdentifier record;
56 leveldb::Status s = backing_store_->PutRecord( 54 leveldb::Status s = backing_store_->PutRecord(
57 &transaction1, 1, 1, m_key1, m_value1, &record); 55 &transaction1, 1, 1, m_key1, m_value1, &record);
58 EXPECT_TRUE(s.ok()); 56 EXPECT_TRUE(s.ok());
59 transaction1.Commit(); 57 transaction1.Commit();
60 } 58 }
61 59
62 { 60 {
63 IndexedDBBackingStore::Transaction transaction2(backing_store_); 61 IndexedDBBackingStore::Transaction transaction2(backing_store_);
64 transaction2.Begin(); 62 transaction2.Begin();
65 std::string result_value; 63 IndexedDBValue result_value;
66 leveldb::Status s = 64 leveldb::Status s =
67 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value); 65 backing_store_->GetRecord(&transaction2, 1, 1, m_key1, &result_value);
68 transaction2.Commit(); 66 transaction2.Commit();
69 EXPECT_TRUE(s.ok()); 67 EXPECT_TRUE(s.ok());
70 EXPECT_EQ(m_value1, result_value); 68 EXPECT_EQ(m_value1.bits, result_value.bits);
71 } 69 }
72 } 70 }
73 71
74 // Make sure that using very high ( more than 32 bit ) values for database_id 72 // Make sure that using very high ( more than 32 bit ) values for database_id
75 // and object_store_id still work. 73 // and object_store_id still work.
76 TEST_F(IndexedDBBackingStoreTest, HighIds) { 74 TEST_F(IndexedDBBackingStoreTest, HighIds) {
77 const int64 high_database_id = 1ULL << 35; 75 const int64 high_database_id = 1ULL << 35;
78 const int64 high_object_store_id = 1ULL << 39; 76 const int64 high_object_store_id = 1ULL << 39;
79 // index_ids are capped at 32 bits for storage purposes. 77 // index_ids are capped at 32 bits for storage purposes.
80 const int64 high_index_id = 1ULL << 29; 78 const int64 high_index_id = 1ULL << 29;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 record); 110 record);
113 EXPECT_TRUE(s.ok()); 111 EXPECT_TRUE(s.ok());
114 112
115 s = transaction1.Commit(); 113 s = transaction1.Commit();
116 EXPECT_TRUE(s.ok()); 114 EXPECT_TRUE(s.ok());
117 } 115 }
118 116
119 { 117 {
120 IndexedDBBackingStore::Transaction transaction2(backing_store_); 118 IndexedDBBackingStore::Transaction transaction2(backing_store_);
121 transaction2.Begin(); 119 transaction2.Begin();
122 std::string result_value; 120 IndexedDBValue result_value;
123 leveldb::Status s = backing_store_->GetRecord(&transaction2, 121 leveldb::Status s = backing_store_->GetRecord(&transaction2,
124 high_database_id, 122 high_database_id,
125 high_object_store_id, 123 high_object_store_id,
126 m_key1, 124 m_key1,
127 &result_value); 125 &result_value);
128 EXPECT_TRUE(s.ok()); 126 EXPECT_TRUE(s.ok());
129 EXPECT_EQ(m_value1, result_value); 127 EXPECT_EQ(m_value1.bits, result_value.bits);
130 128
131 scoped_ptr<IndexedDBKey> new_primary_key; 129 scoped_ptr<IndexedDBKey> new_primary_key;
132 s = backing_store_->GetPrimaryKeyViaIndex(&transaction2, 130 s = backing_store_->GetPrimaryKeyViaIndex(&transaction2,
133 high_database_id, 131 high_database_id,
134 high_object_store_id, 132 high_object_store_id,
135 invalid_high_index_id, 133 invalid_high_index_id,
136 index_key, 134 index_key,
137 &new_primary_key); 135 &new_primary_key);
138 EXPECT_FALSE(s.ok()); 136 EXPECT_FALSE(s.ok());
139 137
(...skipping 12 matching lines...) Expand all
152 } 150 }
153 151
154 // Make sure that other invalid ids do not crash. 152 // Make sure that other invalid ids do not crash.
155 TEST_F(IndexedDBBackingStoreTest, InvalidIds) { 153 TEST_F(IndexedDBBackingStoreTest, InvalidIds) {
156 // valid ids for use when testing invalid ids 154 // valid ids for use when testing invalid ids
157 const int64 database_id = 1; 155 const int64 database_id = 1;
158 const int64 object_store_id = 1; 156 const int64 object_store_id = 1;
159 const int64 index_id = kMinimumIndexId; 157 const int64 index_id = kMinimumIndexId;
160 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId 158 const int64 invalid_low_index_id = 19; // index_ids must be > kMinimumIndexId
161 159
162 std::string result_value; 160 IndexedDBValue result_value;
163 161
164 IndexedDBBackingStore::Transaction transaction1(backing_store_); 162 IndexedDBBackingStore::Transaction transaction1(backing_store_);
165 transaction1.Begin(); 163 transaction1.Begin();
166 164
167 IndexedDBBackingStore::RecordIdentifier record; 165 IndexedDBBackingStore::RecordIdentifier record;
168 leveldb::Status s = backing_store_->PutRecord(&transaction1, 166 leveldb::Status s = backing_store_->PutRecord(&transaction1,
169 database_id, 167 database_id,
170 KeyPrefix::kInvalidId, 168 KeyPrefix::kInvalidId,
171 m_key1, 169 m_key1,
172 m_value1, 170 m_value1,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 EXPECT_EQ(index_name, index.name); 312 EXPECT_EQ(index_name, index.name);
315 EXPECT_EQ(index_key_path, index.key_path); 313 EXPECT_EQ(index_key_path, index.key_path);
316 EXPECT_EQ(unique, index.unique); 314 EXPECT_EQ(unique, index.unique);
317 EXPECT_EQ(multi_entry, index.multi_entry); 315 EXPECT_EQ(multi_entry, index.multi_entry);
318 } 316 }
319 } 317 }
320 318
321 } // namespace 319 } // namespace
322 320
323 } // namespace content 321 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_backing_store.cc ('k') | content/browser/indexed_db/indexed_db_blob_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698