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

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

Issue 308103004: IndexedDB: Using a mock IndexedDBFactory for unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't use GoogleMock with std::pair types Created 6 years, 4 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
« no previous file with comments | « no previous file | content/browser/indexed_db/indexed_db_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <set> 5 #include <set>
6 6
7 #include "base/test/test_simple_task_runner.h" 7 #include "base/test/test_simple_task_runner.h"
8 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h" 8 #include "content/browser/indexed_db/indexed_db_active_blob_registry.h"
9 #include "content/browser/indexed_db/indexed_db_backing_store.h" 9 #include "content/browser/indexed_db/indexed_db_backing_store.h"
10 #include "content/browser/indexed_db/indexed_db_factory_impl.h"
11 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" 10 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h"
11 #include "content/browser/indexed_db/mock_indexed_db_factory.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 class MockIDBFactory : public IndexedDBFactoryImpl { 18 class RegistryTestMockFactory : public MockIndexedDBFactory {
19 public: 19 public:
20 MockIDBFactory() : IndexedDBFactoryImpl(NULL), duplicate_calls_(false) {} 20 RegistryTestMockFactory() : duplicate_calls_(false) {}
21 21
22 virtual void ReportOutstandingBlobs(const GURL& origin_url, 22 virtual void ReportOutstandingBlobs(const GURL& origin_url,
23 bool blobs_outstanding) OVERRIDE { 23 bool blobs_outstanding) OVERRIDE {
24 if (blobs_outstanding) { 24 if (blobs_outstanding) {
25 if (origins_.count(origin_url)) { 25 if (origins_.count(origin_url)) {
26 duplicate_calls_ = true; 26 duplicate_calls_ = true;
27 } else { 27 } else {
28 origins_.insert(origin_url); 28 origins_.insert(origin_url);
29 } 29 }
30 } else { 30 } else {
31 if (!origins_.count(origin_url)) { 31 if (!origins_.count(origin_url)) {
32 duplicate_calls_ = true; 32 duplicate_calls_ = true;
33 } else { 33 } else {
34 origins_.erase(origin_url); 34 origins_.erase(origin_url);
35 } 35 }
36 } 36 }
37 } 37 }
38 38
39 bool CheckNoOriginsInUse() const { 39 bool CheckNoOriginsInUse() const {
40 return !duplicate_calls_ && !origins_.size(); 40 return !duplicate_calls_ && !origins_.size();
41 } 41 }
42
42 bool CheckSingleOriginInUse(const GURL& origin) const { 43 bool CheckSingleOriginInUse(const GURL& origin) const {
43 return !duplicate_calls_ && origins_.size() == 1 && origins_.count(origin); 44 return !duplicate_calls_ && origins_.size() == 1 && origins_.count(origin);
44 } 45 }
45 46
46 protected: 47 private:
47 virtual ~MockIDBFactory() {} 48 virtual ~RegistryTestMockFactory() {}
48 49
49 private:
50 std::set<GURL> origins_; 50 std::set<GURL> origins_;
51 bool duplicate_calls_; 51 bool duplicate_calls_;
52 52
53 DISALLOW_COPY_AND_ASSIGN(MockIDBFactory); 53 DISALLOW_COPY_AND_ASSIGN(RegistryTestMockFactory);
54 }; 54 };
55 55
56 class MockIDBBackingStore : public IndexedDBFakeBackingStore { 56 class MockIDBBackingStore : public IndexedDBFakeBackingStore {
57 public: 57 public:
58 MockIDBBackingStore(IndexedDBFactory* factory, 58 MockIDBBackingStore(IndexedDBFactory* factory,
59 base::SequencedTaskRunner* task_runner) 59 base::SequencedTaskRunner* task_runner)
60 : IndexedDBFakeBackingStore(factory, task_runner), 60 : IndexedDBFakeBackingStore(factory, task_runner),
61 duplicate_calls_(false) {} 61 duplicate_calls_(false) {}
62 62
63 virtual void ReportBlobUnused(int64 database_id, int64 blob_key) OVERRIDE { 63 virtual void ReportBlobUnused(int64 database_id, int64 blob_key) OVERRIDE {
(...skipping 20 matching lines...) Expand all
84 bool duplicate_calls_; 84 bool duplicate_calls_;
85 85
86 DISALLOW_COPY_AND_ASSIGN(MockIDBBackingStore); 86 DISALLOW_COPY_AND_ASSIGN(MockIDBBackingStore);
87 }; 87 };
88 88
89 // Base class for our test fixtures. 89 // Base class for our test fixtures.
90 class IndexedDBActiveBlobRegistryTest : public testing::Test { 90 class IndexedDBActiveBlobRegistryTest : public testing::Test {
91 public: 91 public:
92 IndexedDBActiveBlobRegistryTest() 92 IndexedDBActiveBlobRegistryTest()
93 : task_runner_(new base::TestSimpleTaskRunner), 93 : task_runner_(new base::TestSimpleTaskRunner),
94 factory_(new MockIDBFactory), 94 factory_(new RegistryTestMockFactory),
95 backing_store_(new MockIDBBackingStore(factory_, task_runner_)), 95 backing_store_(new MockIDBBackingStore(factory_, task_runner_)),
96 registry_(new IndexedDBActiveBlobRegistry(backing_store_.get())) {} 96 registry_(new IndexedDBActiveBlobRegistry(backing_store_.get())) {}
97 97
98 void RunUntilIdle() { task_runner_->RunUntilIdle(); } 98 void RunUntilIdle() { task_runner_->RunUntilIdle(); }
99 MockIDBFactory* factory() const { return factory_.get(); } 99 RegistryTestMockFactory* factory() const { return factory_.get(); }
100 MockIDBBackingStore* backing_store() const { return backing_store_.get(); } 100 MockIDBBackingStore* backing_store() const { return backing_store_.get(); }
101 IndexedDBActiveBlobRegistry* registry() const { return registry_.get(); } 101 IndexedDBActiveBlobRegistry* registry() const { return registry_.get(); }
102 102
103 static const int64 kDatabaseId0 = 7; 103 static const int64 kDatabaseId0 = 7;
104 static const int64 kDatabaseId1 = 12; 104 static const int64 kDatabaseId1 = 12;
105 static const int64 kBlobKey0 = 77; 105 static const int64 kBlobKey0 = 77;
106 static const int64 kBlobKey1 = 14; 106 static const int64 kBlobKey1 = 14;
107 107
108 typedef webkit_blob::ShareableFileReference::FinalReleaseCallback 108 typedef webkit_blob::ShareableFileReference::FinalReleaseCallback
109 ReleaseCallback; 109 ReleaseCallback;
110 110
111 private: 111 private:
112 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 112 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
113 scoped_refptr<MockIDBFactory> factory_; 113 scoped_refptr<RegistryTestMockFactory> factory_;
114 scoped_refptr<MockIDBBackingStore> backing_store_; 114 scoped_refptr<MockIDBBackingStore> backing_store_;
115 scoped_ptr<IndexedDBActiveBlobRegistry> registry_; 115 scoped_ptr<IndexedDBActiveBlobRegistry> registry_;
116 116
117 DISALLOW_COPY_AND_ASSIGN(IndexedDBActiveBlobRegistryTest); 117 DISALLOW_COPY_AND_ASSIGN(IndexedDBActiveBlobRegistryTest);
118 }; 118 };
119 119
120 TEST_F(IndexedDBActiveBlobRegistryTest, DeleteUnused) { 120 TEST_F(IndexedDBActiveBlobRegistryTest, DeleteUnused) {
121 EXPECT_TRUE(factory()->CheckNoOriginsInUse()); 121 EXPECT_TRUE(factory()->CheckNoOriginsInUse());
122 EXPECT_TRUE(backing_store()->CheckUnusedBlobsEmpty()); 122 EXPECT_TRUE(backing_store()->CheckUnusedBlobsEmpty());
123 123
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 RunUntilIdle(); 266 RunUntilIdle();
267 267
268 // Nothing changes. 268 // Nothing changes.
269 EXPECT_TRUE(factory()->CheckSingleOriginInUse(backing_store()->origin_url())); 269 EXPECT_TRUE(factory()->CheckSingleOriginInUse(backing_store()->origin_url()));
270 EXPECT_TRUE(backing_store()->CheckUnusedBlobsEmpty()); 270 EXPECT_TRUE(backing_store()->CheckUnusedBlobsEmpty());
271 } 271 }
272 272
273 } // namespace 273 } // namespace
274 274
275 } // namespace content 275 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/indexed_db/indexed_db_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698