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

Side by Side Diff: content/child/indexed_db/webidbcursor_impl_unittest.cc

Issue 311263014: IndexedDB: Fix trivial cpplint.py errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 6 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 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "content/child/indexed_db/indexed_db_dispatcher.h" 7 #include "content/child/indexed_db/indexed_db_dispatcher.h"
8 #include "content/child/indexed_db/indexed_db_key_builders.h" 8 #include "content/child/indexed_db/indexed_db_key_builders.h"
9 #include "content/child/indexed_db/webidbcursor_impl.h" 9 #include "content/child/indexed_db/webidbcursor_impl.h"
10 #include "content/child/thread_safe_sender.h" 10 #include "content/child/thread_safe_sender.h"
(...skipping 10 matching lines...) Expand all
21 using blink::WebIDBKey; 21 using blink::WebIDBKey;
22 using blink::WebIDBKeyTypeNumber; 22 using blink::WebIDBKeyTypeNumber;
23 using blink::WebVector; 23 using blink::WebVector;
24 24
25 namespace content { 25 namespace content {
26 26
27 namespace { 27 namespace {
28 28
29 class MockDispatcher : public IndexedDBDispatcher { 29 class MockDispatcher : public IndexedDBDispatcher {
30 public: 30 public:
31 MockDispatcher(ThreadSafeSender* thread_safe_sender) 31 explicit MockDispatcher(ThreadSafeSender* thread_safe_sender)
32 : IndexedDBDispatcher(thread_safe_sender), 32 : IndexedDBDispatcher(thread_safe_sender),
33 prefetch_calls_(0), 33 prefetch_calls_(0),
34 last_prefetch_count_(0), 34 last_prefetch_count_(0),
35 reset_calls_(0), 35 reset_calls_(0),
36 last_used_count_(0), 36 last_used_count_(0),
37 advance_calls_(0), 37 advance_calls_(0),
38 continue_calls_(0), 38 continue_calls_(0),
39 destroyed_cursor_id_(0) {} 39 destroyed_cursor_id_(0) {}
40 40
41 virtual void RequestIDBCursorPrefetch(int n, 41 virtual void RequestIDBCursorPrefetch(int n,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 class MockContinueCallbacks : public WebIDBCallbacks { 96 class MockContinueCallbacks : public WebIDBCallbacks {
97 public: 97 public:
98 MockContinueCallbacks(IndexedDBKey* key = 0, 98 MockContinueCallbacks(IndexedDBKey* key = 0,
99 WebVector<WebBlobInfo>* webBlobInfo = 0) 99 WebVector<WebBlobInfo>* webBlobInfo = 0)
100 : key_(key), webBlobInfo_(webBlobInfo) {} 100 : key_(key), webBlobInfo_(webBlobInfo) {}
101 101
102 virtual void onSuccess(const WebIDBKey& key, 102 virtual void onSuccess(const WebIDBKey& key,
103 const WebIDBKey& primaryKey, 103 const WebIDBKey& primaryKey,
104 const WebData& value, 104 const WebData& value,
105 const WebVector<WebBlobInfo>& webBlobInfo) OVERRIDE { 105 const WebVector<WebBlobInfo>& webBlobInfo) OVERRIDE {
106
107 if (key_) 106 if (key_)
108 *key_ = IndexedDBKeyBuilder::Build(key); 107 *key_ = IndexedDBKeyBuilder::Build(key);
109 if (webBlobInfo_) 108 if (webBlobInfo_)
110 *webBlobInfo_ = webBlobInfo; 109 *webBlobInfo_ = webBlobInfo;
111 } 110 }
112 111
113 private: 112 private:
114 IndexedDBKey* key_; 113 IndexedDBKey* key_;
115 WebVector<WebBlobInfo>* webBlobInfo_; 114 WebVector<WebBlobInfo>* webBlobInfo_;
116 }; 115 };
(...skipping 16 matching lines...) Expand all
133 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 132 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
134 scoped_ptr<MockDispatcher> dispatcher_; 133 scoped_ptr<MockDispatcher> dispatcher_;
135 134
136 private: 135 private:
137 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; 136 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_;
138 137
139 DISALLOW_COPY_AND_ASSIGN(WebIDBCursorImplTest); 138 DISALLOW_COPY_AND_ASSIGN(WebIDBCursorImplTest);
140 }; 139 };
141 140
142 TEST_F(WebIDBCursorImplTest, PrefetchTest) { 141 TEST_F(WebIDBCursorImplTest, PrefetchTest) {
143
144 const int64 transaction_id = 1; 142 const int64 transaction_id = 1;
145 { 143 {
146 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId, 144 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId,
147 transaction_id, 145 transaction_id,
148 thread_safe_sender_.get()); 146 thread_safe_sender_.get());
149 147
150 // Call continue() until prefetching should kick in. 148 // Call continue() until prefetching should kick in.
151 int continue_calls = 0; 149 int continue_calls = 0;
152 EXPECT_EQ(dispatcher_->continue_calls(), 0); 150 EXPECT_EQ(dispatcher_->continue_calls(), 0);
153 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { 151 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) {
154 cursor.continueFunction(null_key_, new MockContinueCallbacks()); 152 cursor.continueFunction(null_key_, new MockContinueCallbacks());
155 EXPECT_EQ(++continue_calls, dispatcher_->continue_calls()); 153 EXPECT_EQ(++continue_calls, dispatcher_->continue_calls());
156 EXPECT_EQ(0, dispatcher_->prefetch_calls()); 154 EXPECT_EQ(0, dispatcher_->prefetch_calls());
157 } 155 }
158 156
159 // Do enough repetitions to verify that the count grows each time, 157 // Do enough repetitions to verify that the count grows each time,
160 // but not so many that the maximum limit is hit. 158 // but not so many that the maximum limit is hit.
161 const int kPrefetchRepetitions = 5; 159 const int kPrefetchRepetitions = 5;
162 160
163 int expected_key = 0; 161 int expected_key = 0;
164 int last_prefetch_count = 0; 162 int last_prefetch_count = 0;
165 for (int repetitions = 0; repetitions < kPrefetchRepetitions; 163 for (int repetitions = 0; repetitions < kPrefetchRepetitions;
166 ++repetitions) { 164 ++repetitions) {
167
168 // Initiate the prefetch 165 // Initiate the prefetch
169 cursor.continueFunction(null_key_, new MockContinueCallbacks()); 166 cursor.continueFunction(null_key_, new MockContinueCallbacks());
170 EXPECT_EQ(continue_calls, dispatcher_->continue_calls()); 167 EXPECT_EQ(continue_calls, dispatcher_->continue_calls());
171 EXPECT_EQ(repetitions + 1, dispatcher_->prefetch_calls()); 168 EXPECT_EQ(repetitions + 1, dispatcher_->prefetch_calls());
172 169
173 // Verify that the requested count has increased since last time. 170 // Verify that the requested count has increased since last time.
174 int prefetch_count = dispatcher_->last_prefetch_count(); 171 int prefetch_count = dispatcher_->last_prefetch_count();
175 EXPECT_GT(prefetch_count, last_prefetch_count); 172 EXPECT_GT(prefetch_count, last_prefetch_count);
176 last_prefetch_count = prefetch_count; 173 last_prefetch_count = prefetch_count;
177 174
(...skipping 27 matching lines...) Expand all
205 EXPECT_EQ(expected_key++, key.number()); 202 EXPECT_EQ(expected_key++, key.number());
206 } 203 }
207 } 204 }
208 } 205 }
209 206
210 EXPECT_EQ(dispatcher_->destroyed_cursor_id(), 207 EXPECT_EQ(dispatcher_->destroyed_cursor_id(),
211 WebIDBCursorImpl::kInvalidCursorId); 208 WebIDBCursorImpl::kInvalidCursorId);
212 } 209 }
213 210
214 TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) { 211 TEST_F(WebIDBCursorImplTest, AdvancePrefetchTest) {
215
216 const int64 transaction_id = 1; 212 const int64 transaction_id = 1;
217 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId, 213 WebIDBCursorImpl cursor(WebIDBCursorImpl::kInvalidCursorId,
218 transaction_id, 214 transaction_id,
219 thread_safe_sender_.get()); 215 thread_safe_sender_.get());
220 216
221 // Call continue() until prefetching should kick in. 217 // Call continue() until prefetching should kick in.
222 EXPECT_EQ(0, dispatcher_->continue_calls()); 218 EXPECT_EQ(0, dispatcher_->continue_calls());
223 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) { 219 for (int i = 0; i < WebIDBCursorImpl::kPrefetchContinueThreshold; ++i) {
224 cursor.continueFunction(null_key_, new MockContinueCallbacks()); 220 cursor.continueFunction(null_key_, new MockContinueCallbacks());
225 } 221 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // The real dispatcher would call cursor->CachedContinue(), so do that: 320 // The real dispatcher would call cursor->CachedContinue(), so do that:
325 scoped_ptr<WebIDBCallbacks> callbacks(new MockContinueCallbacks()); 321 scoped_ptr<WebIDBCallbacks> callbacks(new MockContinueCallbacks());
326 cursor.CachedContinue(callbacks.get()); 322 cursor.CachedContinue(callbacks.get());
327 323
328 // Now the cursor should have reset the rest of the cache. 324 // Now the cursor should have reset the rest of the cache.
329 EXPECT_EQ(1, dispatcher_->reset_calls()); 325 EXPECT_EQ(1, dispatcher_->reset_calls());
330 EXPECT_EQ(1, dispatcher_->last_used_count()); 326 EXPECT_EQ(1, dispatcher_->last_used_count());
331 } 327 }
332 328
333 } // namespace content 329 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/webidbcursor_impl.h ('k') | content/child/indexed_db/webidbdatabase_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698