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

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

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Address last nits and fix leaks in unit tests. Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 12 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/test_simple_task_runner.h" 14 #include "base/test/test_simple_task_runner.h"
16 #include "content/browser/indexed_db/indexed_db_connection.h" 15 #include "content/browser/indexed_db/indexed_db_connection.h"
17 #include "content/browser/indexed_db/indexed_db_context_impl.h" 16 #include "content/browser/indexed_db/indexed_db_context_impl.h"
18 #include "content/browser/indexed_db/indexed_db_factory_impl.h" 17 #include "content/browser/indexed_db/indexed_db_factory_impl.h"
19 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" 18 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h"
20 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" 19 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h"
21 #include "content/browser/quota/mock_quota_manager_proxy.h" 20 #include "content/browser/quota/mock_quota_manager_proxy.h"
21 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h" 23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" 24 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 #include "url/origin.h" 26 #include "url/origin.h"
27 27
28 using base::ASCIIToUTF16; 28 using base::ASCIIToUTF16;
29 using url::Origin; 29 using url::Origin;
30 30
31 namespace content { 31 namespace content {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 context_ = new IndexedDBContextImpl( 74 context_ = new IndexedDBContextImpl(
75 base::FilePath(), nullptr /* special_storage_policy */, 75 base::FilePath(), nullptr /* special_storage_policy */,
76 quota_manager_proxy_.get(), task_runner_.get()); 76 quota_manager_proxy_.get(), task_runner_.get());
77 idb_factory_ = new MockIDBFactory(context_.get()); 77 idb_factory_ = new MockIDBFactory(context_.get());
78 } 78 }
79 ~IndexedDBFactoryTest() override { 79 ~IndexedDBFactoryTest() override {
80 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 80 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
81 } 81 }
82 82
83 protected: 83 protected:
84 // For timers to post events.
85 base::MessageLoop loop_;
86
87 MockIDBFactory* factory() const { return idb_factory_.get(); } 84 MockIDBFactory* factory() const { return idb_factory_.get(); }
88 void clear_factory() { idb_factory_ = nullptr; } 85 void clear_factory() { idb_factory_ = nullptr; }
89 IndexedDBContextImpl* context() const { return context_.get(); } 86 IndexedDBContextImpl* context() const { return context_.get(); }
90 87
91 private: 88 private:
92 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 89 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
93 scoped_refptr<IndexedDBContextImpl> context_; 90 scoped_refptr<IndexedDBContextImpl> context_;
94 scoped_refptr<MockIDBFactory> idb_factory_; 91 scoped_refptr<MockIDBFactory> idb_factory_;
95 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; 92 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_;
93 TestBrowserThreadBundle thread_bundle_;
94
96 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryTest); 95 DISALLOW_COPY_AND_ASSIGN(IndexedDBFactoryTest);
97 }; 96 };
98 97
99 TEST_F(IndexedDBFactoryTest, BackingStoreLifetime) { 98 TEST_F(IndexedDBFactoryTest, BackingStoreLifetime) {
100 const Origin origin1(GURL("http://localhost:81")); 99 const Origin origin1(GURL("http://localhost:81"));
101 const Origin origin2(GURL("http://localhost:82")); 100 const Origin origin2(GURL("http://localhost:82"));
102 101
103 base::ScopedTempDir temp_directory; 102 base::ScopedTempDir temp_directory;
104 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 103 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
105 scoped_refptr<IndexedDBBackingStore> disk_store1 = 104 scoped_refptr<IndexedDBBackingStore> disk_store1 =
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 243
245 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) { 244 TEST_F(IndexedDBFactoryTest, QuotaErrorOnDiskFull) {
246 const Origin origin(GURL("http://localhost:81")); 245 const Origin origin(GURL("http://localhost:81"));
247 base::ScopedTempDir temp_directory; 246 base::ScopedTempDir temp_directory;
248 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 247 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
249 248
250 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory(context()); 249 scoped_refptr<DiskFullFactory> factory = new DiskFullFactory(context());
251 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks = 250 scoped_refptr<LookingForQuotaErrorMockCallbacks> callbacks =
252 new LookingForQuotaErrorMockCallbacks; 251 new LookingForQuotaErrorMockCallbacks;
253 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks = 252 scoped_refptr<IndexedDBDatabaseCallbacks> dummy_database_callbacks =
254 new IndexedDBDatabaseCallbacks(nullptr, 0, 0); 253 new IndexedDBDatabaseCallbacks(nullptr, 0, nullptr);
255 const base::string16 name(ASCIIToUTF16("name")); 254 const base::string16 name(ASCIIToUTF16("name"));
256 std::unique_ptr<IndexedDBPendingConnection> connection( 255 std::unique_ptr<IndexedDBPendingConnection> connection(
257 base::MakeUnique<IndexedDBPendingConnection>( 256 base::MakeUnique<IndexedDBPendingConnection>(
258 callbacks, dummy_database_callbacks, 0 /* child_process_id */, 257 callbacks, dummy_database_callbacks, 0 /* child_process_id */,
259 2 /* transaction_id */, 1 /* version */)); 258 2 /* transaction_id */, 1 /* version */));
260 factory->Open(name, std::move(connection), nullptr /* request_context */, 259 factory->Open(name, std::move(connection), nullptr /* request_context */,
261 origin, temp_directory.GetPath()); 260 origin, temp_directory.GetPath());
262 EXPECT_TRUE(callbacks->error_called()); 261 EXPECT_TRUE(callbacks->error_called());
263 } 262 }
264 263
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 temp_directory.GetPath()); 501 temp_directory.GetPath());
503 EXPECT_TRUE(callbacks->saw_error()); 502 EXPECT_TRUE(callbacks->saw_error());
504 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name)); 503 EXPECT_FALSE(factory()->IsDatabaseOpen(origin, db_name));
505 } 504 }
506 505
507 // Terminate all pending-close timers. 506 // Terminate all pending-close timers.
508 factory()->ForceClose(origin); 507 factory()->ForceClose(origin);
509 } 508 }
510 509
511 } // namespace content 510 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_dispatcher_host.cc ('k') | content/browser/indexed_db/indexed_db_index_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698