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

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

Issue 1841553002: IndexedDB: Use url::Origin rather than GURL for representing origins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@origin-idb
Patch Set: Created 4 years, 8 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 private: 62 private:
63 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory); 63 DISALLOW_COPY_AND_ASSIGN(DefaultLevelDBFactory);
64 }; 64 };
65 65
66 class TestableIndexedDBBackingStore : public IndexedDBBackingStore { 66 class TestableIndexedDBBackingStore : public IndexedDBBackingStore {
67 public: 67 public:
68 static scoped_refptr<TestableIndexedDBBackingStore> Open( 68 static scoped_refptr<TestableIndexedDBBackingStore> Open(
69 IndexedDBFactory* indexed_db_factory, 69 IndexedDBFactory* indexed_db_factory,
70 const GURL& origin_url, 70 const url::Origin& origin,
71 const base::FilePath& path_base, 71 const base::FilePath& path_base,
72 net::URLRequestContext* request_context, 72 net::URLRequestContext* request_context,
73 LevelDBFactory* leveldb_factory, 73 LevelDBFactory* leveldb_factory,
74 base::SequencedTaskRunner* task_runner, 74 base::SequencedTaskRunner* task_runner,
75 leveldb::Status* status) { 75 leveldb::Status* status) {
76 DCHECK(!path_base.empty()); 76 DCHECK(!path_base.empty());
77 77
78 scoped_ptr<LevelDBComparator> comparator(new Comparator()); 78 scoped_ptr<LevelDBComparator> comparator(new Comparator());
79 79
80 if (!base::CreateDirectory(path_base)) { 80 if (!base::CreateDirectory(path_base)) {
81 *status = leveldb::Status::IOError("Unable to create base dir"); 81 *status = leveldb::Status::IOError("Unable to create base dir");
82 return scoped_refptr<TestableIndexedDBBackingStore>(); 82 return scoped_refptr<TestableIndexedDBBackingStore>();
83 } 83 }
84 84
85 const base::FilePath file_path = path_base.AppendASCII("test_db_path"); 85 const base::FilePath file_path = path_base.AppendASCII("test_db_path");
86 const base::FilePath blob_path = path_base.AppendASCII("test_blob_path"); 86 const base::FilePath blob_path = path_base.AppendASCII("test_blob_path");
87 87
88 scoped_ptr<LevelDBDatabase> db; 88 scoped_ptr<LevelDBDatabase> db;
89 bool is_disk_full = false; 89 bool is_disk_full = false;
90 *status = leveldb_factory->OpenLevelDB( 90 *status = leveldb_factory->OpenLevelDB(
91 file_path, comparator.get(), &db, &is_disk_full); 91 file_path, comparator.get(), &db, &is_disk_full);
92 92
93 if (!db || !status->ok()) 93 if (!db || !status->ok())
94 return scoped_refptr<TestableIndexedDBBackingStore>(); 94 return scoped_refptr<TestableIndexedDBBackingStore>();
95 95
96 scoped_refptr<TestableIndexedDBBackingStore> backing_store( 96 scoped_refptr<TestableIndexedDBBackingStore> backing_store(
97 new TestableIndexedDBBackingStore( 97 new TestableIndexedDBBackingStore(indexed_db_factory, origin, blob_path,
98 indexed_db_factory, origin_url, blob_path, request_context, 98 request_context, std::move(db),
99 std::move(db), std::move(comparator), task_runner)); 99 std::move(comparator), task_runner));
100 100
101 *status = backing_store->SetUpMetadata(); 101 *status = backing_store->SetUpMetadata();
102 if (!status->ok()) 102 if (!status->ok())
103 return scoped_refptr<TestableIndexedDBBackingStore>(); 103 return scoped_refptr<TestableIndexedDBBackingStore>();
104 104
105 return backing_store; 105 return backing_store;
106 } 106 }
107 107
108 const std::vector<IndexedDBBackingStore::Transaction::WriteDescriptor>& 108 const std::vector<IndexedDBBackingStore::Transaction::WriteDescriptor>&
109 writes() const { 109 writes() const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 return true; 146 return true;
147 } 147 }
148 148
149 // Timers don't play nicely with unit tests. 149 // Timers don't play nicely with unit tests.
150 void StartJournalCleaningTimer() override { 150 void StartJournalCleaningTimer() override {
151 CleanPrimaryJournalIgnoreReturn(); 151 CleanPrimaryJournalIgnoreReturn();
152 } 152 }
153 153
154 private: 154 private:
155 TestableIndexedDBBackingStore(IndexedDBFactory* indexed_db_factory, 155 TestableIndexedDBBackingStore(IndexedDBFactory* indexed_db_factory,
156 const GURL& origin_url, 156 const url::Origin& origin,
157 const base::FilePath& blob_path, 157 const base::FilePath& blob_path,
158 net::URLRequestContext* request_context, 158 net::URLRequestContext* request_context,
159 scoped_ptr<LevelDBDatabase> db, 159 scoped_ptr<LevelDBDatabase> db,
160 scoped_ptr<LevelDBComparator> comparator, 160 scoped_ptr<LevelDBComparator> comparator,
161 base::SequencedTaskRunner* task_runner) 161 base::SequencedTaskRunner* task_runner)
162 : IndexedDBBackingStore(indexed_db_factory, 162 : IndexedDBBackingStore(indexed_db_factory,
163 origin_url, 163 origin,
164 blob_path, 164 blob_path,
165 request_context, 165 request_context,
166 std::move(db), 166 std::move(db),
167 std::move(comparator), 167 std::move(comparator),
168 task_runner), 168 task_runner),
169 database_id_(0) {} 169 database_id_(0) {}
170 170
171 int64_t database_id_; 171 int64_t database_id_;
172 std::vector<Transaction::WriteDescriptor> writes_; 172 std::vector<Transaction::WriteDescriptor> writes_;
173 173
174 // This is modified in an overridden virtual function that is properly const 174 // This is modified in an overridden virtual function that is properly const
175 // in the real implementation, therefore must be mutable here. 175 // in the real implementation, therefore must be mutable here.
176 mutable std::vector<int64_t> removals_; 176 mutable std::vector<int64_t> removals_;
177 177
178 DISALLOW_COPY_AND_ASSIGN(TestableIndexedDBBackingStore); 178 DISALLOW_COPY_AND_ASSIGN(TestableIndexedDBBackingStore);
179 }; 179 };
180 180
181 class TestIDBFactory : public IndexedDBFactoryImpl { 181 class TestIDBFactory : public IndexedDBFactoryImpl {
182 public: 182 public:
183 explicit TestIDBFactory(IndexedDBContextImpl* idb_context) 183 explicit TestIDBFactory(IndexedDBContextImpl* idb_context)
184 : IndexedDBFactoryImpl(idb_context) {} 184 : IndexedDBFactoryImpl(idb_context) {}
185 185
186 scoped_refptr<TestableIndexedDBBackingStore> OpenBackingStoreForTest( 186 scoped_refptr<TestableIndexedDBBackingStore> OpenBackingStoreForTest(
187 const GURL& origin, 187 const url::Origin& origin,
188 net::URLRequestContext* url_request_context) { 188 net::URLRequestContext* url_request_context) {
189 blink::WebIDBDataLoss data_loss; 189 blink::WebIDBDataLoss data_loss;
190 std::string data_loss_reason; 190 std::string data_loss_reason;
191 bool disk_full; 191 bool disk_full;
192 leveldb::Status status; 192 leveldb::Status status;
193 scoped_refptr<IndexedDBBackingStore> backing_store = 193 scoped_refptr<IndexedDBBackingStore> backing_store =
194 OpenBackingStore(origin, 194 OpenBackingStore(origin,
195 context()->data_path(), 195 context()->data_path(),
196 url_request_context, 196 url_request_context,
197 &data_loss, 197 &data_loss,
198 &data_loss_reason, 198 &data_loss_reason,
199 &disk_full, 199 &disk_full,
200 &status); 200 &status);
201 scoped_refptr<TestableIndexedDBBackingStore> testable_store = 201 scoped_refptr<TestableIndexedDBBackingStore> testable_store =
202 static_cast<TestableIndexedDBBackingStore*>(backing_store.get()); 202 static_cast<TestableIndexedDBBackingStore*>(backing_store.get());
203 return testable_store; 203 return testable_store;
204 } 204 }
205 205
206 protected: 206 protected:
207 ~TestIDBFactory() override {} 207 ~TestIDBFactory() override {}
208 208
209 scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper( 209 scoped_refptr<IndexedDBBackingStore> OpenBackingStoreHelper(
210 const GURL& origin_url, 210 const url::Origin& origin,
211 const base::FilePath& data_directory, 211 const base::FilePath& data_directory,
212 net::URLRequestContext* request_context, 212 net::URLRequestContext* request_context,
213 blink::WebIDBDataLoss* data_loss, 213 blink::WebIDBDataLoss* data_loss,
214 std::string* data_loss_message, 214 std::string* data_loss_message,
215 bool* disk_full, 215 bool* disk_full,
216 bool first_time, 216 bool first_time,
217 leveldb::Status* status) override { 217 leveldb::Status* status) override {
218 DefaultLevelDBFactory leveldb_factory; 218 DefaultLevelDBFactory leveldb_factory;
219 return TestableIndexedDBBackingStore::Open(this, 219 return TestableIndexedDBBackingStore::Open(
220 origin_url, 220 this, origin, data_directory, request_context, &leveldb_factory,
221 data_directory, 221 context()->TaskRunner(), status);
222 request_context,
223 &leveldb_factory,
224 context()->TaskRunner(),
225 status);
226 } 222 }
227 223
228 private: 224 private:
229 DISALLOW_COPY_AND_ASSIGN(TestIDBFactory); 225 DISALLOW_COPY_AND_ASSIGN(TestIDBFactory);
230 }; 226 };
231 227
232 class IndexedDBBackingStoreTest : public testing::Test { 228 class IndexedDBBackingStoreTest : public testing::Test {
233 public: 229 public:
234 IndexedDBBackingStoreTest() {} 230 IndexedDBBackingStoreTest() {}
235 void SetUp() override { 231 void SetUp() override {
236 const GURL origin("http://localhost:81"); 232 const url::Origin origin(GURL("http://localhost:81"));
237 task_runner_ = new base::TestSimpleTaskRunner(); 233 task_runner_ = new base::TestSimpleTaskRunner();
238 special_storage_policy_ = new MockSpecialStoragePolicy(); 234 special_storage_policy_ = new MockSpecialStoragePolicy();
239 quota_manager_proxy_ = new MockQuotaManagerProxy(nullptr, nullptr); 235 quota_manager_proxy_ = new MockQuotaManagerProxy(nullptr, nullptr);
240 special_storage_policy_->SetAllUnlimited(true); 236 special_storage_policy_->SetAllUnlimited(true);
241 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 237 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
242 idb_context_ = new IndexedDBContextImpl( 238 idb_context_ = new IndexedDBContextImpl(
243 temp_dir_.path(), special_storage_policy_.get(), 239 temp_dir_.path(), special_storage_policy_.get(),
244 quota_manager_proxy_.get(), task_runner_.get()); 240 quota_manager_proxy_.get(), task_runner_.get());
245 idb_factory_ = new TestIDBFactory(idb_context_.get()); 241 idb_factory_ = new TestIDBFactory(idb_context_.get());
246 backing_store_ = 242 backing_store_ =
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 1040
1045 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s); 1041 std::vector<base::string16> names = backing_store_->GetDatabaseNames(&s);
1046 EXPECT_TRUE(s.ok()); 1042 EXPECT_TRUE(s.ok());
1047 EXPECT_EQ(names.size(), 1ULL); 1043 EXPECT_EQ(names.size(), 1ULL);
1048 EXPECT_EQ(names[0], db1_name); 1044 EXPECT_EQ(names[0], db1_name);
1049 } 1045 }
1050 1046
1051 } // namespace 1047 } // namespace
1052 1048
1053 } // namespace content 1049 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698