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

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

Issue 18147009: IndexedDB: Remove unnecessary scoped_refptr<T>::get() calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang-format 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::vector<char> m_value1;
55 std::vector<char> m_value2; 55 std::vector<char> m_value2;
56 std::vector<char> m_value3; 56 std::vector<char> m_value3;
57 }; 57 };
58 58
59 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) { 59 TEST_F(IndexedDBBackingStoreTest, PutGetConsistency) {
60 { 60 {
61 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 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_.get()); 71 IndexedDBBackingStore::Transaction transaction2(backing_store_);
72 transaction2.Begin(); 72 transaction2.Begin();
73 std::vector<char> result_value; 73 std::vector<char> 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::vector<char> 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_.get()); 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,
104 &record); 104 &record);
105 EXPECT_TRUE(ok); 105 EXPECT_TRUE(ok);
106 106
(...skipping 11 matching lines...) Expand all
118 high_index_id, 118 high_index_id,
119 index_key, 119 index_key,
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_.get()); 128 IndexedDBBackingStore::Transaction transaction2(backing_store_);
129 transaction2.Begin(); 129 transaction2.Begin();
130 std::vector<char> result_value; 130 std::vector<char> 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
(...skipping 23 matching lines...) Expand all
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::vector<char> result_value;
171 171
172 IndexedDBBackingStore::Transaction transaction1(backing_store_.get()); 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,
181 &record); 181 &record);
182 EXPECT_FALSE(ok); 182 EXPECT_FALSE(ok);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 const bool unique = true; 262 const bool unique = true;
263 const bool multi_entry = true; 263 const bool multi_entry = true;
264 const IndexedDBKeyPath index_key_path(ASCIIToUTF16("index_key")); 264 const IndexedDBKeyPath index_key_path(ASCIIToUTF16("index_key"));
265 265
266 { 266 {
267 bool ok = backing_store_->CreateIDBDatabaseMetaData( 267 bool ok = backing_store_->CreateIDBDatabaseMetaData(
268 database_name, version, int_version, &database_id); 268 database_name, version, int_version, &database_id);
269 EXPECT_TRUE(ok); 269 EXPECT_TRUE(ok);
270 EXPECT_GT(database_id, 0); 270 EXPECT_GT(database_id, 0);
271 271
272 IndexedDBBackingStore::Transaction transaction(backing_store_.get()); 272 IndexedDBBackingStore::Transaction transaction(backing_store_);
273 transaction.Begin(); 273 transaction.Begin();
274 274
275 ok = backing_store_->CreateObjectStore(&transaction, 275 ok = backing_store_->CreateObjectStore(&transaction,
276 database_id, 276 database_id,
277 object_store_id, 277 object_store_id,
278 object_store_name, 278 object_store_name,
279 object_store_key_path, 279 object_store_key_path,
280 auto_increment); 280 auto_increment);
281 EXPECT_TRUE(ok); 281 EXPECT_TRUE(ok);
282 282
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 399
400 factory = NULL; 400 factory = NULL;
401 EXPECT_FALSE(mem_store1->HasOneRef()); // mem_store1 and 2 401 EXPECT_FALSE(mem_store1->HasOneRef()); // mem_store1 and 2
402 EXPECT_FALSE(mem_store2->HasOneRef()); // mem_store1 and 2 402 EXPECT_FALSE(mem_store2->HasOneRef()); // mem_store1 and 2
403 EXPECT_TRUE(mem_store3->HasOneRef()); 403 EXPECT_TRUE(mem_store3->HasOneRef());
404 404
405 mem_store2 = NULL; 405 mem_store2 = NULL;
406 EXPECT_TRUE(mem_store1->HasOneRef()); 406 EXPECT_TRUE(mem_store1->HasOneRef());
407 } 407 }
408 408
409 TEST(IndexedDBFactoryTest, RejectLongOrigins) 409 TEST(IndexedDBFactoryTest, RejectLongOrigins) {
410 {
411 base::ScopedTempDir temp_directory; 410 base::ScopedTempDir temp_directory;
412 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 411 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
413 const base::FilePath base_path = temp_directory.path(); 412 const base::FilePath base_path = temp_directory.path();
414 scoped_refptr<MockIDBFactory> factory = MockIDBFactory::Create(); 413 scoped_refptr<MockIDBFactory> factory = MockIDBFactory::Create();
415 414
416 int limit = file_util::GetMaximumPathComponentLength(base_path); 415 int limit = file_util::GetMaximumPathComponentLength(base_path);
417 EXPECT_GT(limit, 0); 416 EXPECT_GT(limit, 0);
418 417
419 std::string origin(limit + 1, 'x'); 418 std::string origin(limit + 1, 'x');
420 WebSecurityOrigin too_long_origin = 419 WebSecurityOrigin too_long_origin =
421 WebSecurityOrigin::createFromString(WebKit::WebString::fromUTF8( 420 WebSecurityOrigin::createFromString(WebKit::WebString::fromUTF8(
422 std::string("http://" + origin + ":81/").c_str())); 421 std::string("http://" + origin + ":81/").c_str()));
423 scoped_refptr<IndexedDBBackingStore> diskStore1 = 422 scoped_refptr<IndexedDBBackingStore> diskStore1 =
424 factory->TestOpenBackingStore(too_long_origin, base_path); 423 factory->TestOpenBackingStore(too_long_origin, base_path);
425 EXPECT_FALSE(diskStore1.get()); 424 EXPECT_FALSE(diskStore1);
426 425
427 WebSecurityOrigin ok_origin = 426 WebSecurityOrigin ok_origin =
428 WebSecurityOrigin::createFromString("http://someorigin.com:82/"); 427 WebSecurityOrigin::createFromString("http://someorigin.com:82/");
429 scoped_refptr<IndexedDBBackingStore> diskStore2 = 428 scoped_refptr<IndexedDBBackingStore> diskStore2 =
430 factory->TestOpenBackingStore(ok_origin, base_path); 429 factory->TestOpenBackingStore(ok_origin, base_path);
431 EXPECT_TRUE(diskStore2.get()); 430 EXPECT_TRUE(diskStore2);
432 } 431 }
433 432
434 } // namespace 433 } // namespace
435 434
436 } // namespace content 435 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_backing_store.h ('k') | content/browser/indexed_db/indexed_db_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698